Baf for cross compiling

From berofix - professional SIP gateway
Jump to: navigation, search

Often it is necessary to run a linux tool or deamon which is not part of the standard firmware or another app of the beroNet Gateway. baf provides the complete toolchain to cross compile any in source code available tool. It might though often be necessary to modify and adjust some of the source code, so that it is compatible with the uclibc and the rather old libraries that run on the beroNet gateway.

NOTE: you should have baf already installed in order to use this documentation.

This page explains the way how to approach a cross compilation and what to do with the resulting binary. The overview is:


Setup the Path

It is very useful to setup the path, so that the compiler can be found by configure:

export PATH=/usr/local/share/baf/toolchain/bin/:$PATH

It can be handy to put this into your .bash_profile or such, so that you don't need to setup the path each time you open a new shell.


download the source package

Find the package on the internet or get it via the

apt-get source $package$

under debian/ubuntu like distros. Unpack it and make sure there is a "configure" script.

In this example we're showing how to cross compile siproxd to run it on the beroNet Gateway.

After downloading and unpacking the siproxd source (in this case version 0.8.2) change into the source folder:

cd siproxd-0.8.2 

passing the cross compile arguments to configure

The configure script needs to know that it is used for cross compilation:

./configure --prefix=/home/crich/src/target/ --host=arm-linux

--prefix tells configure where the binaries and libraries should be installed and --host tells it to use the arm-linux compiler which can be found in the $PATH


After running configure we learn that siproxd requires libosip2, which is not present on the beroNet gateway:

*** ERROR: libosip2 is required!   Maybe you need to use --with-libosip-prefix ?

so we need to donwload and compile it too.

compiling required libraries

siproxd requires libosip which needs to be downloaded as source and compiled for the arm platform. after downloading and unpacking libosip configure needs to get the right arguments:

 ./configure --prefix=/home/crich/src/target/ --host=arm-linux

--prefix tells configure where the library and header files should be installed and --host tells it to use the cross compiler.

after configure ran the libary needs to be compiled and installed with

make install


re-running configure

After having compiled and installed the necessary libraries, we can re-run configure:

./configure --prefix=/home/crich/src/target/ --host=arm-linux --with-libosip-prefix=/home/crich/src/target/

this time telling configure where the library libosip can be found.


compile the package

The compilation process starts with the command

make

During compilation you will notice that the compiler "arm-linux-gcc" is used instead of "gcc". At the end of the compilation process there should be no error and the binary should be available under:

src/siproxd 

with

make install 

the binary and all necessary libraries will be installed in the target directory. This can be helpful to figure out which files need to be copied later into the App.

To check if the binary can be run on the beroNet Gateway use file:

file src/siproxd
#src/siproxd: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped

The output shows ARM, Version 1, which stands for the ARM CPU of the beroNet Gateway, everything looks fine!

strip the binary

To remove debugging symbols and make the binary smaller the tool "arm-linux-strip" can be used:

arm-linux-strip -s siproxd

create an app

Create the app with baf:

baf create siproxd

in the siproxd-appsfolder there is a template folder. This folder is used to build the app.

cd siproxd/template/

You can simply copy all binaries and libraries into the bin and lib folder.

cp  /home/crich/src/target/sbin/siproxd bin/
cp -a /home/crich/src/target/lib/libosip2.* lib/
cp -a /home/crich/src/target/lib/libosipparser2.* lib/

Now the app can be created:

cd ..
baf make


and installed through the beroNet Gateway GUI (Apps->Market)

After installation you can login to the gateway with the admin user through ssh (make sure to have ssh access enabled Preferences->security):

ssh admin@172.20.10.19 

Now move to

cd /apps/siproxd/

when you try to start siproxd with:

bin/siproxd

you will get an error message:

./bin/siproxd: can't load library 'libosipparser2.so.11'

you can check if library depencies exists with ldd:

ldd bin/siproxd

It is necessary to tell the shell where it can find the library by using the env variable LD_LIBRARY_PATH:

LD_LIBRARY_PATH=/apps/siproxd/lib/ bin/siproxd  --help

now it runs and shows us the help page:

siproxd-0.8.2-7996 (c) 2002-2011 Thomas Ries

Usage: siproxd [options] 
options:
       -h, --help                 help
       -d, --debug <pattern>      set debug-pattern
       -c, --config <cfgfile>     use the specified config file
       -p, --pid-file <pidfile>   create pid file <pidfile>