Skip to content

Instantly share code, notes, and snippets.

@chetbox
Last active March 5, 2025 16:04

Revisions

  1. chetbox revised this gist Jul 15, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion launch-qemu-rpi-3.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ qemu-system-aarch64 \
    -drive "if=sd,format=raw,file=$1" \
    -kernel kernel8.img \
    -m 1G -smp 4 \
    -serial stdio \
    -serial mon:stdio \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \
    -usb -device usb-mouse -device usb-kbd \
  2. chetbox created this gist Jul 15, 2023.
    41 changes: 41 additions & 0 deletions launch-qemu-rpi-3.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/bin/bash

    # Requirements:
    # - macOS
    # - qemu - `brew install qemu`
    # - A raw 64-bit Raspberry Pi system image to boot (Usually a .img)

    set -e

    if [[ -z "$1" ]]; then
    echo "Disk image expected as argument" 1>&2
    exit 1
    fi

    # Mount disk and find where /boot is mounted
    BOOT_MOUNT=$(
    hdiutil attach -imagekey diskimage-class=CRawDiskImage "$1" | grep 'Windows_FAT_32' | sed 's/.*\t//'
    )

    # Copy required files to local folder
    cp "$BOOT_MOUNT/bcm2710-rpi-3-b-plus.dtb" ./
    cp "$BOOT_MOUNT/kernel8.img" ./

    # Unmount disk
    hdiutil detach "$BOOT_MOUNT"

    # Make sure the disk is on a power of two boundary for QEMU
    qemu-img resize -f raw "$1" 8G

    qemu-system-aarch64 \
    -M raspi3b \
    -cpu cortex-a72 \
    -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" \
    -dtb bcm2710-rpi-3-b-plus.dtb \
    -drive "if=sd,format=raw,file=$1" \
    -kernel kernel8.img \
    -m 1G -smp 4 \
    -serial stdio \
    -device usb-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \
    -usb -device usb-mouse -device usb-kbd \