Skip to content

Instantly share code, notes, and snippets.

@AndrewFasano
Last active March 10, 2020 15:20
Show Gist options
  • Save AndrewFasano/ec8806671cdbc91d3b9e9407bffa7eff to your computer and use it in GitHub Desktop.
Save AndrewFasano/ec8806671cdbc91d3b9e9407bffa7eff to your computer and use it in GitHub Desktop.
Guide to running a raspberry PI image in PANDA

Instructions for botting a Raspberry PI image in PANDA:

These steps mostly mirror those from the great guide at https://azeria-labs.com/emulate-raspberry-pi-with-qemu/ except for how to modify the guest's fstab file.

Download and extract filesystem

$ wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2017-04-10/2017-04-10-raspbian-jessie.zip
$ unzip 2017-04-10-raspbian-jessie.zip

Get pre-built linux kernel for RPi

$ git clone git@github.com:dhruvvyas90/qemu-rpi-kernel.git

Update fstab so the filesystem mounts correctly. Note the offset argument is 512 * the start offset of the 2nd partition from fdisk -l. Should be 47185920 unless the image changes.

$ OFFSET=$(fdisk -l 2017-04-10-raspbian-jessie.img  | grep img2 | awk '{print $2*512}')
$ sudo mkdir /mnt/rpi
$ sudo mount -v -o offset=$OFFSET -t ext4 ./2017-04-10-raspbian-jessie.img /mnt/rpi/

Edit fstab to change PARTUUID-based identification to /dev/sdaX

$ sudo vim /mnt/rpi/etc/fstab

Replace PARTUUID-...01 with /dev/sda1 and PARTUUID-...02 with /dev/sda2

Unmount the filesystem

$ sudo umount /mnt/rpi

Run PANDA

$ panda-system-arm \
  -M versatilepb \
  -cpu arm1176 \
  -m 256 \
  -kernel ./qemu-rpi-kernel/kernel-qemu-4.14.79-stretch \
  -append "root=/dev/sda2 rootfstype=ext4 rw" \
  -dtb ./qemu-rpi-kernel/versatile-pb.dtb \
  -hda ./2017-04-10-raspbian-jessie.img \
  -nographic \
  -no-reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment