Setting up the Cross-Compiler

Let’s set up the cross-compiler on our working Operative System using the well known Buildroot.
You can find more information in the official website.

A compiler is a program that turns source code into executable code. Cross compilation allows to compile a program that will run on another machine.

The computer the compiler runs on is called the host, and the computer the new programs run on is called the target. When the host and target are the same type of machine, the compiler is a native compiler. When the host and target are different, the compiler is a cross compiler. So why do we use cross-compilation? Sometimes target’s processors are too slow to compile kernel with and the process would take too long.


We will create our workspace for the project, in the home folder, with the following commands

userk@dopamine:~$ cd && mkdir RaspberryPi && cd RaspberryPi
userk@dopamine:~/RaspberryPi$

In order to install the cross-compiler we need to download the latest version of Buildroot from the official website and untar the compressed file.

userk@dopamine:~/RaspberryPi$ wget http://buildroot.uclibc.org/downloads/buildroot-2013.11.tar.bz2
userk@dopamine:~/RaspberryPi$ tar xjf buildroot-2013.11.tar.bz2 && cd buildroot-2013.11
userk@dopamine:~/RaspberryPi/buildroot-2013.11$

Now it’s time to configure the downloaded tool and compile it. Two options:

Using a basic pre-configured version

Newbie Level
You can use a default configuration file to build your file system. You can compile the minimal configuration raspberrypi_defconfig with:

userk@dopamine:~/RaspberryPi/buildroot-2013.11$ sudo make raspberrypi_defconfig

For manual configuration see infos at the bottom of the page. Now compile the sources with:

userk@dopamine:~/RaspberryPi/buildroot-2013.11$sudo make

If a blu window shows up, just exit pressing ESC and type again the previous command.
It’s going to take a while. When the compilation ends verify that the toolchain has been correctly installed by displaying the version of the arm-linux-gcc file in the /usr/local/cross-rpi/usr/bin/ folder.

userk@dopamine:~/RaspberryPi/buildroot-2013.11$ /usr/local/cross-rpi/usr/bin/arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/cross-rpi/usr/bin/arm-linux-gcc
COLLECT_LTO_WRAPPER=/usr/local/cross-rpi/usr/libexec/gcc/arm-buildroot-linux-uclibcgnueabi/4.7.3/lto-wrapper
Target: arm-buildroot-linux-uclibcgnueabi
[...] Thread model: posix gcc version 4.7.3 (Buildroot 2013.11) userk@dopamine:~/RaspberryPi/buildroot-2013.11$ cd ..

And check the content of the output/images folder, it should be:

userk@dopamine:~/RaspberryPi/buildroot-2013.11$ tree output/images
output/images
├── rootfs.tar
├── rpi-firmware
│   ├── bootcode.bin
│   ├── cmdline.txt
│   ├── config.txt
│   ├── fixup_cd.dat
│   ├── fixup.dat
│   ├── fixup_x.dat
│   ├── start_cd.elf
│   ├── start.elf
│   └── start_x.elf
└── zImage

If something went wrong, you can clean the configuration files and delete all the downloaded file with the sudo make clean command.
Done! Ok, pretty easy so far, but this is just a basic configuration. If you want to test the system, jump to the extraction of the filesystem image in the Root partition. Or continue to personalize your distribution adding packages and features.