Sunday, April 27, 2014

Busybox run on Qemu

Preparation
  1. Install developer ncurses library. It will be used during linux kernel configuration.
  2. Install latest Qemu from Linaro repository. You can refer to my previous posting, Install Qemu on Ubuntu.
  3. Download arm cross compiler from CodeSourcery. Make sure you already become member of mentor.com website. Currently latest version of compiler is 2012.09-64. But I already tried that version and when always be fail. I also tried previous version, it is 2012.03-57, and the result is same. And I have been successfully compile linux kernel and install busybox using version 2011.09-70.
  4. Download latest linux source code from kernel.org. Currently I am using linux version 3.9. File name should be linux-3.9.tar.xz.
  5. Download latest busybox from busybox.net. Currently, latest version of busybox is busybox-1.21.0.
Install Developer ncurses Library
$ sudo apt-get install libncurses5-dev
Files and Folders Arrangement
  1. Create folder for our project.
    # cd
    # mkdir Project
    # cd Project
  2. Create folder for our source code that we already downloaded previously.
    # mkdir Sources
    # cd Sources
  3. Copy all files (encrypted files) to Sources folder. Make sure we already collected these files,
    linux-3.9.tar.xz, busybox-1.21.0.tar.bz2.tar.bz2, and arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2.tar.bz2.
  4. Extract all those files.
    # tar -xJvf linux-3.9.tar.xz
    # tar -xjvf busybox-1.21.0.tar.bz2.tar.bz2
    # tar -xjvf arm-2011.09-70-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2.tar.bz2
    Now we already have 3 new folders: busybox-1.21.0, linux-3.9, and arm-2011.09.
Make Path for The Compiler
  1. Open ~/.bashrc file and add text in order to inform OS that compiler will be added to path.
    $ nano ~/.bashrc
    After open .bashrc file, add this text,
    export PATH=/home/your_user/Project/arm-2011.09/bin:$PATH
    Exit from editor, then refresh .bashrc file,
    $ source ~/.
  2. Test whether your compiler already successfully added to path or not.
    $ arm-none-linux-gnueabi-gcc --version
Compile Linux Kernel
  1. Go to linux source code folder.
    $ cd ~/Project/Sources/linux-3.9
  2. Preparation before compile linux source code.
    $ make mrproper
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- versatile_defconfig
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
    In linux kernel configuration window, go to “Enable loadable module support”. Press space or N key button, to un-check this feature. Next is go to Kernel Features, then activate ARM EABI compilation feature.
  3. Compile linux kernel.
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- all
    In this process, it will take a few minutes, depend on your computer speed.
  4. After compilation finished, we will get linux kernel image (zImage) from folder ./arch/arm/boot. Copy the image into your project folder.
    $ cp ./arch/arm/boot/zImage ~/Project
    Now, our linux kernel image is ready to be used.
Install BusyBox
  1. Go to busybox source code folder.
    $ cd ~/Project/Sources/busybox-1.21.0
  2. Preparation before install BusyBox.
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
    In Busybox Configuration window, go to Busybox Setting -> Build Options -> check Build BusyBox as a static binary. Then go to Busybox Setting -> Installation Options -> Installation Prefix. Remember that folder name, because that folder will be destination of our installation files.
  3. Install BusyBox.
    $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
  4. Go to _install folder and add some new folders.
    $ cd _install
    $ mkdir proc sys dev etc etc/init.d
  5. Add rcS file in folder init.d, and add code to mount proc and sysfs when launch kernel on Qemu.
    $ touch etc/init.d/rcS
    $ nano etc/init.d/rcS
    Add this code,
    #!/bin/sh
    mount -t proc none /proc
    mount -t sysfs none /sys
    /sbin/mdev -s
    Change permission of rcS file,
    $ chmod +x etc/init.d/rcS
  6. Convert _install folder to rootfs.img, and copy to Project folder.
    $ find . | cpio -o --format=newc > ..rootfs.img
    $ cd ..
    $ gzip -c rootfs.img > rootfs.img.gz
    $ cp rootfs.img.gz ~/Project
Launch Qemu
$ cd ~/Project
$ qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/bin/sh"
After qemu launched, suppose it will show # sign. And you can type some commands same as linux commands.

1 comment:

  1. Hi,
    Why do you need to use another arm cross compiler from CodeSourcery but not just using "arm-linux-gnueabi-gcc"? There's only trial version on CodeSourcery. That's why I tried not to use it.
    But I got problem to run u-boot.bin on QEMU by using vexpress-a9 and cross-compiler: arm-linux-gnueabi-gcc". I don't know it's compiler issue or not.
    Do you have any idea?

    Thanks!

    ReplyDelete