View on GitHub

2.5 Custom Kernel

Download this project as a .zip file Download this project as a tar.gz file

2.5 Custom Kernel


For the default install of gentoo so far I've used the kernel image that comes with raspian. It turns out there's already an ebuild for the rpi kernel sources under sys-kernel/raspberrypi-sources

With the rpi2 there are 2 main differences from the default kernel sources.
Based on this Link

Typically with raspian the current kenel version as of writing is 3.18.7-v7+
To get the current kernel version number

uname -r

Kernel sources link:

Emerging the sources

I've setup my own overlay under GBD.Rpi2.Gentoo with an ebuild called sys-kernel/grbdrpi2-sources. It's exactly the same as sys-kernel/raspberrypi-sources except it has a higher version number and is set for bcm2709_defconfig

Any ebuild ending in 9999 will get the latest version from github, 3.19.1 is one I've set to a particular commit

emerge --autounmask-write sys-kernel/grbdrpi2-sources-3.18.1
emerge =sys-kernel/grbdrpi2-sources-3.18.1

It'll probably take a while to download since it downloads the whole git tree

We also need the following tools

emerge --autounmask-write sys-boot/raspberrypi-mkimage
emerge sys-boot/raspberrypi-mkimage

Building the Sources

At this stage after the emerge you'll probably find it's installed the sources under /usr/src/linux-version, with a symbolic link pointing from /usr/src/linux to that directory

When you compile certain apps via emerge, they use the files under the path /usr/src/linux to act as a basis for the linux sources during compilation (such as additional drivers)

selecting a different kernel that the link needs to point to can be done via eselect kernel

eselect kernel list

Configuring the Kernel

First lets jump into the kernel directory

cd /usr/src/linux

Optionally to fully clean the sources

make distclean

The default configuration for the rpi2 can be setup by doing the following:

make bcm2709_defconfig

This will output a file .config which is the config that will be used for building. If you want to pull back the config that currently running at present in memory

zcat /proc/config.gz >/usr/src/linux/config.raspian

To alter config options with a menu

make menuconfig

The following command can be used to convert a config from an older kernel to the current kernel

make oldconfig

To compare the old config vs the new

diff -Naur config.raspian .config >diff1.t

Some thngs I've noticed

Building the kernel

To build the kernel and modules using all quad cores

make -j5

Installing the kernel

First to install the kernel modules. This should copy the kernel modules From /usr/src/linux into /lib/modules/kernel-version

make modules_install

Next to install the kernel image

cd /usr/src/linux
cp arch/arm/boot/Image /boot/kernel7-gentoo.img

Note with older bootloaders a script called used to be needed to copy / alter the kernel
However with more recent bootloaders this is no longer required, in fact I found when using Noobs it can actually prevent the kernel from booting altogether.

Lets make a backup of the old raspian kernel

cd /boot/
cp kernel7.img kernel7-raspian.img

Finally lets add some new conifg options to cmdline.txt

nano -w /boot/config.txt

# Original

# New

In the event this doesn't work you can hold down shift at boot, click e to edit configs. Then comment out the new kernel / uncomment the old kernel file

Finally a reboot