There is already a thread discussing this and a few other complementary threads and posts adding to the subject, none of which having a suggestive enough title and some posts might be obsolete (I wrote one myself related to the kernel firmware) or lacking details. I considered starting this new thread, with a specific subject and put all gathered knowledge and experience in it.
Credits:
https://www.raspberrypi.org/document...el/building.md
https://www.linuxquestions.org/quest...is-4175621155/
https://lemariva.com/blog/2018/07/ra...-kernel-4-14-y
Compiling the Raspberry Pi Foundation-provided kernel for the Raspberry boards under Slackware ARM is mainly a simple process, but there are some details about the structure of the boot process and the required files, the kernel&firmware version choice and the kernel source files source that are worth detailing.
The kernel is floating point "agnostic", which means no binary floating point instructions are generated during the build. But the ARM code - ARMv6/ARMv7 is important and because of that only native builds are accepted. The toolchain from Slackware ARM 14.2 is only able to generate ARMv5/6 code and the one from Slackware ARM -current ARMv7.
I'll cover both Slackware ARM releases and all the existent Raspberry boards - P1 1/0 -ARMv6, Pi2B-ARMv7, Pi3B(+)ARMv8 for 32bit builds:
https://en.wikipedia.org/wiki/Raspbe...Specifications
Using "pi1" will imply Slackware ARM 14.2 - SoftFloat on ARMv6
Using "pi2-3" will imply Slackware ARM current - HardFloat on ARMv7 or ARMv8 (same kernel configuration file provided by Raspberry ATM)
Limitations: I only was able to build for ARMv6 (Pi Zero) and ARMv7 (Pi2B) since I don't own any ARMv8 Raspberry boards (Pi3B(+)), but the instructions are the same for both ARMv7 and ARMv8.
Time and space considerations: the cloned or downloaded&unpacked kernel source takes around 1GB of space, compiled it can grow to around 1,5GB. For both the pi1 & pi2-3 kernel builds I used a Pi2B board, loaded with Slackware ARM 14.2 SF for the pi1 and with Slackware ARM -current HardFloat for the pi2-3, and used 4 make jobs. It took around 3 hours per build and I don't know how much it'll take to build directly on a Pi1 / PiZero with only one make job. Since the kernel source files are pretty small, the RAM requirements are low too - I observed peaks at 500-600MB, even with 4 make jobs.
Again, for consistency considerations I'll use absolute paths and the /kernel-build/ as working directory. If you do not plan to do all the steps as root, chown /kernel-build/ to your user, or work in /tmp if it fits the compilation.
First things first -
Always have a backup!
Code:
#as root
cd /
tar -czpf raspberry-boot-stuff-kernel-x-x-x-date-x-x-x.tgz /boot/ /lib/modules/ /lib/firmware/
# save these files again, separetlly
cp /boot/cmdline.txt /boot/config.txt .
- consider copying the archive on an external drive
Prepare the workplace:
Code:
mkdir -p /kernel-build/ && cd /kernel-build/
1. Raspberry Pi Firmware - the firmware Raspberry uses to load into the GPU and boot the board, it's residing in /boot, not to be confused with the (former) kernel in-tree firmware from /lib/firmware.
It's recommended to match the firmware with the kernel release and a good guide for that is:
https://downloads.raspberrypi.org/ra...ease_notes.txt
For the Linux kernel 4.14.79 the firmware is 12e0bf86e08d6067372bc0a45d7e8a10d3113210 and you can get it (unfortunately it comes with a lot of stuff you don't need) with:
Code:
wget https://github.com/raspberrypi/firmware/archive/12e0bf86e08d6067372bc0a45d7e8a10d3113210.zip
#extract only the /boot/ directory into your pi-firmware/ destination
unzip /kernel-build/12e0bf86e08d6067372bc0a45d7e8a10d3113210.zip 'firmware-12e0bf86e08d6067372bc0a45d7e8a10d3113210/boot/*' -d /kernel-build/pi-firmware/
mv -r /kernel-build/pi-firmware/firmware-12e0bf86e08d6067372bc0a45d7e8a10d3113210/boot/* /kernel-build/pi-firmware/
rm -rf /kernel-build/pi-firmware/firmware-12e0bf86e08d6067372bc0a45d7e8a10d3113210/ /kernel-build/pi-firmware/overlays/ /kernel-build/pi-firmware/*.dtb /kernel-build/pi-firmware/*.img /kernel-build/12e0bf86e08d6067372bc0a45d7e8a10d3113210.zip
- the possibility to use an older firmware exists, not officially supported and you might loose some functionality, even not be able to boot if it's too old. Therefore, you can leave the version you already have in /boot and don't care about updating it, if you choose to - on your own risk...
- to obtain the latest development firmware, just clone it from the Raspberry git repo (again, you'll download extra stuff you don't need):
Code:
git clone --depth=1 git://github.com/raspberrypi/firmware.git /kernel-build/pi-firmware/
mv /kernel-build/pi-firmware/boot/* /kernel-build/pi-firmware/
rm -rf /kernel-build/pi-firmware/.git/ /kernel-build/pi-firmware/boot /kernel-build/pi-firmware/documentation/ /kernel-build/pi-firmware/extra/ /kernel-build/pi-firmware/hardfp/ /kernel-build/pi-firmware/modules/ /kernel-build/pi-firmware/opt/ /kernel-build/pi-firmware/overlays/ /kernel-build/pi-firmware/*.dtb /kernel-build/pi-firmware/*.img
2. Kernel source - the only source you can use for this kernel compilation guide is the official Raspberry Pi Foundation-provided kernel, it contains modifications, adaptations and drivers required for the Raspberry boards. The mainstream source from kernel.org is not suitable for the steps described in this guide! There are choices of kernel versions to use:
a. - the developement "bleeding-edge" master - use on your own risk. Get the code:
Code:
git clone --depth=1 https://github.com/raspberrypi/linux
b. - use a branch of your choice, still the the development "bleeding-edge" master, by looking at the available ones at
https://github.com/raspberrypi/linux and using, for example:
Code:
git clone --depth=1 --branch rpi-4.18.y https://github.com/raspberrypi/linux
c. - the stable release, matching the one compiled and released in the official Raspbian images, the recommended one but pretty useless to rebuild, since it can be easily extracted from the Raspbian image. Still, useful if some extra drivers or driver patches are required.
- look at
https://downloads.raspberrypi.org/ra...ease_notes.txt first and make your choice, then browse the releases from:
https://github.com/raspberrypi/linux/releases
- click on the commit link for each release to find out the exact kernel version.
The raspberrypi-kernel_1.20181112-1 matches the latest official stable release - Linux kernel 4.14.79 - from release_notes.txt
Grab the code and unpack it:
Code:
wget https://github.com/raspberrypi/linux/archive/raspberrypi-kernel_1.20181112-1.tar.gz
tar -xzpf /kernel-build/raspberrypi-kernel_1.20181112-1.tar.gz
mv /kernel-build/raspberrypi-kernel_1.20181112-1/ /kernel-build/linux/
3. Building the kernel. The Raspberry kernel has ATM (documented) two make targets that will prepare a default .config file for the platform you choose:
a. For pi1 - ARMv6 use:
Code:
cd /kernel-build/linux
KERNEL=kernel
make bcmrpi_defconfig
b. For pi2-3 - ARMv7&ARMv8 use:
Code:
cd /kernel-build/linux
KERNEL=kernel7
make bcm2709_defconfig
- you can add some patches or edit the .config file / configure the kernel and move to the common steps for the building process:
Code:
#on pi1 use only one make job - use make -j1
make -j4 V=1 zImage
make -j4 V=1 modules
make -j4 V=1 dtbs
4. Installing the modules & kernel & dtb & dto files & pi firmware & boot configuration
- once the compilation finishes you'll need to install the modules. If the version you're compiling differs from the one you are running, then you can leave the older modules in /lib/modules, clean them later. Otherwise, make sure you clean the content of /lib/modules and run:
Code:
make modules_install
- then install the kernel. Here you can either choose a different name for it and use /boot/config.txt to point which kernel to load (pretty useless) or (better) create a /boot/backup folder and move there the content of your actual /boot. Leave /boot clean (only the backup folder available).
a. For pi1 - ARMv6 use:
Code:
cp -f arch/arm/boot/zImage /boot/kernel.img
b. For pi2-3 - ARMv7&ARMv8 use:
Code:
cp -f arch/arm/boot/zImage /boot/kernel7.img
- then for both, continue with the following steps:
- copy over the System.map
Code:
cp -f System.map /boot/System.map
- install the device tree binaries *.dtb and device tree overlay *.dto
Code:
cp -f arch/arm/boot/dts/*.dtb /boot/
mkdir -p /boot/overlays/
cp -f arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
cp -f arch/arm/boot/dts/overlays/README /boot/overlays/
- reference on *dtb & *dto:
https://www.raspberrypi.org/document...device-tree.md
- install the pi firmware
Code:
cp -f /kernel-build/pi-firmware/* /boot/
- put back/overwrite the boot configuration files
Code:
cp -f /cmdline.txt /config.txt /boot/
5. Kernel firmware, residing in /lib/firmware and needed by the kernel + device drivers. Since before the kernel 4.14.x release it was removed from the kernel source tree:
http://lkml.iu.edu/hypermail/linux/k...9.1/04650.html
And there are two ways to obtain an updated version for Raspberry under Slackware ARM.
a) The slimmed down (less than 50MB) standard version obtained from the raspbian image (manual installation method):
https://docs.slackware.com/howtos:ha...rm:raspberrypi
b) Getting it from Raspberry, a little bigger, still under 150MB:
Code:
cd /kernel-build/
git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree
rm -rf /kernel-build/firmware-nonfree/.git/
rm -rf /kernel-build/firmware-nonfree/.pc/
cp -rf /kernel-build/firmware-nonfree/ /lib/firmware/
- For the Raspberry Pi boards that have a WiFi&Bluetooth module, you also need the firmware for it. The files will reside in /lib/firmware/brcm:
Code:
wget -N -P /lib/firmware/brcm https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/master/broadcom/BCM43430A1.hcd
wget -N -P /lib/firmware/brcm https://raw.githubusercontent.com/RPi-Distro/bluez-firmware/master/broadcom/BCM4345C0.hcd
That's pretty much it, reboot and enjoy your freshly compiled kernel.
It was also my first compilation(s) and I haven't got into any issues.
If you want to revert to your previous version, clean the actual one and restore the backup:
Code:
cd /
rm -rf /lib/modules/ /lib/firmware/ /boot/*
tar -xzpf raspberry-boot-stuff-kernel-x-x-x-date-x-x-x.tgz
Have fun!
P.S. If you want to keep the kernel source tree for future use, archive /kernel-build/linux/ and store it somewhere. At least backup the Module.symvers file if you plan to build some modules in the future, the source archive you can always download again if needed.