Skip to content

Instantly share code, notes, and snippets.

@smoser
Last active January 18, 2023 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/19fc21d9dc142ac7ea7b5339858f5116 to your computer and use it in GitHub Desktop.
Save smoser/19fc21d9dc142ac7ea7b5339858f5116 to your computer and use it in GitHub Desktop.
raspberry pi in qemu / Romi emulation

Raspberry pi / Romi in qemu

When working with photonvision and without a romi in front of me, I decided to give qemu a try.

It works, but it is very slow.

See the 'boot' script provided for booting.

Getting Romi 2023 image going.

Romi notes

  • system reboots twice before staying up
  • first boot runs /usr/lib/raspberrypi-sys-mods/firstboot
  • not sure what the second boot does
  • third boot stays up.

Get system deps

sudo apt-get install qemu-system-arm cloud-image-utils

Download

Download the image and grab kernel and dtb (device tree) file out.

$ wget https://github.com/wpilibsuite/WPILibPi/releases/download/v2023.1.1/WPILibPi_image-v2023.1.1-Romi.zip
$ unzip WPILibPi_image-v2023.1.1-Romi.zip
$ sudo mount-image-callback --read-only --part=1 \
    WPILibPi-v2023.1.1_2023-01-16-Romi.img -- \
    sh -c \
    'cp -v $MOUNTPOINT/cmdline.txt $MOUNTPOINT/bcm2710-rpi-3-b.dtb $MOUNTPOINT/kernel8.img .'

Boot

Use 'boot' script below. Things to note:

  • I took the cmdline from cmdline.txt and adjusted a bit
  • I do not think the root=PARTUUID parameter to work although it should have (partition table is MBR and the disk label-id matched the PARTUUID per sfdisk --dump).
  • console=ttyAMA0 is what you want for console output.
  • Once it is up, you can ssh to localhost port 22, get to guests romi web interface at http://localhost:5580 and photonvision web interface at http://localhost:5800

Links

Just some links to pages that helped me along:

#!/bin/sh
boot() {
local cmdline="console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait"
local extra="$1"
[ $# -ge 1 ] && shift
local hfwd="hostfwd=tcp::5555-:22"
hfwd="$hfwd,hostfwd=tcp::5800-:5800"
hfwd="$hfwd,hostfwd=tcp::5580-:80"
qemu-system-aarch64 -machine type=raspi3b -m 1024 \
-nographic \
-sd disk.img -nographic \
-kernel kernel8 -dtb ./bcm2710-rpi-3-b-plus.dtb \
-device usb-net,netdev=net0 \
-netdev "user,id=net0,$hfwd" \
-append "$cmdline${extra:+ $extra}" "$@"
}
raw="${1:-WPILibPi-v2023.1.1_2023-01-16-Romi.img}"
first=false
if [ ! -f disk.img ]; then
qemu-img create -fqcow2 -Fraw -b "$raw" disk.img 8G
first=true
fi
if [ "$first" = "true" ]; then
boot init=/usr/lib/raspberrypi-sys-mods/firstboot -no-reboot
echo "finished first boot"
fi
boot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment