Emulating a Raspberry Pi in QEMU | Interrupt

I notice two things with this command:

  1. usb-ehci device is used, which attaches to a PCI bus.

    $ qemu-system-aarch64 -device help  | grep -i usb-ehci
     name "ich9-usb-ehci1", bus PCI
     name "ich9-usb-ehci2", bus PCI
     name "usb-ehci", bus PCI
    
  1. bcm2711-rpi-4-b.dtb devicetree is passed, but the emulated machine is raspi3, rather than raspi4
  • You should match the dtb file passed to the emulated hardware machine
  • In this case, the raspi3 machine would need the bcm2710-rpi-3-b.dtb

Note that for raspi4, the bcm2711-rpi-4-b.dtb devicetree file has disabled the USB controller. So, to enable USB keyboard & mouse, the .dtb file must be decompiled to .dts, patched, and recompiled back to .dtb. I have created a Makefile-based qemu-raspbian project here to assist with this.

Whichever machine you choose to emulate, use the corresponding .dtb devicetree file that matches that machine. Also, keep in mind that some of the raspi* machines don’t support a PCI bus. Therefore, avoid using PCI devices on those QEMU machine types and opt for the usb-* devices instead.

For the Raspbian USB driver, you may choose between using the usb_otg and the dwc2 drivers. For example, my project disabled usb_otg and used dwc2, configuring these in /boot/config.txt. If you choose usb_otg, nothing else needs to be done, because the current Raspbian bookworm image already has this enabled by default.