Whilst you can technically run eclipse on the Raspberry Pi, in reality it doesn't have the power to make it usable.  This guide is based on virtualizing Raspbian using QEMU

Sorry – but qemu is not the magic solution it seems it should be even running on Linux rather than windows.  After doing all this you will have raspbian and eclipse running on your Linux PC, but whilst its faster than the Windows version, its still quite slow.  The final making it fast part of this guide doesn't apply to the GUI – it just seems to be a method of making command line compiling fast.  If anyone finds a solution to this or wants to take on creating a better kernel for qemu to run to solve the problem please share it in the comments below!

QEMU

QEMU is an emulator for various CPUs. It works on Linux, Windows, FreeBSD and Mac OS X.

Resources

This guide was helped by these pages:

http://sentryytech.blogspot.co.uk/2013/02/faster-compiling-on-emulated-raspberry.html

http://imvoid.wordpress.com/2013/05/21/6-connecting-qemu-to-network/

This guide is based heavily on the brilliant page here which you may want to follow instead

 

Our Linux For PC Platform

We're windows users primarily and we did this using ubuntu 64bit running in vmware workstation. We gave it 2 processor cores and 2GB or ram (no science to this – just for info).

Most of the steps below are based on typing commands into the Terminal application in ubuntu.

Install QEMU For Linux

1. Install QEMU


sudo apt-get install qemu-kvm-extras

2. Create a directory for our virtual os files


mkdir ~/development
mkdir ~/development/raspberrypi-qemu

3. Download a QEMU-ready linux kernel for the Raspberry Pi from here

http://xecdesign.com/downloads/linux-qemu/kernel-qemu

Install Your Raspbian OS

Copy your .img file into the raspberrypi-qemu directory. This can be by downloading the latest Raspbian image file from http://www.raspberrypi.org/downloads. Unzip it if necessary and store the .img file in the directory.  The new images don't just work due to the new "/etc/ld.so.preload" file in in the raspbian image.  This typically causes the error "INIT: ID "1" respawning too fast: disabled for 5 minutes"​ and if you search on that error message you'll find guide of how to edit the "/etc/ld.so.preload" file within the iso to make it ready for use.

There's another way to deal with this though that we used instead. Just setup your SD card as you normally would for the raspberry pi and run it in a raspberry pi.   You can do the normal things like expand the filesystem to fill your SD card, which will mean you get the same size of disk in qemu also.  You still need to edit the "/etc/ld.so.preload" file as it will stop you being able to log on in qemu (it causes the load of some shared-library, which will make you unable to login causes "kernel panic" apparently), so from the command line on the RPi use:


sudo nano /etc/ld.so.preload

Now insert a # as the start of the only line in there to comment it out, giving:


#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so

Use CTRL+X to save and exit.  Then use this before powering off:


sudo halt

Now use Win32DiskImager to read the SD card and create an .iso image file.  Copy this into the raspberrypi-qemu directory used above.

Finally

Rename the ,iso image file to the following so all of the command below will work with a single common name (or leave it as is and modify the name in the commands below)

my_rpi_image.img

Running It

Paste the following into Terminal:


qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda my_rpi_image.img

 

You should get raspbian opening in a new window.   There will be a few error messages as it boots due to hardware that isn't there, but it should load to the login prompt and be ready to go.

QEMU Tips

To exit the QEMU window and get your mouse back use CTRL+ALT or CTRL+TAB

RAM Size

You might be tempted to alter the "-m 256" to something more useful like "-m 1024"?  You can't, you'll just get a black screen of nothing.  The physical memory map on versatile hardware does not allow more than 256MB of space for RAM and as we're using the versatile kernel we can't have more.

Networking

Qemu doesn't sort out an network bridge so you've got to provide it yourself. Its painful on linux but here's as simple a solution as we've found:


sudo apt-get install bridge-utils uml-utilities openvpn firestarter

Insert the TUN device module to the kernel


sudo modprobe tun

Look in the /dev/net folder and check a node called tun has been created. If not create it manually by typing the following commands


sudo mkdir /dev/net
sudo mknod /dev/net/tun c 10 200
sudo chmod 660 /dev/net/tun

You may well already have qemu-ifup and ifdown files so rename them to make way for new ones:


sudo mv /etc/qemu-ifup /etc/qemu-ifup-original

Open the Text Editor as root:


sudo gedit

Paste the following into the file


#!/bin/sh

#
# script to bring up the tun device in QEMU in bridged mode
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host ? change to suit your host
#

ETH0IP=192.168.0.73
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
IPNETMASK=255.255.255.0

#
# First take eth0 down, then bring it up with IP 0.0.0.0
#
ifconfig eth0 down
ifconfig eth0 0.0.0.0 promisc up

#
# Bring up the tap device (name specified as first argument, by QEMU)
#
openvpn --mktun --dev $1 -user 'id -un'
ifconfig $1 0.0.0.0 promisc up

