Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designed and presented by Emile Belanger

Similar presentations


Presentation on theme: "Designed and presented by Emile Belanger"— Presentation transcript:

1 Designed and presented by Emile Belanger
A short presentation on uClinux, its applications and my experience with it. Designed and presented by Emile Belanger

2 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(?) We will start with a brief overview of what uClinux acutaly is Ill show you a few commerical products powered by it Next will be some of the key difference between linux and uClinux, this will help engineers who are already familiar with linux Lastly Ill show you a small project I made which runs it

3 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 is a cut version of the standard Linux kernel. It was designed to run on embedded devices with limited memory and processing power. Even though it is cut down it still supports many of the feature of a full distribution like network, different file systems and GUIs

4 Commercial applications
Established, powerful multitasking operating system. Royalty Free! Large software base PDAs There are already lots of commercial products running it, like routers , PDAs, Voice over IP phones. Data terminals Routers Security VoIP

5 uClinux Requirement 32 bit Microcontroller or Microprocessor
512KB RAM min. (2MB+ recommended) 515KB ROM min. Hardware Timer + Interrupt Fully functional C/C++ complier These are the main hardware requirements needed for it to run. 32bit CPU, although iv seen it implemented on 16 and maybe even 8bit processors somewhere on the internet. To run the kernel and anything useful you need at least 0.5 meg of ram. Although anything you design is likely to have a lot more than that. You need some ROM, probably flash to sort the kernal and application. The CPU must have supprt for a timer with interupt. And finaly you must have a compliant complier for you CPU

6 uClinux vs. Linux The main differences revolve around the lack of MMU
Most of the difference between microcontroller Linux and standard is that its been designed to work without an Memory management unit. The MMU sits between the CPU core and external memory in all desktop PCs

7 uClinux vs. Linux The Memory Management Unit allows the use of Virtual Memory (VM) Translates Virtual Address space into physical address space It’s important to understand what an MMU does in order to understand how the lack of it affects the engineer. These are three important features which it performs. Firstly it translates virtual address into the physical address to be written from or read too. The running process in the CPU only sees the virtual address which appears as a contiguous block of memory, when in fact its physicaly scattered throughout the systems RAM.

8 uClinux vs. Linux Enables page swapping
The next 2 features are a direct result of this virtual to physical mapping Because the process memory can change its physical address page swapping to be performed. This allows chunks of memory belonging to a running process can be moved arbitrarily to say the hard drive. This increases the total amount of perceived RAM in the system

9 uClinux vs. Linux Memory Protection
The MMU can also detect if a process is try to access memory outside of it allowed scope, thereby implememting memory protection. This can stop rouge programs overwriting random bits of code.

10 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 No page swapping: The lack of VM prevents page swapping to say a hard drive or slower RAM. No hardware memory protection: The programmer must be very careful when writing to memory, especially arrays as its possible to write to any part of memory, even the kernel code! Flat format: The standard ELF (executable and linkable format) must be converted Page_alloc2: use as alternate allocator in uClinux. Uses memory more efficiently (small allocations at bottom, large at top- minimised fragmentation) Non dynamic stack: on standard Linux the stack grows dynamically when more is needed. uClinux requires the programmer to set the stack at compile time For application programmers, fork is replaced with vfork XIP: execute in place I will explain in a bit more detail the bottom 3 points

11 uClinux vs. Linux Memory fragmentation
Even though there is 32KB reported free memory, the maximum process size which can run is 12KB The lack of MMU means memory can quickly become fragmented easily. This is a problem because for an application to load an run, it must have a contiguous are of memory to be loaded into. In this example the system will report 32kB free memory, but you wont be able to load an application more than 12kB in size.

12 uClinux vs. Linux fork()
Parent (1)When fork() is called, a child process is created, and continues to run from fork() fork()(!=0) Stack/heap(0) The fork routine is used to make a child thread which is identical to the parent. As mentioned before, vfork has to be used instead of fork. First ill show you how fork performs The diagram is supposed to show a running process which calls fork()

13 uClinux vs. Linux fork()
Parent Child (2)When the child is created, it first shares the parents memory. The shared variables tag is incremented by 1 fork()(!=0) fork() (==0) Stack/heap(1) The MMU allows an optimisation called Copy-on-write to be used with fork This means when then new child process is created, all the memory from the parent to not copied to a new location in RAM. Instead the child process will read from the same memory locations as the parent. The variables are also tagged to indicate more than one process is using the variable This is all ok until either the parent or child wishes to write to any variables

