I don't claim that the following is the best way to install scratchbox2, qemu and a seed rootfs and configure them to produce binaries that will run on the real Raspberry Pi hardware. I don't even claim it is the correct way but it works for me and I can almost do it in my sleep by now. The way I do things will probably seem a bit inefficient and in some cases just plain wrong but it's how I work and hopefully they are easy to follow and adapt to your style of working. I also make no guarantees that it will actually work for you at all. Hopefully it will but if it doesn't sorry but oh well. I made the decision when I first started building the development vm that I would place all the required software under the users home directory rather than installing it globally as
- Installing in subdirectories in the user's home directory makes it easy to keep things organised.
- It makes things almost idiotproof when you want to upgrade the ARM toolchain, scratchbox2, qemu or change the seed rootfs etc. as it's pretty much just rename the old directory, create a new directory and if neccessary rerun sb2-init.
- Open a terminal
- If you haven't already got git & wget installed. Install them now. On Ubuntu or Debian the command to install them is
- Create a directory for temporary use. I personally call it hold and change to it.
- Download scratchbox2 and qemu from their respective git repositories
- Download the codesourcery ARM toolchain. I have been using the 2011.03 version successfully and I believe it was the last released version before codesourcery was bought by Mentor Graphics who seem to have closed sourced the more recent releases of the toolchain.
- Then download an ARM rootfs. Eventually we will be able to use the official Raspberry Pi standard rootfs but until that time any ARM based one will do. As I believe that the official Raspberry Pi distribution is going to be Fedora we'll download a Fedora one. In this case we use one I found on the fedora-arm mailing list. http://lists.fedoraproject.org/pipermail/arm/2011-December/002386.html
- If you now do a directory listing you will have a terminal window that looks this
- Now create some more directories.
- Untar the rootfs The reason we extract the seed rootfs using sudo is that there are some special files that a normal user cannot create when untarring a tarred rootfs. Lots of filenames will scroll before your eyes as the seed rootfs is untarred into the rootfs subdirectory. This will take quite a while so it might be a good time to go and get a drink or take a bathroom break.
- Extract the codesourcery ARM toolchain into the raspberry_pi_development directory.
- Do a directory listing of the raspberry_pi_development directory and it will look like the image below.
- If you haven't already got the SDL and ncurses libaries and headers installed. Install them now. In Ubuntu and Debian
- You should also install autoconf, fakeroot and realpath. Fedora users will need to find their own copy of the realpath source as it is not included in the distribution. I found a copy that works on stackoverflow. In Ubuntu and Debian change to scratchbox2 directory and run the autogen.sh script.
- then run makeYou can ignore all the warnings that will scroll passed and when it finishes the screen will look something like the one below. The interesting lines are the final 4 or 5 which should basically say the same thing that the screenshot does.
- Scratchbox2 is now installed and we now need to build qemu so cd to the qemu directory
- To use scratchbox2 you only need to build qemu usermode for ARM, however, I find it useful to also build the ARM system emulation as well (I use the qemu full system emulation for some little hacks and tricks that are beyond the scope of this howto but I will write them up at a later date along with how to use scratchbox2 with real hardware once I have the process down pat & actually have a real Raspberry Pi to test on).
- Now that scratchbox2, the toolchain, qemu and the seed rootfs are installed we just have a few more steps before we can actually use the VM for compiling software. First of all we need add the scratchbox2 and qemu bin directories to our PATH environment variable. You can do this as a single export statement but so it's clear i'll do it as two. You will also want to add the previous two lines to your .bashrc file. Start your favourite editor and open the .bashrc file and add them to the bottom and in the case of nano save the file using ^x y <enter>. If you are using vi the it would be <esc> :wq
- Now that you have added scratchbox2 and qemu to your PATH (and in .bashrc as well) check that it works.The version numbers returned might be different but that doesn't matter it's the fact that you actually got the version numbers that confirms that the PATH environment variable is set correctly.
- change to the rootfs directory
- before we can use the seed rootfs inside scratchbox2 we need to change the owner, group and permissions so that it is read/writable by our non-root account. When I installed Ubuntu into the VM I was asked to make a default user. In my case I called it raspberry and gave it a password of password. You might have called your default user something different replace raspberry in the following lines with your user name.
- There is just one more thing to do before we can start using scratchbox2. We need to initialize it. While inside the the seed rootfs directory. In this case rootfs_f14sb2-init actually has a lot of options you can use but in most cases they just complicate matters and for our needs the above command line is good enough. What it actually means is configure scratchbox2 to create a target called raspberry and use the toolchain binaries that we have installed in
As you get more familar with scratchbox2 you might want to experiment with things such as having multiple targets with a single scratchbox2 installation etc.
- After a short wait your screen will look something like this
- You are now ready to start using scratchbox2 to compile software. However, I do a few more things just to make life easier that you might also want to do. I create a directory called $HOME/build, install an ssh server and apache2 and put a symlink of the build directory in the apache2 directory tree. This allows me to keep all my ARM binaries an source seperate from anything else and lets me get them out of the VM easily although I could also use shared folders but I prefer using a webserver as then any machine on my network can access them. I got a bit bored doing the screenshots and cutting out the relevant parts so here is a video of me doing this final bit of setup
If you have got this far you are now ready to start building software for the Raspberry Pi. As a test I create a C hello world program and check that it compiles and runs both in the host os and also inside scratchbox2 and if that works then I check that the seed rootfs's package manager works. If both do then i'll start using the vm. Again because I am bored with doing screenshots here is a short video of that process.
When and if I get time I might do some more blog posts about some advanced scratchbox2 and qemu usage, tips and tricks but for this post i say