#
# create the bridge between eth0 and the tap device
#
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 $1

#
# only a single bridge so loops are not possible, turn off spanning
# tree protocol
#
brctl stp br0 off

#
# Bring up the bridge with ETH0IP and add the default route
#
ifconfig br0 $ETH0IP netmask $IPNETMASK broadcast $BROADCAST
route add default gw $GATEWAY

#
# stop firewall ? comment this out if you don?t use Firestarter
#
service firestarter stop

Edit this if necessary for your local network:


ETH0IP=192.168.0.73
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
IPNETMASK=255.255.255.0

Save it as /etc/qemu-ifup

Use this to make it executible


sudo chmod +x /etc/qemu-ifup

Look at your current ip configuration


ifconfig

Now run the script


sudo /etc/qemu-ifup tap0

Now look at the ip configuration again to see the new bridge


ifconfig

Now we modify the qemu launch string to include:


-net nic -net tap,ifname=tap0

So it becomes:


cd development/raspberrypi-qemu

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda my_rpi_image.img -net nic -net tap,ifname=tap0

That's it, save the file, double click it and when raspbian boots it will have an IP address on your local network.

Setting The Raspberry Pi IP Address

To set it to a correct address on the local network use


sudo nano /etc/network/interfaces

Change this line


sudo ifdown eth0 && sudo ifup eth0

To this with your settings as needed


iface eth0 inet static
     address 192.168.0.74
     netmask 255.255.255.0
     gateway 192.168.0.1

Press CTRL+X to Exit

Restarting ubunto will reset the networking and clear the bridge.

Display Resolution

Qemu is limited to a max resolution of 800×600.  You can run the raspbian GUI in it fine, but who wants to at that resolution.  To get round this you can just use remote desktop to give the full 1920×1080.  


sudo apt-get install xrdp

This will install XRDP which allows you to use Remote desktop to remote into the qemu instance and get full monitor resolution.

To use it run the Remote Desktop application in ubuntu.  Enter the RPi IP address, username and password and connect.  You'll get a full size grey screen followed by the raspbian GUI.

 

Install Eclipse


sudo apt-get install eclipse

 

Making The Command Line Run Fast!

OK, this gets you to a similar point as using qemu on Windows – raspbian running on your desktop but pretty slowly.   This is where Linux architectural chroot magic comes in!  We don't pretend to understand the detail on this – its copied from the excellent guide here.

Install qemu-user-static


sudo apt-get install qemu-user-static

Now use kpartx to mount the image using loopback:


cd development/raspberrypi-qemu

​sudo kpartx -a -v my_rpi_image.img

If it doesn't work install kpartx


sudo apt-get install kpartx

Finish the loopboack:


sudo mount /dev/mapper/loop0p2 /mnt/temp

If that doesn't work create the temp directory first


sudo mkdir /mnt/temp

 

Now, copy the static QEMU binary and mount the special directories:


sudo cp /usr/bin/qemu-arm-static /mnt/temp/usr/bin
sudo mount -o bind /dev /mnt/temp/dev
sudo mount -o bind /proc /mnt/temp/proc
sudo mount -o bind /sys /mnt/temp/sys

 

Before we can enter the chroot environment, it's time for the magic command. First change to being the root user:


sudo -s

Now enter this (as a single line):


echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register

This registers the static QEMU we copied as arm-interpreter to the kernel. The path specified needs to be the same on both your linux machine and the Raspberry Pi environment.

Exit root user mode:


exit


Now we can chroot:


sudo chroot /mnt/temp

To see if it worked enter this and see if you get a armv7l respose:


uname -a

 

Now That Its All Done – The Commands To Startup Virtual Raspbian In Default QEMU Mode


sudo /etc/qemu-ifup tap0

cd development/raspberrypi-qemu

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda my_rpi_image.img -net nic -net tap,ifname=tap0

The Commands To Startup Virtual Raspbian In FAST CHROOT QEMU Mode

Do the following in Terminal:


sudo /etc/qemu-ifup tap0

cd development/raspberrypi-qemu

sudo kpartx -a -v my_rpi_image.img

sudo mount /dev/mapper/loop0p2 /mnt/temp

sudo cp /usr/bin/qemu-arm-static /mnt/temp/usr/bin

sudo mount -o bind /dev /mnt/temp/dev

sudo mount -o bind /proc /mnt/temp/proc

sudo mount -o bind /sys /mnt/temp/sys

sudo -s

echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register

exit

home

 

Thats it – you should be up and running as raspbian on the command line

 

And The Commands To Stop FAST CHROOT Virtual Raspbian


exit

sudo umount /mnt/temp/dev

sudo umount /mnt/temp/proc

sudo umount /mnt/temp/sys

sudo umount /mnt/temp

sudo kpartx -d -v my_rpi_image.img

 

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

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