2014-05-26 21:31:00 +02:00
---
2015-11-13 12:59:26 +01:00
layout: arm
2014-05-26 21:31:00 +02:00
title: How to configure Qemu
---
2014-05-27 11:30:12 +02:00
##Target Pi on Mac
2014-04-15 18:25:35 +02:00
So even the idea is to run software on the Pi, not everyone has a Pi (yet :-)
2015-11-13 12:59:26 +01:00
Others, like me, prefer to develop on a laptop and not carry the Pi around.
2014-04-15 18:25:35 +02:00
For all those, this here explains how to emulate the Pi on a Mac.
2014-05-27 11:30:12 +02:00
Even if you have a Pi, [this explains ](/remote_pi.html ) a nice way to develop with it.
###Replace the buggy llvm
2014-04-15 18:25:35 +02:00
Written April 2014: as of writing the latest and greatest llvm based gcc (5.1) on Maverick (10.9) has a bug that makes qemu hang.
2014-05-28 19:52:26 +02:00
So type gcc -v and if the output contains "LLVM version 5.1", you must install gcc4.2. Easily done with homebrew:
2014-04-15 18:25:35 +02:00
2014-05-27 11:30:12 +02:00
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
2014-04-15 18:25:35 +02:00
2015-11-13 12:59:26 +01:00
This will not interfere with the systems compiler as the gcc4.2 has postfixed executables (ie gcc-4.2)
2014-04-15 18:25:35 +02:00
2014-05-27 11:30:12 +02:00
###Qemu
2014-04-15 18:25:35 +02:00
Then its time to get the Qemu. There may be other emulators out there, and i have read of armulator, but this is what i found discribed and it works and is "easy enough".
2014-05-27 11:30:12 +02:00
brew install qemu --env=std --cc=gcc-4.2
2014-04-15 18:25:35 +02:00
2015-11-13 12:59:26 +01:00
For people not on Maverick it may work without the -cc option.
2014-04-15 18:25:35 +02:00
2014-05-27 11:30:12 +02:00
###Pi images
2014-04-15 18:25:35 +02:00
Create a directory for the stuff on your mac, ie pi.
Get the latest Raspian image.
There seems to be some chicken and egg problem, so quemu needs the kernel seperately. There is one in the links.
2014-05-27 11:30:12 +02:00
###Configure
2014-04-15 18:25:35 +02:00
In the blog post there is some fun configuration, I did it and it works. Not sure what happens if you don't.
The booting is described below (you may or may not need an extra init=/bin/bash in the root... quotes), so boot your Pi and then configure:
2014-05-27 11:30:12 +02:00
nano /etc/ld.so.preload
2014-04-15 18:25:35 +02:00
Put a # in front of the first to comment it out. Should just be one line there.
Press ctrl-x then y then enter to save and exit.
(Optional) Create a file /etc/udev/rules.d/90-qemu.rules with the following content:
2014-05-27 11:30:12 +02:00
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
2014-04-15 18:25:35 +02:00
2015-11-13 12:59:26 +01:00
The kernel sees the disk as /dev/sda, while a real pi sees /dev/mmcblk0.
2014-04-15 18:25:35 +02:00
This will create symlinks to be more consistent with the real pi.
2014-05-27 11:30:12 +02:00
###Boot
2014-04-15 18:25:35 +02:00
There is quite a bit to the command line to boot the pi (i have an alias), here it is:
2014-05-27 11:30:12 +02:00
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 raspbian.img -redir tcp:2222::22
2014-04-15 18:25:35 +02:00
- the cpu is what braodcom precifies, ok
- memory is unfortuantely hardcoded in the versatilepb "machine"
- the kernel is the file name of the kernel you downloaded (or extracted)
- raspbian.img is the image you downloaded. Renamed as it probably had the datestamp on it
- the redir redircts the port 2222 to let you log into the pi
2014-05-27 11:30:12 +02:00
So
ssh -p 2222 -l pi localhost
2015-11-13 12:59:26 +01:00
2014-05-27 11:30:12 +02:00
will get you "in". Ie username pi (password raspberry is the default) and port 2222
2014-04-15 18:25:35 +02:00
Qemu bridges the network (that it emulates), and so your pi is now as connected as your mac.
2014-05-27 11:30:12 +02:00
###More Disk
2014-04-15 18:25:35 +02:00
The image that you download has only 200Mb free. Since the gcc is included and we're developing (tiny little files of) ruby, this may be ok. If not there is a 3 step procedure to up the space.
2015-11-13 12:59:26 +01:00
dd if=/dev/zero bs=1m count=2048 >> raspbian.img
2014-04-15 18:25:35 +02:00
The 2048 gets you 2Gb as we specified 1m (meg).
2015-11-13 12:59:26 +01:00
On the pi launch
2014-05-27 11:30:12 +02:00
sudo fdisk /dev/sda
2015-11-13 12:59:26 +01:00
2014-05-27 11:30:12 +02:00
This will probably only work if your do the (Optional) config above.
2014-04-15 18:25:35 +02:00
Say p, and write down the start of the second partition (122880 for me).
d 2 will delete the second partition
n p 2 will create a new primary second partition
write the number as start and just return to the end.
p to check
w to write and quit.
2015-11-13 12:59:26 +01:00
Reboot, and run
2014-05-27 11:30:12 +02:00
resize2fs
2014-04-15 18:25:35 +02:00
Links
-----
2014-05-27 11:30:12 +02:00
Blog post: [http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/ ](http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/ )
Kernel: [http://xecdesign.com/downloads/linux-qemu/kernel-qemu ](http://xecdesign.com/downloads/linux-qemu/kernel-qemu )
Rasbian file system(preferably be torrent): [http://www.raspberrypi.org/downloads/ ](http://www.raspberrypi.org/downloads/ )