Last active
November 16, 2024 20:18
-
-
Save chetbox/3d2624b3727b35cf82d68f21f2449e2c to your computer and use it in GitHub Desktop.
Run Raspberry Pi 64 system image with QEMU on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 mon:stdio \ | |
-device usb-net,netdev=net0 \ | |
-netdev user,id=net0,hostfwd=tcp::5555-:22 \ | |
-usb -device usb-mouse -device usb-kbd \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment