Difference between revisions of "QEMU"

From ArmadeusWiki
Jump to: navigation, search
m (Launch it)
(new way for rootfs)
Line 63: Line 63:
 
</pre>
 
</pre>
  
==Get/generate simulation images==
+
==Get/generate simulation images (Linux & rootfs)==
* In our tests we used the QEMU Versatile PB emulated hardware. To get a compatible Linux kernel for this board then:
+
* As QEMU doesn't support (yet) the APF, we will use the Versatile PB emulated hardware. To get a compatible Linux kernel for this board do:
 
<pre class="host">
 
<pre class="host">
 
  $ cd your_armadeus_view/
 
  $ cd your_armadeus_view/
Line 78: Line 78:
 
  ttySMX0::respawn:/sbin/getty -L ttySMX0 115200,57600,38400 vt100
 
  ttySMX0::respawn:/sbin/getty -L ttySMX0 115200,57600,38400 vt100
 
</pre>
 
</pre>
* Generate your Armadeus Rootfs as an EXT2 image:
+
* Re-generate your Armadeus rootfs:
<pre class="host">
+
$ make menuconfig
+
</pre>
+
<pre class="config">
+
Target filesystem options  --->
+
    [*] ext2 root filesystem
+
    ... (keep all default options)
+
</pre>
+
 
<pre class="host">
 
<pre class="host">
 
  $ make
 
  $ make
 
</pre>
 
</pre>
* be sure that your rootfs image is less than 16Mbytes (Ramdisk limit)
+
* check the size of your rootfs image
 
<pre class="host">
 
<pre class="host">
$ ls -al $ARMADEUS_BINARIES/*.ext2
+
$ ls -al $ARMADEUS_ROOTFS_TAR
 
</pre>
 
</pre>
* and zip it (we will use it as Ramdisk first):
+
* generate a dummy image larger than your rootfs; here 60 MBytes for a 45 MBytes tared rootfs:
 
<pre class="host">
 
<pre class="host">
$ gzip -9 $ARMADEUS_BINARIES/apfxx-rootfs.arm.ext2
+
$ dd if=/dev/zero of=armadeus-qemu.img bs=1MB count=60
 +
$ sudo mke2fs -F -m 0 -b 1024 armadeus-qemu.img
 
</pre>
 
</pre>
* Create a fake QEMU Hard disk image
+
* mount it and copy it your rootfs:
 
<pre class="host">
 
<pre class="host">
$ qemu-img create -f qcow rootfs.arm_nofpu2.img 20M
+
$ mkdir qemu_mnt
 +
$ sudo mount -t ext2 -o loop armadeus-qemu.img qemu_mnt/
 +
$ sudo tar xf $ARMADEUS_ROOTFS_TAR -C qemu_mnt/
 +
$ sudo umount qemu_mnt/
 
</pre>
 
</pre>
 +
* now you have all you need to launch Qemu
  
 
==Launch it==
 
==Launch it==

Revision as of 18:39, 16 June 2009

Page under construction... Construction.png Informations on this page are not guaranteed !!

Well, you don't have enough money to buy an Armadeus board and just want to be part of the "Software" side of the project ? Then QEMU can be a good choice for you !!

Warning Warning:

Just be aware that currently Armadeus hardware is not emulated under QEMU, we are just using an other board hardware emulation (ARM Versatile) and Linux kernel to launch our rootfs and test our software which is not hardware related (ie User interface, Network, etc...)


In order to build a hardware matching machine for Armadeus boards under Qemu, follow this link and add devices you are interested to see emulated in Qemu: Qemu machine development

Installation

  • on Debian, *Ubuntu just do a:
[armadeus]$ sudo apt-get install qemu bridge-utils ?vde?

Configuration

QEMU has several ways of emulating the network:

  • user mode (by default): you can access Internet from your emulated target or an internal Samba/TFTP server but your are not directly accessible
  • bridge mode: you can communicate directly with the Host


Note Note: For a first try you can skip following part and go directly here.

As we want to mimic the devt environment with a real target (that has its own IP adress and is eccesible from the host) we will use "bridged mode". This mode require some configuration on your Host:

  • Install bridge_utils package
  • Activate IPv4 forwarding, for example on Ubuntu, uncomment the following line in /etc/sysctl.conf:
 $ sudo vim /etc/sysctl.conf
 
   # Uncomment the next line to enable packet forwarding for IPv4
   #net/ipv4/ip_forward=1
  • In /etc/network/interface comment the line referring to your current Ethernet card and replace them with:
auto br0
iface br0 inet dhcp
 bridge_ports eth0
 bridge_fd 9
 bridge_hello 2
 bridge_maxage 12
 bridge_stp off 

#auto eth0
#iface eth0 inet dhcp
Note Note: If you are using a modern linux distribution like Ubuntu, also be sure NetworkManager is disabled/not configured. Otherwise conflict occur and network does not work at all.


  • Create a script /etc/qemu-ifup that will be executed upon the start of QEMU:
#!/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
  • Now you can append the following options to the qemu command line:
-net nic,vlan=0,macaddr=00:16:3e:00:00:01 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup

You don't need to give a MAC address if you are emulating only one machine, as QEMU will use a default one. However if you have more than one emulated machine (don't forget QEMU can also emulate other architectures than ARM), you will have to specify a unique MAC address for each machine.

  • Once booted, on your guest you can configure the network simply as follows:
 # udhcpc -i eth0

Get/generate simulation images (Linux & rootfs)

  • As QEMU doesn't support (yet) the APF, we will use the Versatile PB emulated hardware. To get a compatible Linux kernel for this board do:
 $ cd your_armadeus_view/
 $ wget http://people.debian.org/~aurel32/arm-versatile/vmlinuz-2.6.26-2-versatile
  • get some useful environment variables:
 $ make shell_env
 $ source armadeus_env.sh
  • in $ARMADEUS_ROOTFS_DIR/etc/inittab, comment following line:
 ttySMX0::respawn:/sbin/getty -L ttySMX0 115200,57600,38400 vt100
  • Re-generate your Armadeus rootfs:
 $ make
  • check the size of your rootfs image
$ ls -al $ARMADEUS_ROOTFS_TAR
  • generate a dummy image larger than your rootfs; here 60 MBytes for a 45 MBytes tared rootfs:
$ dd if=/dev/zero of=armadeus-qemu.img bs=1MB count=60
$ sudo mke2fs -F -m 0 -b 1024 armadeus-qemu.img
  • mount it and copy it your rootfs:
$ mkdir qemu_mnt
$ sudo mount -t ext2 -o loop armadeus-qemu.img qemu_mnt/
$ sudo tar xf $ARMADEUS_ROOTFS_TAR -C qemu_mnt/
$ sudo umount qemu_mnt/
  • now you have all you need to launch Qemu

Launch it

  • At first boot, you have to launch the system as a Ramdisk:
[armadeus]$ qemu-system-arm -m 32 -M versatilepb -kernel vmlinuz-2.6.18-6-versatile \
    -initrd apf9328-rootfs.arm.ext2.gz -append "root=/dev/ram" -hda ./apf9328-rootfs.arm_nofpu2.img

Qemu apf ramdisk.png

  • When system has booted, we will create the "hard disk" image. But first, if you are French, load a usable keymap:
 # loadkmap < /etc/i18n/fr.kmap
    =>    loqdk,qp < !etc!i&_n!fr:k,qp    on your PC keyboard
  • then:
 # mkdir /tmp/dev
 # mknod /tmp/dev/sda b 8 0
 # mknod /tmp/dev/sda1 b 8 1
 # fdisk /tmp/dev/sda
   n p 1 <enter> <enter> w
 # mkfs.ext2 /tmp/dev/sda1
  • Now we can mount our brand new file system:
 # mkdir /mnt/root
 # mount /tmp/dev/sda1 /mnt/root
Note Note: Following steps need you already configured tftp on your host and networking up and running


  • And now we can populate it:
 # cd /mnt/root
 # tftp -g -r apf27-rootfs.arm.tar -l rootfs.arm.tar [HOST IP]
 # tar -xvf rootfs.arm.tar
  • Finally halt the emulated system and, next boot, we can omit the initrd image:
[armadeus]$ qemu-system-arm -m 32 -M versatilepb -kernel vmlinuz-2.6.18-6-versatile \
    -append "root=/dev/sda1" -hda ./apf9328-rootfs.arm_nofpu2.img

Links