Preparation
- Install developer ncurses library. It will be used during linux kernel configuration.
- Install latest Qemu from Linaro repository. You can refer to my previous posting, Install Qemu on Ubuntu.
- 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.
- 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.
- Download latest busybox from busybox.net. Currently, latest version of busybox is busybox-1.21.0.
$ sudo apt-get install libncurses5-devFiles and Folders Arrangement
- Create folder for our project.
# cd # mkdir Project # cd Project
- Create folder for our source code that we already downloaded previously.
# mkdir Sources # cd Sources
- 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. - 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.
- 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 ~/.
- Test whether your compiler already successfully added to path or not.
$ arm-none-linux-gnueabi-gcc --version
- Go to linux source code folder.
$ cd ~/Project/Sources/linux-3.9
- 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. - 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. - 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.
- Go to busybox source code folder.
$ cd ~/Project/Sources/busybox-1.21.0
- 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. - Install BusyBox.
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
- Go to _install folder and add some new folders.
$ cd _install $ mkdir proc sys dev etc etc/init.d
- Add
rcS
file in folderinit.d
, and add code to mountproc
andsysfs
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 ofrcS
file,
$ chmod +x etc/init.d/rcS
- Convert
_install
folder torootfs.img
, and copy toProject
folder.$ find . | cpio -o --format=newc > ..rootfs.img $ cd .. $ gzip -c rootfs.img > rootfs.img.gz $ cp rootfs.img.gz ~/Project
$ 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.
Hi,
ReplyDeleteWhy 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!