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