Executing Gummiworms The trials and tribulations of a grumpy curmudgeonly old git


Setting up Scratchbox2 from scratch (for the Raspberry Pi)

It has been confirmed that binaries built using this method will run on real Raspberry Pi hardware (alphaboard).

Below is the method i used to setup Scratchbox2. I am doing this using a Ubuntu 11.4 virtual machine in VirtualBox. It works for me but YMMV.

Because the version of Scratchbox2 and qemu available in the Ubuntu repositories are pretty old and the version of qemu available doesn't have support for the arm1176 I am going to use the git versions of qemu and Scratchbox2.

mkdir RaspberryPi
cd RaspberryPi
git clone git://gitorious.org/scratchbox2/scratchbox2.git
git clone git://git.qemu.org/qemu.git


You'll also need an ARM toolchain. Unless you want to build your own ARM toolchain you'll want to download the codesourcery ARM toolchain. https://sourcery.mentor.com/sgpp/lite/arm/portal/release1803

cd ~/RaspberryPi
wget https://sourcery.mentor.com/sgpp/lite/arm/portal/package8739/public/arm-none-linux-gnueabi/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
tar xjvf arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2


You will now have the codesourcery ARM toolchain in the directory ~/RaspberryPi/arm-2011.03

Now that you have a toolchain available it's time to build Scratchbox2 and qemu. Earlier you cloned the latest git versions available and if you haven't already got them installed you'll need to install "fakeroot" and "realpath" using your distributions package management system. To build and install Scratchbox2.

cd ~/RaspberryPi/scratchbox2
mkdir ../sb2
make install prefix=$HOME/RaspberryPi/sb2

Then build and install qemu

cd ~/RaspberryPi/qemu
./configure --prefix=$HOME/RaspberryPi/sb2 --target-list=arm-linux-user
make && make install

Now that your toolchain, scratchbox2 and qemu are installed you'll need to seed your development environment with some libs, include files and binaries and initilize Scratchbox2

mkdir ~/RaspberryPi/devel
cd ~/RaspberryPi/devel
export PATH=$HOME/RaspberryPi/sb2/bin:$PATH
cp -a ~/RaspberryPi/arm-2011.03/arm-none-linux-gnueabi/libc/{lib,etc,usr} .
sb2-init Raspi $HOME/RaspberryPi/arm-2011.03/bin/arm-none-linux-gnueabi-gcc
This will generate a working target configuration. If anything fails you can redo it again manually after fixing the problem.

You'll probably want to add

export PATH=$HOME/RaspberryPi/sb2/bin:$PATH

to your .bashrc as well

Now you have a working cross compile environment for the RaspberryPi (it isn't optimised or tweaked for the hardware but it's good enough for now and can be improved at a later date when we have more details about the hardware in particular the GPU and CPU).

To actually test that everything is working correctly write a small program (a hello, world program is a good choice).

raspberry@raspberrypi-VirtualBox:~/RaspberryPi/devel$ gcc hello.c -o hello
raspberry@raspberrypi-VirtualBox:~/RaspberryPi/devel$ file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
raspberry@raspberrypi-VirtualBox:~/RaspberryPi/devel$ sb2 gcc hello.c -o hello
raspberry@raspberrypi-VirtualBox:~/RaspberryPi/devel$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
raspberry@raspberrypi-VirtualBox:~/RaspberryPi/devel$ sb2 ./hello
hello, world
If you have any questions you can find me on the raspberrypi forum, the irc channel or contact me via this blog.

[Addendum: Instead of seeding usign the libs and include files etc. from the codesourcery toochain you can use a rootfs of any ARM based distro. Just download an ARM rootfs from somewhere (exercise left for the user) and as root extract it into the ~RaspberryPi/devel directory and then chown -R user ~/RaspberryPi/devel and chgrp -R user ~/RaspberryPi/devel -- If you user a debian based rootfs (squeeze) the you can use apt to update and upgrade the files in the rootfs using the command

sb2 -eR apt-get update
sb2 -eR apt-get upgrade



Comments (11) Trackbacks (2)
  1. On the line :

    git clone http://git.qemu.org/qemu.git

    I found that did not work but

    git clone git://git.qemu.org/qemu.git

    seems to work fine.

    • Seems I typed too soon, it runs the count of objects but hangs at that point without downloading. I think that git.qemu may be having problems, perhaps too many Rpi downloads ;-)

      On the positive side, the SB2 and the toolchain downloads without a problem and SB2 builds.

    • yes sorry. brain said one thing, hands typed another. my only excuse is a lap full of cats and the lateness of the hour

  2. Everything is really open and extremely clear explanation of troubles. was truly data. Your site is extremely useful. Many thanks for sharing.

  3. After several unsuccessful attempts I used the –progress option to git clone and the download happened after the object count ended.

    qEMU configure complained about needing glib-2.0, the solution is to install libgtk2.0-dev

    The make of qemu just finished ….

    The line

    cp -a ~/RaspberryPi/arm-2011.03/arm-none-linux-gnueabi/libc/{lib, etc.usr} .

    is interpreted as :

    cp -a ~/RaspberryPi/arm-2011.03/arm-none-linux-gnueabi/libc/lib .
    cp -a ~/RaspberryPi/arm-2011.03/arm-none-linux-gnueabi/libc/etc .
    cp -a ~/RaspberryPi/arm-2011.03/arm-none-linux-gnueabi/libc/usr .

    The line
    export PATH=$HOME/RaspberryPi/arm-2011.03/bin:$HOME/RaspberryPi/sb2:$PATH
    should read
    export PATH=$HOME/RaspberryPi/arm-2011.03/bin:$HOME/RaspberryPi/sb2/bin:$PATH

    sb2-init Raspi arm-none-linux-gnuabi-gcc
    should be
    sb2-init Raspi arm-none-linux-gnueabi-gcc

    With these changes, my sb2-init succeeds !!

    • yes thanks. i have been fixing it up during the day as i was running through it again and also forum user ahven who has been telling me where the typos were. it should all be fixed now.

  4. Apparently the links for the codesourcery changed earlier today. i’ve now fixed them so all should be good again

  5. I think there is a typo:
    sb2-init Raspi $HOME/RaspberryPi/arm-2011.03/bin/arm-none-linux-gneabi-gcc
    Should be
    sb2-init Raspi $HOME/RaspberryPi/arm-2011.03/bin/arm-none-linux-gnueabi-gcc
    (missing “u” in gnueabi-gcc)

  6. Ok, besides the typo, it works great. The executable even works on my Nokia N900.

  7. Here are the packages you need to install in Ubuntu (11.04, x64) for the howto to work straight away!
    build-essential git fakeroot realpath automake libglib2.0-dev g++-multilib zlib1g-dev libglib2.0-dev

  8. Hi, this tutorial is great on 11.04.

    but when I moved to 13.04

    I got a problem – hello.c can be compiled, but the binary file hello I compiled can’t be executed.

    it seems it didn’t use qemu-arm to transparency when execute the hello binary file.

    any idea would be appreciated.

Leave a comment