A few years ago, people were saying they were able to emulate a Raspberry Pi 2 or 3 in QEMU. However as of late 2020, I am unable to do so. Can anyone let me know what the correct command line arguments are to emulate a Raspberry Pi 3 or 4 in either 32- or 64-bit mode is today? My goal is 64-bit Raspberry Pi OS. I have Qemu 5.1.0 installed.
You can use
qemu-system-arm -machine type=raspi2 -m 1024 -kernel vmlinux -initrd initramfs qemu-system-aarch64 -machine type=raspi3 -m 1024 -kernel vmlinux -initrd initramfs
The kernel and initramfs you can find on the first partition of your SD card or extract from the OS image for a Raspian Pi.
If you want a 64bit OS then you need to use qemu-system-aarch64 with the raspi3 type and a 64bit kernel.
Note: qemu only emulates some aspects of the Rapsberry Pi. Linux kernel can be build generic enough to handle the differences on the fly but that depends on what your distribution has configured for the kernel. You might have to get a more generic kernel for it to boot properly.
What you are asking for precisely is apparently not yet possible for a normal user without developments.
Firstly, QEMU 5.0.0 does not support Raspberry Pi 3 or 4:
% qemu-system-arm -version QEMU emulator version 5.0.0 (Debian 1:5.0-5ubuntu9.2) % qemu-system-arm -M help|grep rasp raspi2 Raspberry Pi 2B
I don't have qemu version 5.1.0, please check.
Secondly, the latest Raspberry Pi OS Buster uses 32 bits, see https://www.raspberrypi.org/software/operating-systems/.
64 bits is unnecessary as long as Raspberry Pi does not have more than 4GB of RAM.
Indeed I see that Raspberry Pi 4 can have up to 8GB of RAM now and that 64 bit OS is coming:
I can answer for Raspberry Pi 2 with Raspberry Pi OS Buster 32 bits, if you are interested, let me know.
After many trials, I could emulate my Raspberry Pi 2 with this:
qemu-system-arm \ -M versatilepb \ -cpu arm1176 \ -m 256 \ -drive "file=raspbian_backup-2.img,if=none,index=0,media=disk,format=raw,id=disk0" \ -device "virtio-blk-pci,drive=disk0,disable-modern=on,disable-legacy=off" \ -net "user,hostfwd=tcp::5022-:22" \ -dtb versatile-pb-buster-5.4.51.dtb \ -kernel kernel-qemu-5.4.51-buster \ -append 'root=/dev/vda2 panic=1' \ -no-reboot
where raspbian_backup-2.img is the image of my personal Raspberry Pi 2 micro SDcard.
Unfortunately, I did this a few weeks ago and don't remember much more.
I use Ubuntu 20.10 with up to date packages.
One problem when trying this is that QEMU reacts slowly (at least on my old machine) so it may look as if stuck.
I don't like these parameters :
-m 256 -M versatilepb
I tried to do something like this :
--memory 1024 \ --import \ --disk /root/Desktop/zi/Work/Android/Raspy/Debian/2019-09-26-raspbian-buster-lite.img,format=raw,bus=virtio --network user,model=virtio
--boot 'uefi=RPI_EFI.fd,dtb=bcm2710-rpi-3-b-plus.dtb,kernel=kernel8.img,kernel_args=root=/dev/vda2 rootwait panic=1 dwc_otg.fiq_fsm_enable=0'
But I get this error :
ERROR internal error: Unexpected enum value 0 for virDomainDeviceAddressType