RaspberryPISourceInstall

Version 23 (scotty, 03/05/2017 21:15)

1 5 coder
h1. RaspberryPiSourceInstall
2 1 coder
3 23 scotty
This page explains how to install the libavg developer version from github on a Raspberry Pi by either native or cross compiling. The latter involves compiling libavg on a separate Linux machine. The benefit of this is that native compiling on the Pi 2/3 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 23 scotty
Tested on Pi 2/3 with 2017-04-10-raspbian-jessie, cross compiling on ubuntu-16.04.2-desktop-amd64.
6 1 coder
7 23 scotty
Note that Raspberry Pi support is still beta - we're working on fixing all remaining issues.
8 1 coder
9 23 scotty
_TODO:_ notes on architecture flags
10 21 coder
11 1 coder
h2. Install libSDL
12 18 coder
13 23 scotty
To build and run libavg on a Pi, libSDL2>=2.0.4 is needed. As current raspbian ships version 2.0.2, manual installation on the Pi is required.
14 23 scotty
15 18 coder
<pre>
16 23 scotty
<code>$ sudo apt-get install automake autoconf libtool libfreeimage-dev libopenal-dev \
17 23 scotty
libsndfile-dev libudev-dev libasound2-dev libtiff5-dev libwebp-dev
18 18 coder
</code></pre>
19 18 coder
20 21 coder
On Wheezy, libevdev-dev isn't available, so add the following line to @/etc/apt/sources.list@:
21 18 coder
22 18 coder
<pre>
23 18 coder
<code>deb http://http.debian.net/debian wheezy-backports main
24 18 coder
</code></pre>
25 18 coder
26 18 coder
Then:
27 1 coder
28 18 coder
<pre>
29 18 coder
<code>$ sudo apt-get -t wheezy-backports install libevdev-dev
30 1 coder
</code></pre>
31 1 coder
32 1 coder
Say 'Y' to the 'Install without verification' prompt.
33 1 coder
34 1 coder
On Jessie, just install libevdev-dev:
35 1 coder
36 1 coder
<pre>
37 1 coder
<code>$ sudo apt-get install libevdev-dev
38 21 coder
</code></pre>
39 1 coder
40 23 scotty
Download libSDL 2.0.5 from libsdl.org, unpack the tarball. Then build and install libSDL:
41 1 coder
42 1 coder
<pre>
43 23 scotty
<code>$ wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
44 23 scotty
$ tar -xzf SDL2-2.0.5.tar.gz 
45 23 scotty
$ cd SDL2-2.0.5
46 23 scotty
$ ./configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl
47 1 coder
$ make -j5
48 1 coder
$ sudo make install
49 1 coder
</code></pre>
50 1 coder
51 1 coder
52 23 scotty
h2. Install dependencies on the Pi (for native and cross compiling)
53 1 coder
54 23 scotty
*_On the Pi_*, install the needed packages:
55 23 scotty
56 23 scotty
<pre>
57 23 scotty
<code>$ sudo apt-get install libjpeg62-turbo-dev libjpeg-dev libxml2-dev \
58 23 scotty
libpango1.0-dev librsvg2-dev libgdk-pixbuf2.0-dev libavcodec-dev \
59 23 scotty
libavformat-dev libswscale-dev libavresample-dev python-dev libboost-python-dev \
60 23 scotty
libboost-thread-dev libxxf86vm-dev libdc1394-22-dev linux-libc-dev libxi-dev
61 23 scotty
</code></pre>
62 23 scotty
63 23 scotty
h2. Native compiling on the Pi
64 23 scotty
65 23 scotty
Install some build tools:
66 23 scotty
67 23 scotty
<pre>
68 23 scotty
<code>$ sudo apt-get install git cmake g++
69 23 scotty
</code></pre>
70 23 scotty
71 23 scotty
Check out libavg and build:
72 23 scotty
73 23 scotty
<pre>
74 23 scotty
<code>$ git clone https://github.com/libavg/libavg.git
75 23 scotty
$ cd libavg
76 23 scotty
$ git checkout feature/raspi_jessie
77 23 scotty
$ mkdir build
78 23 scotty
$ cd build
79 23 scotty
$ cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
80 23 scotty
$ make
81 23 scotty
$ make check
82 23 scotty
$ sudo make install
83 23 scotty
</code></pre>
84 23 scotty
85 23 scotty
Note that the available RAM is the bottleneck here and things are getting very slow when the kernel starts swapping. Parallel builds with @make -jx@ will fail with an out of memory error. It is suggested to free as much RAM as possible for the build process (e.g. by setting the GPU memory to 16 MB and booting only into the console, not X).
86 23 scotty
87 23 scotty
h2. Cross compiling on a Linux host
88 23 scotty
89 1 coder
This work is done *_on the Linux machine_*.
90 1 coder
91 23 scotty
This is the directory structure we'll end up with:
92 1 coder
93 7 coder
<pre>
94 1 coder
rpi
95 1 coder
    libavg        - the libavg source tree
