ARM Emulation Using QEMU

From Embedded Nirvana

Jump to: navigation, search

Contents

About QEMU

QEMU emulates a full computer system, including a processor and various peripherals. It can be used to provide virtual hosting of several virtual computers on a single computer. QEMU can boot many guest operating systems, including Linux, Solaris, Microsoft Windows, DOS, and BSD; it supports emulating several hardware platforms, including x86, x86-64 (AMD64/Intel 64), ARM, Alpha, ETRAX CRIS, MIPS, MicroBlaze, PowerPC and SPARC.

Fun with ARM

QEMU emulates the armv5tej instruction set and all the derivative processors families like ARM7, ARM9E, ARM10E and XScale. It emulates full systems like Integrator/CP board, Versatile baseboard, RealView Emulation baseboard, XScale-based PDAs, Palm Tungsten|E PDA, Nokia N800 and Nokia N810 internet tablets etc. QEMU also powers the Android emulator which is part of the Android SDK (most current Android implementations are ARM based).

In this tutorial we shall be compiling the Kernel, the RootFS and run our embedded distribution on an ARM based machine (Versatile PB) emulated using QEMU.

For the impatient ones, who have grabbed the Embedded Studio VM disc, go to the Quickstart for Embedded Studio VM section.

Setting Up System

  • Installing Toolchain : You can use the arm-linux-gcc 4.3.2 toolchain from here, or any other one of your choice too.
  • Instaling QEMU :

For Fedora

yum install qemu-system-arm

For Ubuntu

apt-get install qemu qemu-kvm-extras 
  • Compiling Uboot
wget -c ftp://ftp.denx.de/pub/u-boot/u-boot-2010.03.tar.bz2
wget --no-check-certificate https://github.com/tuxdna/arm-experiments/raw/master/u-boot-2010.03-versatilepb.patch
tar -xvf u-boot-2010.03.tar.bz2
cd u-boot-2010.03
patch -p0 < ../u-boot-2010.03-versatilepb.patch
export CROSS_COMPILE=arm-linux-
export ARCH=arm
make versatilepb_config
  • Kernel Compilation (version 2.6.29) : You can get the latest kernel too, and follow the steps.
tar -xvf linux-2.6.29.tar.gz
cd linux-2.6.29
cd arch/arm/configs
make ARCH=arm versatile_defconfig
cd ../../../
make ARCH=arm menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux- all
  • Running standalone User Application : Make your application and save as test.c
arm-none-linux-gnueabi-gcc -static test.c -o test
echo test | cpio -o --format=newc > test_rootfs

Test your application by the following arguments 

qemu-system-arm -M versatilepb -m 128M -kernel path/to/zImage -initrd path/to/test_rootfs -append "root=/dev/ram rdinit=/test"
  • Prepare minimal RootFS (BusyBox) : For making a rootFS we shall be using the BusyBox utility which implements most of the functionality (commands)
export ROOTFS_PATH=path/of/your/choice/for/rootfs
wget http://www.busybox.net/downloads/busybox-1.16.0.tar.bz2
tar jxf busybox-1.16.0.tar.bz2
cd busybox-1.16.0
make ARCH=arm CROSS_COMPILE=arm-linux- defconfig
make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig

If make throws an error, do some small changes are required in Makefile. Then set (BusyBox Settings -> Build Options -> Static Executable) in menuconfig.

make ARCH=arm CROSS_COMPILE=arm-linux- install
cd _install
find . | cpio -o --format=newc > ../../rootfs.img

Thats it. You have the krnel and filesystem ready.

  • Testing System : To test your system,
qemu-system-arm -M versatilepb -m 128M -serial stdio -kernel path/to/zImage -initrd path/to/rootfs.img -append "root=/dev/ram rdinit=/bin/sh"

Quickstart for Embedded Studio VM

  • The ES virtual machine has been setup already with the required tools. Start the ES VM and give the password as pass
  • Start gnome-terminal and cd to ~/Desktop/tools/qemu-experiments directory. In this directory, you will find a Busybox source, prebuilt rootfs (rootfs.img) and the kernel source directory. Compile the kernel and filesystem and start with the instriuctions as stated above.
Personal tools