LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM
User Name
Password
Slackware - ARM This forum is for the discussion of Slackware ARM.

Notices


Reply
  Search this Thread
Old 02-09-2019, 12:02 AM   #1
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 904

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Building a kernel for all Raspberry Pi boards under Slackware ARM 14.2 and -current


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.

Last edited by abga; 02-09-2019 at 11:40 PM. Reason: formatting + P.S.
 
Old 02-09-2019, 12:12 AM   #2
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 904

Original Poster
Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Interesting sites where you can grab official Raspberry "stuff" without having to download the Raspbian image and extract the "stuff" from it:
https://github.com/RPi-Distro
https://archive.raspberrypi.org/debian/pool/main/r/
https://archive.raspberrypi.org/debi...rypi-firmware/

Useful info about the boot sequence on the Raspberry Pi boards:
https://www.raspberrypi.org/document...es/bootflow.md
https://raspberrypi.stackexchange.co...-boot-sequence
 
1 members found this post helpful.
Old 02-09-2019, 05:02 PM   #3
SCerovec
Senior Member
 
Registered: Oct 2006
Location: Cp6uja
Distribution: Slackware on x86 and arm
Posts: 1,447
Blog Entries: 2

Rep: Reputation: 318Reputation: 318Reputation: 318Reputation: 318
subscribed
 
Old 02-09-2019, 10:00 PM   #4
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 904

Original Poster
Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
The mainstream kernel can also be used as source, but I didn't test it with the steps presented in the first post from this thread, nor am I interested about it ATM. A partially working kernel is no good for me. That doesn't mean that you cannot play with it, if you have some spare time to kill.
For the history and status of the support for the Raspberry boards in the mainstream kernel, follow:
https://github.com/raspberrypi/linux/wiki/Upstreaming
What works and what doesn't is not yet clear and there are very recent issues, like:
https://github.com/raspberrypi/firmware/issues/957
Plus, the Raspberry folks are "encouraging" you that you're on your own if you get into issues with the mainstream kernel, like:
https://www.raspberrypi.org/forums/v...c.php?t=203923

There are some mainstream kernel compilation guides that can be used for inspiration:
https://elinux.org/RPi_Upstream_Kernel_Compilation
(try to omit the cross-compilation requirements and switches)
https://wiki.gentoo.org/wiki/Raspber...ainline_Kernel
(covering only Pi2 and Pi3)

The kernel configuration defaults required by the Raspberry boards do exist in the mainline:
https://github.com/torvalds/linux/tr...ch/arm/configs
bcm2835_defconfig - Raspberry Pi1
multi_v7_defconfig - Raspberry Pi2 and Pi3

To play with the mainstream kernel you'll need the following amendments to the guide from the first post:
Step 2 - Get the source (don't know for sure what branch to use, but the latest master might be more appropriate):
Code:
git clone --depth=1 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Step 3 - Building the kernel
a. For pi1 - ARMv6 use:
Code:
cd /kernel-build/linux
KERNEL=kernel
make bcm2835_defconfig
b. For pi2-3 - ARMv7&ARMv8 use:
Code:
cd /kernel-build/linux
KERNEL=kernel7
make multi_v7_defconfig
The rest of the steps should be the same.

Good luck!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] KODI Leia - 18.x MediaPlayer - Optimized for Raspberry Pi1/Zero/Pi2B/Pi3B(+) on Slackware ARM 14.2 SF & Slackware ARM - current HF abga Slackware - ARM 7 02-17-2019 02:54 PM
[SOLVED] KODI Krypton - 17.x MediaPlayer - Optimized for Raspberry Pi1/Pi2/Pi3 on Slackware ARM 14.2 SF & Slackware ARM - current HF abga Slackware - ARM 40 08-28-2018 09:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware > Slackware - ARM

All times are GMT -5. The time now is 03:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration