-
Notifications
You must be signed in to change notification settings - Fork 7
Cross Compiling for ARM RaspberryPi
- run:
sudo apt-get install git rsync cmake libc6-i386 lib32z1 lib32stdc++6
mkdir ~/raspberrypi
cd ~/raspberrypi
git clone git://github.com/raspberrypi/tools.git .
cd ~
echo "export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin" >> ~/.bashrc
source ~/.bashrc
- verify the cross-compiler in in the path by running arm-linux-gnueabihf-gcc -v
- create dir rootfs in the raspberrypi folder
- copy /lib and /usr from a raspbian wheezy image into the rootfs directory or rsync it from a live pi (see https://raspberrypi.stackexchange.com/a/13138 or https://stackoverflow.com/a/19269715/1944510) (vanilla image might not work as PCAP is missing)
- copy the pi.cmake (https://ipvs.informatik.uni-stuttgart.de/redmine/attachments/download/270/pi.cmake) file attached to this article into the raspberrypi directory
If you want to test if the setup works so far you can run
git clone https://github.com/jameskbride/cmake-hello-world.git
cd cmake-hello-world
mkdir build
cd build
cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../
make
To verify the compiled binary has the right format, run "file CMakeHelloWorld". The output should be similar to this:
17:19:26 zsdn@ubuntu: ~/cmake-hello-world/build $ file CMakeHelloWorld
CMakeHelloWorld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=1495242f0dc55f2fe5990fc44a9794b076e4cf0b, not stripped
Now after the crosscompilation environment is set up, the libraries used by zsdn need to be crosscompiled for the pi. In the util folder in the zsdn repo a init_dependencies.sh script exists that will invoke the upgrade_XXX.sh scripts, which will download and compile the libraries zsdn uses. If you run those scripts without any parameter they will build the libraries for your local system. If you pass -pi as argument, they will crosscompile the libs for the RaspberryPi. If your dependencies directory already contains the libraries for your local system, you might want to copy it before crosscompiling them. The dependencies folder does not only contain the libraries as the libraries 'make install' step will 'install' them in the dependencies directory using the --prefix option for automake/cmake.
So you can either use the init_dependencies.sh script with the -pi flag or run the XXX_upgrade.sh scripts with the -pi flag.
For example to cross compile libtins run ./libtins_upgrade.sh -pi you can verify that the created libary has the correct format by checking the shared lib:
17:49:30 zsdn@ubuntu: ~/zsdn-git/dependencies/lib $ file libtins.so.3.3
libtins.so.3.3: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=30ce2ad7b8879d6ea0cbd256ad44080f297b218c, not stripped
Make sure that there are no leftovers in your Download folder, as they may mess up the configuration
After all libraries were successfully cross compiled, you can crosscompile the zmf and commons libraries. to crosscompile zmf use the build-zmf-pi.sh script. The unittest compilation will fail atm as the toolfile wont be passed to the cmake of the UT's, but libzmf.so will be build regardless. Check if everything worked by running
18:08:52 zsdn@ubuntu: ~/zsdn-git/dependencies/lib $ file libzmf.so
libzmf.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=86187269e263d29ce60439be2fda34528fb79995, not stripped
to build the commons lib, run build-commons-pi.sh. As for zmf, the unittests will also fail.
Now the modules can be build by running the build-all-modules-pi.sh script.
Checking the executable binaries should show something like this:
18:13:39 zsdn@ubuntu: ~/zsdn-git/modules/SwitchAdapter/build $ file SwitchAdapter
SwitchAdapter: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0eac8fd16c33eb3e82748d12a5d59abcac00a403, not stripped
In order to run zsdn on a pi first the dependencies/lib folder has to be transfered to the pi, eg by using scp or rsync. (move to /home/pi/zsdn/lib) Now this lib folder must be registered with ldconfig: Edit /etc/ld.so.conf on the pi and add /home/pi/zsdn/lib Then run ldconfig as root now the modules can be transfered onto the pi and if everything worked, will execute