Difference between revisions of "Xen ARM with Virtualization Extensions/qemu-system-aarch64"

From Xen
Line 22: Line 22:
 
== Install Xen ==
 
== Install Xen ==
   
QEMU works well with UEFI firmware for the emulated machine. To get the system working, download an Aarch64 UEFI ready distro image, like [https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-arm64-uefi1.img xenial-server-cloudimg-arm64-uefi1.img], then:
+
QEMU works well with UEFI firmware for the emulated machine. To get the system working, download an Aarch64 UEFI ready distro image, like [https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-arm64-uefi1.img xenial-server-cloudimg-arm64-uefi1.img].
  +
Then, clone Linux and build the kernel using the defconfig for arm64 (make defconfig && make Image.gz).
   
  +
Run QEMU the first time, booting Linux directly (replace the MAC_ADDRESS and the paths). The following command uses user-networking and forwards port 2222 from the host to port 22 inside the virtual machine:
$ losetup /dev/loop0 /path/to/xenial-server-cloudimg-arm64-uefi1.img
 
$ kpartx -a /dev/loop0
 
$ mount /dev/mapper/loop0p15 /mnt
 
   
  +
$ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
Follow [[Xen_ARM_with_Virtualization_Extensions#Building_Xen_on_ARM]] to build Xen on ARM. Then, copy the Xen on ARM efi binary to the image:
 
  +
-machine virt,gic_version=3 -machine virtualization=true \
  +
-cpu cortex-a57 -machine type=virt -nographic \
  +
-smp 4 -m 4000 \
  +
-kernel /path/to/linux.git/arch/arm64/boot/Image.gz --append "console=ttyAMA0 root=/dev/vda1" \
  +
-netdev user,id=hostnet0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=hostnet0,mac=MAC_ADDRESS \
  +
-drive if=none,file=/path/to/xenial-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0
   
  +
Follow [[Xen_ARM_with_Virtualization_Extensions#Building_Xen_on_ARM]] to build Xen on ARM. Then, copy the Xen on ARM efi binary and the Linux kernel to the image:
$ cp /path/to/xen.git/xen/xen.efi /mnt
 
  +
  +
$ scp -P2222 /path/to/linux.git/arch/arm64/boot/Image.gz root@127.0.0.1:/boot/efi/kernel
  +
$ scp -P2222 /path/to/xen.git/xen/xen.efi root@127.0.0.1:/boot/efi
   
 
Let's write a config file for it:
 
Let's write a config file for it:
   
$ vi /mnt/boot/xen.cfg
+
$ vi /boot/xen.cfg
   
 
Let's use the following config:
 
Let's use the following config:
Line 41: Line 49:
 
kernel=kernel root=/dev/vda1 init=/bin/sh rw console=hvc0
 
kernel=kernel root=/dev/vda1 init=/bin/sh rw console=hvc0
 
dtb=virt-gicv3.dtb
 
dtb=virt-gicv3.dtb
 
Build a Linux kernel image for Dom0 and copy the binary to /mnt/kernel.
 
   
 
Now we need the device tree binary. QEMU can generate one for you with the following command:
 
Now we need the device tree binary. QEMU can generate one for you with the following command:
   
$ /local/path/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
+
$ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
 
-machine virt,gic_version=3 \
 
-machine virt,gic_version=3 \
 
-machine virtualization=true \
 
-machine virtualization=true \
 
-cpu cortex-a57 -machine type=virt \
 
-cpu cortex-a57 -machine type=virt \
 
-smp 4 -m 4096 -display none \
 
-smp 4 -m 4096 -display none \
-machine dumpdtb=/mnt/virt-gicv3.dtb.dtb
+
-machine dumpdtb=virt-gicv3.dtb.dtb
  +
$ scp -P2222 virt-gicv3.dtb.dtb root@127.0.0.1:/boot/efi
   
We have written everything we need to the disk image. Let's umount /mnt and proceed to download the UEFI firmware binary from Linaro: [http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_CLANG35/QEMU_EFI.fd].
+
We have written everything we need to the disk image. Let's poweroff the virtual machine and proceed to download the UEFI firmware binary from Linaro: [http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_CLANG35/QEMU_EFI.fd].
   
   
 
== Run QEMU ==
 
== Run QEMU ==
   
The following command create a new emulated AArch64 machine with 4 Cortex A57s, 4G of RAM. The command below uses user networking in QEMU, other network configuration (bridging) are possible. Please change MAC_ADDRESS for the emulated machine and path to the guest image.
+
The following command create a new emulated AArch64 machine with 4 Cortex A57s, 4G of RAM, booting from EFI. The command below uses user networking in QEMU, other network configuration (bridging) are possible. Please change MAC_ADDRESS for the emulated machine and path to the guest image.
   
 
$ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
 
$ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \

Revision as of 00:21, 24 October 2017

QEMU AArch64 Emulator

QEMU is an Open Source GPLv2 software emulator. It can emulate a large range of machines of different architectures, including Cortex A57s based platforms.

The following steps help you setup QEMU to emulate an ARM64 machine and run Xen inside it.

Build QEMU

QEMU v2.10 requires a few fixes to be able to run Xen on ARM in a nested fashion. QEMU v2.11 will likely work out of the box. For now, the simplest thing to do is to apply the appended patch. The following steps apply the patch and build QEMU:

$ git clone git://git.qemu.org/qemu.git

If you are running QEMU <= v2.10, save this patch to a text file, then:

$ patch -p1 < /path/to/Qemu-aarch64.patch

Finally build QEMU:

$ ./configure --target-list=aarch64-softmmu
$ make

Install Xen

QEMU works well with UEFI firmware for the emulated machine. To get the system working, download an Aarch64 UEFI ready distro image, like xenial-server-cloudimg-arm64-uefi1.img. Then, clone Linux and build the kernel using the defconfig for arm64 (make defconfig && make Image.gz).

Run QEMU the first time, booting Linux directly (replace the MAC_ADDRESS and the paths). The following command uses user-networking and forwards port 2222 from the host to port 22 inside the virtual machine:

 $ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
   -machine virt,gic_version=3 -machine virtualization=true \
   -cpu cortex-a57 -machine type=virt -nographic \
   -smp 4 -m 4000 \
   -kernel /path/to/linux.git/arch/arm64/boot/Image.gz --append "console=ttyAMA0 root=/dev/vda1" \
   -netdev user,id=hostnet0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=hostnet0,mac=MAC_ADDRESS \
   -drive if=none,file=/path/to/xenial-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0

Follow Xen_ARM_with_Virtualization_Extensions#Building_Xen_on_ARM to build Xen on ARM. Then, copy the Xen on ARM efi binary and the Linux kernel to the image:

 $ scp -P2222 /path/to/linux.git/arch/arm64/boot/Image.gz root@127.0.0.1:/boot/efi/kernel
 $ scp -P2222 /path/to/xen.git/xen/xen.efi root@127.0.0.1:/boot/efi

Let's write a config file for it:

 $ vi /boot/xen.cfg

Let's use the following config:

 options=console=dtuart noreboot dom0_mem=512M
 kernel=kernel root=/dev/vda1 init=/bin/sh rw console=hvc0
 dtb=virt-gicv3.dtb

Now we need the device tree binary. QEMU can generate one for you with the following command:

 $ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
   -machine virt,gic_version=3 \
   -machine virtualization=true \
   -cpu cortex-a57 -machine type=virt \
   -smp 4 -m 4096 -display none \
   -machine dumpdtb=virt-gicv3.dtb.dtb
 $ scp -P2222 virt-gicv3.dtb.dtb root@127.0.0.1:/boot/efi

We have written everything we need to the disk image. Let's poweroff the virtual machine and proceed to download the UEFI firmware binary from Linaro: [1].


Run QEMU

The following command create a new emulated AArch64 machine with 4 Cortex A57s, 4G of RAM, booting from EFI. The command below uses user networking in QEMU, other network configuration (bridging) are possible. Please change MAC_ADDRESS for the emulated machine and path to the guest image.

 $ /path/to/qemu.git/aarch64-softmmu/qemu-system-aarch64 \
   -machine virt,gic_version=3 \
   -machine virtualization=true \
   -cpu cortex-a57 -machine type=virt \
   -smp 4 -m 4096 -display none \
   -serial mon:stdio \
   -bios /path/to/QEMU_EFI.bin \
   -netdev user,id=hostnet0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=hostnet0,mac=MAC_ADDRESS \
   -drive if=none,file=/path/to/xenial-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0