{"id":1227,"date":"2013-09-27T12:21:55","date_gmt":"2013-09-27T12:21:55","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=1227"},"modified":"2014-09-26T15:05:13","modified_gmt":"2014-09-26T15:05:13","slug":"installing-eclipse-on-qemu-emulated-raspberry-pi-linux","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/compilers-and-ides\/eclipse-raspberry-pi\/installing-eclipse-on-qemu-emulated-raspberry-pi-linux","title":{"rendered":"Installing Eclipse on QEMU Emulated Raspberry Pi \u2013 Linux"},"content":{"rendered":"<p>\nWhilst you can technically run eclipse on the Raspberry Pi, in reality it doesn&#39;t have the power to make it usable. &nbsp;This guide is based on&nbsp;virtualizing&nbsp;Raspbian&nbsp;using&nbsp;QEMU\n<\/p>\n<p>\n\u200b<em style=\"color: rgb(255, 0, 0); font-size: 10px;\"><strong>Sorry &#8211; but&nbsp;qemu&nbsp;is not the magic solution it seems it should be even running on Linux rather than windows. &nbsp;After doing all this you will have&nbsp;raspbian&nbsp;and eclipse running on your Linux PC, but whilst its faster than the Windows version, its still quite slow. &nbsp;The final making it fast part of this guide doesn&#39;t apply to the GUI &#8211; it just seems to be a method of making command line compiling fast.&nbsp; If anyone finds a solution to this or wants to take on creating a better kernel for&nbsp;qemu&nbsp;to run to solve the problem please share it in the comments below!<\/strong><\/em>\n<\/p>\n<h4>\nQEMU<br \/>\n<\/h4>\n<p>\nQEMU&nbsp;is an emulator for various CPUs. It works on Linux, Windows,&nbsp;FreeBSD&nbsp;and Mac OS X.\n<\/p>\n<div>\n<h4>\nResources<br \/>\n<\/h4>\n<p>\nThis guide was helped by these pages:\n<\/p>\n<p>\n<a href=\"http:\/\/sentryytech.blogspot.co.uk\/2013\/02\/faster-compiling-on-emulated-raspberry.html\" target=\"_blank\">http:\/\/sentryytech.blogspot.co.uk\/2013\/02\/faster-compiling-on-emulated-raspberry.html<\/a>\n<\/p>\n<p>\n<a href=\"http:\/\/imvoid.wordpress.com\/2013\/05\/21\/6-connecting-qemu-to-network\/\" target=\"_blank\">http:\/\/imvoid.wordpress.com\/2013\/05\/21\/6-connecting-qemu-to-network\/<\/a>\n<\/p>\n<p>\n<strong>This guide is based heavily on the brilliant page&nbsp;<a href=\"http:\/\/sentryytech.blogspot.co.uk\/2013\/02\/faster-compiling-on-emulated-raspberry.html\" target=\"_blank\">here&nbsp;<\/a>which you may want to follow instead<\/strong>\n<\/p>\n<\/div>\n<p>\n&nbsp;\n<\/p>\n<h4>\nOur Linux For PC Platform<br \/>\n<\/h4>\n<p>\nWe&#39;re windows users primarily and&nbsp;we did this using&nbsp;ubuntu 64bit running in vmware workstation. We gave it 2 processor cores and 2GB or ram (no science to this &#8211; just for info).\n<\/p>\n<p>\nMost of the steps below are based on typing commands into the Terminal application in ubuntu.\n<\/p>\n<h4>\nInstall QEMU&nbsp;For Linux<br \/>\n<\/h4>\n<p>\n1. Install QEMU\n<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install qemu-kvm-extras\r\n<\/code><\/pre>\n<p>\n2. Create a directory for our virtual os&nbsp;files\n<\/p>\n<pre>\r\n<code>\r\nmkdir ~\/development\r\nmkdir ~\/development\/raspberrypi-qemu\r\n<\/code><\/pre>\n<p>\n3. Download a&nbsp;QEMU-ready linux kernel for the Raspberry Pi from here\n<\/p>\n<p>\n<a href=\"http:\/\/xecdesign.com\/downloads\/linux-qemu\/kernel-qemu\" target=\"_blank\">http:\/\/xecdesign.com\/downloads\/linux-qemu\/kernel-qemu<\/a>\n<\/p>\n<h4>\nInstall Your Raspbian&nbsp;OS<br \/>\n<\/h4>\n<p>\nCopy your .img file into the raspberrypi-qemu&nbsp;directory. This can be by downloading the latest&nbsp;Raspbian&nbsp;image file from&nbsp;<a href=\"http:\/\/www.raspberrypi.org\/downloads\" target=\"_blank\">http:\/\/www.raspberrypi.org\/downloads<\/a>.&nbsp;Unzip it if necessary and store the .img file in the&nbsp;directory. &nbsp;The new images don&#39;t just work due to the new &quot;\/etc\/ld.so.preload&quot; file in in the raspbian&nbsp;image. &nbsp;This typically causes the error&nbsp;&quot;INIT: ID &quot;1&quot; respawning too fast: disabled for 5 minutes&quot;\u200b and if you search on that error message you&#39;ll find guide of how to edit the&nbsp;&quot;\/etc\/ld.so.preload&quot; file within the iso to make it ready for use.\n<\/p>\n<p>\nThere&#39;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. &nbsp; You can do the normal things like expand the&nbsp;filesystem&nbsp;to fill your SD card, which will mean you get the same size of disk in&nbsp;qemu&nbsp;also. &nbsp;You still need to edit the&nbsp;&quot;\/etc\/ld.so.preload&quot; file as it will stop you being able to log on in&nbsp;qemu&nbsp;(it causes the load of some shared-library, which will make you unable to login causes &quot;kernel panic&quot; apparently), so from the command line on the RPi use:\n<\/p>\n<pre>\r\n<code>\r\nsudo nano \/etc\/ld.so.preload\r\n<\/code><\/pre>\n<p>\nNow insert a # as the start of the only line in there to comment it out, giving:\n<\/p>\n<pre>\r\n<code>\r\n#\/usr\/lib\/arm-linux-gnueabihf\/libcofi_rpi.so\r\n<\/code><\/pre>\n<p>\nUse CTRL+X to save and exit. &nbsp;Then use this before powering off:\n<\/p>\n<pre>\r\n<code>\r\nsudo halt\r\n<\/code><\/pre>\n<p>\nNow use&nbsp;Win32DiskImager&nbsp;to read the SD card and create an .iso image file. &nbsp;Copy this into the&nbsp;raspberrypi-qemu&nbsp;directory used above.\n<\/p>\n<h5>\nFinally<br \/>\n<\/h5>\n<p>\nRename 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)\n<\/p>\n<p style=\"margin-left: 40px;\">\nmy_rpi_image.img\n<\/p>\n<h4>\nRunning It<br \/>\n<\/h4>\n<p>\nPaste the following into Terminal:\n<\/p>\n<pre>\r\n<code>\r\nqemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append &quot;root=\/dev\/sda2 panic=1&quot; -hda my_rpi_image.img\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<div>\nYou should get raspbian&nbsp;opening in a new window. &nbsp;&nbsp;There will be a few error messages as it boots due to hardware that isn&#39;t there, but it should load to the login prompt and be ready to go.\n<\/div>\n<div>\n<h4>\nQEMU&nbsp;Tips<br \/>\n<\/h4>\n<p>\nTo exit the&nbsp;QEMU&nbsp;window and get your mouse back use CTRL+ALT or CTRL+TAB\n<\/p>\n<\/div>\n<div>\n<h4>\nRAM Size<br \/>\n<\/h4>\n<p>\nYou might be tempted to alter the &quot;-m 256&quot; to something more useful like &quot;-m 1024&quot;? &nbsp;You can&#39;t, you&#39;ll just get a black screen of nothing. &nbsp;The physical memory map on versatile hardware does not allow more than 256MB of space for RAM and as we&#39;re using the&nbsp;versatile&nbsp;kernel we can&#39;t have more.\n<\/p>\n<h4>\nNetworking<br \/>\n<\/h4>\n<p>\nQemu doesn&#39;t sort out an network bridge so you&#39;ve got to provide&nbsp;it yourself. Its painful on linux but here&#39;s as simple a solution as we&#39;ve found:\n<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install bridge-utils uml-utilities openvpn firestarter\r\n<\/code><\/pre>\n<p>\nInsert the TUN device module to the kernel\n<\/p>\n<pre>\r\n<code>\r\nsudo modprobe tun\r\n<\/code><\/pre>\n<p>\nLook in the \/dev\/net folder and check a node called tun has been created. If not create it manually by typing the following commands\n<\/p>\n<pre>\r\n<code>\r\nsudo mkdir \/dev\/net\r\nsudo mknod \/dev\/net\/tun c 10 200\r\nsudo chmod 660 \/dev\/net\/tun\r\n<\/code><\/pre>\n<p>\nYou may well already have qemu-ifup and ifdown files so rename them to make way for new ones:\n<\/p>\n<pre>\r\n<code>\r\nsudo mv \/etc\/qemu-ifup \/etc\/qemu-ifup-original\r\n<\/code><\/pre>\n<p>\nOpen the Text Editor as root:\n<\/p>\n<pre>\r\n<code>\r\nsudo gedit\r\n<\/code><\/pre>\n<p>\nPaste the following into the file\n<\/p>\n<pre>\r\n<code>\r\n#!\/bin\/sh\r\n\r\n#\r\n# script to bring up the tun device in QEMU in bridged mode\r\n# first parameter is name of tap device (e.g. tap0)\r\n#\r\n# some constants specific to the local host ? change to suit your host\r\n#\r\n\r\nETH0IP=192.168.0.73\r\nGATEWAY=192.168.0.1\r\nBROADCAST=192.168.0.255\r\nIPNETMASK=255.255.255.0\r\n\r\n#\r\n# First take eth0 down, then bring it up with IP 0.0.0.0\r\n#\r\nifconfig eth0 down\r\nifconfig eth0 0.0.0.0 promisc up\r\n\r\n#\r\n# Bring up the tap device (name specified as first argument, by QEMU)\r\n#\r\nopenvpn --mktun --dev $1 -user &#39;id -un&#39;\r\nifconfig $1 0.0.0.0 promisc up\r\n\r\n#\r\n# create the bridge between eth0 and the tap device\r\n#\r\nbrctl addbr br0\r\nbrctl addif br0 eth0\r\nbrctl addif br0 $1\r\n\r\n#\r\n# only a single bridge so loops are not possible, turn off spanning\r\n# tree protocol\r\n#\r\nbrctl stp br0 off\r\n\r\n#\r\n# Bring up the bridge with ETH0IP and add the default route\r\n#\r\nifconfig br0 $ETH0IP netmask $IPNETMASK broadcast $BROADCAST\r\nroute add default gw $GATEWAY\r\n\r\n#\r\n# stop firewall ? comment this out if you don?t use Firestarter\r\n#\r\nservice firestarter stop\r\n<\/code><\/pre>\n<p>\nEdit this if necessary for your local network:\n<\/p>\n<pre>\r\n<code>\r\nETH0IP=192.168.0.73\r\nGATEWAY=192.168.0.1\r\nBROADCAST=192.168.0.255\r\nIPNETMASK=255.255.255.0\r\n<\/code><\/pre>\n<p>\nSave it as \/etc\/qemu-ifup\n<\/p>\n<p>\nUse this to make it executible\n<\/p>\n<pre>\r\n<code>\r\nsudo chmod +x \/etc\/qemu-ifup\r\n<\/code><\/pre>\n<p>\nLook at your current ip configuration\n<\/p>\n<pre>\r\n<code>\r\nifconfig\r\n<\/code><\/pre>\n<p>\nNow run the script\n<\/p>\n<pre>\r\n<code>\r\nsudo \/etc\/qemu-ifup tap0\r\n<\/code><\/pre>\n<p>\nNow look at the ip configuration again to see the new bridge\n<\/p>\n<pre>\r\n<code>\r\nifconfig\r\n<\/code><\/pre>\n<p>\nNow we modify the qemu launch string to include:\n<\/p>\n<pre>\r\n<code>\r\n-net nic -net tap,ifname=tap0\r\n<\/code><\/pre>\n<p>\nSo it becomes:\n<\/p>\n<pre>\r\n<code>\r\ncd development\/raspberrypi-qemu\r\n\r\nqemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append &quot;root=\/dev\/sda2 panic=1&quot; -hda my_rpi_image.img -net nic -net tap,ifname=tap0\r\n<\/code><\/pre>\n<p>\nThat&#39;s it, save the file, double click it and when raspbian boots it will have an IP address on your local network.\n<\/p>\n<h5>\nSetting The Raspberry Pi IP Address<br \/>\n<\/h5>\n<p>\nTo set it to a correct address on the local network use\n<\/p>\n<pre>\r\n<code>\r\nsudo nano \/etc\/network\/interfaces\r\n<\/code><\/pre>\n<p>\nChange this line\n<\/p>\n<pre>\r\n<code>\r\nsudo ifdown eth0 &amp;&amp; sudo ifup eth0\r\n<\/code><\/pre>\n<p>\nTo this with your settings as needed\n<\/p>\n<pre>\r\n<code>\r\niface eth0 inet static\r\n     address 192.168.0.74\r\n     netmask 255.255.255.0\r\n     gateway 192.168.0.1\r\n<\/code><\/pre>\n<p>\nPress CTRL+X to Exit\n<\/p>\n<p>\nRestarting&nbsp;ubunto will reset the networking and clear the bridge.\n<\/p>\n<h4>\nDisplay Resolution<br \/>\n<\/h4>\n<p>\nQemu is limited to a max resolution of 800&#215;600. &nbsp;You can run the raspbian&nbsp;GUI in it fine, but who wants to at that resolution. &nbsp;To get round this you can just use remote desktop to give the full&nbsp;1920&#215;1080. &nbsp;\n<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install xrdp\r\n<\/code><\/pre>\n<p>\nThis will install XRDP&nbsp;which allows you&nbsp;to use Remote desktop to remote into the qemu instance and&nbsp;get full monitor resolution.\n<\/p>\n<p>\nTo use it run the Remote Desktop application in ubuntu. &nbsp;Enter the RPi IP address, username and password and connect. &nbsp;You&#39;ll get a full size grey screen followed by the raspbian GUI.\n<\/p>\n<div>\n&nbsp;\n<\/div>\n<div>\n<h4>\nInstall Eclipse<br \/>\n<\/h4>\n<pre style=\"font-size: 10px;\">\r\n<code>\r\nsudo apt-get install eclipse\r\n<\/code><\/pre>\n<p style=\"font-size: 10px;\">\n&nbsp;\n<\/p>\n<\/div>\n<\/div>\n<h4>\nMaking The Command Line Run Fast!<br \/>\n<\/h4>\n<p>\nOK, this gets you to a similar point as using qemu on Windows &#8211; raspbian running on your desktop but pretty slowly. &nbsp; This is where Linux architectural chroot&nbsp;magic comes in! &nbsp;We don&#39;t pretend to understand the detail on this &#8211; its copied from the excellent guide <a href=\"http:\/\/sentryytech.blogspot.co.uk\/2013\/02\/faster-compiling-on-emulated-raspberry.html\" target=\"_blank\">here<\/a>.\n<\/p>\n<p>\nInstall&nbsp;qemu-user-static\n<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install qemu-user-static\r\n<\/code><\/pre>\n<p>\nNow use kpartx to mount the image using loopback:\n<\/p>\n<pre>\r\n<code>\r\ncd development\/raspberrypi-qemu\r\n\r\n\u200bsudo kpartx -a -v my_rpi_image.img\r\n<\/code><\/pre>\n<p>\nIf it doesn&#39;t work install kpartx\n<\/p>\n<pre>\r\n<code>\r\nsudo apt-get install kpartx\r\n<\/code><\/pre>\n<p>\nFinish the loopboack:\n<\/p>\n<pre>\r\n<code>\r\nsudo mount \/dev\/mapper\/loop0p2 \/mnt\/temp\r\n<\/code><\/pre>\n<p>\nIf that&nbsp;doesn&#39;t work create the temp directory first\n<\/p>\n<pre>\r\n<code>\r\nsudo mkdir \/mnt\/temp\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\nNow, copy the static QEMU binary and mount the special directories:\n<\/p>\n<pre>\r\n<code>\r\nsudo cp \/usr\/bin\/qemu-arm-static \/mnt\/temp\/usr\/bin\r\nsudo mount -o bind \/dev \/mnt\/temp\/dev\r\nsudo mount -o bind \/proc \/mnt\/temp\/proc\r\nsudo mount -o bind \/sys \/mnt\/temp\/sys\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\nBefore we can enter the chroot environment, it&#39;s time for the magic command. First change to being the root user:\n<\/p>\n<pre>\r\n<code>\r\nsudo -s\r\n<\/code><\/pre>\n<p>\nNow enter this&nbsp;(as a single line):\n<\/p>\n<pre>\r\n<code>\r\necho &#39;: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:&#39; &gt; \/proc\/sys\/fs\/binfmt_misc\/register\r\n<\/code><\/pre>\n<p>\nThis 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.\n<\/p>\n<p>\nExit root user mode:\n<\/p>\n<pre>\r\n<code>\r\nexit\r\n<\/code><\/pre>\n<p>\n<br \/>\nNow we can chroot:\n<\/p>\n<pre>\r\n<code>\r\nsudo chroot \/mnt\/temp\r\n<\/code><\/pre>\n<p>\nTo see if it worked enter this and see if you get a armv7l respose:\n<\/p>\n<pre>\r\n<code>\r\nuname -a\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<h4>\nNow That Its All Done &#8211; The Commands To Startup Virtual&nbsp;Raspbian In Default QEMU Mode<br \/>\n<\/h4>\n<pre>\r\n<code>\r\nsudo \/etc\/qemu-ifup tap0\r\n\r\ncd development\/raspberrypi-qemu\r\n\r\nqemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append &quot;root=\/dev\/sda2 panic=1&quot; -hda my_rpi_image.img -net nic -net tap,ifname=tap0\r\n<\/code><\/pre>\n<h4>\nThe Commands To Startup Virtual&nbsp;Raspbian In FAST CHROOT QEMU Mode<br \/>\n<\/h4>\n<p>\nDo the following in Terminal:\n<\/p>\n<pre>\r\n<code>\r\nsudo \/etc\/qemu-ifup tap0\r\n\r\ncd development\/raspberrypi-qemu\r\n\r\nsudo kpartx -a -v my_rpi_image.img\r\n\r\nsudo mount \/dev\/mapper\/loop0p2 \/mnt\/temp\r\n\r\nsudo cp \/usr\/bin\/qemu-arm-static \/mnt\/temp\/usr\/bin\r\n\r\nsudo mount -o bind \/dev \/mnt\/temp\/dev\r\n\r\nsudo mount -o bind \/proc \/mnt\/temp\/proc\r\n\r\nsudo mount -o bind \/sys \/mnt\/temp\/sys\r\n\r\nsudo -s\r\n\r\necho &#39;: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:&#39; &gt; \/proc\/sys\/fs\/binfmt_misc\/register\r\n\r\nexit\r\n\r\nhome<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\nThats it &#8211; you should be up and running as raspbian on the command line\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<h4>\nAnd The Commands To Stop FAST CHROOT Virtual&nbsp;Raspbian<br \/>\n<\/h4>\n<pre>\r\n<code>\r\nexit\r\n\r\nsudo umount \/mnt\/temp\/dev\r\n\r\nsudo umount \/mnt\/temp\/proc\r\n\r\nsudo umount \/mnt\/temp\/sys\r\n\r\nsudo umount \/mnt\/temp\r\n\r\nsudo kpartx -d -v my_rpi_image.img\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whilst you can technically run eclipse on the Raspberry Pi, in reality it doesn&#39;t have the power to make it usable. &nbsp;This guide is based on&nbsp;virtualizing&nbsp;Raspbian&nbsp;using&nbsp;QEMU \u200bSorry &#8211; but&nbsp;qemu&nbsp;is not the magic solution it seems it should be even running on Linux rather than windows. &nbsp;After doing all this you will have&nbsp;raspbian&nbsp;and eclipse running on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80],"tags":[],"class_list":["post-1227","post","type-post","status-publish","format-standard","hentry","category-eclipse-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=1227"}],"version-history":[{"count":25,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1256,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1256"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}