uClinux - Virgin Media

Download Report

Transcript uClinux - Virgin Media

A short presentation on uClinux, its applications and my experience with it.
Designed and presented by Emile Belanger
uClinux, 28th November 2005, Emile Belanger
Overview
• What is uClinux
• Commercial application for uClinux
• The key differences between uClinux and
Linux
• What the engineer should know
• Porting uClinux to a μC/Processor.
• My experience using uClinux
• A short demonstration(?)
uClinux, 28th November 2005, Emile Belanger
What is uClinux?
• Pronounced ‘You-See-Linux’
• A derivative of the 2.0/4/6 Linux kernel
• Designed to work with microcontrollers or
CPUs without an MMU, with limited storage
and RAM
• Full networking support
• Support for many file systems.
• Graphical windowing
uClinux, 28th November 2005, Emile Belanger
Commercial applications
• Established, powerful multitasking operating
system.
• Royalty Free!
• Large software base
PDAs
Data terminals
Routers
Security
VoIP
uClinux, 28th November 2005, Emile Belanger
uClinux Requirement
•
•
•
•
•
32 bit Microcontroller or Microprocessor
512KB RAM min. (2MB+ recommended)
515KB ROM min.
Hardware Timer + Interrupt
Fully functional C/C++ complier
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
• The main differences revolve around the
lack of MMU
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
• The Memory Management Unit allows the use of
Virtual Memory (VM)
– Translates Virtual Address space into physical address
space
Application virtual memory allocation:
0x0000
0x4000
Code
Stack
Heap
MMU
Physical memory allocation:
0x0000
1 Page
0xFFFF
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– Enables page swapping
Application virtual memory allocation:
0x0000
0x4000
Code
Stack
Application virtual memory allocation:
0x0000
Heap
0x4000
Code
Stack
Heap
MMU
Physical memory allocation:
0xFFFF
0x0000
Hard drive or slow RAM:
20%
10%
10%
30% 10%
20%
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– Memory Protection
.
.
.
adiw
ld
mov
sts
andi
cpi
.
.
.
YL,11
r17,Y
r18,r17
YL,r17
r18,0b00001111
r18,0b00001111
MMU
Protection fault!
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
• What this means to the software engineer.
– No page swapping
– No hardware memory protection
– Only the Binary Flat Format (BFLT) executable
type is supported
– Use page_alloc2 as a kernel memory allocator
– Non dynamic stack
– Memory can not be ‘defragmented’
– fork() replaced with vfork()
– XIP
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– Memory fragmentation
X
X
X
X
X
=4KB (used)
X
X
X
X
X
X
X
X
=4KB (free)
Even though there is 32KB reported free
memory, the maximum process size which can
run is 12KB
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– fork()
Parent
fork()(!=0)
Stack/heap(0)
(1)When fork() is
called, a child
process is created,
and continues to run
from fork()
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– fork()
Parent
fork()(!=0)
Stack/heap(1)
Child
fork() (==0)
(2)When the child is
created, it first shares
the parents memory.
The shared variables
tag is incremented by 1
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– fork()
Parent
Child
fork()(!=0)
fork() (==0)
Stack/heap(0)
Stack/heap(0)
(3)If the child tries to write
to any global variables,
the C.O.W is executed
and a new copy of the
variable is created.
The tag is decremented.
If the tag = 0, then the variable is not
shared
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– vfork()
Parent
vfork()(!=0)
Stack/heap(0)
(1)When vfork() is
called, a child
process is created,
and continues to run
from vfork().
However, the parent
process if BLOCKED
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– vfork()
Parent
vfork()(!=0)
Child
vfork() (==0)
_exit()
Stack/heap(1)
(2)When the child is
created, it ALWAYS
shares the memory of
the parent.
Changes made by the
child will also be made
in the parent.
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
• How to overcome the shared memory
vfork() limitation.
int main(void)
{
pid_t pid;
int value = 10;
if ((pid = vfork()) == 0) {
int new_value = value;
new_value-=5;
printf("The child process thinks value=%d\n", new_value);
exit(EXIT_SUCCESS);
}
printf("The parent process thinks value=%d\n", value);
printf("Goodbye.\n");
return EXIT_SUCCESS;
}
Ref: http://www.uclinux.org/pub/uClinux/archive/0772.html
uClinux, 28th November 2005, Emile Belanger
uClinux vs. Linux
– XIP (Execute In Place)
Process 1
RAM
Process 2
Process 3
Code
Code
Code
Stack/heap
Stack/heap
Stack/heap
Stack/heap
Stack/heap
Stack/heap
ROM
Code
Code
uClinux, 28th November 2005, Emile Belanger
Porting uClinux to a μC/Processor
• Supported architectures
– Motorola DragonBall,
– Motorola ColdFire
– ADI Blackfin
– Motorola QUICC
– ETRAX
– ARM7TDMI
– MC68EN302
– Microblaze
– + Others being added all the time!
uClinux, 28th November 2005, Emile Belanger
Porting uClinux to a μC/Processor
• If your Processor and Board are not already
supported:
– /linux/arch
• Edit around two dozen files relating to instructions
specific to the CPU core
– /linux/platform
•
•
•
•
•
Interrupt vectors
Hardware registers
Timer initialisation
Amount of memory
External Peripherals
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
My experience getting uClinux running on a
custom board.
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
8 LEDs
28 I/O
4 DIP switch
64MB
SDRAM
Spartan 3
40MHZ
64KB
EEPROM
64KB
EEPROM
2Mb
PROM
2.5V DC/DC
1.2V DC/DC
JTAG
Connector
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
• The Microblaze soft processor:
– 32 bit Harvard RISC architecture
– 3-stage pipeline with 32 general-purpose
registers
– FPU
– Hardware divide and multiply
– Instruction and Data Caches
– Many configurable peripherals
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
• Possible user implemented features:
– Graphical controller (LCD)
– Custom IO standards
– Hardware acceleration
FPGA
DCT/IDCT
Microblaze
SSL
IO
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
• Primary components
– XC3S400 Xilinx FPGA
– 2Mb Xilinx PROM
– 256Mb SDRAM
– 1.2V and 2.5V DC/DC converter
– 40MHZ xtal
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
Top
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
Underside
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
• Outline of steps require to get uClinux
functional
– Implement Microblaze, SDRAM controller,
UART, Timer + interrupt in FPGA.
– Download latest uClinux tree via CVS
– Copy autoconfig file generated by Xilinx
software to uClinux tree
– Run ‘make config’, ‘make dep’, ‘make all’
– Upload binary image file into SDRAM via Jtag
debug cable
– Reset Microblaze to run!
uClinux, 28th November 2005, Emile Belanger
uClinux on Microblaze
Linux version 2.4.31-uc0 (root@fedora3) (gcc version 2.95.3-4 Xilinx EDK 6.3 Build EDK_Gmm.12.2) #24 Sun Oct 2 12:58:50 BST 2005
On node 0 totalpages: 8192
zone(0): 8192 pages.
zone(1): 0 pages.
zone(2): 0 pages.
CPU: MICROBLAZE
Kernel command line: °
Console: xmbserial on UARTLite
Calibrating delay loop... 1.32 BogoMIPS
Memory: 32MB = 32MB total
Memory: 30916KB available (562K code, 927K data, 32K init)
Dentry cache hash table entries: 4096 (order: 3, 32768 bytes)
Inode cache hash table entries: 2048 (order: 2, 16384 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 8192 (order: 3, 32768 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Microblaze UARTlite serial driver version 1.00
ttyS0 at 0x40600000 (irq = 1) is a Microblaze UARTlite
Starting kswapd
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
uclinux[mtd]: RAM probe address=0x220bd93c size=0xb7000
uclinux[mtd]: root filesystem index=0
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 32K
Mounting proc:
Mounting var:
Populating /var:
Running local start scripts.
Remounting / (rw):
Mounting /etc/config:
Populating /etc/config:
flatfsd: Nonexistent or bad flatfs (-43), creating new one...
flatfsd: Failed to write flatfs (-43): No such device
flatfsd: Created 3 configuration files (346 bytes)
Setting hostname: uclinux-auto login:root
Password:
# ls
bin dev etc home lib mnt proc sbin tmp usr var
#
uClinux, 28th November 2005, Emile Belanger
Thank you for listening.
Are there any Question?
www.uclinux.org
www.ucdot.org
http://www.arcturusnetworks.com/uclinux.shtml
http://www-128.ibm.com/developerworks/linux/library/l-embl.html
http://www.linuxjournal.com/article/7221
http://linuxdevices.com/articles/AT9541681360.html
http://www.uclinux.org/pub/uClinux/archive/0772.html
uClinux, 28th November 2005, Emile Belanger