With my Raspberry Pi on-order, I thought I’d get a head-start on having some fun by getting the Debian image running under QEMU. A few false starts later and it’s working just fine, however I wanted to get USB going… QEMU supports USB emulation, but I had to compile my own version – then compile my own kernel to run inside QEMU… Here is what I did:
The first problem I faced was that the supplied QEMU for my Debian Squeeze (stable) workstation doesn’t support the right ARM processor emulator, so get and build QEMU from scratch, but first make sure you don’t already have one installed:
dpkg -l | fgrep -i qemu
and if you find anything, then purge it. Now fetch and install QEMU:
cd
mkdir -p rpi/qemu ; cd rpi/qemu
wget http://wiki.qemu.org/download/qemu-1.0.tar.gz
tar zzvf qemu-1.0.tar.gz
cd qemu-1.0
./configure –target-list=arm-softmmu,arm-linux-user
make
sudo make install
with a bit of luck that will just work although the ./configure stage may suggest some packages to install.
The next step is to get, configure and compile a new Linux Kernel. This may be quite daunting if you’ve never done it before, and I offer a few alternatives – the first is to fetch a pre-compiled kernel (easy), then next is to fetch the kernel config file and finally to create your own kernel config file (harder) and compile your own kernel (harder) However, before you compile the kernel, there is a patch you need to apply to it which can be found online in several places, but also on my server as detailed below.
I suggest starting with my pre-compiled kernel, then fetch the config file and patch to compile your own.
cd ~/rpi
wget http://unicorn.drogon.net/rpi/zImage
or if you want to get the kernel .config file:
wget http://unicorn.drogon.net/rpi/config
wget http://unicorn.drogon.net/rpi/linux-arm.patch
You’ll then need to fetch a kernel (I used 3.1.9 here), get the cross compiler tools, compile and install the kernel, etc. I’ll do another article on that, but at it gets close to hardware time, it might not be needed as you will be able to compile a kernel on the Raspberry Pi itself (although it might take all night!)
The final part of the puzzle is to get the Debian SD card image. I used BitTorrent to fetch the file and it’s probably still the best way to get it now. Start at the downloads page on the Raspberry Pi website, or use this direct link to get the torrent file.
You may have read a lot of writings on splitting up that file, working out some magical offsets, etc. but none of that is required at all! This is what’s needed to start QEMU using the supplied Debian image and the kernel you just fetched:
Lets assume you have the zImage kernel and the Debian image in the same directory. Edit this into a little script called (e.g.) go:
qemu-system-arm -M versatilepb -cpu arm1176 -m 192 \
-hda debian6-17-02-2012.img \
-kernel zImage \
-append "root=/dev/sda2" \
-serial stdio -redir tcp:2222::22 \
-usb -usbdevice host:0403:6001
and run it by typing
sh go
Note the last line – that tells QEMU to use USB device with id 0403:6001 on the host PC and assign it to the emulated CPU. You identify the device with the lsusb command on the host. That device on my workstation is the USB serial port to an Arduino – more on connecting the Raspberry Pi to an Arduino later…
If all goes well, it should look like this:
I can’t claim originality for it all – I’ve picked a lot of this up from online resources, the Raspberry Pi forums and elsewhere – e.g. cnx-software