SHOW:
|
|
- or go back to the newest paste.
| 1 | #Setup Scratchbox2, qemu & a Raspberry Pi rootfs for cross compiling for the Raspberry Pi | |
| 2 | #Start with a debian(other base distros will work but the commands will be slightly | |
| 3 | #different) install correctly configured (if the install is inside a VM such as VirtualBox make sure | |
| 4 | #that guest-additions or the equivilent is installed). These instructions assume that your shell | |
| 5 | #is bash, which 99.9% of the time it will be. | |
| 6 | ||
| 7 | #Install packages required to install Scratchbox2 & qemu plus a few useful extras. Fedora | |
| 8 | #does not have realpath available as a package installable via yum so you'll need to find the | |
| 9 | #source for one (or write your own) and install it manually. | |
| 10 | sudo apt-get install build-essential mc openssh-server apache2 wget git subversion fakeroot \ | |
| 11 | realpath libsdl1.2debian-all libsdl1.2-dev libncurses5 libncurses5-dev libcurl3 libcurl4-openssl-dev \ | |
| 12 | gftp autoconf | |
| 13 | ||
| 14 | #Create a tempory working directory | |
| 15 | mkdir work ; cd work | |
| 16 | ||
| 17 | #Get Scratchbox2, qemu & a toolchain (you can build your own crosscompile toolchain but | |
| 18 | #there is one freely available so might as well use that. | |
| 19 | git clone git://gitorious.org/scratchbox2/scratchbox2.git | |
| 20 | git clone git://git.linaro.org/qemu/qemu-linaro.git | |
| 21 | 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 | |
| 22 | ||
| 23 | #Install the toolchain | |
| 24 | mkdir $HOME/ARMDevelopmentTools | |
| 25 | tar xjvf arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C $HOME/ARMDevelopmentTools | |
| 26 | ||
| 27 | #Configure, build & install scratchbox2 | |
| 28 | cd $HOME/work/scratchbox2 | |
| 29 | ./autogen.sh | |
| 30 | mkdir $HOME/ARMDevelopmentTools/Scratchbox2 | |
| 31 | make install prefix=$HOME/ARMDevelopmentTools/Scratchbox2 | |
| 32 | ||
| 33 | #Configure, build & install qemu (linaro "fork"). configure options other that --target-list | |
| 34 | #are pretty much a matter of taste and/or requirements. The ones listed are ones I find work | |
| 35 | #for me. | |
| 36 | cd $HOME/work/qemu-linaro | |
| 37 | mkdir $HOME/ARMDevelopmentTools/qemu-linaro | |
| 38 | ./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 | |
| 39 | make && make install | |
| 40 | ||
| 41 | #Add the following lines to $HOME/.bashrc using your favourite editor (in the running shell as well) | |
| 42 | export PATH=$HOME/ARMDevelopmentTools/Scratchbox2/bin:$HOME/ARMDevelopmentTools/qemu-linaro/bin:$PATH | |
| 43 | alias doch='sudo $(history -p !-1)' | |
| 44 | ||
| 45 | #Create a directory for keeping all your Raspberry Pi related files & builds in | |
| 46 | - | mkdir $HOME/Raspberry_Pi_Development |
| 46 | + | mkdir $HOME/RaspberryPiDevelopment |
| 47 | ||
| 48 | #Go back to the working directory | |
| 49 | cd $HOME/work | |
| 50 | ||
| 51 | #Download the desired rootfs from the downloads page on http://raspberrypi.org/downloads and | |
| 52 | #copy it to your working directory. If you download using a non-bittorrent direct link using a | |
| 53 | #browser it'll be in the downloads directory. On debian cp $HOME/Downloads/debian*.zip $HOME/work | |
| 54 | #If you download it using bittorrent then it'll be in the directory that your bittorent client | |
| 55 | #puts things. If you are going to use a direct link you can also just wget it as shown below. | |
| 56 | wget http://<direct link you go from http://raspberrypi.org/downloads> | |
| 57 | #I am going to use the latest available debian rootfs | |
| 58 | unzip debian6-17-02-2012.zip | |
| 59 | cd debian6-17-02-2012 | |
| 60 | file debian6-17-02-2012.img | |
| 61 | ||
| 62 | # You will get output similar to below | |
| 63 | debian6-17-02-2012.img: x86 boot sector; partition 1: ID=0xc, starthead 0, startsector 2048, | |
| 64 | 153600 sectors; partition 2: ID=0x83, starthead 3, startsector 157696, 3256320 sectors; | |
| 65 | partition 3: ID=0x82, starthead 3, startsector 3416064, 391168 sectors, code offset 0xb8 | |
| 66 | ||
| 67 | #You need to note the value of startsector for partition 2 which in this case is 157696 | |
| 68 | #and multiply it by 512. using bc calculator i get the value 80740352 | |
| 69 | ||
| 70 | #Mount the rootfs image as a loop device offset at the start of the second partition in the image | |
| 71 | #which is the actual rootfs in the image. | |
| 72 | sudo losetup -o 80740352 /dev/loop0 debian6-17-02-2012.img | |
| 73 | sudo mkdir /mnt/rootfs | |
| 74 | sudo mount /dev/loop0 /mnt/rootfs | |
| 75 | ||
| 76 | #Copy the files from the rootfs to the directory which we will be using for all our Raspberry Pi | |
| 77 | #developing etc. (if your userid/groupid are not raspberrypi then change change the raspberrypi | |
| 78 | #in the chown & chgrp commands to your userid and groupid | |
| 79 | sudo mkdir $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 80 | sudo cp -v -r /mnt/rootfs/* $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 81 | sudo chown -R raspberrypi $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 82 | sudo chgrp -R raspberrypi $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 83 | sudo chmod -R 777 $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 84 | ||
| 85 | #Unmount, detach the rootfs & delete the mountpoint | |
| 86 | sudo umount /mnt/rootfs | |
| 87 | sudo losetup -d /dev/loop0 | |
| 88 | sudo rmdir /mnt/rootfs | |
| 89 | ||
| 90 | #Initialise Scratchbox2 | |
| 91 | cd $HOME/RaspberryPiDevelopment/.debian6_rootfs | |
| 92 | sb2-init raspberrypi_debian6 $HOME/ARMDevelopmentTools/arm-2011.03/bin/arm-none-linux-gnueabi-gcc | |
| 93 | ||
| 94 | #Move back to your developemnt directory and test that everything is working | |
| 95 | cd .. | |
| 96 | mkdir hello | |
| 97 | vi hello.c | |
| 98 | #include <stdio.h> | |
| 99 | void main(){
| |
| 100 | printf("hello, world\n");
| |
| 101 | } | |
| 102 | sb2 gcc -o hello.arm hello.c | |
| 103 | ||
| 104 | #If everything is installed and configured correctly the thenfile hello.arm will output like below | |
| 105 | hello.arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped | |
| 106 | ||
| 107 | #Running hello.arm using the command sb2 hello.arm will print hello, world |