qemu How to emulate a Raspberry Pi 3 and boot FreeBSD?

I've spent the better part of the day trying to figure this out. But as I'm new to QEMU, I can't seem to figure it out. Writing up all the different ways would take way too long to condense together into a readable form. Rest assured that I've worked my way through all of this and countless Linux-based instructions that won't help:


This is why I'm asking if someone has figured out a working qemu-system-aarch64 command to get this up and running.

My goal is to be able to test (and mess with) images for various Pi's that currently run on Raspbian.

Please note that I'm not looking to emulate FreeBSD on a Raspberry Pi or Linux in general (there are countless guides for that), I'd like to run an emulated Raspberry Pi 3 in QEMU running FreeBSD instead of Raspbian.

Any kind of useful pointer is highly appreciated, thank you!
 
Have you tried "qemu-system-aarch64 -M raspi3b ..."? You can see which boards are supported with "qemu-system-aarch64 -M help".
From https://www.qemu.org/docs/master/system/target-arm.html :
Because Arm systems differ so much and in fundamental ways, typically operating system or firmware images intended to run on one machine will not run at all on any other. This is often surprising for new users who are used to the x86 world where every system looks like a standard PC. (Once the kernel has booted, most userspace software cares much less about the detail of the hardware.)

If you already have a system image or a kernel that works on hardware and you want to boot with QEMU, check whether QEMU lists that machine in its -machine help output. If it is listed, then you can probably use that board model. If it is not listed, then unfortunately your image will almost certainly not boot on QEMU. (You might be able to extract the filesystem and use that with a different kernel which boots on a system that QEMU does emulate.)
 
Tried it occasionally some time ago with optiion -M raspi3b with a working rpi3 SD image. It gives a black vm screen and the host cpu causes high load on all cores but nothing happens. I have no idea what the CPU is doing. Iy might be in a boot-loop.
 
Sorry all, I should've posted the general command I tried different variations of.


sh:
qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a72 \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 init_uart_clock=3000000 enable_uart=1 kernel=u-boot.bin kernel7=u-boot.bin dtoverlay=mmc" \
    -dtb ./bcm2709-rpi-2-b.dtb \
    -sd ./FreeBSD-15.1-RELEASE-arm-armv7-GENERICSD.img \
    -m 1G -smp 4 \
    -serial stdio \
    -kernel ./u-boot.bin \
    -usb -device usb-mouse -device usb-kbd \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22

I can drop the append flag, use "-drive" instead of "-sd", remove all lines except the bare minimum, nothing changes at all.

Whatever I try, it just leads to what MG described: a black screen and high CPU usage. Even running without graphics and trying to dump to stdio doesn't yield any additional output. Doing the same with a Raspbian image (swapping the kernel file of course) works pretty much immediately.
 
Try bcm2710-rpi-3-b.dtb and cortex-a53 as they correctly reflect rpi3b. Finally, use FreeBSD-15.1-RELEASE-arm64-aarch64-RPI.img instead of arm7 & generic. Also, make it a multiple of GB with the truncate command. Though I can believe something is broken.
 
With the following it shows a screen in X11 and boots until it can't find root (also failed on usb). No further input is possible in the X screen or the sshed-in terminal window where I started the command below. Hopefully this points you in the right direction. Now it is a matter of picking the right options!
Code:
qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a53 \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 init_uart_clock=3000000 enable_uart=1 kernel=u-boot.bin kernel7=u-boot.bin dtoverlay=mmc" \
    -dtb ./bcm2710-rpi-3-b.dtb \
    -sd ./FreeBSD-15.1-RELEASE-arm64-aarch64-RPI.img \
    -m 1G -smp 4 \
    -serial stdio \
    -kernel ./u-boot.bin \
    -usb -device usb-mouse -device usb-kbd \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22
 
Back
Top