3 Haziran 2013 Pazartesi

Embedded Linux Practical Hints


  • Every embedded linux system requires a MMU (Memory management unit) in order to work. MMU is responsible for handling accesses to memory requested by the CPU.
  • Every system is mainly composed of 4 methods: open, read, write and close.
  • Nowadays linux kernel 2.6.32 and 2.6.35 are robost versions for embedded development.
  • We always need Toolchains for embedded linux development. We should create or copy the toolchains under /opt directory.
  • While dealing with arm boards, one can face with eabi, oabi etc. These are related with D and I busses. eabi stands for 32-bit-fast, and oabi stands for 8-bit slow. One can also face with hard-float and soft-float issues which are confusing. soft-float means implemented on fpga as a software, and hard-float means implemented as hardware.
  • arm-linux-gnueabi-gcc can be the cross-compiler of your life.
  • In order to simulate or emulate embedded linux system, you can use qemu.
    • sudo apt-get install qemu qemu-kvm qemu-kvm-extras
    • For instance, in order to cross-compile a mips architecture you can use qemu-system-mips compiler.
    • In order to run a cross-compiled program in arm architecture just use qemu-arm
  • You always get tar.bz2 or tar.gz while download toolchains or kernel etc.
            tar.bz2->                         tar -jxvf  ....... -C /your directory
            tar.gz->                           tar -zxvf ....... -C /your directory
  • Kernel source code has architecture under the /arch directory. There are template configuartion files for these architectures.
  • For cross-compilation of Kernel source: (an example of arm versatile)
    • $ make ARCH=arm versatile_defconfig
    • $ make ARCH=arm menuconfig
    • Enable EABI from Kernel features
    • $ make ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi-
    • the cross-compiler appends gcc at the end of arm-angstrom-linux-gnueabi- at the compile time.
    • After the compilation, the output files will be located in /arch/arm/boot/
    • To test zImage (kernel image) via qemu:
      • qemu-system-arm -M versatilepb -m 128M -kernel zImage
      • After run the command above, you will get a rootfs problem, since we do not have it yet.
  • In order to create rootfs or let's say userspace, we can use busybox or System.
  • However buildroot is a really useful tool to build user space. Let's use it:
    • cd buildroot
    • make menuconfig
    • Choose Target Architecture (arm) and Target Architecture Variant (arm926t)
    • Choose Target ABI (EABI)
    • Choose Target Filesystem options ->cpio->compression method (gzip)
    • After the configuartion, save and exit.
    • make V=1
    • the command above will start to build your userspace. V can be between 1 and 10. 1 means low compression, 10 means high compression.
    • After the operation completes, the output is rootfs.cpio.gz.
    • Now we can test our system with qemu:
      • qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.cpio.gz
  • A linux system is mainly composed of:
    • primary bootloader ( cpu )
      • intermediate stage MLO (Mloader which is specific to board producers.)
    • secondary bootloader (FAT file system)
    • Kernel
    • User Space
      • /User Space/boot/Kernel. User Space shall include kernel image too. Because after boot up and the rootfs is mounted, the kernel operations should be done in user space not in fat partition. So, after boot up,  a swap operation is done and the kernel in the user space which is the same as in the FAT file system becomes active.
  • To boot a simple linux system up from SD Card:
    • First of all, divide your SD card into two partitions: boot (FAT) and Angstrom(ext3). You should use a script. Angstrom is just an example, change it according to your system.
    • To FAT partition, copy MLO (MLoader), u-boot.bin and uImage under the boot partition sequentially. The copy order is very important. Because in FAT file system, the files are written with starting adress 0.
    • To ext3 partition, copy uImage under /boot/ with the name uImage.
    • Our SD card is ready now to boot up.
  • To access hardware in a linux system, just check /sys/class/. 
    • cd gpio
    • ls -l
      • export unexport
    • Let's say our gpio is 139.
    • echo 139 > export
    • gpio139 folder is formed.
    • cd gpio139
    • cat direction
      • in
    • echo out > direction
    • echo 1 > value
    • We have set gpio to output and the value to 5.
  • In order to start our target linux system with a program:
    • Write your script that is running your program.
    • copy your script under /etc/init.d/
    • Make sybolic links under /etc/rc*.d (rc0.d, rc1.d, rc2.d...rc5.d) In rc5.d root screen appears.
    • rc0.d and rc1.d are mostly responsible for hardware initalizations, you can start your applications after these two operations.K stands for Kill, S stands for Start.
    • To automatize above operations, write your script, boot up your target system, copy script under /etc/init.d and write command: update -rc.d blabla.sh defaults