RaspberryPi Notes

(!) Note: (!)
This is outdated. There are current cross-compile instructions at RaspberryPISourceInstall

These are temporary notes on how to get libavg running on a Raspberry Pi. The easy way is to simply install the precompiled package, but this might not always be up-to-date. Alternatively, you can also compile libavg yourself.

Installing the precompiled package

We have a tarball that you can copy to /usr/local to install libavg for now. The tarball is just a build of an svn snapshot and thus beta, but passes all but a few minor tests. To get this running, install the dependencies first:

$ sudo apt-get install libxml2 libpango1.0-0 librsvg2-2 libgdk-pixbuf2.0-0 \
  libavcodec53 libavformat53 libswscale2 libboost-python1.49.0 \
  libboost-thread1.49.0 libsdl1.2debian libxxf86vm1

Then, download libavg-raspberry.tar.bz2 and unpack it to /usr/local:

$ tar -C /usr/local -xjf libavg-raspberry.tar.bz2

Compiling libavg from source

libavg needs to be compiled on a separate machine because the Raspberry would a) take hours to do it and b) gives up with an out of memory error before it's done. So we take a stock Raspberry disk image, mount it on the host computer, install libavg prerequisites there and compile in a chroot environment. This is not nearly as complicated as it sounds and gives you compile times of about 20 mins for a complete compile on a modern computer.

The procedure described below has been tested under Ubuntu 12.04 LTS, but should work with other releases/distros, too. QEMU version >= 1.0 is required.

Command lines starting with a "$" are executed on the x-build host system, lines starting with "#" inside QEMU or the chroot environment.

Install QEMU (from universe repository)

$ sudo apt-get install qemu qemu-user-static qemu-system

Download raspbian wheezy image

Download the image from http://www.raspberrypi.org/downloads/. The hard float one is the image we want.

$ unzip 2013-09-10-wheezy-raspbian.zip

Create larger root file system image, copy data to image

As-is, the file system image downloaded doesn't have enough free space, so we copy the data to a new, larger image.

$ qemu-img create  wheezy-raspbian-devel.ext3 4G
$ mkfs.ext3 wheezy-raspbian-devel.ext3
$ mkdir rootfs tmp
$ sudo mount wheezy-raspbian-devel.ext3 rootfs/ -t ext3 -o loop
$ sudo mount 2013-09-10-wheezy-raspbian.img tmp/ -o loop,offset=$[122880*512]
$ sudo cp -a tmp/* rootfs/
$ sudo cp /usr/bin/qemu-arm-static rootfs/usr/bin/
$ sudo umount tmp
$ rmdir tmp

Note: All raspbian images newer than 2012-12-16-wheezy-raspbian don't work with QEMU without a minor tweak: Before unmounting rootfs open rootfs/etc/ld.so.preload and comment out the single line it contains. Older images can be found at http://mirrors.arizona.edu/raspberrypi/images/raspbian/.

Download linux kernel

$ wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu

Start emulation, prepare libavg build:

Always unmount image before starting QEMU! If you forget this, you will very likely have a trashed image and need to start over again.

$ sudo umount rootfs
$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda panic=1" -hda wheezy-raspbian-devel.ext3 -clock dynticks

Emulation starts, drops to maintenance shell because of wrong file system mount time (on 1st boot only). Do a file system check:

# fsck.ext3 /dev/sda
# reboot

In qemu emulation

# sudo apt-get update
# sudo apt-get install subversion automake autoconf libtool libxml2-dev \
  libpango1.0-dev librsvg2-dev libgdk-pixbuf2.0-dev libavcodec-dev libavformat-dev \
  libswscale-dev python-dev libboost-python-dev libboost-thread-dev g++ libSDL-dev \
  libxxf86vm-dev linux-libc-dev

Checkout libavg (still in qemu)

# cd /home/pi/
# mkdir -p devel/libavg
# cd devel/libavg/
# git clone https://github.com/libavg/libavg.git

Stop the emulation.

Chroot, x-compile libavg

Make sure the emulation is stopped, then:

$ sudo mount wheezy-raspbian-devel.ext3 rootfs/ -t ext3 -o loop
$ sudo chroot rootfs/
# export LANG=en_GB.utf8
# cd /home/pi/devel/libavg/libavg
# ./bootstrap
# ./configure --enable-rpi --prefix=/home/pi/devel/libavg/install
# make -j9
# make install

For some QEMU configurations chroot fails to start bash with a xmalloc error ("cannot allocate x bytes"). To remedy this, run:

$ sudo chroot rootfs/ /bin/sh
# QEMU_RESERVED_VA=0 bash

Move the compiled libavg to the Raspberry

After the make install, there is a tree of files in devel/libavg/install that can be copied to /usr/local/ on the Raspberry. Rename /usr/local/lib/python2.7/site-packages to dist-packages. For the uninstalled version (e.g. to run src/test/Test.py), copy devel/libavg/libavg to the raspberry.

I use this simple script for the task:

#!/bin/bash
cd devel/libavg/install/lib/python2.7
sudo rm -rf dist-packages
sudo mv -T site-packages/ dist-packages
cd ../..
scp -r * pi@192.168.2.104:/usr/local

Further development / testing notes

To get rid of ALSA sound buffer underruns, change avgrc:

<outputbuffersamples>4096</outputbuffersamples>