Building a custom toolchain for the BeagleBone
This post is about creating a custom (linaro) toolchain using using cross-ng. The motivation for this came about when I found I was unable to build the ffmpeg library directly on a beaglebone (specifically, the older beaglebone white model) because of insufficient memory during the build process 1.
First, we need to download cross-ng with linaro support. I used the source at https://github.com/Christopher83/linaro_crosstool-ng. To install crosstool-ng:
git clone https://github.com/Christopher83/linaro_crosstool-ng
cd linaro_crosstool-ng
./bootstrap
./configure --prefix=/install/path (e.g. /opt/cross)
make
sudo make install
Then, make a directory to build your tool chain
mkdir /home/<user>/ctng
cd /home/<user>/ctng
Now, we configure the toolchain using the crosstool-ng interface
/opt/cross/bin/ct-ng menuconfig
- Under
Path and misc options- Select
Try features marked as EXPERIMENTAL - Set
Prefix directoryto `${HOME}/x-tools/${CT_TARGET}’ or whatever you choose 2 - Set
Number of parallel jobsto 2 times the number of CPU cores on the host
- Select
- Under
Operating SytemschangeTarget OStolinux - Under
Target options- Set
Target Architecturetoarm - Select
Use the MMU - Set
EndiannesstoLittle endian - Set
Default instruction set modetothumb - Select
Use EABI - Set
Tune for CPUtocortex-a8 - Set
Floating pointtohardware (FPU) - Set
Use specific FPUtoneon - Set
Architecture leveltoarmv7-a
- Set
- Under
Toolchain OptionssetTuple's Vendor Stringtolinaro - Under
C Library- Set
C Librarytoeglibc - (Important) Set
eglibc versiontoLinaro 2.19-2014.08(should be same as version of glibc on target)
- Set
- Under
C Compiler- Select
Show Linaro versions - Set gcc version to latest linaro-gcc
- Optionally, select additional supported languages (e.g. C++)
- Select
Exit and save settings. Then, to build the toolchain, type
/opt/cross/bin/ct-ng build
This will take a while (20 min on my quad core i7). When it’s done create a file containing the following lines:
export PATH=$PATH:$HOME/x-tools/arm-linaro-linux-gnueabihf/bin
export CCPREFIX="$HOME/x-tools/arm-linaro-linux-gnueabihf/bin/arm-linaro-linux-gnueabihf-"
You can now source this file anytime to set up the environment variables necessary to compile with your toolchain. Let’s sanity check the compiler:
$ arm-linaro-linux-gnueabihf-gcc --version
arm-linaro-linux-gnueabihf-gcc (crosstool-NG 1.20.0) 4.9.3 20150209 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat > test.c
#include <stdio.h>
int main() { printf("Hello, world!\n"); return 0; }
^D
$ arm-linaro-linux-gnueabi-gcc -o test test.c
Copy the test executable from this last step to your beaglebone and execute it there. You should see the Hello World output. Success!
adding swap space.
cannot be run as root but writing to /opt/cross requires root.