14 uClinux vs. Linux fork()
Parent Child (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. fork()(!=0) fork() (==0) Stack/heap(0) Stack/heap(0) When this happens, that particular variable is copied to a new location in memory so it can be changed without effecting the other running process. The parent and child run at the same time If the tag = 0, then the variable is not shared

15 uClinux vs. Linux vfork()
Parent (1)When vfork() is called, a child process is created, and continues to run from vfork(). However, the parent process if BLOCKED vfork()(!=0) Stack/heap(0) Now with vfork the behaviour is different. Before the child and parent would run at the same time on different threads, this time when vfork is called the parent is blocked With vfork when a child process is called, the parent process is blocked

16 uClinux vs. Linux vfork()
Parent Child (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. vfork()(!=0) vfork() (==0) _exit() Stack/heap(1) The parent is blocked utill exit() is called in the child, upon which the parent can continue to execute The next major difference is that the child will always share the parents variables, so if the child changes a global variable, it will also change in the parent. This is one of the biggest problems when porting linux application to run on uClinux.

17 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; One method of overcoming the problem of sharing variables is to create a new variable and assign the old value when ever the child wishes to modify it. Ref:

18 uClinux vs. Linux XIP (Execute In Place) RAM ROM Process 1 Process 2
Code Code Code Code Stack/heap Stack/heap Stack/heap One of the best features of uCLinux is the use of execute in place. This enables multiply instances of an application to run directly from ROM, instead of first being copied to ram. The top half shows the memory usage without XIP being used when 3 processes are running. The bottom half is when XIP is being used. As you can see there is only one copy of the code with XIP, and 4 without There are a few limitations using this: Firstly the compiler must support it, also only the romfs file system supports it as the application must b sorted contiguously in memory for it to work. Code Stack/heap Stack/heap Stack/heap

19 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! This is a list of some of the CPUs what are supported and have been made public

20 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 In order to support a CPU which hasn’t been done before you have to edit files in the Linux/arch and Linux/platform directories. usually you can modify the existing files from one of the processors on the previous page

21 My experience getting uClinux running on a custom board.
uClinux on Microblaze My experience getting uClinux running on a custom board. Ok, this is the second bit of the tlak, and im going to share some of my experiences getting uCLinux to run Earlier on this during the summer I decided to make a portable board capable of running it.

22 uClinux on Microblaze This is a block digarame of the board I made
The reason I chose an FPGA was so I could use the board for other projects. The FPAG was a Spartan 3 form Xilinx, which supports the Microblaze soft processor also from Xilinx.

23 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 This is a little bit of info on the Microblaze cpu The choice of and FPGA with soft processor means I can easily add extra features directly attached to the processor. Such as

24 uClinux on Microblaze Possible user implemented features:
Graphical controller (LCD) Custom IO standards Hardware acceleration Add an LCD controller to support GUI Custom IO, such as keypads, data acquisition Hardware acceleration like video DCT/IDTC, SSH (Secure Sockets Layer)

25 uClinux on Microblaze Uaing Eagle I designed and entered the schematic. Sorry its not very neat!

26 uClinux on Microblaze Primary components XC3S400 Xilinx FPGA
2Mb Xilinx PROM 256Mb SDRAM 1.2V and 2.5V DC/DC converter 40MHZ xtal

27 uClinux on Microblaze Then the design was routed. I tehn sent the board file to be manufactured. This cost about £65 for 4 identical boards.

28 uClinux on Microblaze Top

29 uClinux on Microblaze Underside

30 uClinux on Microblaze

31 uClinux on Microblaze

32 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! The Xilinx software allows you to generate the Microblaze soft processor and peripherals quite easily Download from The xilinx software generates a file which has all the design specific memory locations (memory start + size, rs232 registers, timer registers ect) Build the kernels + applications on a Linux machine Upload the image file into the onboard SDRAM Reset the fpga board and use the rs232 as a terminal!

33 uClinux on Microblaze Linux version uc0 (gcc version 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 BogoMIPS Memory: 32MB = 32MB total Memory: 30916KB available (562K code, 927K data, 32K init) Dentry cache hash table entries: 4096 (order: 3, bytes) Inode cache hash table entries: 2048 (order: 2, 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, 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 0x (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 #

34 Thank you for listening. Are there any Question?


Download ppt "Designed and presented by Emile Belanger"

Similar presentations


Ads by Google