Getting Started with Embedded Linux: Part Ten -- Building a Raspberry Pi kernel

April 23, 2015

mike_eager-April 23, 2015

In the last installment, we set up a Raspberry Pi SBC (Single Board Computer) and used it to build a simple driver. This is an example of self-hosting, the development model in which we use an embedded target as our development platform.

We are going to take this one step further in this installment. First we will build the kernel on the Raspberry Pi, and then build it on a faster host system. Using a separate host for development is an example of the cross-development model.

Building the Kernel on the RPi
Last time, we used the rpi-source script to download and install the headers required to build a kernel module on the RPi. The same developer, notro, who created that script, has also created a rpi-build script which makes it easy to build the kernel. Instructions can be found on the GitHub page:

$ wget
$ sudo mv rpi-build /usr/bin/rpi-build
$ sudo chmod +x /usr/bin/rpi-build

While the rpi-source script was written in Python, the rpi-build script is written in Ruby which needs to be installed before we can run it:

$ sudo apt-get update
$ sudo apt-get install ruby

The first time you run rpi-build, it will check for missing dependencies. Reply Y when asked whether you want to install these dependencies. After this, we can build the kernel using this script:

$ rpi-build use[stdlib] linux install

This is going to take a while. While the script downloads files and starts compiling the kernel files, let's bring up our VM running Fedora and look at building the Raspberry Pi kernel on a faster system.

We are going to use the git source control system to make a copy of the cross tool chain and kernel from the Rasbberry Pi repository on First we need to install git as root:

$ su
Password: <enter root password>
# yum install git

And then we can download the tool chain and kernel source:

$ git clone --depth 1 git://
$ git clone --depth 1 git://

Let's get the Linux kernel ready to build:

$ cd ~/linux
$ make mrproper
$ export CCPREFIX=~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-

This selects the Linaro version of GCC-4.8.3 as our cross compiler. A cross compiler runs on one system, in this case our VM running on an X86-64 host system, and generates object code which will execute on a different processor, in this case, ARM, and specifically for the Broadcom BCM2708 processor used by the Raspberry Pi.

We are going to use the default Linux configuration for the Raspberry Pi:

$ cp arch/arm/configs/bcmrpi_defconfig .config
$ make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

Alternately, we could have copied the configuration from the Raspberry Pi, which can be found in /proc/config.gz. Use gunzip to unpack this file and rename it from config to .config before running make oldconfig as shown above. When you do this, you will be asked about new options which have been added to the kernel but which are not mentioned in the .config file you are using. I simply hit return for all of these (many) options, selecting the default.

< Previous
Page 1 of 2
Next >

Loading comments...