wiki:projects/synapse/raspberry

Version 14 (modified by Edwin Eefting, 11 years ago) (diff)

--

Cross-compiling Synapse for raspberry (ARM) and other architectures

This is a quick howto on how i cross compiled synapse for the raspberrypi, using qemu to emulate the arm cpu architecture. This is the least tricky methode to cross compile, but also the slowest.

I used arch linux on my host system and debian on the rasp.

Learn your host system how to handle arm binaries

1. Steal a statically compiled qemu-arm from some distro:

its a shame archlinux doesnt have a static qemu :(

[root@lab1 tmp]# cd /tmp
[root@lab1 tmp]# mkdir qemu
[root@lab1 tmp]# cd qemu
[root@lab1 qemu]# dpkg -x /home/psy/Downloads/qemu-user-static_1.1.2+dfsg-2_amd64.deb  .
[root@lab1 qemu]# cp usr/bin/qemu-*-static /usr/bin

2. learn your kernel how to handle arm binaries

Create a file called /usr/share/binfmts/qemu-arm:

[root@lab1 binfmts]# cat /usr/share/binfmts/qemu-arm          
package qemu
interpreter /usr/bin/qemu-arm-static
magic \x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00
mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff

[root@lab1 binfmts]# update-binfmts --import

Set up the build environment

1. copy the rootfilesystem from your raspberry

We just copy the whole rootfs, so we have an exact copy of the environment we want to cross compile for:

[root@lab1 psy]# rsync -ax root@192.168.13.238:/ rasprootfs
root@192.168.13.238's password: 
....

2. entering the build environment

The only thing you have to do to be able to enter the environent is copy qemu-arm-static into it:

[root@lab1 psy]# cp /usr/bin/qemu-arm-static rasprootfs/usr/bin/
[root@lab1 psy]# export QEMU_CPU=arm1176
[root@lab1 psy]# chroot rasprootfs/
[rasproot] root@lab1:/# arch
armv6l

w000h...now we can chroot to the local raspberry environment and start to compile stuff!

note that arch says armv61 and NOT armv7l. (if it doesnt you forgot to set the environment variable)

compiling and installing synapse

1. install dependencies neccesary to compile synapse

Inside the chroot do this:

root@lab1:~/Synapse# apt-get install libboost-all-dev cmake libcurl4-openssl-dev liboauth-dev libvlc-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done

(....... takes a while)

2. clone the source tree

root@lab1:~# git clone git://github.com/psy0rz/Synapse.git
Cloning into 'Synapse'...
remote: Counting objects: 4533, done.
remote: Compressing objects: 100% (1258/1258), done.
remote: Total 4533 (delta 3311), reused 4429 (delta 3207)
Receiving objects: 100% (4533/4533), 2.04 MiB | 835 KiB/s, done.
Resolving deltas: 100% (3311/3311), done.

wow...even while emulated git STILL is superquick! git is awesome :)

3. compile it

We usually wanna compile a Release-version for the raspberry, since performance is much better that way.

root@lab1:~# cd Synapse/
root@lab1:~/Synapse# cmake -DCMAKE_BUILD_TYPE=Release .
-- The C compiler identification is GNU 4.6.3
......

root@lab1:~/Synapse# make -j 4 
Scanning dependencies of target test_http_json
Scanning dependencies of target pl_dir
.....takes forever the first time...

4. run it

Now you can run it. However, qemu doesnt support some syscalls, so its seems to segfault and crash a lot when you run it directly under qemu.

If you copy it to the rasp it does work perfectly. I tried, and the performance of internetnetpaper for example, is very good.

[rasproot] root@psysamsungtop:/root/Synapse# ./synapse 
0x9b63a8 test: Selftesting CVAR_LONG_DOUBLE [/root/Synapse/cvar.cpp:611]
0x9b63a8 test: empty long value [/root/Synapse/cvar.cpp:613]
0x9b63a8 test: use long as boolean [/root/Synapse/cvar.cpp:617]
0x9b63a8 test: long construct [/root/Synapse/cvar.cpp:621]
0x9b63a8 test: long assignment [/root/Synapse/cvar.cpp:625]
0x9b63a8 test: long assignment reference [/root/Synapse/cvar.cpp:630]
0x9b63a8 test: int to string [/root/Synapse/cvar.cpp:636]
0x9b63a8 test: long to string [/root/Synapse/cvar.cpp:640]
0x9b63a8 test: long to map [/root/Synapse/cvar.cpp:646]
...