Raspberry Pi notes : Emulating RPi (Raspbian wheezy) on Qemu

Emulation is a necessary aspect of embedded system development and Qemu is the right open source tool to do so for linux based SBCs.

To emulate RPi on Qemu, you will need two necessary files.

1) Rpi kernel (`git clone https://github.com/dhruvvyas90/qemu-rpi-kernel.git` or dowload this zip file)

2) Rpi rootfs (That would be second portion of official .img file) You can have a look at https://www.raspberrypi.org/downloads/

You will also need to have latest Qemu for your OS. Go to official (http://wiki.qemu.org/Download).

You can probably download Qemu by using package manager as well.

1) For ubuntu (and any debian based OSes):

`sudo apt-get install qemu`

2) For Mac OS X :

`brew install qemu`

3) For windows users :

You will have to download Qemu installer.

Once, Qemu installed and you have necessary files for emulation as mentioned above, Follow these particular steps for emulating RPi.

This particular guide shows you how to prepare image for emulating Raspbian-wheezy image. If you’re trying to emulate Jessie images, you should follow the other guide on this blog.

  1. `qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda image-file-name.img`
  2. You should get # prompt (bash) at the end of processing.
  3. `nano /etc/ld.so.preload
  4. Comment the 1st line saying /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so by putting # in front of it.
  5. Now, `nano /etc/udev/rules.d/90-qemu.rules`
  6. Add these lines.

KERNEL=="sda", SYMLINK+="mmcblk0"

KERNEL=="sda?", SYMLINK+="mmcblk0p%n"

KERNEL=="sda2", SYMLINK+="root"

  1. `sudo poweroff`
  2. Re-emulate by this command, `qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda image-file-name.img`

Key notes :

You can have maximum ram upto 256 only as there’s a bug in versatilepb which doesn’t allow to emulate more than 256 MB.

You might want to set up ssh by adding this extra flag while using Qemu-redir tcp:2222::22

Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *