Saturday 23 May 2015

Building the compiler and a few essential libraries

Do not expect anything revolutionary in this article, but I will document it for the sake of completeness. So, here is a trivial how-to to compile and install an up-to-date gcc and an (hopefully) optimized version of the SDL library.

Compiling gcc 4.9.1 and its dependencies


I decided to use an up-to-date gcc version to benefit as much as possible from the improvements introduced on the ARM targets. Honestly, I am not sure this had a great impact. But, hey, I had time to do this, so why not?

gmp-5.1.3

Official link: ftp://ftp.gmplib.org/pub/gmp/gmp-5.1.3.tar.bz2

In some temporary folder:
tar -xjf gmp-5.1.3.tar.bz2
cd gmp-5.1.3
CFLAGS= ./configure --prefix=/media/BBB
make && make install    

mpfr-3.1.2


In some temporary folder:
tar -xzf mpfr-3.1.2.tar.gz 
cd mpfr-3.1.2
CFLAGS= ./configure --with-gmp-include=/media/BBB/include/ --with-gmp-lib=/media/BBB/lib/ --prefix=/media/BBB
make && make install

mpc-1.0.2


In some temporary folder:
tar -xzf mpc-1.0.2.tar.gz
cd mpc-1.0.2
CFLAGS= ./configure --with-gmp-include=/media/BBB/include/ --with-gmp-lib=/media/BBB/lib/ --prefix=/media/BBB --with-mpfr-lib=/media/BBB/lib/ --with-mpfr-include=/media/BBB/include/
make && make install

gcc-4.9.1


In some temporary folder:
tar -xzf gcc-4.9.1.tar.gz
cd gcc-4.9.1
./configure  --enable-languages=c,c++ --prefix=/media/BBB --with-gmp-include=/media/BBB/include --with-mpc-include=/media/BBB/include --with-mpfr-include=/media/BBB/include --with-mpc-lib=/media/BBB/lib --with-gmp-lib=/media/BBB/lib --with-mpfr-lib=/media/BBB/lib --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf && make && make install

Tweaking the compilation flags

Aiming at getting the most of the BBB, I tested several benchmarks (e.g. himeno: http://accc.riken.jp/2444.htm) to get an idea of the influence of several compilation flags on the actual performances of the compiler. I know this has its limits, as emulators are highly dependent on integer computation performance, and some benchmarks focus more on the FPU aspect for example (see himeno). I just used these results as a "hint" that the compiler was doing sensible things, and hoping everything would be for the best in the SDL/emulation world.

I ended up with the following flags, that I added to my /etc/profile./pixbox.sh script:
export CFLAGS="-O3  -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -ffast-math"
export CXXFLAGS="$CFLAGS"

Compiling the SDL library and the required modules

I intended to compile the SDL library myself as this library is essential for the performance of lots of emulators. At least, I know how this has been compiled, and especially, that the hard float ABI has been used.

SDL-1.2.15


In some temporary folder:
tar -xzf SDL-1.2.15.tar.gz
cd SDL-1.2.15
./configure --prefix=/media/BBB/ && make && make install

SDL modules:

Do exactly the same for the following libraries:

Friday 22 May 2015

A word on the file system

As I tested several distributions and versions of libraries, I decided to separate what was "vanilla" installation from my experimentations. I decided to install "my" libraries, executables (and roms, artwork, etc.) on a micro-SD card, formatted in ext3, mounted on /mnt/BBB. The tree in this folder matches the classic Linux hierarchy (i.e. /mnt/BBB/bin, /mnt/BBB/lib, etc.)

Here is my /etc/fstab entry for this:
/dev/mmcblk0 /media/BBB ext3 defaults,noatime 0 0

And of course, we have to override the default PATH and LD_LIBRARY_PATH environment variables. There are several ways to do this, I chose to put all this (and several other commands to come later on) in a script in profile.d : /etc/profile.d/pixbox.sh.
#!/bin/bash
export LD_LIBRARY_PATH=/media/BBB/lib:
export PATH=/media/BBB/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Don't forget to make it executable (chmod a+x /etc/profile.d/pixbox.sh).

From now on, all the installations can be done in /media/BBB.

Tuesday 19 May 2015

An OS for my 'Bone (*)

(*) Fellow French-speaking people, enjoy the subtle pun! Others can safely ignore :-)

My first impression when manipulating my BeagleBone Black was a mix of excitation and a pinch of doubt. Excitation, when seeing the possibilities of such a small piece of hardware. Doubt, when getting in touch with the default Angstrom OS - not bad per se, but leaving a disappointing feeling of sluggishness when it came to X applications.

So I went on trying and installing several versions of Linux: an up-to-date Angstrom, several Debian builds, Ubuntu... Good, but still slow. The use of hardware acceleration was a theorical possibility, but at the time, noone seemed to have managed to get it working.

Rather than wait for a hypothetical saviour, I decided to go the other way around: is X too slow? Drop X. I would focus on the framebuffer device: a few tests managed to convince me that this was viable performance-wise, and lots of emulators are based on SDL, which allows fb as its device.

So, in the end, I opted for a Debian image: BBB-eMMC-flasher-debian-7.4-2014-03-04-2gb.img. You can check for more recent images at http://elinux.org/BeagleBoardDebian#eMMC:_BeagleBone_Black , but my experience is on this precise build only. For the install procedure on the eMMC, just check the official wiki: http://www.crashcourse.ca/wiki/index.php/BBB_software_update_process.

I removed the following packages which were obviously useless (use apt-get or aptitude):
  • xkb-data
  • x11-common
  • xserver-common
  • lxde-common
  • libx11-data
  • apache-2.2
And while we are dealing with packages, install the following ones, they will come in handy later in the process:
  • fastjar
  • libfreetype6-dev
  • git
  • libpng12-dev
  • unzip
  • ligbl1-mesa-dev
  • ligblu1-mesa-dev
  • libflac-dev
  • libvorbis-dev
  • libsndfile1-dev
We now have a nice environment to start working. Next steps: compiler and libraries.