-
-
Notifications
You must be signed in to change notification settings - Fork 17
Cross compile for raspberry PI
❗ Not fully tested ❗
This page explain how to cross compile Yadoms on a linux computer for the RaspberryPI target. This wiki page has been tested with :
- Ubuntu 14.04 (64 bits)
- Ubuntu 16.04 (64 bits)
- RaspberryPI and Ubuntu are connected to network
- SSH is activated on the RaspberryPI
We assume user knows :
- RaspberryPI ip address
- RaspberryPI sudoer account (login and password); i.e. : pi / raspberry
Start with making a folder in your home directory called 'raspberry'. For convenience, outputs of some cross-compiled libraries will be directed to a specific folder. Create it now :
mkdir raspberry
cd raspberry
mkdir depsBuild
Before you start, you need to make sure the following is installed on the linux machine :
sudo apt-get install git cmake libssl-dev libgnutls-dev libopencv-gpu-dev autoconf automake libtool curl make g++ unzip
From the 'raspberry' follder, pull down the entire tools folder :
git clone --depth=1 git://github.com/raspberrypi/tools.git
The tools repository contains many toolchains. Go into your home directory , edit the file ~/.bashrc and add the following file at end:
export PATH=$PATH:$HOME/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin
Now you can either log out and log back in (i.e. restart your terminal session), or run . ~/.bashrc in your terminal to pick up the PATH addition in your current terminal session. Now, verify that you can access the compiler arm-linux-gnueabihf-gcc. You should get something like this :
arm-linux-gnueabihf-gcc --version
arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 4.8.3 20140106 (prerelease)
Copyright © 2013 Free Software Foundation, Inc.
Ce logiciel est libre; voir les sources pour les conditions de copie. Il n'y a PAS
GARANTIE; ni implicite pour le MARCHANDAGE ou pour un BUT PARTICULIER.
Boost must be cross-compiled because the apt-get do not provide all requested libraries.
Download boost and extract it
wget https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2
tar xjf boost_1_64_0.tar.bz2
Create bootstrap
cd boost_1_64_0
./bootstrap.sh
Create the user-config.jam in the user directory (cd ~)
nano ~/user-config.jam
using gcc : arm : arm-linux-gnueabihf-g++ ;
Cross compile boost (only useful libraries)
./b2 --with-atomic --with-chrono --with-date_time --with-filesystem --with-regex --with-serialization --with-thread --with-system --no-samples --no-tests toolset=gcc-arm link=static cxxflags=-fPIC
Remove user-config.jam
rm ~/user-config.jam
Download OpenSSL and extract it
Version 1.0.x is working.
Version 1.1.x is not working well
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
tar xzf openssl-1.0.2l.tar.gz
Build OpenSSL
cd openssl-1.0.2l
./Configure --prefix=$HOME/raspberry/depsBuild/openssl os/compiler:arm-linux-gnueabihf
make CC="arm-linux-gnueabihf-gcc" AR="arm-linux-gnueabihf-ar r" RANLIB="arm-linux-gnueabihf-ranlib"
make install
Download POCO and extract it
wget http://pocoproject.org/releases/poco-1.7.8/poco-1.7.8p2-all.tar.gz
tar xzf poco-1.7.8p2-all.tar.gz
In order to make it cross-compile, we need to define the RaspberryPI platform :
cd poco-1.7.8p2-all
echo 'TOOL = arm-linux-gnueabihf' > build/config/RaspberryPI
cat build/config/ARM-Linux >> build/config/RaspberryPI
echo 'STATICOPT_CC = -fPIC' >> build/config/RaspberryPI
echo 'STATICOPT_CXX = -fPIC' >> build/config/RaspberryPI
Configure and build POCO :
./configure --static --config=RaspberryPI --no-samples --no-tests --omit=CppUnit,CppUnit/WinTestRunner,Data,Data/SQLite,Data/ODBCData/MySQL,MongoDB,PageCompiler,PageCompiler/File2Page --include-path=$HOME/raspberry/depsBuild/openssl/include --library-path=$HOME/raspberry/depsBuild/openssl/lib
make
Protobuf is divided in two parts :
- The protoc compiler, used to generate C++ code from proto file : must be build for the host machine
- The protobuf library, which C++ generated code will link against : must be built for the target
wget https://github.com/google/protobuf/releases/download/v3.3.1/protobuf-3.3.1.tar.gz
tar -vxzf ./protobuf-3.3.1.tar.gz
mv protobuf-3.3.1 protobuf-3.3.1-host
cd protobuf-3.3.1-host
mkdir build
cd build
cmake ../cmake
cmake --build .
sudo make install
sudo ldconfig
cd ..
wget https://github.com/google/protobuf/releases/download/v3.3.1/protobuf-3.3.1.tar.gz
tar -vxzf ./protobuf-3.3.1.tar.gz
cd protobuf-3.3.1
./autogen.sh
./configure --enable-shared=no --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar STRIP=arm-linux-gnueabihf-strip RANLIB=arm-linux-gnueabihf-ranlib --prefix=$HOME/raspberry/depsBuild/protobuf --with-protoc=protoc --with-pic
make
make install
cd ..
To install swig 3 (apt-get give swig 2); you must install prerequisites.
sudo apt-get install libpcre3 libpcre3-dev
Download and build Swig source
wget http://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
tar xzf swig-3.0.12.tar.gz
cd swig-3.0.12
./configure
make
sudo make install
cd ..
Python must be build in 2 phases :
- Build of PGen
- Cross-compiled for the target
sudo apt-get install python-dev
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar xzf Python-2.7.13.tgz
mv Python-2.7.13 Python-2.7.13-host
cd Python-2.7.13-host
./configure
make python Parser/pgen
sudo make install
mkdir ../depsBuild/pythonhost
cp python ../depsBuild/pythonhost
cp Parser/pgen ../depsBuild/pythonhost
cd ..
sudo apt-get install python-dev
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar xzf Python-2.7.13.tgz
cd Python-2.7.13
CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar RANLIB=arm-linux-gnueabihf-ranlib ./configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --build=x86_64-linux-gnu --prefix=$HOME/rapsberry/depsBuild/python --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no ac_cv_have_long_long_format=yes --enable-shared
make HOSTPYTHON=$HOME/raspberry/depsBuild/pythonhost/python HOSTPGEN=$HOME/raspberry/depsBuild/pythonhost/Parser/pgen BLDSHARED="arm-linux-gnueabihf-gcc -shared" CROSS-COMPILE=arm-linux-gnueabihf- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=arm-linux-gnueabihf
wget https://ftp.postgresql.org/pub/source/v9.6.2/postgresql-9.6.2.tar.bz2
tar xjf postgresql-9.6.2.tar.bz2
cd postgresql-9.6.2
CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar RANLIB=arm-linux-gnueabihf-ranlib ./configure --host=arm-linux --build=arm-linux-gnueabihf --without-readline --without-zlib --disable-spinlocks
cd src/interfaces/libpq
make
cd ../../../..
sudo apt-get install cmake
Retrieve libudev.h and libudev.so files from a target. Create a directory /path/toLibudev where you copy these files.
this directory path will be used for yadoms configuration file.
git clone https://github.com/Yadoms/yadoms.git
cd yadoms
Be sure to be in 'yadoms' folder. Type these lines to create the sources/CMakeListsUserConfig.txt file :
echo 'set(BOOST_ROOT "'$PWD'/raspberry/boost_1_64_0")' > sources/CMakeListsUserConfig.txt
echo 'set(POCO_ROOT "'$PWD'/raspberry/poco-1.7.8p2-all")' >> sources/CMakeListsUserConfig.txt
echo 'set(SWIG_ROOT "'$PWD'/raspberry/swig-3.0.12")' >> sources/CMakeListsUserConfig.txt
echo 'set(COTIRE_USE ON)' >> sources/CMakeListsUserConfig.txt
echo 'set(COTIRE_USE_UNITY ON)' >> sources/CMakeListsUserConfig.txt
echo 'set(PROTOBUF_ROOT "'$HOME'/raspberry/depsBuild/protobuf")' >> sources/CMakeListsUserConfig.txt
echo 'set(PROTOBUF_PROTOC_EXECUTABLE "'`which protoc`'")' >> sources/CMakeListsUserConfig.txt
echo 'set(PROTOBUF_INSTALLED_TO_CUSTOM_DIRECTORY ON)' >> sources/CMakeListsUserConfig.txt
echo 'set(OPENSSL_ROOT "'$HOME'/raspberry/depsBuild/openssl")' >> sources/CMakeListsUserConfig.txt
echo 'set(DEBUG_WITH_GCC OFF)' >> sources/CMakeListsUserConfig.txt
echo 'set(PYTHON_USE_PKGCONFIG OFF)' >> sources/CMakeListsUserConfig.txt
echo 'set(PYTHON_USE_SOURCES ON)' >> sources/CMakeListsUserConfig.txt
echo 'set(PYTHON_ROOT "'$PWD'/raspberry/Python-2.7.13")' >> sources/CMakeListsUserConfig.txt
echo 'set(PYTHON_LIBRARIES "'$PWD'/raspberry/Python-2.7.13/libpython2.7.so")' >> sources/CMakeListsUserConfig.txt
echo 'set(PostgreSQL_ROOT ' >> sources/CMakeListsUserConfig.txt
echo ' "'$PWD'/raspberry/postgresql-9.6.2/src/interfaces/libpq"' >> sources/CMakeListsUserConfig.txt
echo ' "'$PWD'/raspberry/postgresql-9.6.2/src/include")' >> sources/CMakeListsUserConfig.txt
echo 'set(CC_RPI_ROOT "'$PWD'/raspberry/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf")' >> sources/CMakeListsUserConfig.txt
echo 'set(LIBUDEV_ROOT "/path/toLibudev")' >> sources/CMakeListsUserConfig.txt
echo 'set(UDEV_PATH_LIB "/path/toLibudev")' >> sources/CMakeListsUserConfig.txt
echo 'set(UDEV_PATH_INCLUDES "/path/toLibudev")' >> sources/CMakeListsUserConfig.txt
sh cmake_raspberry.sh c
To make using standard makefile:
cd projects
make
To make using "cotired" makefile (really much faster):
cd projects
make all_unity
Assume you know : pi_login : for this example : pi pi_address: 192.168.0.7
Create these directories on target where to copy files:
ssh pi_login@pi_address
mkdir /home/pi/dev
mkdir /home/pi/dev/ccyadoms
mkdir /home/pi/dev/ccyadoms/www
mkdir /home/pi/lib_tmp
exit
First step : copy yadoms executable
cd yadoms
cd build
scp -r * pi_login@pi_address:/home/pi/dev/ccyadoms
Second step : copy shared files to target
As /usr/local/lib needs root rights, use the lib_tmp folder in home
scp path/to/poco-1.7.8p2/lib/Linux/armv7l/* pi_login@pi_address:/home/pi/lib_tmp
scp path/to/boost_1_64_0/stage/lib/* pi_login@pi_address:/home/pi/lib_tmp
Third step : copy web site files to target
scp -r www/* pi_login@pi_address:/home/pi/dev/ccyadoms/www
Endly, go to the target to move shared files to /usr/local/lib
ssh pi_login@pi_address
sudo mv lib_tmp/* /usr/local/lib
rmdir lib_tmp
exit
On the target, do a ldconfig to update available libraries
ssh pi_login@pi_address
sudo ldconfig
Workaround for a known bug (will be fixed) : make logs directory
mkdir logs
Run yadoms
./yadoms
Yadoms -- The ultimate house automation solution