Compilation et installation de QEMU

Résumé

Installation de QEMU et compilation à partir des sources pour un système Debian ou Debian like comme Ubuntu.

Compiler QEMU

  • Installation des packages nécessaires.

$ sudo apt-get install pip
$ pip install tomli
$ wget https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip
$ unzip ninja-linux.zip
$ sudo apt install unzip
$ unzip ninja-linux.zip
$ sudo mv ninja /usr/local/bin/
$ mv ninja-linux.zip ~/Downloads/
$ sudo apt install meson
$ sudo apt install libglib2.0-dev
  • Clonage des sources

Cloner et choisir le tag de la dernière version stable. Vous ne voulez pas travailler sur le master…

$ git clone https://github.com/qemu/qemu.git
$ git tag
...
v9.2.1
v9.2.2
v9.2.3
v9.2.4
$ git checkout v9.2.4
$ git switch -c v9.2.4-local
Switched to a new branch 'v9.2.4-local'
  • Construire QEMU

$ cd qemu
$ mkdir build
$ cd build/
$ ../configure --target-list=aarch64-softmmu,arm-softmmu
$ make -j 8
$ sudo make install
  • Démarrer avec u-boot sur une carte virtuelle

#!/bin/sh

UBOOT=/.PATH.TO.UBOOT/u-boot

[[ -e envstore.img ]] || qemu-img create -f raw envstore.img 64M
[[ -e disk01.img ]] || qemu-img create -f qcow2 disk01.img 8M

qemu-system-arm -machine virt \
        -bios $UBOOT/u-boot/u-boot.bin \
        -drive if=pflash,format=raw,index=1,file=envstore.img \
        -netdev tap,id=net0 -device e1000,netdev=net0 \
        -drive if=none,file=disk01.img,id=mydisk \
        -device nvme,drive=mydisk,serial=foo \
        -nographic

Utilisation de QEMU avec une carte Vexpress

Démarrer QEMU avec Linux

Choisir la carte Vexpress et compiler Linux

#!/bin/sh

LINUX=/.PATH.TO.LINUX/linux

qemu-system-arm --machine vexpress-a9 \
        -kernel $LINUX/arch/arm/boot/zImage \
        -dtb $LINUX/arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb \
        -append "console=ttyAMA0" \
        -initrd initrd.gz \
        -net nic -net tap \
        -nographic

Démarrer QEMU avec u-boot et charger Linux

  • Préparer Linux Vexpress pour QEMU

$ cd linux
$ make vexpress_defconfig
$ export LOADADDR=0x62008000
$ make uImage
  • fabrication initrd pour uboot

$ mkimage -A arm -O linux -T ramdisk -C gzip -d initrd.gz initramfs.uImage
  • copie vers serveur

$ cp arch/arcm/boot/uImage /srv/tftp/
$ cp arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb /srv/tftp/
$ cp initramfs.uImage /srv/tftp/
  • Démarrer avec u-boot sur une carte vexpress

# LINUX=/home/pmorel/Dev/linux
# UBOOT=/home/pmorel/Dev/u-boot-master

# qemu-system-arm --machine vexpress-a9 \
        -kernel $UBOOT/u-boot \
        -dtb $LINUX/arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb \
        -append "console=ttyAMA0" \
        -net nic -net tap \
        -m 1G \
        -nographic
  • Lancer Linux depuis un serveur TFTP

qemu> set serverip 192.168.2.1
qemu> set ipaddr 192.168.2.2
qemu> tftp 0x90000000 uImage
qemu> tftp 0x70000000 initramfs.uImage
qemu> tftp 0x80000000 vexpress-v2p-ca9.dtb
qemu> bootm 0x90000000 0x70000000 0x80000000

qemu> set bootcmd "set serverip 192.168.2.1; set ipaddr 192.168.2.2; tftp 0x90000000 uImage; tftp 0x70000000 initramfs.uImage; tftp 0x80000000 vexpress-v2p-ca9.dtb; bootm 0x90000000 0x70000000 0x80000000 "
$ make vexpress_defconfig