Building the code
Last updated : Thursday, 26th March 2015
This tutorial shows how to build a Raspberry PI kernel and install it on to your device. It is based on information that can be found in the official Raspberry Pi documentation.
The instructions detail the two main methods for building the kernel. You can build locally on a Raspberry Pi or you can cross-compile, which is much quicker, but requires more setup so the local build is recommended unless you are already familar with cross-compiling. Throughout this tutorial the term Local Build will refer to specfic instructions for building on the Raspberry Pi, the term Cross-compile Build will refer to specfic instruction for building on a Linux based system and the term All Builds refers to common instructions. The instructions are designed to work on Debian based systems.
Hardware platforms tested and supported by these instructions include:
- Raspberry Pi Model B and Wolfson Audio Card
- Raspberry Pi Model B+ and Cirrus Audio Card
- Raspberry Pi Model A+ and Cirrus Audio Card
- Raspberry Pi 2 Model B and Cirrus Audio Card
Note: This has been tested with the lastest updates to Raspbian as of the time of writing. Download Raspbian from here. To install Raspbian follow the instructions here.
All Builds
- Download the Raspberry Pi tools and configure environment:
cd ~
mkdir bin
cd ~/bin
mkdir raspberrypi
cd raspberrypi
git clone --depth 1 https://github.com/raspberrypi/tools
Local Build
Add missing dependencies:
sudo apt-get install bc
Cross-compile Build
- 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
All Builds
- Download the Cirrus Raspberry PI kernel
cd ~
mkdir code
cd code
git clone --depth 1 https://github.com/CirrusLogic/rpi-linux.git
All Builds
- Build the code
cd rpi-linux
Local Build
Configure the kernel. This will use the default config. You may want to configure your kernel in more detail or apply patches from another source to add or remove required functionality. Raspberry Pi 1 default build configuration
make bcmrpi_defconfig
Raspberry Pi 2 default build configuration
make bcm2709_defconfig
Build the kernel; this step takes a lot of time...
make
make modules
sudo make modules_install
Important! The Element 14 Cirrus Logic audio driver is a device tree enabled driver which requires a further step to add a valid trailer to the image file. Further information about device tree can be found here. If you miss this step the driver will not be loaded.
cd ~/bin/raspberrypi/tools/mkimage/
./mkknlimg ~/code/rpi-linux/arch/arm/boot/zImage <kernel.img>
Now we can copy the kernel image and the device tree overlay file to the boot section
sudo cp <kernel.img> /boot/<kernel.img>
sudo cp ~/code/rpi-linux/arch/arm/boot/dts/rpi-cirrus-wm5102-overlay.dtb /boot/overlays/
Where <kernel.img>
is kernel.img
for Raspberry Pi 1 and kernel7.img
for Raspberry Pi 2.
Note: that you can put both the Raspberry Pi 1 and 2 images on the same card if you want to use the card across multiple Raspberry Pi platforms. Just run though the build instructions for both types on the same card.
Cross-compile Build
Configure the kernel. This will use the default config. You may want to configure your kernel in more detail or apply patches from another source to add or remove required functionality. Raspberry Pi 1 default build configuration
make ARCH=arm bcmrpi_defconfig
Raspberry Pi 2 default build configuration
make ARCH=arm bcm2709_defconfig
Build the kernel:
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
Important! The Element 14 Cirrus Logic audio driver is a device tree enabled driver which requires a further step to add a valid trailer to the image file. Further information about device tree can be found here. If you miss this step the driver will not be loaded.
cd ~/bin/raspberrypi/tools/mkimage/
./mkknlimg ~/code/rpi-linux/arch/arm/boot/zImage <kernel.img>
Now we can copy the code to the Raspberry Pi
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
Where <kernel.img>
is kernel.img
for Raspberry Pi 1 and kernel7.img
for Raspberry Pi 2 and <ip-addr>
is the ip address of your Raspberry Pi.
Note: that you can put both the Raspberry Pi 1 and 2 images on the same card if you want to use the card across multiple Raspberry Pi platforms. Just run though the build instructions for both types on the same card.
##Install the kernel, modules and dtb file on the Raspberry Pi.
- At the console of your Raspberry Pi do the following :
Local Build
As the code has been built locally the files have been put in the right place in step 2) of the build instructions above so there is no additional action for this type of build
Cross-compile Build
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
All Builds
- 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
There are certain modules those should be loaded before loading of other modules.
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Add the following lines to the file
softdep arizona-spi pre: arizona-ldo1
softdep spi-bcm2708 pre: fixed
All Builds
- Restart the Raspberry Pi
sudo shutdown -r now
All Builds
- When the Raspberry Pi reboots run
uname -a
This will display the new kernel version
All Builds
- Check the audio card has been enabled successfully
aplay -l
You should then get the following output on the console:
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpiwsp [snd_rpi_wsp], device 0: WM5102 AiFi wm5102-aif1-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
All Builds
- Download script files for configuring the card
Download the scripts from github, move them to your home directory and make them executable.
cd ~
git clone --depth 1 https://github.com/CirrusLogic/wiki-content.git
mv wiki-content/scripts/* ~/
chmod +x *.sh