RaspberryPISourceInstall

Version 24 (scotty, 03/05/2017 21:39)

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 24 scotty
To enable architecture specific optimizations, compiler flags can be provided. Just add them to the @cmake@ calls below.
8 24 scotty
(However, they don't seems to make much of a difference.)
9 1 coder
10 24 scotty
For Raspbian on the Pi 3:
11 24 scotty
12 24 scotty
<pre><code>-DAVG_RPI_ARCHFLAGS="-mcpu=cortex-a53 -mfpu=neon-vfpv4"</code></pre>
13 24 scotty
14 24 scotty
on the Pi 2:
15 24 scotty
16 24 scotty
<pre><code>-DAVG_RPI_ARCHFLAGS="-mcpu=cortex-a7 -mfpu=neon-vfpv4"</code></pre>
17 24 scotty
18 24 scotty
and for the older Pi:
19 24 scotty
20 24 scotty
<pre><code>-DAVG_RPI_ARCHFLAGS="-march=armv6 -mfloat-abi=hard -mfpu=vfp"</code></pre>
21 24 scotty
22 24 scotty
For other distros, run <code>gcc -mcpu=native -march=native -Q --help=target</code> on the Pi to find out what to set AVG_RPI_ARCHFLAGS to.
23 24 scotty
24 24 scotty
_Note that Raspberry Pi support is still beta - we're working on fixing all remaining issues._
25 21 coder
26 1 coder
h2. Install libSDL
27 18 coder
28 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.
29 23 scotty
30 18 coder
<pre>
31 23 scotty
<code>$ sudo apt-get install automake autoconf libtool libfreeimage-dev libopenal-dev \
32 23 scotty
libsndfile-dev libudev-dev libasound2-dev libtiff5-dev libwebp-dev
33 18 coder
</code></pre>
34 18 coder
35 21 coder
On Wheezy, libevdev-dev isn't available, so add the following line to @/etc/apt/sources.list@:
36 18 coder
37 18 coder
<pre>
38 18 coder
<code>deb http://http.debian.net/debian wheezy-backports main
39 18 coder
</code></pre>
40 18 coder
41 18 coder
Then:
42 1 coder
43 18 coder
<pre>
44 18 coder
<code>$ sudo apt-get -t wheezy-backports install libevdev-dev
45 1 coder
</code></pre>
46 1 coder
47 1 coder
Say 'Y' to the 'Install without verification' prompt.
48 1 coder
49 1 coder
On Jessie, just install libevdev-dev:
50 1 coder
51 1 coder
<pre>
52 1 coder
<code>$ sudo apt-get install libevdev-dev
53 21 coder
</code></pre>
54 1 coder
55 23 scotty
Download libSDL 2.0.5 from libsdl.org, unpack the tarball. Then build and install libSDL:
56 1 coder
57 1 coder
<pre>
58 23 scotty
<code>$ wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
59 23 scotty
$ tar -xzf SDL2-2.0.5.tar.gz 
60 23 scotty
$ cd SDL2-2.0.5
61 23 scotty
$ ./configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl
62 1 coder
$ make -j5
63 1 coder
$ sudo make install
64 1 coder
</code></pre>
65 1 coder
66 1 coder
67 23 scotty
h2. Install dependencies on the Pi (for native and cross compiling)
68 1 coder
69 23 scotty
*_On the Pi_*, install the needed packages:
70 23 scotty
71 23 scotty
<pre>
72 23 scotty
<code>$ sudo apt-get install libjpeg62-turbo-dev libjpeg-dev libxml2-dev \
73 23 scotty
libpango1.0-dev librsvg2-dev libgdk-pixbuf2.0-dev libavcodec-dev \
74 23 scotty
libavformat-dev libswscale-dev libavresample-dev python-dev libboost-python-dev \
75 23 scotty
libboost-thread-dev libxxf86vm-dev libdc1394-22-dev linux-libc-dev libxi-dev
76 23 scotty
</code></pre>
77 23 scotty
78 23 scotty
h2. Native compiling on the Pi
79 23 scotty
80 23 scotty
Install some build tools:
81 23 scotty
82 23 scotty
<pre>
83 23 scotty
<code>$ sudo apt-get install git cmake g++
84 23 scotty
</code></pre>
85 23 scotty
86 23 scotty
Check out libavg and build:
87 23 scotty
88 23 scotty
<pre>
89 23 scotty
<code>$ git clone https://github.com/libavg/libavg.git
90 23 scotty
$ cd libavg
91 23 scotty
$ git checkout feature/raspi_jessie
92 23 scotty
$ mkdir build
93 23 scotty
$ cd build
94 23 scotty
$ cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
95 23 scotty
$ make
96 23 scotty
$ make check
97 23 scotty
$ sudo make install
98 23 scotty
</code></pre>
99 23 scotty
100 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).
101 23 scotty
102 23 scotty
h2. Cross compiling on a Linux host
103 23 scotty
104 1 coder
This work is done *_on the Linux machine_*.
105 1 coder
106 23 scotty
This is the directory structure we'll end up with:
107 1 coder
108 7 coder
<pre>
109 1 coder
rpi
110 1 coder
    libavg        - the libavg source tree
111 23 scotty
    rootfs        - (partial) copy of the Pi root filesystem
112 23 scotty
    tools         - the toolchain (compiler, linker, etc.) used to cross compile
113 23 scotty
    staging       - the compiled version of libavg that will be copied to the Pi
114 1 coder
</pre>
115 1 coder
116 23 scotty
Install some build tools:
117 23 scotty
118 23 scotty
<pre>
119 23 scotty
<code>$ sudo apt-get install git cmake
120 23 scotty
</code></pre>
121 23 scotty
122 1 coder
Tell the build system where the directory hierarchy is:
123 1 coder
124 7 coder
<pre>
125 23 scotty
<code>$ mkdir rpi
126 23 scotty
$ cd rpi
127 23 scotty
$ export AVG_RPI_PATH=$PWD
128 23 scotty
</code></pre>
129 1 coder
130 23 scotty
h3. Set up the cross compile toolchain
131 1 coder
132 23 scotty
Download the cross compile tools to @rpi/tools@:
133 23 scotty
134 1 coder
<pre>
135 1 coder
<code>$ cd rpi
136 23 scotty
$ git clone git://github.com/raspberrypi/tools.git
137 1 coder
</code></pre>
138 6 coder
139 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):
140 1 coder
141 1 coder
<pre>
142 23 scotty
<code>$ cd rpi
143 23 scotty
$ mkdir rootfs
144 23 scotty
$ cd rootfs
145 1 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/{lib,usr} .
146 7 coder
$ rsync -rl --delete-after --safe-links pi@$PI:/opt/vc opt
147 1 coder
</code></pre>
148 1 coder
149 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:
150 1 coder
151 23 scotty
_rootfs/usr/lib/arm-linux-gnueabihf/libpthread.so_:
152 1 coder
153 7 coder
<pre>
154 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
155 1 coder
GROUP ( libpthread.so.0 libpthread_nonshared.a )
156 20 coder
</code></pre>
157 1 coder
158 23 scotty
_rootfs/usr/lib/arm-linux-gnueabihf/libc.so_:
159 11 coder
160 7 coder
<pre>
161 1 coder
<code>OUTPUT_FORMAT(elf32-littlearm)
162 1 coder
GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-armhf.so.3 ) )
163 1 coder
</code></pre>
164 8 coder
165 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@:
166 8 coder
167 8 coder
<pre>
168 23 scotty
<code>[...]
169 23 scotty
Libs: -L${libdir} -lglib-2.0 -lpcre
170 23 scotty
Libs.private: -pthread     
171 23 scotty
[...]
172 8 coder
</code></pre>
173 8 coder
174 23 scotty
Fix some symlinks:
175 8 coder
176 8 coder
<pre>
177 23 scotty
<code>$ cd rootfs/usr/lib/arm-linux-gnueabihf/
178 23 scotty
$ ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so
179 23 scotty
$ ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
180 1 coder
</code></pre>
181 1 coder
182 23 scotty
h3. Check out and build libavg
183 15 coder
184 15 coder
<pre>
185 15 coder
<code>$ cd rpi
186 10 coder
$ git clone https://github.com/libavg/libavg.git
187 11 coder
$ cd libavg
188 23 scotty
$ git checkout feature/raspi_jessie 
189 23 scotty
$ mkdir build
190 23 scotty
$ cd build
191 23 scotty
$ cmake -DCMAKE_TOOLCHAIN_FILE=../rpi-toolchain.cmake -DAVG_ENABLE_EGL=TRUE -DAVG_ENABLE_RPI=TRUE ..
192 23 scotty
$ make -j5
193 23 scotty
$ make install
194 1 coder
</code></pre>
195 6 coder
196 23 scotty
h3. Install on the Pi
197 1 coder
198 7 coder
Copy the compiled libavg to the Pi:
199 1 coder
200 11 coder
<pre>
201 23 scotty
<code>$ cd rpi/staging
202 23 scotty
$ mv usr/local/lib/python2.7/site-packages usr/local/lib/python2.7/dist-packages
203 23 scotty
$ rsync -au usr pi@$PI:/home/pi/Desktop
204 7 coder
</code></pre>
205 1 coder
206 1 coder
Back *_on the Pi_*, copy libavg from the desktop to its final destination:
207 1 coder
208 6 coder
<pre>
209 17 coder
<code>$ sudo cp -R ~/Desktop/usr/* /usr
210 1 coder
</code></pre>
211 7 coder
212 1 coder
h2. Run the tests
213 5 coder
214 1 coder
<pre>
215 1 coder
<code>$ cd /usr/local/lib/python2.7/dist-packages/libavg/test/
216 1 coder
$ python Test.py
217 1 coder
</code></pre>
218 1 coder
219 1 coder
That's it! libavg should now be running on your Pi.