Please note that this blog has been moved.
Now it has its own domain: mynixworld.info 🙂
If you want to read the latest version of this article (recommended) please click here and I open the page for you.
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://github.com/raspberrypi/linux.git)
- fetching the (last) RPi firmware (git://github.com/raspberrypi/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.
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 <working directory> 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 <CC prefix> 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 <boot partition> 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 <partition type> is the type of the <boot partition>. If nothing is supplied then ext4 will be assumed by default.
The script can be downloaded from here.