Programming - programming languages that might be used on the Raspberry Pi.

Overview

First, you are going to get and build the linux kernel and its modules using a suitable compiler (a "cross-compiler" if you aren't building it on the same hardware you will be running it on) and then you are going to create a kernel image from the uncompressed kernel (Image) to place on the sd, along with the modules you build alongside it.

See below for the various guides to get and compile a suitable kernel for your RPi, and then create a kernel.img according to the steps at the end.

Raspberry PI kernel compilation

You can compile the kernel on the board itself, but because of the limited resources it will take a lot of time. Alternatively you can crosscompile the kernel on another machine running Linux, Windows or OS X.

Compiling on the Raspberry pi itself

Arch Linux

getting the compiler

You will need GIT to clone the kernel source tree from GitHub, compiler (gcc) and GNU Make:

pacman -S git gcc make

(NOTE: git might be omitted if you decide to download sources in compressed format; this is far faster)

getting the sources

create a directory where you can work on the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.

(NOTE: git might fail due to memory constraints; in this case creation of swap file might help. Be warned - this takes ages! To omit the revision history and reduce the download, you can add "--depth 1" to the end of the git clone command.)

unpack and enter the extracted directory (this is your kernel directory - its sources to be precise)

configuring the kernel

Next, the kernel options are configured. Either copy the cut down Raspberry Pi .config file from the kernel source configs directory:

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config

Or alternatively, to use the configuration from a currently running Raspberry Pi image, connect to the target and extract the .config file. Then copy the resultant .config file into the Linux kernel source root directory:

compiling

Next, the kernel options are configured. Either copy the cut down Raspberry Pi .config file from the kernel source configs directory:

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config

Or alternatively, to use the configuration from a currently running Raspberry Pi image, connect to the target and extract the .config file. Then copy the resultant .config file into the Linux kernel source root directory:

Gentoo Linux

getting the compiler

Build the cross toolchain:

crossdev -S -v -t arm-unknown-linux-gnueabi

theBuell: on 2012-05-06, cross -S -v -A gnueabi arm works just fine

This command should create a cross-toolchain using the latest stable versions of the required packages. If it fails, you can specify exact versions by removing the "-S" flag and adding the "--b", "--g", "--k" and "--l" flags. For the exact usage refer to the crossdev manpage. A good starting point for figuring out the right versions are those which are stable for the arm architecture.

getting the sources

create a directory where you can work on the raspberry pi software. I called mine "raspberrypi". Then clone the git repository.

You can use the "-j" flag to improve compilation time. If you have a dual core machine you can use "-j 3", for a quad core machine you can use "-j 6", and so on. (Don't use these for the oldconfig option because it messes up the input and output).

Final step: Making the 'kernel.img' for your Pi

Finally you need to build a kernel.img for your Pi to boot from. The next two sections describe how to do this, depending on which firmware/bootloader version you're using.

Image Generation For Latest Firmware

With the latest firmware (available from https://github.com/raspberrypi/firmware), you no longer need to create an explicit kernel image; you can directly use Image or zImage from the kernel build process as /boot/kernel.img.

Image Generation For Older Firmware

For this, you need the mkimage tool from the raspberrypi github repository: