Skip to content

Instantly share code, notes, and snippets.

@26
Created May 18, 2021 14:02
Show Gist options
  • Save 26/b9e34b72eb80db89de0e1f830723913c to your computer and use it in GitHub Desktop.
Save 26/b9e34b72eb80db89de0e1f830723913c to your computer and use it in GitHub Desktop.
Script that handles everything (including downloads) to emulate a Raspberry Pi on your Linux machine
#/bin/sh
# Copyright 2021 Marijn van Wezel
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
image_zip_url='https://downloads.raspberrypi.org/raspios_full_armhf/images/raspios_full_armhf-2021-03-25/2021-03-04-raspios-buster-armhf-full.zip'
dtb_url='https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/10774708f17f5fbe528ab161978b0c19afebdb23/versatile-pb-buster-5.4.51.dtb?raw=true'
kernel_url='https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/10774708f17f5fbe528ab161978b0c19afebdb23/kernel-qemu-5.4.51-buster?raw=true'
image=2021-03-04-raspios-buster-armhf-full.img
dtb=versatile-pb-buster-5.4.51.dtb
kernel=kernel-qemu-5.4.51-buster
wget -nc $image_zip_url -O $image.zip
wget -nc $dtb_url -O $dtb
wget -nc $kernel_url -O $kernel
unzip -n $image.zip
# https://raspberrypi.stackexchange.com/a/120765
qemu-system-arm \
-M versatilepb \
-cpu arm1176 \
-m 256 \
-drive "file=$image,if=none,index=0,media=disk,format=raw,id=disk0" \
-device "virtio-blk-pci,drive=disk0,disable-modern=on,disable-legacy=off" \
-net "user,hostfwd=tcp::5022-:22" \
-dtb $dtb \
-kernel $kernel \
-append 'root=/dev/vda2 panic=1' \
-no-reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment