Published on

Embedded Linux System

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Building Embedded Linux System on Samsung 2410 Platform 1
  2. 2. Agenda Basic Concepts Kernel Considerations Root Filesystem Content Device Driver Application and GUI 2
  3. 3. Basic Concepts 3
  4. 4. Cross-Development Environment Target has limited resource (memory, storage, low speed processor) . Host and Target are different architecture Target Host •Bootloader Cross-platform •Kernel Development •Root Filesystem Environment 4
  5. 5. Hardware Connection 5
  6. 6. ARM Cross-Development Toolkit ASM Source C Source C Libraries C Compiler Assembler .aof Object Linker Libraries .aif debug System model ARMsd Development ARMulator board 6
  7. 7. Development Environment GUN development toolchains A compiler that runs on one computer but produces object code for a different type of computer. Cross compilers are used to generate software that can run on computers with a new architecture or on special-purpose devices that cannot host their own compilers. Cross-compiler for ARM gcc : arm-linux-gcc g++ : arm-linux-g++ ar : arm-linux-ar strip : arm-linux-strip 7
  8. 8. Create Target Linux System A target Linux system is created by configuring and bundling together the appropriate system components. Programming and development aspects are a separate subject There are four main steps to creating a target Linux system: Determine system components Configure and build the kernel Build root filesystem Set up boot software and configuration 8
  9. 9. System Boot Flow Bootloader Extract and decompress the Kernel Image and RAMDISK Launch kernel Kernel Initialize Memory and Hardware Mount Root Filesystem (RAMDISK) Run /sbin/init User Programs 9
  10. 10. All the things we need Cross-Platform development toolchain Bootloader Provide by vendor Linux kernel Linux kernel + some patches if needed Filesystem Busybox Device node Configuration 10
  11. 11. Build the GNU Cross-Platform Development Toolchain We can download the cross-platform (toolchains) from The toolchain do not need recompile, just decompress it and set the system path. GNU Toolchain’s Component Binutils including AS, LD and other binary file tools GCC the well known C,C++ complier supported variable platform GLIBC the C runtime library GDB the command line source debugger, including remote 11 debugging
  12. 12. Bootloader 12
  13. 13. ARM Linux Kernel ARM Linux is a port of the successful Linux Operating System to ARM processor based machines mainly by Russell King with contributions from others. The patch change log can be found at 2.4.0.shtml The Linux Kernel and most of the programs that make up the Linux system are quot;open sourcequot;, using the GNU tools provided by the Free Software Foundation. ARM Linux is being ported, or has been ported to more than 100 different machine variations, including complete computers, network computers 13 and evaluation boards. There are also projects for
  14. 14. Filesystem - initrd initrd provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root file system and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root (from initrd) is then moved to a directory and can be subsequently unmounted. initrd is mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and 14 where additional modules are loaded from initrd.
  15. 15. Filesystem - BusyBox Combine tiny versions of many common UNIX into a single small executable. Provide a fairly complete environment for any small or embedded system. BusyBox has been written with size- optimization and limited resources in mind. It is also extremely modular so you can easily include or exclude commands (or features) at compile time. This makes it easy to customize your embedded systems 15
  16. 16. Kernel Considerations 16
  17. 17. Make Linux Kernel Download Linux kernelOptions: from Additional source CROSS_COMPILE=arm-linux- ARCH=arm make clean make menuconfig Building Kernel CROSS_COMPILE=arm-linux dep make ARCH=arm make clean make ARCH=arm CROSS_COMPILE=arm-linux zImage make menuconfig make ARCH=arm CROSS_COMPILE=arm-linux modules make ARCH=arm CROSS_COMPILE=arm-linux make dep (this step is no needed in version 2.6) modules_install make bzImage make ARCH=arm CROSS_COMPILE=arm-linux install make modules make modules_install make install 17
  18. 18. Make Linux Kernel After make bzImage, the kernel image will be at ./path/to/linux_src/arch/i386/boot/bzImage The quot;bzImagequot; name stands for quot;big zImage,quot; and has nothing to do with the bzip2 compression utility. In fact, both the bzImage and zImage Makefile targets rely on the gzip algorithm. The difference between the two Makefile targets is that the compressed kernel images generated using zImage cannot be larger than 512 KB, while those generated using bzImage are not bound by this limit.18
  19. 19. Root Filesystem Content 19
  20. 20. Building Root Filesystem Download the BusyBox source code from Building BusyBox make clean make all make install After make complete, the busybox will be at ./path/to/busybox_src/_install/ 20
  21. 21. Building Root Filesystem The BusyBox has all needed utilities, such as, ls, kill, chroot, mount, …,etc. Building the Root Filesystem Create a directory ~/root-fs Copy all files in busybox/_install to ~/root-fs/ Create some standard directory, such as, /dev, /etc /proc /mnt /tmp /var Make some device node Write some boot shell scripts Make directory ~/root-fs to a initrd image 21
  22. 22. Create Device Nodes cd ~/root-fs/dev/ mknod tty c 5 0 mknod console c 5 1 mknod tty0 c 4 0 mknod ttyS0 c 4 64 mknod ttyS0 c 4 64 mknod ram0 b 1 0 mknod null c 1 3 22
  23. 23. Write Shell Script /etc/inittab ::sysinit:/etc/rc.S ::askfirst:/bin/sh /etc/rc.S #!/bin/sh mount -t proc proc /proc 23
  24. 24. Make INITRD image dd if=/dev/zero of=/home/initrd.img bs=1k count=8192 su root mke2fs -F -v -m0 /home/initrd.img mkdir tmp mount -o loop initrd.img tmp/ cp ~/root-fs/* /home/tmp/ -dpRrf umount tmp/ gzip -9 < initrd.img > initrd.bin file 8MB mount is null Write DATA ~/root-fs file 8MB unmount with data 24
  25. 25. Customize Application and Configuration In order to meet the system requirement, we must write some applications base on some drivers. Maybe we’ll setting up the Ethernet or Wireless network or build up some Internet Protocol. Customize the GUI or MMI 25
  26. 26. Device Driver 26
  27. 27. Major and Minor Numbers Special files under /dev “c” for char & “b” for block Major number identifies driver use at open time Minor number is used only by driver to control several devices crw-rw-rw- 1 root root 1, 3 Feb 23 1999 null crw------- 1 root root 10, 1 Feb 23 1999 psaux crw------- 1 rubini tty 4, 1 Aug 16 22:22 tty1 crw-rw-rw- 1 root dialout 4, 64 Jun 30 11:19 ttyS0 crw-rw-rw- 1 root dialout 4, 65 Aug 16 00:00 ttyS1 crw------- 1 root sys 7, 1 Feb 23 1999 vcs1 crw------- 1 root sys 7, 129 Feb 23 1999 vcsa1 crw-rw-rw- 1 root root 1, 5 Feb 23 1999 zero 27
  28. 28. Major Number Adding a new driver at module initialization int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); fops point to a global structure which kernel finds To create device node : mknod /dev/scull0 c 254 0 If major is 0, the register_chrdev return a free number For dynamic allocation, script to extract /proc/devices device number, then invoke mknod to create device file int unregister_chrdev(unsigned int major, const char *name); 28
  29. 29. Register a Character Device Driver Kernel Major 0 … Major 98 Major 99 … Major 255 Driver 2 2 (1)Insmod module, Driver Major 99 register a Major number to 1 Kernel Driver 1 (2)Kernel know the Major num, Major 98 Kernel will link the major num to The Driver Module 29
  30. 30. Major and Minor Kernel Major 0 … Major 98 Major 99 … Major 255 2 Driver 2 Device A 3 Major 99 Major 98 Minor 1 (1) Open、Read、 Write Driver 1 (2) Pass Major&Minor 1 Major 98 to Kernel (3) Kernel Passes Minor User Program to Driver 30
  31. 31. Application and Graphic User Interface 31
  32. 32. Console Application Write C/C++ programs and compile it as static link or dynamic link executable files. Static Copy the executable file to Root Filesystem Execute it. Dynamic Copy the executable file and needed libraries to Root Filesystem Set the library path by using “export LD_LIBRARY” Execute it 32
  33. 33. Graphic User Interface Window System X Window (TinyX) QPE (Qt Plamtop Environment) / Qtopia GPE (GPE Palmtop Environment) Microwindows MiniGUI 33
  34. 34. Programming with QT 34
  35. 35. Building the QT/Embedded Environment Step1: # tar zxvf qt-embedded-3.3.1.tar.gz Step2: # export QTDIR=home/qt-embedded-3.3.1 # export LD_LIBRARY_PATH=home/qt-embedded- 3.3.1/lib:$LD_LIBRARY_PATH # cp /usr/bin/uic /qt-embedded-3.3.1/bin # cd qt-embedded-3.3.1 # ./configure -embedded arm -shared –debug # gmake 35
  36. 36. Building the QT/Embedded Environment 36
  37. 37. Programming QT Applications / **Import** check your environment variables QTDIR=/qt-embedded-3.3.1 LD_LIBRARY_PATH=/qt-embedded-3.3.1/lib:LD_LIBRARY_PATH */ [command#]cd ~/test /* go to your project directory */ [command#test]qmake –o Makefile [command#test]make 1. [root@locahost ]# mkdir busybox/qt-embedded-3.3.1/lib/fonts 2. [root@locahost ]# cp /qt-embedded/lib/fonts/* /home/busybox/qt-embedded-3.3.1/lib/fonts/ 37