Qemu provides qemu-system-aarch64 command to emulate aarch64 device.
Serial tty address is /dev/ttyAMA0.
Just as in x86_64, you may use raw or qcow2 disk images to run aarch64. After you initialized and partitioned one, download armtix rootfs archive with init of choice and unpack to this disk. Additional steps may be required depending on bootloader you choose.
You can use either u-boot or efi to boot qemu aarch64 VM.
This method is closer to the majority of real boards.
Firstly, you have to build u-boot binary. Clone u-boot git repo and cd to it. Configure and build with:
make CROSS_COMPILE=aarch64-linux-gnu- qemu_arm64_defconfig
make CROSS_COMPILE=aarch64-linux-gnu-
Copy u-boot.bin to directory you will run qemu from. In order to use
it as bootloader, pass -bios u-boot.bin
to qemu command
line.
For u-boot to find your kernel & initramfs, create the following script in the root of your boot partition:
setenv bootargs "root=/dev/<partname> rw rootwait console=ttyAMA0"
load scsi 0:1 ${kernel_addr_r} /Image
load scsi 0:1 ${ramdisk_addr_r} /initramfs-linux.img
booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr}
Here, scsi
is used for scsi disk bus, 0:1
means that kernel Image
and initramfs
initramfs-linux.img
are located in the root of the first
partition of the first disk. If you use virtio disk, replace
scsi
with virtio
. For loop devices you have to
use 0:0
to refer to the drive.
Assuming your script is saved as boot.cmd, run the following command:
mkimage -A arm -T script -d boot.cmd boot.scr
Do not replace other arguments of this command. File boot.scr must be in the root of the partition u-boot can read from (FAT32, ext2 / 3 /4).
Alternatively, you can use efi firmware provided by
edk2-aarch64
package. Copy
/usr/share/AAVMF/AAVMF_CODE.fd
and
/usr/share/AAVMF/AAVMF_VARS.fd
to the directory you run
qemu from. In order to use this firmware, pass
-drive file=AAVMF_CODE.fd,format=raw,if=pflash \
-drive file=AAVMF_VARS.fd,format=raw,if=pflash \
to qemu command line.
Using this method, you can then install and use aarch64 version of grub or efi stub to boot OS like in x86_64. Note, however, that installing grub on aarch64 booted w/o efi might be challenging.
If running on x86-64 machine, use the command like following:
qemu-system-aarch64 -machine virt -cpu cortex-a53 -smp 2 -m 1024 -bios u-boot.bin
You may use other cpu model (see “qemu-system-aarch64 -machine virt -cpu help” for full list).
On aarch64 you can use kvm:
qemu-system-aarch64 -machine virt,accel=kvm -cpu host -smp 2 -m 1024 -bios u-boot.bin
If you use EFI instead of u-boot, replace
-bios u-boot.bin
with commands provided in previous
section.
If you want your raw disk to be connected as scsi, add the following to your qemu command line:
-drive id=disk,file=root.img,format=raw,if=none -device ahci,id=ahci -device ide-drive,drive=disk,bus=ahci.0
Alternatively, to use virtio and qcow2, use:
-drive id=disk,if=none,index=0,format=qcow2,file=root.qcow2 -device virtio-blk,drive=disk,bootindex=0
You can also add virtual audio & video devices and any type of input devices similarly to how it is done for x86_64.