RaspberryPISourceInstall

Version 13 (coder, 04/05/2015 23:45)

1 5 coder
h1. RaspberryPiSourceInstall
2 1 coder
3 13 coder
This page explains how to install the libavg developer version from github on a Raspberry Pi by cross-compiling. The process involves compiling libavg on a separate Linux machine. The benefit of this is that compiling on the Pi 2 takes around an hour, while cross-compiling takes a few minutes (The original Pi would finish in 4-6 hours or fail with an out of memory condition). The downside is that it's a bit harder to set up. Alternatively, you can compile directly on the Pi by following the [[UbuntuSourceInstall]] directions and pass <code>--enable-rpi --enable-egl</code> to configure.
4 1 coder
5 13 coder
Note that Raspberry Pi support is still beta - we're working on fixing all remaining issues.
6 1 coder
7 5 coder
h2. Install dependencies on the Pi
8 1 coder
9 5 coder
*_On the Pi_*, install the needed packages:
10 1 coder
11 1 coder
<pre>
12 1 coder
<code>$ sudo apt-get install git automake autoconf libtool libxml2-dev \
13 1 coder
libpango1.0-dev librsvg2-dev libgdk-pixbuf2.0-dev libavcodec-dev libavformat-dev \
14 1 coder
libswscale-dev libavresample-dev python-dev libboost-python-dev libboost-thread-dev g++ libSDL-dev \
15 1 coder
libxxf86vm-dev libdc1394-22-dev linux-libc-dev
16 7 coder
</code></pre>
17 1 coder
18 1 coder
h2. Set up the Cross-compile Toolchain
19 1 coder
20 11 coder
This work is done *_on the Linux machine_*.
21 1 coder
22 11 coder
This is the directory structure we'll need:
23 11 coder
24 7 coder
<pre>
25 7 coder
rpi
26 1 coder
    libavg        - the libavg source tree
27 1 coder
    root          - copy of the PI filesystem
28 1 coder
    rpi-tools     - the toolchain (compiler, linker, etc.) used to cross-compile
29 1 coder
    staging       - the compiled version of libavg that will be copied to the PI
30 1 coder
</pre>
31 1 coder
32 11 coder
Tell the build system where the directory hierarchy is:
33 1 coder
34 11 coder
<pre>
35 11 coder
$ export AVG_RPI_ROOT=.....
36 11 coder
</pre>
37 1 coder
38 11 coder
Download the crosscompile tools to rpi-tools:
39 1 coder
40 6 coder
<pre>
41 1 coder
<code>$ cd rpi
42 1 coder
$ git clone git://github.com/raspberrypi/tools.git
43 7 coder
</code></pre>
44 1 coder
45 1 coder
Copy /usr, /lib, and /opt/vc directory trees from the Pi (replace $PI with the IP address of the Pi):
46 1 coder
47 1 coder
<pre>
48 1 coder
<code>$ mkdir root
49 1 coder
$ cd root
50 1 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/{lib,usr} .
51 1 coder
$ rsync -rl --delete-after --safe-links pi@192.168.2.PI:/opt/vc opt
52 7 coder
</code></pre>
53 1 coder
54 1 coder
Then, fix some system libraries so they don't contain references to absolute directories. Open the files in a text editor and change them. They are:
55 1 coder
56 1 coder
_root/usr/lib/arm-linux-gnueabihf/libpthread.so_:
57 1 coder
58 6 coder
<pre>
59 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
60 1 coder
GROUP ( libpthread.so.0 libpthread_nonshared.a )
61 7 coder
</code></pre>
62 1 coder
63 1 coder
_root/usr/lib/arm-linux-gnueabihf/libc.so_:
64 1 coder
65 1 coder
<pre>
66 6 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
67 1 coder
GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-armhf.so.3 ) )
68 7 coder
</code></pre>
69 1 coder
70 1 coder
Fix some symlinks:
71 1 coder
72 1 coder
<pre>
73 1 coder
<code>$ cd root/usr/lib/arm-linux-gnueabihf/
74 1 coder
$ ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
75 7 coder
$ ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
76 1 coder
</code></pre>
77 1 coder
78 1 coder
Put the toolchain into the path ($RPI is the absolute path to your rpi directory):
79 1 coder
80 6 coder
<pre>
81 11 coder
<code>$ export PATH=$PATH:$AVG_RPI_ROOT/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
82 7 coder
</code></pre>
83 1 coder
84 1 coder
h2. Build libavg
85 1 coder
86 8 coder
Tell configure which architecture to build for. For Raspbian on the Pi 2:
87 8 coder
88 8 coder
<pre>
89 8 coder
<code>$ export ARCHFLAGS="-mcpu=cortex-a7 -mfpu=neon-vfpv4"
90 8 coder
</code></pre>
91 8 coder
92 8 coder
and for the older Pi:
93 8 coder
94 8 coder
<pre>
95 8 coder
<code>$ export ARCHFLAGS="-march=armv6 -mfloat-abi=hard -mfpu=vfp"
96 8 coder
</code></pre>
97 8 coder
98 8 coder
for other distros, run <code>gcc -mcpu=native -march=native -Q --help=target</code> on the Pi
99 8 coder
to find out what to set ARCHFLAGS to.
100 8 coder
101 1 coder
Once you've set the architecture, build:
102 1 coder
103 1 coder
<pre>
104 10 coder
<code>$ ./bootstrap
105 10 coder
$ ./rpi-configure
106 11 coder
$ DESTDIR=$AVG_RPI_ROOT/staging make -j6
107 11 coder
$ DESTDIR=$AVG_RPI_ROOT/staging make install
108 1 coder
</code></pre>
109 5 coder
110 1 coder
h2. Install on the Pi
111 1 coder
112 1 coder
Copy the compiled libavg to the Pi:
113 1 coder
114 6 coder
<pre>
115 12 coder
<code>$ cd ../staging
116 1 coder
$ rsync -au usr pi@$IP:/home/pi/Desktop
117 7 coder
</code></pre>
118 1 coder
119 11 coder
Back *_on the Pi_*, copy libavg from the desktop to its final destination:
120 6 coder
121 1 coder
<pre>
122 1 coder
<code>$ sudo cp -R ~/Desktop/usr/* /usr
123 7 coder
</code></pre>
124 1 coder
125 1 coder
h2. Run the tests
126 1 coder
127 6 coder
<pre>
128 1 coder
<code>$ cd /usr/local/share/python-libavg/test/
129 1 coder
$ python Test.py
130 7 coder
</code></pre>
131 1 coder
132 5 coder
That's it! libavg should now be running on your Pi.