Run Nixos rpi4 image (ARM SD image) by QEMU emulation

Hi Folks,

I want to test Raspberry Pi builds on my laptop by emulating Raspberry Pi.

I know that this is possible by running QEMU with official Raspberry Pi image and with Ubuntu Raspberry Pi images as described for example here.

I tried to do the same with NixOS Raspberry Pi image (which is generic SD image).

I downloaded https://hydra.nixos.org/build/237120771/download/1/nixos-sd-image-23.11pre531102.fdd898f8f79e-aarch64-linux.img.zst and:

I prepared disk image:

cat ....img.zst | unzstd -o disk.img
qemu-img resize disk.img 8G

I temporarily mounted each partitions and copied:

cp mounted/bcm2711-rpi-4-b.dtb treeblob.dtb # from first partition
cp mounted/boot/nixos/vgr4bvi1msxfjhkr6sijqj07slchvbf4-linux-6.1.55-Image kernel.img # from second partition

and then I run

qemu-system-aarch64 \
    -machine raspi3b \
    -cpu cortex-a72 \
    -smp 4 -m 1G \
    -dtb treeblob.dtb \
    -drive "file=disk.img,format=raw,index=0,if=sd" \
    -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::50022-:22 \
    -monitor tcp:127.0.0.1:50021,server,nowait \
    -nographic

And nothing. I tried with -nographic which should give me serial port output and I also tried without -nographic which should give me VGA output. But I didn’t get any serial / VGA output.

I assume there is something wrong with QEMU configuration and what works for Raspbian, doesn’t work for NixOS.

Could you please help? Do you know how to run it?

Thank you.

Maybe try -cpu arm1176

Thank you, but that doesn’t work.

I tried another 10 configurations with -kernel linux-6.1.55-Image and -kernel u-boot-rpi3.bin and -kernel u-boot-rpi4.bin but nothing is giving me any serial / VGA output.

Maybe instead of -kernel get BIOS file and run it like:

qemu-system-aarch64 -M virt -cpu cortex-a72 \
  -m 256M -smp 2 -nographic \
  -bios QEMU_EFI.fd \
  -drive if=none,file=disk.img,id=hd0,format=raw -device virtio-blk-device,drive=hd0 \
  -device virtio-net-device,netdev=vmnic -netdev user,id=vmnic

I found QEMU_EFI.fd in qemu-efi-aarch64_2022.11-6_all.deb but I’m getting

BdsDxe: failed to load Boot0001 "UEFI Misc Device" from VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000): Not Found

>>Start PXE over IPv4.

I don’t get it - why NixOS SD image that works on rpi doesn’t run under QEMU…

It would be super useful to figure out how to run Raspberry Pi image to test ARM config before build.

Any QEMU experts?

Thank you.

The following works with Raspbian:

qemu-system-aarch64 \
    -machine raspi3b \
    -cpu cortex-a72 \
    -smp 4 -m 1G \
    -kernel kernel.img \
    -dtb treeblob.dtb \
    -drive "file=2023-05-03-raspios-bullseye-arm64.img disk.img,format=raw,index=0,if=sd" \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
    -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::1234-:22 \
    -nographic

Does it not work with NixOS image?

Unfortunately it doesn’t

This thread is related but we never were able to get SSH running.

1 Like

Thank you.

For some reason my Google foo didn’t find the post.

I’ve just run

qemu-system-aarch64 \
    -M raspi3b \
    -dtb ./bcm2837-rpi-3-b.dtb \
    -m 1G \
    -smp 4 \
    -drive "format=raw,file=disk.img" \
    -kernel ./u-boot-rpi3.bin \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::2222-:22 \
    -append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait" \
    -nographic

and it gives me some output. As you mentioned I can’t SSH-in but it’s a progress :wink: .