Preparations

Prepare your RPi

Plug in and boot your RPi. If you are using Putty for control, make sure you have the correct IP-address to your RPi and that you have the network cable from your RPi plugged into the network. Start up Putty and connect. Don't forget to log in.

To prevent error-messages about time and date, make sure you set up the time and date on your RPi. Time will be set to the date your version of Raspbian was released. To set up time and date, use the following code:

To make it easier following this guide and to gather all materials in the same directory, make a new directory calles something like "kernel" in /home/pi/:

mkdir kernel

Get Kernel Source

The kernel source should be downloaded from the RPI linux section on GitHub. Although you could just compile the vanilla kernel from Kernel.org, it will not have the necessary drivers and modules for the Broadcom SoC on the RPi. You can however apply patches from the vanilla kernel to the RPi one - be prepared for potential compiler grumbles though!

At the time of writing, three branches of interest are available:

rpi-3.2.27 - This is the version of the kernel currently used in Raspbian, but not exactly the same - Raspbian stock kernel image (the one available from the foundation's website) has a 3.2.27+ version marking. Please see this post for more details.

rpi-3.6-y - This is a development branch based on the current vanilla kernel( GIT rebased ) . It replaced the 3.2 development branch end marc 2013.

At the time of writing, the exact version is 3.6.11.

rpi-3.8-y - This is a Alpha development branch based on the current vanilla kernel( GIT rebased) . It will eventually replace the 3.6 branch.

At the time of writing, the exact version is 3.8.8 ( 22-04-2013 ).

If you are using the kernel directory in /home/pi/kernel/, move to the kernel directory before you download.

Perform compilation

Next, in all cases, you will want to get a working kernel configuration to start from. You can get the one running on the RPi by typing the following (on the RPi):

zcat /proc/config.gz > .config

then copy .config into your build directory.

Ensure that your configuration file is up-to-date:

make oldconfig

If any configuration options have been added, you will be asked what set each option to. If you don't know the answer, just press enter to accept the default.

To make sure that loading modules is enabled by running make menuconfig. If the option Enable loadable module support is checked you are good to go and can just exit. If not, check the option and exit.

Now you are ready to build:

make

The modules will be build with the following command.

make modules

Transfer Build

First you need to make a backup copy of your original kernel image. Got to /boot/ and run the following command to copy kernel.img to /home/pi/.

sudo mv kernel.img /home/pi/

Now copy the new kernel image into Boot directory

sudo cp /home/pi/kernel/arch/arm/boot/Image /boot/kernel.img

Go back to your build directory, /home/pi/kernel/, and run the following command:

make modules_install

Update firmware

In most cases this will not be needed, but it will not harm anything to do it so I recommend updating if you're not sure.
To update, simply run the following command:

sudo rpi-update

After update, reboot your RPi.

Wiring

Before you can see if your new kernel is working you have to wire up the led you want. The picture to the right shows how to wire a LED to GPIO 17 and Ground.