Wednesday, August 11, 2010

QEMU emulated ARM System

This is my notes basic on my own expirement (alone of-course) to build Linux system on QEMU emulated ARM Versatile board. I use Linux 2.6.27.49 and BusyBox 1.17.1. My host is a x86-PC, run Fedora 12 (Constantine), the Fedora's developer fortunately provide ARM toolchain repository in this page. Okay here my steps

Getting the Toolchains

Activate the repo by adding these lines to /etc/yum.conf

[fedora-arm-toolchain]
name=Fedora ARM Toolchain
failovermethod=priority
baseurl=http://ftp.linux.org.uk/pub/linux/arm/fedora/cross/latest/i386/
enabled=1
gpgcheck=0


After this, we are going to install the toolchains. Issuing this command will also install all of it's dependencies.

# yum install armv5tel-redhat-linux-gnueabi-gcc

and tell the world for our new toolchain's family commands

$ export ARM_TOOLCHAIN=armv5tel-redhat-linux-gnueabi-

Preparing BusyBox and the initramfs

It's time to configure BusyBox, feel free to customize for your own configuration, all configuration below is only for my own experiment.

$ make ARCH=arm defconfig
$ make ARCH=arm CROSS_COMPILE=$ARM_TOOLCHAIN install

Goto BusyBox install directory to create our rootfs for initramfs, create these following directories and files

# cd _install
# mkdir -p etc/init.d/
# mkdir proc/

Here a simple /etc/inittab file

# /etc/inittab

::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh


and a simple /etc/init.d/rcS file

#!/bin/sh

echo "Mounting /proc file system"
mount -t procfs /proc
echo
echo "Welcome to `uname -rsm`"
echo


Create minimal device files

# mknod dev/tty c 5 0
# mknod dev/console c 5 1

And create the rootfs archive

# ln -sf bin/busybox init
$ find . | cpio -o -H newc | gzip > /path/to/rootfs.cpio.gz

Build the Kernel

Prepare our kernel, we use initramfs support through the kernel config. This page contains great documentation for initramfs and rootfs creation.

IMPORTANT since we are using toolchain that support ARM ABI (EABI), don't forget to enable this in kernel configuration called CONFIG_EABI, otherwise you will get "Kernel panic not syncing" error because different ABI version between the kernel and the toolchains.

You will need to enable initramfs/initrd support in kernel configuration and point your rootfs archive, that is our rootfs.cpio.gz

$ make ARCH=arm versatile_defconfig
$ make ARCH=arm menuconfig
$ make ARCH=arm CROSS_COMPILE=$ARM_TOOLCHAIN zImage


After compiling, lets try and pray for our new ARM Versatile's kernel, testing the kernel with

$ qemu-system-arm -M versatilepb -kernel /path/to/zImage

If everything okay, you would see the kernel is boot up and bring the init process, congrats! your kernel is running, you are probably taken to the shell and playing with our very simple and emulated embedded system.

to be hardly re-written...