RaspberryPISourceInstall

Version 4 (coder, 25/04/2015 20:02)

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