96 23 scotty
    rootfs        - (partial) copy of the Pi root filesystem
97 23 scotty
    tools         - the toolchain (compiler, linker, etc.) used to cross compile
98 23 scotty
    staging       - the compiled version of libavg that will be copied to the Pi
99 1 coder
</pre>
100 1 coder
101 23 scotty
Install some build tools:
102 23 scotty
103 23 scotty
<pre>
104 23 scotty
<code>$ sudo apt-get install git cmake
105 23 scotty
</code></pre>
106 23 scotty
107 1 coder
Tell the build system where the directory hierarchy is:
108 1 coder
109 7 coder
<pre>
110 23 scotty
<code>$ mkdir rpi
111 23 scotty
$ cd rpi
112 23 scotty
$ export AVG_RPI_PATH=$PWD
113 23 scotty
</code></pre>
114 1 coder
115 23 scotty
h3. Set up the cross compile toolchain
116 1 coder
117 23 scotty
Download the cross compile tools to @rpi/tools@:
118 23 scotty
119 1 coder
<pre>
120 1 coder
<code>$ cd rpi
121 23 scotty
$ git clone git://github.com/raspberrypi/tools.git
122 1 coder
</code></pre>
123 6 coder
124 23 scotty
Copy @/usr@, @/lib@, and @/opt/vc@ directory trees from the Pi to @rpi/rootfs@ (replace @$PI@ with the IP address of the Pi):
125 1 coder
126 1 coder
<pre>
127 23 scotty
<code>$ cd rpi
128 23 scotty
$ mkdir rootfs
129 23 scotty
$ cd rootfs
130 1 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/{lib,usr} .
131 7 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/opt/vc opt
132 1 coder
</code></pre>
133 1 coder
134 23 scotty
Then, fix some system libraries so they don't contain references to absolute paths. Open the files in a text editor and change them. They are:
135 1 coder
136 23 scotty
_rootfs/usr/lib/arm-linux-gnueabihf/libpthread.so_:
137 1 coder
138 7 coder
<pre>
139 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
140 1 coder
GROUP ( libpthread.so.0 libpthread_nonshared.a )
141 20 coder
</code></pre>
142 1 coder
143 23 scotty
_rootfs/usr/lib/arm-linux-gnueabihf/libc.so_:
144 11 coder
145 7 coder
<pre>
146 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
147 1 coder
GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-armhf.so.3 ) )
148 1 coder
</code></pre>
149 8 coder
150 23 scotty
Adjust the pkg-config file _rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig/glib-2.0.pc_ to have @-lpcre@ in @Libs@, not in @Libs.private@:
151 8 coder
152 8 coder
<pre>
153 23 scotty
<code>[...]
154 23 scotty
Libs: -L${libdir} -lglib-2.0 -lpcre
155 23 scotty
Libs.private: -pthread     
156 23 scotty
[...]
157 8 coder
</code></pre>
158 8 coder
159 23 scotty
Fix some symlinks:
160 8 coder
161 8 coder
<pre>
162 23 scotty
<code>$ cd rootfs/usr/lib/arm-linux-gnueabihf/
163 23 scotty
$ ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
164 23 scotty
$ ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
165 1 coder
</code></pre>
166 1 coder
167 23 scotty
h3. Check out and build libavg
168 15 coder
169 15 coder
<pre>
170 15 coder
<code>$ cd rpi
171 10 coder
$ git clone https://github.com/libavg/libavg.git
172 11 coder
$ cd libavg
173 23 scotty
$ git checkout feature/raspi_jessie 
174 23 scotty
$ mkdir build
175 23 scotty
$ cd build
176 23 scotty
$ cmake -DCMAKE_TOOLCHAIN_FILE=../rpi-toolchain.cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
177 23 scotty
$ make -j5
178 23 scotty
$ make install
179 1 coder
</code></pre>
180 6 coder
181 23 scotty
h3. Install on the Pi
182 1 coder
183 7 coder
Copy the compiled libavg to the Pi:
184 1 coder
185 11 coder
<pre>
186 23 scotty
<code>$ cd rpi/staging
187 23 scotty
$ mv usr/local/lib/python2.7/site-packages usr/local/lib/python2.7/dist-packages
188 23 scotty
$ rsync -au usr pi@$PI:/home/pi/Desktop
189 7 coder
</code></pre>
190 1 coder
191 1 coder
Back *_on the Pi_*, copy libavg from the desktop to its final destination:
192 1 coder
193 6 coder
<pre>
194 17 coder
<code>$ sudo cp -R ~/Desktop/usr/* /usr
195 1 coder
</code></pre>
196 7 coder
197 1 coder
h2. Run the tests
198 5 coder
199 1 coder
<pre>
200 1 coder
<code>$ cd /usr/local/lib/python2.7/dist-packages/libavg/test/
201 1 coder
$ python Test.py
202 1 coder
</code></pre>
203 1 coder
204 1 coder
That's it! libavg should now be running on your Pi.