Last updated : Tuesday, 10 March 2015
This tutorial shows how to build a Raspberry PI kernel and install it on to your device. This tutorial assumes that you are building on a Linux machine as building on the Raspberry PI nativily is very slow.
Note: This has been tested with the lastest updates to Raspian as of the time of writing. Download Raspian from here. To install Raspian follow the instructions here.
- Download the Raspberry PI cross-compilers:
cd ~/bin
mkdir raspberrypi
cd raspberrypi
git clone https://github.com/raspberrypi/tools
- Set CCPREFIX environment variable:
For 32 bit tools
export CCPREFIX=~/bin/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
${CCPREFIX}gcc -v
For 64 bit tools
export CCPREFIX=~/bin/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
${CCPREFIX}gcc -v
- Download the Cirrus Raspberry PI kernel
cd ~
mkdir code
cd code
git clone https://github.com/CirrusLogic/rpi-linux.git
cd rpi-linux
git checkout -b rpi-3.18.y origin/rpi-3.18.y
- Create a .config file that includes the audio card code.
when the target platform is bcm2708 i.e. Raspberry Pi boards
make ARCH=arm bcmrpi_defconfig
when the target platform is bcm2709 i.e. Raspberry Pi 2 boards
make ARCH=arm bcm2709_defconfig
You could be asked a lot of questions but you can answer the default to all of these.
- Build the kernel and kernel modules
ARCH=arm CROSS_COMPILE=${CCPREFIX} make -j <num-cores>
ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=../modules make modules_install
Note : Where <num-cores>
is the number of processor cores dedicated to the build
- Upload the new kernel, modules and dtb file to the Raspberry PI
cd ~/bin/raspberrypi/tools/mkimage
./mkknlimg ~/code/rpi-linux/arch/arm/boot/zImage <kernel_img>
scp <kernel_img> pi@<ip-addr>:/tmp
cd ~/code/rpi-linux/modules
tar czf modules.tgz *
scp modules.tgz pi@<ip-addr>:/tmp
scp ~/code/rpi-linux/arch/arm/boot/dts/rpi-cirrus-wm5102-overlay.dtb pi@<ip-addr>:/tmp
Note : Where <kernel_img>
is kernel.img
for bcm2708, kernel7.img
for bcm2709
- Install the kernel, modules and dtb file on the Raspberry PI. Connect to your Raspberry PI over SSH and do the following:
cd /
sudo mv /tmp/<kernel_img> /boot/
sudo tar xzf /tmp/modules.tgz
sudo mv /tmp/rpi-cirrus-wm5102-overlay.dtb /boot/overlays/
rm /tmp/modules.tgz
- Device tree configuration for cirrus audio card
Open the
config.txt
file and add entry fordtoverlay
sudo nano /boot/config.txt
dtoverlay=rpi-cirrus-wm5102-overlay
- Dependancies between modules: There are certain modules those should be loaded before loading of other modules. Connect to the Raspberry PI over SSH and do the following:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Note : create raspi-blacklist.conf
if it is not existed
Add the following lines to the file
softdep arizona-spi pre: arizona-ld
softdep spi-bcm2708 pre: fixed
- Restart the Raspberry PI
sudo shutdown -r now
- When the Raspberry PI reboots connect over SSH and run:
uname -a
This will display the new kernel version.