2.5 Custom Kernel
Overview
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
- Instead of bcmrpidefconfig we use **bcm2709defconfig**
- The bootloader instead of looking for kernel.img, looks for kernel7.img instead
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
etc-update
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
etc-update
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
- Auditing seems to be enabled on raspian, but disabled for the latest rpi2 kernel default config that suggests we may get some noticable speed increases by compiling our own kernel
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 imagetool-uncompressed.py 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
#kernel=kernel7-raspian.img
# New
kernel=kernel7-gentoo.img
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
reboot
TODO
- TODO try setting up a 2nd boot partition on the SD card that can be selected by Noobs for gentoo
Look at recompiling Noobs, there's a pull request for usb disk support under https://github.com/raspberrypi/noobs/pulls
TODO Look into DeviceTree's
http://www.raspberrypi.org/documentation/configuration/device-tree.md