My *nix world

Boost Linux kernel compilation for Raspberry Pi

I do a lot of experiments with my new RPi nowadays. It's like in the old days, in the early of '90s, when I've got my HC-91, the Romanian ZX-Spectrum clone.

There is one small difference, though: the HC-91 has been delivered with a case an ROM-stored BASIC interpretor. The RPi has no case nor a pre-installed OS, so you have to take care of both.

To compile the Linux kernel for Raspberry Pi (i.e. ARM architecture) one should accomplish at least 8 different steps:

  • fetching the (last) Linux kernel source code (git://
  • fetching the (last) RPi firmware (git://
  • configuring the kernel according with the target architecture
  • compiling the kernel and its modules
  • copying the kernel image to the boot partition
  • copying the RPi firmware to the boot partition
  • (optional) configuring the kernel boot command-line and its start-up configuration
  • last but not least, copying the RPi firmware utilities to the target /opt/ directory

If you have to do often this task then it would be better to automate those steps. Because I did that many times and because I love to create my own scripts that makes my live easier (in the future), I wrote an automation script that accomplish all these steps in order to boost Linux kernel compilation for Raspberry Pi.

This script assumes that you have already a crossdev environment prepared so you can use your cross-arm-compiler right away:

Raspberry Pi kernel compilation automation script.
Usage       : /usr/sbin/rpi-build [options]
Options   :
           -w : the working directory (mandatory)
           -c : CC prefix for the TARGET architecture
           -f : the path to your predefined Linux kernel .config file
           -p : the name of the boot partition of your RPi
           -t : the type of the partition specified by -p parameter
           -h : print this help message
Report bugs to eugenmihailescux at gmail dot com

The is the place where the Linux kernel and firmware source code will be downloaded, where the build.log will be saved, where the final output directory will be deployed.

The is the full path of the crossdev toolkit that will be used to compile the kernel for the TARGET architecture. For instance, if your cross compiler toolkit is installed at ~/x-tools/armv6-rpi-linux-gnueabi/bin/ and the compiler prefix is something like armv6-rpi-linux-gnueabi, then the CC prefix you specify should be ~/x-tools/armv6-rpi-linux-gnueabi/bin/armv6-rpi-linux-gnueabi- (note the dash at the end of the prefix!).

The <.config> is the path to a predefined Linux kernel .config file. You can use a predefined .config Linux kernel configuration file so that you don't have to configure the kernel every time you run this script. For my RPi model B I have already created a cut-down RPi configuration and can be found here.

The is the name of your RPi boot partition on the SD Card. If nothing is supplied then /dev/mmcblk0p2 will be assumed by default.

The is the type of the . If nothing is supplied then ext4 will be assumed by default.

The script can be downloaded from here.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
Boost Linux kernel compilation for Raspberry Pi

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Boost Linux kernel compilation for Raspberry Pi

Latest posts by Eugen Mihailescu (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *