Difference between revisions of "QEMU"

From ArmadeusWiki
Jump to: navigation, search
m (Get/generate simulation images)
(Get/generate simulation images (Linux & rootfs))
 
(33 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==UNDER CONSTRUCTION==
+
{{Under_Construction}}
[[Image:Construction.png]]
+
  
 
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 !! <br><br>
 
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 !! <br><br>
'''Just be aware that currently Armadeus hardware is not emulated under QEMU, we are just using an other board hard and linux kernel to launch our Rootfs an test our software which is not custom hardware related (ie User interface, Network, etc...)'''
+
{{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 under Qemu for Armadeus boards, follow this link and add devices you are intrested to see emulated in Qemu:  
+
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:  
 
[[QemuMachineDevelopment | Qemu machine development]]
 
[[QemuMachineDevelopment | Qemu machine development]]
  
 
==Installation==
 
==Installation==
 
* on Debian, *Ubuntu just do a:
 
* on Debian, *Ubuntu just do a:
  [armadeus]$ sudo apt-get install qemu bridge-utils ?vde?
+
  [armadeus]$ sudo apt-get install qemu bridge-utils vde
 +
* on Kubuntu 9.10 do:
 +
[armadeus]$ sudo apt-get install qemu bridge-utils qemu-kvm-extras vde
 +
* on Ubuntu 20.04:
 +
<pre>
 +
$ sudo apt-get install qemu qemu-system-arm
 +
</pre>
  
 
==Configuration==
 
==Configuration==
Line 19: Line 26:
  
 
<br>
 
<br>
{{Note|For a first try you can skip following part.}}
+
{{Note|For a first try you can skip following part and go directly [[QEMU#Get.2Fgenerate_simulation_images_.28Linux_.26_rootfs.29|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".
 
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:
 
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'':
 
* Activate IPv4 forwarding, for example on Ubuntu, uncomment the following line in ''/etc/sysctl.conf'':
 
<pre class=host>
 
<pre class=host>
Line 32: Line 40:
  
 
  auto br0
 
  auto br0
  iface br0 inet static
+
  iface br0 inet dhcp
  address 192.168.1.2 ??
+
  network 192.168.1.0 ??
+
  netmask 255.255.255.0
+
  broadcast 192.168.1.255 ??
+
  gateway 192.168.1.1 ??
+
 
   bridge_ports eth0
 
   bridge_ports eth0
 
   bridge_fd 9
 
   bridge_fd 9
Line 46: Line 49:
 
  #auto eth0
 
  #auto eth0
 
  #iface eth0 inet dhcp
 
  #iface eth0 inet dhcp
 +
{{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.}}
  
==Get/generate simulation images==
+
* Create a script ''/etc/qemu-ifup'' that will be executed upon the start of QEMU:
* In our tests we used the QEMU Versatile PB emulated hardware. To get a compatible Linux kernel for this board then:
+
#!/bin/sh
[armadeus]$ wget http://people.debian.org/~aurel32/arm-versatile/vmlinuz-2.6.18-6-versatile
+
echo "Executing /etc/qemu-ifup"
* in ''buildroot/project_build_armv4t/apf9328/root/etc/inittab'', comment following line:
+
echo "Bringing up $1 for bridged mode..."
ttySMX0::respawn:/sbin/getty -L ttySMX0 115200,57600,38400 vt100
+
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
* Generate your Armadeus Rootfs as an EXT2 image:
+
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:
 +
<pre class="apf">
 +
# udhcpc -i eth0
 +
</pre>
 +
 
 +
==Get/generate simulation images (Linux & rootfs)==
 +
 
 +
{| border="1" cellpadding="10" cellspacing="0" summary="" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! APF27 !! APF6
 +
|-
 +
| * 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">$ cd your_armadeus_view/
 +
$ wget ftp://ftp2.armadeus.com/armadeusw/download/qemu/vmlinuz-2.6.29.6-versatile-armadeus</pre>
 +
one wanting to rebuild this image itself will find the corresponding config file in the same dir. (after compiling, take ''arch/arm/boot/zImage'')
 +
|| * As QEMU doesn't support (yet) the APF6, we will use the SabreLite emulated hardware.
 +
|}
 +
 
 +
* get some useful environment variables:
 
<pre class="host">
 
<pre class="host">
  [armadeus]$ make menuconfig
+
  $ make shell_env
 +
$ source armadeus_env.sh
 
</pre>
 
</pre>
 +
* deactivate login on serial port:
 +
** in Buildroot menuconfig:
 
<pre class="config">
 
<pre class="config">
Target filesystem options --->  
+
System configuration --->
    [*] ext2 root filesystem
+
    () Port to run a getty (login prompt) on
 
</pre>
 
</pre>
 +
: * and in ''$ARMADEUS_ROOTFS_DIR/etc/inittab'', comment following lines:
 
<pre class="host">
 
<pre class="host">
[armadeus]$ make
+
# Put a getty on the serial port
 +
ttymxcX::respawn:/sbin/getty -L ttymxcX 115200 vt100 # GENERIC_SERIAL
 +
 
 +
This can be achieved with sed :
 +
sed --in-place -e "s/^ttymcX/#ttymcX/" $ARMADEUS_ROOTFS_DIR/etc/inittab
 
</pre>
 
</pre>
* be sure that your rootfs image is less than 16Mbytes (Ramdisk limit)
+
* Re-generate your Armadeus rootfs:
* and zip it (we will use it as Ramdisk first):
+
 
<pre class="host">
 
<pre class="host">
  [armadeus]$ gzip -9 buildroot/binaries/apf9328/apf9328-rootfs.arm.ext2
+
  $ make
 
</pre>
 
</pre>
* Create a fake QEMU Hard disk image
+
{| border="1" cellpadding="10" cellspacing="0" summary="" class="wikitable"
 +
|- style="background:#efefef;" align="center"
 +
! APF27 !! APF6
 +
|-
 +
|* check the size of your rootfs image
 
<pre class="host">
 
<pre class="host">
[armadeus]$ qemu-img create -f qcow rootfs.arm_nofpu2.img 20M
+
$ ls -al $ARMADEUS_ROOTFS_TAR
 
</pre>
 
</pre>
 +
* generate a dummy image larger than your rootfs; here 60 MBytes for a 45 MBytes tared rootfs:
 +
<pre class="host">
 +
$ dd if=/dev/zero of=armadeus-qemu.img bs=1MB count=60
 +
$ sudo mke2fs -F -m 0 -b 1024 armadeus-qemu.img
 +
</pre>
 +
* mount it and copy it your rootfs:
 +
<pre class="host">
 +
$ 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>
 +
|* APF6 has already EXT4 generated rootfs images
 +
|}
 +
* now you have all you need to launch Qemu
  
 
==Launch it==
 
==Launch it==
* At first boot, you have to launch the system as a Ramdisk:
+
===APF9328/27/51/28===
[armadeus]$ qemu-system-arm -m 32 -M versatilepb -kernel vmlinuz-2.6.18-6-versatile \
+
* Example with 64 MBytes of RAM:
    -initrd apf9328-rootfs.arm.ext2.gz -append "root=/dev/ram" -hda ./apf9328-rootfs.arm_nofpu2.img
+
<pre class="host">
 +
$ qemu-system-arm -M versatilepb -kernel ./vmlinuz-2.6.29.6-versatile-armadeus -hda armadeus-qemu.img -m 64 \
 +
                                -append "root=/dev/sda mem=64M ro"      (rw for read/write works, too instead of tw two last characters ro)
 +
</pre>
 +
option ''-cpu arm926'' can be added on APF27 <br>
 +
 
 +
===APF6===
 +
* here we use i.MX6 sabrelite board emulation and APF6 generated kernel. One may modify his APF6 Linux configuration to increase Ramdisk max size if needed (64 Mbytes by default).
 +
<pre clas="host">
 +
$ qemu-system-arm -M sabrelite -smp 4 -m 1G -display none -serial null -serial stdio \
 +
    -kernel buildroot/output/images/zImage \
 +
    -dtb buildroot/output/build/linux-4.19.227/arch/arm/boot/dts/imx6q-sabrelite.dtb \
 +
    -initrd buildroot/output/images/rootfs.ext4 -append "root=/dev/ram"
 +
</pre>
  
 
[[Image:qemu_apf_ramdisk.png]]
 
[[Image:qemu_apf_ramdisk.png]]
  
* When system has booted, we will create the "hard disk" image. But first, if you are French, do:
+
===Common tips===
 +
* When system has booted, if you are French, load a usable keymap:
 +
<pre class="apf">
 
  # loadkmap < /etc/i18n/fr.kmap
 
  # loadkmap < /etc/i18n/fr.kmap
* then:
+
</pre>
# mkdir /tmp/dev
+
<pre class="host">
# mknod /tmp/dev/sda b 8 0
+
    =>    loqdk,qp < !etc!i&_n!fr:k,qp    on your PC keyboard
# mknod /tmp/dev/sda b 8 1
+
</pre>
# fdisk /tmp/dev/sda
+
Another solution is to generate the command one wants to lanch on your PC, with a normal keyboard layout
  n p 1 <enter> <enter>
+
 
# mkfs.ext2 /tmp/dev/sda1
+
<pre class="host">
 +
$echo "loadkmap</etc/i18n/fr.kmap" > kfr
 +
</pre>
 +
 
 +
or
 +
<pre class="host">
 +
$echo "loadkmap</etc/i18n/de.kmap" > kde
 +
 
 +
chmod +x k*
 +
</pre>
 +
 
 +
and to copy it on the virtual image, before it is unmounted and qemu is launched
 +
<pre class="host">
 +
$cp -uv k* $IMAGE/usr/local/bin/. # it will be in the guest PATH
 +
</pre>
 +
 
 +
Once qemu has been launched, and one is connected, just type kfr (or kde) to get a keyboard layout one is accustomed to (these letters are layout agnostic, and they can be directly executed).
 +
 
 +
A bash script to avoid typing all these lines can be found here, and might make  things simpler, if adapted.
 +
[[http://www.armadeus.com/wiki/index.php?title=User:DenisB]]
 +
 
 +
==To Be Continued... ;-) ==
  
 
==Links==
 
==Links==
 
* [http://fabrice.bellard.free.fr/qemu/ QEMU WebPage]
 
* [http://fabrice.bellard.free.fr/qemu/ QEMU WebPage]
* http://www.aurel32.net/info/debian_arm_qemu.php + http://qemu-forum.ipi.fi/viewtopic.php?t=3919
+
* [http://www.aurel32.net/info/debian_arm_qemu.php Debian on an emulated ARM machine tutorial by Aurel32] + [http://qemu-forum.ipi.fi/viewtopic.php?t=3919 comments about it]
* http://909ers.apl.washington.edu/~dushaw/ARM/
+
* [http://909ers.apl.washington.edu/~dushaw/ARM/ Debian ARM Linux on Qemu]
 
* http://www.gnome.org/~markmc/qemu-networking.html
 
* http://www.gnome.org/~markmc/qemu-networking.html
* http://compsoc.dur.ac.uk/~djw/qemu.html
+
* [http://compsoc.dur.ac.uk/~djw/qemu.html QEMU - Debian - Linux - TUN/TAP - network bridge]
 +
* [http://gumstix.net/wiki/index.php?title=Running_qemu Gumstix's way of using QEmu]
 +
* [http://gumstix.net/wiki/index.php?title=Making_qemu_images Gumstix's way of generating QEmu's images]
 +
* [https://wiki.ubuntu.com/ARM/RootfsFromScratch Generating Ubuntu for ARM with QEMU]
 +
* [http://balau82.wordpress.com/2010/03/22/compiling-linux-kernel-for-qemu-arm-emulator/ compiling-linux-kernel-for-qemu-arm-emulator]
 +
 
  
 
[[Category:Emulation]]
 
[[Category:Emulation]]

Latest revision as of 12:14, 13 January 2023

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
  • on Kubuntu 9.10 do:
[armadeus]$ sudo apt-get install qemu bridge-utils qemu-kvm-extras vde
  • on Ubuntu 20.04:
 $ sudo apt-get install qemu qemu-system-arm

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)

APF27 APF6
* 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 ftp://ftp2.armadeus.com/armadeusw/download/qemu/vmlinuz-2.6.29.6-versatile-armadeus

one wanting to rebuild this image itself will find the corresponding config file in the same dir. (after compiling, take arch/arm/boot/zImage)

* As QEMU doesn't support (yet) the APF6, we will use the SabreLite emulated hardware.
  • get some useful environment variables:
 $ make shell_env
 $ source armadeus_env.sh
  • deactivate login on serial port:
    • in Buildroot menuconfig:
System configuration  --->
    () Port to run a getty (login prompt) on
* and in $ARMADEUS_ROOTFS_DIR/etc/inittab, comment following lines:
# Put a getty on the serial port
ttymxcX::respawn:/sbin/getty -L ttymxcX 115200 vt100 # GENERIC_SERIAL

This can be achieved with sed :
sed --in-place -e "s/^ttymcX/#ttymcX/" $ARMADEUS_ROOTFS_DIR/etc/inittab 
  • Re-generate your Armadeus rootfs:
 $ make
APF27 APF6
* 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/
* APF6 has already EXT4 generated rootfs images
  • now you have all you need to launch Qemu

Launch it

APF9328/27/51/28

  • Example with 64 MBytes of RAM:
$ qemu-system-arm -M versatilepb -kernel ./vmlinuz-2.6.29.6-versatile-armadeus -hda armadeus-qemu.img -m 64 \
                                -append "root=/dev/sda mem=64M ro"       (rw for read/write works, too instead of tw two last characters ro)

option -cpu arm926 can be added on APF27

APF6

  • here we use i.MX6 sabrelite board emulation and APF6 generated kernel. One may modify his APF6 Linux configuration to increase Ramdisk max size if needed (64 Mbytes by default).
$ qemu-system-arm -M sabrelite -smp 4 -m 1G -display none -serial null -serial stdio \
    -kernel buildroot/output/images/zImage \
    -dtb buildroot/output/build/linux-4.19.227/arch/arm/boot/dts/imx6q-sabrelite.dtb \
    -initrd buildroot/output/images/rootfs.ext4 -append "root=/dev/ram"

Qemu apf ramdisk.png

Common tips

  • When system has booted, 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

Another solution is to generate the command one wants to lanch on your PC, with a normal keyboard layout

$echo "loadkmap</etc/i18n/fr.kmap" > kfr

or

$echo "loadkmap</etc/i18n/de.kmap" > kde

chmod +x k*

and to copy it on the virtual image, before it is unmounted and qemu is launched

$cp -uv k* $IMAGE/usr/local/bin/. # it will be in the guest PATH

Once qemu has been launched, and one is connected, just type kfr (or kde) to get a keyboard layout one is accustomed to (these letters are layout agnostic, and they can be directly executed).

A bash script to avoid typing all these lines can be found here, and might make things simpler, if adapted. [[1]]

To Be Continued... ;-)

Links