Saturday, May 4, 2013

Build vanilla kernel for Raspberry Pi

Check this post if you're looking for the build instructions.
Check this post if you're looking for the git main commands.

Raspberry Pi's official kernel git repository :

We could have cloned this repository, built it and ran a linux on our Pi.... yes we could, but we are a bit sadistic and as they say in my fitness club : "No pain, no gain". So let's try something fun : cloning the mainline kernel ( the latest stable version ) and adapt it for the Pi.

Our repository is hosted on bitbucket - which is free by the way - and is a clone of the mainline kernel 3.8.9 :

What we need to do first is grabbing the raspberry Pi's defconfig file. Manually configuring the build would take too much time and requires strong technical skills. This method will be experimented later...
Now we got the file, copy it to arch/arm/configs, and run :
make bcmrpi_defconfig
(ARCH and CROSS_COMPILE must be defined)

First build attempt will fail with :
ERROR: "v7wbi_flush_kern_tlb_range" [drivers/staging/zsmalloc/zsmalloc.ko] undefined!
make[1]: *** [__modpost] Error 1
make: *** [modules] Error 2
Not surprising, otherwise a git repository dedicated to the Pi would certainly not exist. The next step is to modify our sources to make them build for the Pi.

Generate a patch to merge the vanilla sources with the rpi ones

The following method is not really the best way for the patch generation, you should consider using git format-patch instead, but, if like me you're living in a building with a poor internet connection, you may want to do it like this :

1. Download the official linux rpi-3.8.y archive from github (about 100 MB, not a big deal compared to GBs of data that you have to download using git fetch command with the rpi remote repo)
2. Create a local git repo with your rpi sources :
# Create a directory where you'll store the rpi linux sources
mkdir rpi-3.8.y
cd rpi-3.8.y
# Move the archive to the current directory
mv /Downloads/linux-rpi-3.8.y.tar.gz .
# Extract it
tar -xf linux-rpi-3.8.y.tar.gz
# Initialize the repository
git init
# Add all elements
git add .
# Commit them
git commit -m "added : rpi-3.8.y sources"
3. Let's assume that your vanilla kernel sources are in a directory named linux_vanilla_kernel :
# Add the vanilla kernel git repo 
git remote add vanilla ../linux_vanilla_kernel/
# Fetch the vanilla kernel repo
git fetch vanilla
After a while, you should obtain an output saying that a branch has been created with vanilla kernel sources :
master --> master/vanilla
4. Generate the patch
git diff --no-prefix master/vanilla HEAD > patchfile

5. You can now apply the patch to your vanilla kernel sources
# Move the patch to your vanilla kernel working directory
mv patchfile ../linux_vanilla_kernel/
cd ../linux_vanilla_kernel
# Apply the patch
patch -p0 < patchfile
6.Build again
make bcmrpi_defconfig
make -j8
The build process should end successfully now.


  1. Hello, the access to the repo is not free anymore,please? I could download the mainline kernel from other source but I dont find the bcmrpi_defconfig.

  2. Hi there,

    Sorry for the inconvenience, the repo access was set to private. I modified it to public.
    Try again and let me know if everything is fine now.


  3. This comment has been removed by the author.