Raspberry Pi/Mainline Kernel

From Gentoo Wiki
Jump to: navigation, search

This guide is intended as a supplement to Install Guide and an alternative to Raspberry Pi Kernel.

Important
This guide is accurate as of kernel 4.9, and tested on the Raspberry Pi 2 and newer.

Build tools

root #emerge --ask sys-apps/dtc

Fetch sources

root #emerge --ask sys-kernel/vanilla-sources

For the rest of this example, I will be assuming vanilla-sources-4.9.5.

root #cd /usr/src/linux-4.9.5

Kernel modifications

Raspberry Pi 2

No patching necessary.

Raspberry Pi 3 (32 bit)

Important
This section only applies to the Raspberry Pi 3 in 32 bit mode

Symlink the dts from arm64 to arm

root #ln -s ../../../arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts arch/arm/boot/dts/bcm2837-rpi-3-b.dts
root #ln -s ../../../arm64/boot/dts/broadcom/bcm2837.dtsi arch/arm/boot/dts/bcm2837.dtsi

Patch the makefile as necessary

FILE arm/boot/dts/Makefile
--- arch/arm/boot/dts/Makefile	2017-01-22 09:24:52.557206694 +0000
+++ arch/arm/boot/dts/Makefile	2017-01-22 08:50:08.202326376 +0000
@@ -71,6 +71,7 @@
 	bcm2835-rpi-a-plus.dtb \
 	bcm2836-rpi-2-b.dtb \
 	bcm2835-rpi-zero.dtb
+dtb-$(CONFIG_ARCH_BCM2835) += bcm2837-rpi-3-b.dtb
 dtb-$(CONFIG_ARCH_BCM_5301X) += \
 	bcm4708-asus-rt-ac56u.dtb \
 	bcm4708-asus-rt-ac68u.dtb \

Configure the kernel

Raspberry Pi 2

root #make multi_v7_defconfig

Note: multi_v7_defconfig will enable more than you need, but it is currently the most appropriate included defconfig to choose from.

Raspberry Pi 3 (32 bit)

root #make multi_v7_defconfig

Note: multi_v7_defconfig will enable more than you need, but it is currently the most appropriate included defconfig to choose from.

Build the kernel

Important
If you're not building this on an armv7 machine / VM see cross build environment and adjust the instructions as necessary.
Important
Ensure you've mounted your /boot partition before running the install phase.
root #make
root #make zinstall modules_install dtbs_install

Configuring bootloader

Contrary to popular belief, you don't need u-boot to boot the mainline kernel, just populate the appropriate required files:

Raspberry Pi 2

FILE /boot/config.txt
kernel=vmlinuz-4.9.5
device_tree=dtbs/4.9.5/bcm2836-rpi-2-b.dtb
avoid_warnings=2
FILE /boot/cmdline.txt
root=/dev/mmcblk0p2 rw rootwait elevator=noop cma=256M@512M

You can specify the root as a device or via PARTUUID, just ensure it's accurate for your system.

Raspberry Pi 3 (32 bit)

FILE /boot/config.txt
kernel=vmlinuz-4.9.5
device_tree=dtbs/4.9.5/bcm2837-rpi-3-b.dtb
avoid_warnings=2
FILE /boot/cmdline.txt
root=/dev/mmcblk0p2 rw rootwait elevator=noop cma=256M@512M

You can specify the root as a device or via PARTUUID, just ensure it's accurate for your system.

Installing firmware

Finally, until rpi-open-firmware is ready, you'll need to copy the following binary blobs from raspberrypi-firmware to your /boot partition.

  • bootcode.bin
  • start.elf
  • fixup_*.dat
  • start_*.bin