Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Setup Scratchbox2, qemu & a Raspberry Pi rootfs for cross compiling for the Raspberry Pi
- #Start with a debian(other base distros will work but the commands will be slightly
- #different) install correctly configured (if the install is inside a VM such as VirtualBox make sure
- #that guest-additions or the equivilent is installed). These instructions assume that your shell
- #is bash, which 99.9% of the time it will be.
- #Install packages required to install Scratchbox2 & qemu plus a few useful extras. Fedora
- #does not have realpath available as a package installable via yum so you'll need to find the
- #source for one (or write your own) and install it manually.
- sudo apt-get install build-essential mc openssh-server apache2 wget git subversion fakeroot \
- realpath libsdl1.2debian-all libsdl1.2-dev libncurses5 libncurses5-dev libcurl3 libcurl4-openssl-dev \
- gftp autoconf
- #Create a tempory working directory
- mkdir work ; cd work
- #Get Scratchbox2, qemu & a toolchain (you can build your own crosscompile toolchain but
- #there is one freely available so might as well use that.
- git clone git://gitorious.org/scratchbox2/scratchbox2.git
- git clone git://git.linaro.org/qemu/qemu-linaro.git
- 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
- #Install the toolchain
- mkdir $HOME/ARMDevelopmentTools
- tar xjvf arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C $HOME/ARMDevelopmentTools
- #Configure, build & install scratchbox2
- cd $HOME/work/scratchbox2
- ./autogen.sh
- mkdir $HOME/ARMDevelopmentTools/Scratchbox2
- make install prefix=$HOME/ARMDevelopmentTools/Scratchbox2
- #Configure, build & install qemu (linaro "fork"). configure options other that --target-list
- #are pretty much a matter of taste and/or requirements. The ones listed are ones I find work
- #for me.
- cd $HOME/work/qemu-linaro
- mkdir $HOME/ARMDevelopmentTools/qemu-linaro
- ./configure --prefix=$HOME/ARMDevelopmentTools/qemu-linaro --target-list=arm-linux-user,arm-softmmu --audio-drv-list=alsa,sdl,oss --audio-card-list=ac97,sb16 --enable-mixemu
- make && make install
- #Add the following lines to $HOME/.bashrc using your favourite editor (in the running shell as well)
- export PATH=$HOME/ARMDevelopmentTools/Scratchbox2/bin:$HOME/ARMDevelopmentTools/qemu-linaro/bin:$PATH
- alias doch='sudo $(history -p !-1)'
- #Create a directory for keeping all your Raspberry Pi related files & builds in
- mkdir $HOME/RaspberryPiDevelopment
- #Go back to the working directory
- cd $HOME/work
- #Download the desired rootfs from the downloads page on http://raspberrypi.org/downloads and
- #copy it to your working directory. If you download using a non-bittorrent direct link using a
- #browser it'll be in the downloads directory. On debian cp $HOME/Downloads/debian*.zip $HOME/work
- #If you download it using bittorrent then it'll be in the directory that your bittorent client
- #puts things. If you are going to use a direct link you can also just wget it as shown below.
- wget http://<direct link you go from http://raspberrypi.org/downloads>
- #I am going to use the latest available debian rootfs
- unzip debian6-17-02-2012.zip
- cd debian6-17-02-2012
- file debian6-17-02-2012.img
- # You will get output similar to below
- debian6-17-02-2012.img: x86 boot sector; partition 1: ID=0xc, starthead 0, startsector 2048,
- 153600 sectors; partition 2: ID=0x83, starthead 3, startsector 157696, 3256320 sectors;
- partition 3: ID=0x82, starthead 3, startsector 3416064, 391168 sectors, code offset 0xb8
- #You need to note the value of startsector for partition 2 which in this case is 157696
- #and multiply it by 512. using bc calculator i get the value 80740352
- #Mount the rootfs image as a loop device offset at the start of the second partition in the image
- #which is the actual rootfs in the image.
- sudo losetup -o 80740352 /dev/loop0 debian6-17-02-2012.img
- sudo mkdir /mnt/rootfs
- sudo mount /dev/loop0 /mnt/rootfs
- #Copy the files from the rootfs to the directory which we will be using for all our Raspberry Pi
- #developing etc. (if your userid/groupid are not raspberrypi then change change the raspberrypi
- #in the chown & chgrp commands to your userid and groupid
- sudo mkdir $HOME/RaspberryPiDevelopment/.debian6_rootfs
- sudo cp -v -r /mnt/rootfs/* $HOME/RaspberryPiDevelopment/.debian6_rootfs
- sudo chown -R raspberrypi $HOME/RaspberryPiDevelopment/.debian6_rootfs
- sudo chgrp -R raspberrypi $HOME/RaspberryPiDevelopment/.debian6_rootfs
- sudo chmod -R 777 $HOME/RaspberryPiDevelopment/.debian6_rootfs
- #Unmount, detach the rootfs & delete the mountpoint
- sudo umount /mnt/rootfs
- sudo losetup -d /dev/loop0
- sudo rmdir /mnt/rootfs
- #Initialise Scratchbox2
- cd $HOME/RaspberryPiDevelopment/.debian6_rootfs
- sb2-init raspberrypi_debian6 $HOME/ARMDevelopmentTools/arm-2011.03/bin/arm-none-linux-gnueabi-gcc
- #Move back to your developemnt directory and test that everything is working
- cd ..
- mkdir hello
- vi hello.c
- #include <stdio.h>
- void main(){
- printf("hello, world\n");
- }
- sb2 gcc -o hello.arm hello.c
- #If everything is installed and configured correctly the thenfile hello.arm will output like below
- hello.arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
- #Running hello.arm using the command sb2 hello.arm will print hello, world
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement