Angstrom narcissus, SD Image et QEMU pour Mini2440 sur Debian
21 juillet 2011 Category :mini2440 0
Compilation de qemu :
mkdir mini2440 cd mini2440 git clone git://repo.or.cz/qemu/mini2440.git qemu cd qemu ./configure make
Pour permettre l’accès réseau à partir d’une VM QEMU, il faut configurer un bridge avec TUN/TAP.
Installation des packages nécessaires :
sudo apt-get install bridge-utils uml-utilities
Vérification du support TUN par le kernel :
grep CONFIG_TUN= /boot/config-`uname -r`
Normalement /dev/net/tun est déjà présent sinon :
mknod /dev/net/tun c 10 200
Ma config réseau (/etc/network/interfaces) à modifier selon vos besoins :
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
iface eth0 inet manual
# The bridge network interface(s)
auto br0
iface br0 inet static
address 10.0.1.202
network 10.0.1.0
netmask 255.255.255.0
broadcast 10.0.1.255
gateway 10.0.1.138
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
QEMU ne tournant pas en root, vous devez configurer sudo pour vous permettre de lancer les commandes nécessaires en utilisant visudo.
Mon fichier /etc/sudoers :
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
Cmnd_Alias QEMU=/sbin/ifconfig, \
/sbin/modprobe, \
/usr/sbin/brctl
# User privilege specification
root ALL=(ALL) ALL
# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
# %sudo ALL=NOPASSWD: ALL
ziki ALL=(ALL) ALL
ziki ALL=NOPASSWD: QEMU
Ensuite, il faut un créer script /etc/qemu/qemu-ifup que QEMU lancera pour configurer le réseau :
#!/bin/sh /sbin/ifconfig $1 0.0.0.0 promisc up /usr/sbin/brctl addif br0 $1
Rendre le script exécutable:
chmod +x /etc/qemu/qemu-ifup
Nous pouvons maintenant nous lancer dans la création de l’image du rootfs via http://narcissus.angstrom-distribution.org/ en choisissant bien mini2440 comme machine.
Téléchargement de l’image (utilisez l’url fournie par le site pour votre image) :
cd ~/mini2440 wget http://narcissus.angstrom-distribution.org/deploy/mini2440/473a05/test-image-mini2440.tar.gz
Création de l’image de la carte SD (ici 512Mo) pour l’utiliser avec QEMU :
Installation des packages nécessaires :
sudo apt-get install nbd-client kpartx
Création de l’image :
cd ~/mini2440/qemu ./qemu-img create mini2440/mini2440_sd.img 512M
Connection à l’image :
./qemu-nbd mini2440/mini2440_sd.img & sudo nbd-client localhost 1024 /dev/nbd0
Partitionnement :
sudo fdisk /dev/nbd0
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x8ebafad6. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): o Building a new DOS disklabel with disk identifier 0xa45c4dac. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-65, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-65, default 65): +50M Command (m for help): t Selected partition 1 Hex code (type L to list codes): b Changed system type of partition 1 to b (W95 FAT32) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (8-65, default 8): Using default value 8 Last cylinder or +size or +sizeM or +sizeK (8-65, default 65): Using default value 65 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks.
Puis :
sudo kpartx -a /dev/nbd0
Création des filesystems sur l’image et copie des fichiers de l’image générée sur le site d’Angstrom :
cd ~/mini2440 mkdir disk sudo mkfs.vfat /dev/mapper/nbd0p1 sudo mkfs.ext3 /dev/mapper/nbd0p2 sudo mount /dev/mapper/nbd0p2 ./disk sudo mkdir -p disk/boot sudo mount /dev/mapper/nbd0p1 ./disk/boot cd disk sudo tar -xzf ../test-image-mini2440.tar.gz (vous aurez probablement une erreur du à la tentative de la création du lien symbolique /boot/uImage sur une fat mais ce n'est pas grave) cd .. sudo umount disk/boot disk sudo nbd-client -d /dev/nbd0
Notre image terminée, nous pouvons maintenant nous lancer dans la configuration de QEMU.
Voici mon script de démarrage de QEMU (~/mini2440/qemu/startqemu-sd)
#!/bin/bash
user=`whoami`
base=$(dirname $0)
echo Starting in $base
name_nand="$base/mini2440_nand.bin"
name_sd="$base/mini2440/mini2440_sd.img"
if [ ! -f "$name_nand" ]; then
echo $0 : creating NAND empty image : "$name_nand"
dd if=/dev/zero of="$name_nand" bs=528 count=131072
fi
iface=`sudo tunctl -b -u $user`
cmd="arm-softmmu/qemu-system-arm \
-M mini2440 $* \
-serial stdio \
-mtdblock "$name_nand" \
-sd $name_sd \
-show-cursor \
-usb -usbdevice keyboard -usbdevice mouse \
-net nic,vlan=0 \
-net tap,vlan=0,ifname=$iface,script=/etc/qemu/qemu-ifup \
-monitor telnet::5555,server,nowait"
echo $cmd
$cmd
sudo tunctl -d $iface &>/dev/null
Il reste maintenant à mettre le fichier u-boot.bin que vous pouvez par exemple trouver la dans le répertoire ~/mini2440/qemu/mini2440/.
Ensuite, nous pouvons lancer QEMU avec notre script :
./startqemu-sd
Starting in . arm-softmmu/qemu-system-arm -M mini2440 -serial stdio -mtdblock ./mini2440_nand.bin -sd ./mini2440/mini2440_sd.img -show-cursor -usb -usbdevice keyboard -usbdevice mouse -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu/qemu-ifup -monitor telnet::5555,server,nowait S3C: CLK=240 HCLK=240 PCLK=240 UCLK=57 QEMU: ee24c08_init DM9000: INIT QEMU MAC : 52:54:00:12:34:56 QEMU mini2440_reset: loaded default u-boot from NAND QEMU mini2440_reset: loaded override u-boot (size 3a600) S3C: CLK=240 HCLK=240 PCLK=240 UCLK=48 S3C: CLK=304 HCLK=304 PCLK=304 UCLK=48 S3C: CLK=304 HCLK=101 PCLK=50 UCLK=48 S3C: CLK=304 HCLK=76 PCLK=38 UCLK=48 S3C: CLK=304 HCLK=76 PCLK=38 UCLK=48 S3C: CLK=405 HCLK=101 PCLK=50 UCLK=48 U-Boot 1.3.2-dirty-moko12 (Apr 16 2009 - 18:14:52) I2C: ready DRAM: 64 MB Flash: 2 MB NAND: Bad block table not found for chip 0 Bad block table not found for chip 0 64 MiB *** Warning - bad CRC or NAND, using default environment USB: S3C2410 USB Deviced In: serial Out: serial Err: serial MAC: 08:08:11:18:12:27 Hit any key to stop autoboot: 0 MINI2440 #
Il y a une erreur avec la NAND puisque celle-ci n’a pas été initialisée et ne contient que des zeros, corrigeons cela :
MINI2440 # nand scrub
NAND scrub: device 0 whole chip
Warning: scrub option will erase all factory set bad blocks!
There is no reliable way to recover them.
Use this command only for testing purposes if you
are sure of what you are doing!
Really scrub this NAND flash?
Erasing at 0x3ffc000 -- 100% complete.
Bad block table not found for chip 0
Bad block table not found for chip 0
OK
MINI2440 #
ensuite :
MINI2440 # nand createbbt Create BBT and erase everything ?Skipping bad block at 0x03ff0000 Skipping bad block at 0x03ff4000 Skipping bad block at 0x03ff8000 Skipping bad block at 0x03ffc000 Creating BBT. Please wait ...Bad block table not found for chip 0 Bad block table not found for chip 0 Bad block table written to 0x03ffc000, version 0x01 Bad block table written to 0x03ff8000, version 0x01 MINI2440 #
puis :
MINI2440 # dynenv set 40000 device 0 offset 0x40000, size 0x3fc0000 45 4e 56 30 - 00 00 04 00 MINI2440 #
Ensuite on sauve l’environnement et on reboot :
MINI2440 # saveenv Saving Environment to NAND... Erasing Nand...Writing to Nand... done MINI2440 # reset S3C: CLK=240 HCLK=240 PCLK=240 UCLK=57 QEMU mini2440_reset: loaded default u-boot from NAND QEMU mini2440_reset: loaded override u-boot (size 3a600) S3C: CLK=240 HCLK=240 PCLK=240 UCLK=48 S3C: CLK=304 HCLK=304 PCLK=304 UCLK=48 S3C: CLK=304 HCLK=101 PCLK=50 UCLK=48 S3C: CLK=304 HCLK=76 PCLK=38 UCLK=48 S3C: CLK=304 HCLK=76 PCLK=38 UCLK=48 S3C: CLK=405 HCLK=101 PCLK=50 UCLK=48 U-Boot 1.3.2-dirty-moko12 (Apr 16 2009 - 18:14:52) I2C: ready DRAM: 64 MB Flash: 2 MB NAND: 64 MiB Found Environment offset in OOB.. USB: S3C2410 USB Deviced In: serial Out: serial Err: serial MAC: 08:08:11:18:12:27 Hit any key to stop autoboot: 0 MINI2440 #
On peut constater que les erreurs ont disparues. On peut maintenant initialiser la « carte SD » et configurer bootcmd, bootargs et redémarrer :
MINI2440 # mmcinit trying to detect SD Card... Manufacturer: 0xaa, OEM "XY" Product name: "QEMU!", revision 0.1 Serial number: 3735928559 Manufacturing date: 2/2006 CRC: 0x0c, b0 = 1 READ_BL_LEN=15, C_SIZE_MULT=3, C_SIZE=3453 size = 4066377728 MINI2440 # fatls mmc 0:1 2155084 uimage-2.6.31.1 1 file(s), 0 dir(s) MINI2440 # setenv bootcmd 'mmcinit ; fatload mmc 0:1 0x31000000 uimage-2.6.31.1 ; bootm 0x31000000' MINI2440 # setenv bootargs 'noinitrd rootdelay=3 root=/dev/mmcblk0p2 console=ttySAC0,115200 rootwait' MINI2440 # saveenv Saving Environment to NAND... Erasing Nand...Writing to Nand... done MINI2440 # reset
Si tout va bien, cela devrait démarrer et vous devriez arriver au login :
.-------.
| | .-.
| | |-----.-----.-----.| | .----..-----.-----.
| | | __ | ---'| '--.| .-'| | |
| | | | | |--- || --'| | | ' | | | |
'---'---'--'--'--. |-----''----''--' '-----'-'-'-'
-' |
'---'
The Angstrom Distribution mini2440 ttySAC0
Angstrom 2010.7-test-20110310 mini2440 ttySAC0
mini2440 login:
Bon amusement!
Merci aux auteurs de ces différents articles qui m’ont beaucoup aidé :
http://trac.mixam.info/mini2440/wiki/Qemu
http://code.google.com/p/mini2440/wiki/QEmuSDCardImage
http://project4fun.com/node/33





