-
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 )
copy the following code and save it as a pi.cmake file into the raspberrypi directory
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSROOT $ENV{HOME}/raspberrypi/rootfs)
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs)
SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
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:
user@server: ~/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 cross compilation environment is set up, the libraries used by ZSDN need to be cross compiled for the pi. In the util folder of the 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 cross compile the libs for the RaspberryPi. If your dependencies directory already contains the libraries for your local system, you might want to copy it before cross compiling 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 library has the correct format by checking the shared lib:
user@server: ~/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 cross compile the ZMF and commons libraries. to cross compile ZMF use the build-zmf-pi.sh script. The unittest compilation will fail atm as the tool file wont be passed to the cmake of the UT's, but libzmf.so will be build regardless. Check if everything worked by running
user@server: ~/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 unit tests 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:
user@server: ~/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, e.g. 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.