Saturday, December 5, 2009

ARM on QEMU

Goal : Run linux on a verstaline board (simulated by QEMU)

why : Because it is not always possible to have the real board available for development.

Prerequisites:
==============

1. QEMU : ofcourse
on debian systems : sudo apt-get install qemu
on RH systems : sudo yum install qemu

2. This one depends on what kind of communication mechanism is used between the host (your development) system and the guest sytem on QEMU. I prefer to use networking.

---- Have DHCP running so that guest system on qemu can use it to get an IP address.
---- host TAP devices used to connect to QEMU. The kernel config of the host should have TAP/TUN networking enabled. The switch for this is CONFIG_TUN.

grep CONFIG_TUN= /boot/config-`uname -r`

This should return you the state of the switch.

nemesis@nemesis-laptop:~$ grep CONFIG_TUN= /boot/config-`uname -r`
CONFIG_TUN=m


nemesis@nemesis-laptop:~$ ls -al /dev/net/tun
crw-rw-rw- 1 root root 10, 200 2009-11-03 11:46 /dev/net/tun


This verifies that the device exists indeed. If not, create it manually.

mknod /dev/net/tun c 10 200


Configure bridge-control
==================
Add the following to a script file

#!/bin/sh
/usr/sbin/brctl addbr br0 ### Add a bridge
/sbin/ifconfig eth0 0.0.0.0 promisc up ### set up eth0
/usr/sbin/brctl addif br0 eth0 ### add an intf(eth0) to the bridge (br0)
/sbin/dhclient br0 ### enable dhcp
/sbin/iptables -F FORWARD

Build kernel
=========

The quickest way is to use the default config file for the versatile platform.
Simply copy the config file from configs directory for ARM arch and rename it as .config

cp /arch/arm/configs/versatile_defconfig /.config

Config the Linux kernel (xconfig, menuconfig or simply using vim to edit..have it your way)

1. Enable ARM EABI support : switch CONFIG_AEABI (part of kernel features)
2. Enable DHCP : Switch CONFIG_IP_PNP_DHCP
3. Enable Universal TUN/TAP driver : switch CONFIG_TUN
4. Enable tmpfs : Switch CONFIG_TMPFS

Now we are ready to make (my day)
Ofcourse ARCH = arm
and CROSS_COMPILE = your_cross_compiler (I use codesourcery and for me it is
arm-none-linux-gnueabi-)

What about the Root File System ?
=======================

We will NFS mount the root filesystem. Build your rootfs.

1. edit /etc/exports ===> Add the following line

/mnt/arm-linux-rootfs / *(rw,sync,no_root_squash)

Here the untarred rootfs is at /mnt/arm-linux-rootfs and it is accessible as rw filesystem from any systems (indicated by *). If static ip-addresses are assigned, use the ip-address of the peer here.

2. restart the nfs service so that our changes come into effect.

/etc/init.d/nfs restart


Boot into Linux on QEMU
======================

qemu-system-arm -M versatilepb -kernel zImage-versatile -append root="/dev/nfs nfsroot=:/mnt/arm-linux-rootfs rw ip=dhcp" \
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup


qemu-ifup
=============================

#!/bin/sh

echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2



Source : http://fedoraproject.org/wiki/Architectures/ARM/HowToQemu
http://www.aurel32.net/info/debian_arm_qemu.php

No comments: