Wednesday, July 2, 2014

Raspberry-Pi Emulation on OSX Maverick

Here's what did to emulate a Raspberry-PI on OSX Mavericks (v10.9.3)

 1. Install qemu
 2. Setup emulator (http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/)
 3. Make a golden image
 4. Copy WIP image to SD card

Install qemu

You will need homebrew installed, then simply run:

> brew update ; brew install qemu

If you have problems, maybe fallback to this blog post that I used before homebrew had a qemu formula.

Setup emulator

Take a look at this blog post from xecdesign.com. Follow the instructions for "Preparing the environment", "Check that you have everything" and "First Boot".

The key points are to create a working directory and download the kernel and an .img file to it.  The .img file should the one you want to boot/configure.

Here is the command that I used to launch my image for the first time:

> 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" -hda 2013-12-20-wheezy-raspbian.img


Make a "Golden Image"

The "First Boot" section of that blog post mentions changing some stuff.  As mentioned, I had to comment out the libcofi_rpi.so line in /etc/ld.so.preload, as well as, creating the new file /etc/udev/rules.d/90-qemu.rules, then halt the system.

Now that my .img is a good base image for the emulator and my PI,  I treat it as a "golden image" (2013-12-20-wheezy-raspbian.img in the above example).  As such, my process is to make a copy named wip.img and use this copy for subsequent boots.  Using wip.img allows me to simply delete it if I foobar something  -- then I can start over with a fresh copy from my golden image.  But this is simply a suggestion.

Now lets boot out image and start configuring it!  I do so with the same command as above, but I point it to my WIP image:

> 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" -hda wip.img

Once you are done hacking on it, then halt the system and copy the image to an SD card.

Copy image to SD Card

Once you get the image on your mac configured the way you want it.  Copy your .imf file to an SD card and see if it will boot on your PI.

   > sudo dd bs=1024 if=wip.img of=/dev/disk1
 > sync

Credits

Special thanks to http://xecdesign.com/ and http://mikelev.in/ for their tips that got this going!

3 comments:

Arangs said...

Pretty cool @caryp!

DM Mace said...
This comment has been removed by the author.
Mike Levin said...

You're welcome!