RaspberryPISourceInstall

Version 9 (coder, 25/04/2015 21:44)

1 5 coder
h1. RaspberryPiSourceInstall
2 1 coder
3 5 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.
4 1 coder
5 9 coder
Alternatively, you can compile directly on the Pi by following the [[UbuntuSourceInstall]] directions and pass <code>--enable-rpi --enable-egl</code> to configure.
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 1 coder
This is the directory structure on the Linux machine:
21 1 coder
22 7 coder
<pre>
23 7 coder
rpi
24 1 coder
    libavg        - the libavg source tree
25 1 coder
    root          - copy of the PI filesystem
26 1 coder
    rpi-tools     - the toolchain (compiler, linker, etc.) used to cross-compile
27 1 coder
    staging       - the compiled version of libavg that will be copied to the PI
28 1 coder
</pre>
29 1 coder
30 1 coder
31 1 coder
32 1 coder
*_On the Linux machine_*, download the crosscompile tools to rpi-tools:
33 1 coder
34 6 coder
<pre>
35 1 coder
<code>$ cd rpi
36 1 coder
$ git clone git://github.com/raspberrypi/tools.git
37 7 coder
</code></pre>
38 1 coder
39 1 coder
Copy /usr, /lib, and /opt/vc directory trees from the Pi (replace $PI with the IP address of the Pi):
40 1 coder
41 1 coder
<pre>
42 1 coder
<code>$ mkdir root
43 1 coder
$ cd root
44 1 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/{lib,usr} .
45 1 coder
$ rsync -rl --delete-after --safe-links pi@192.168.2.PI:/opt/vc opt
46 7 coder
</code></pre>
47 1 coder
48 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:
49 1 coder
50 1 coder
_root/usr/lib/arm-linux-gnueabihf/libpthread.so_:
51 1 coder
52 6 coder
<pre>
53 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
54 1 coder
GROUP ( libpthread.so.0 libpthread_nonshared.a )
55 7 coder
</code></pre>
56 1 coder
57 1 coder
_root/usr/lib/arm-linux-gnueabihf/libc.so_:
58 1 coder
59 1 coder
<pre>
60 6 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
61 1 coder
GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-armhf.so.3 ) )
62 7 coder
</code></pre>
63 1 coder
64 1 coder
Fix some symlinks:
65 1 coder
66 1 coder
<pre>
67 6 coder
<code>$ cd root/usr/lib/arm-linux-gnueabihf/
68 1 coder
$ ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
69 1 coder
$ ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
70 7 coder
</code></pre>
71 1 coder
72 1 coder
Put the toolchain into the path ($RPI is the absolute path to your rpi directory):
73 1 coder
74 6 coder
<pre>
75 6 coder
<code>$ export PATH=$PATH:$RPI/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
76 7 coder
</code></pre>
77 1 coder
78 1 coder
h2. Build libavg
79 1 coder
80 8 coder
Tell configure which architecture to build for. For Raspbian on the Pi 2:
81 8 coder
82 8 coder
<pre>
83 8 coder
<code>$ export ARCHFLAGS="-mcpu=cortex-a7 -mfpu=neon-vfpv4"
84 8 coder
</code></pre>
85 8 coder
86 8 coder
and for the older Pi:
87 8 coder
88 8 coder
<pre>
89 8 coder
<code>$ export ARCHFLAGS="-march=armv6 -mfloat-abi=hard -mfpu=vfp"
90 8 coder
</code></pre>
91 8 coder
92 8 coder
for other distros, run <code>gcc -mcpu=native -march=native -Q --help=target</code> on the Pi
93 8 coder
to find out what to set ARCHFLAGS to.
94 8 coder
95 8 coder
Once you've set the architecture, build:
96 8 coder
97 1 coder
<pre>
98 6 coder
<code>$ ./rpi-configure
99 1 coder
$ DESTDIR=$RPI/staging make -j6
100 1 coder
$ DESTDIR=$RPI/staging make install
101 7 coder
</code></pre>
102 1 coder
103 5 coder
h2. Install on the Pi
104 1 coder
105 1 coder
Copy the compiled libavg to the Pi:
106 1 coder
107 6 coder
<pre>
108 1 coder
<code>$ cd staging
109 1 coder
$ rsync -au usr pi@$IP:/home/pi/Desktop
110 7 coder
</code></pre>
111 1 coder
112 1 coder
*_On the Pi_*, copy libavg from the desktop to its final destination:
113 6 coder
114 1 coder
<pre>
115 1 coder
<code>$ sudo cp -R ~/Desktop/usr/* /usr
116 7 coder
</code></pre>
117 1 coder
118 1 coder
h2. Run the tests
119 1 coder
120 6 coder
<pre>
121 1 coder
<code>$ cd /usr/local/share/python-libavg/test/
122 1 coder
$ python Test.py
123 7 coder
</code></pre>
124 1 coder
125 5 coder
That's it! libavg should now be running on your Pi.