Cross-compiling the Linux kernel for the pinenote (or other arm device)
(Restored: original date: January 8, 2022)
This blog post is mostly so I can link to it from my other post, dual-booting debian on the pinenote, but might prove useful for other purposes.
All of the commands to get smauel's kernel and build it are available as a Dockerfile here too.
Note: it has been suggested to use the official arm toolchain rather than the gnu one because if you later use the compiler on the device, incompatibilities can happen, I may write an update to this post later, but you have been warned!
There's also a release on my github repo using github actions if you just want to download a zip with the completed files. The usual warnings about downloading random binary files from the internet apply but at least you can look at the ci config there too.
Prerequisites/assumptions : * A debian-based linux distro on an amd64 or other powerful machine (kernel compilation is a heavy process) * AT LEAST 6Gb of disk space free on the build machine.
First, check you have deb-src lines in /etc/apt/sources.list for the magic “get me almost all the dependencies to build a kernel please, debian”. If you don't have that, you have a lot more deps to install.
If your sources.list doesn't contain deb-src lines, here's a handy script to add them :
cat /etc/apt/sources.list | sed s/^deb/deb-src/ | sudo tee /etc/apt/sources.list.d/sources.src.list
then run apt update to get them updated.
I like to run the commands in ~/.local/src/ as I'm a bit old-school and the kernel sources are usually in /usr/src/linux but to run as non-root you usually locate /usr/ to ~/.local/. You can run anywhere, just change there, but if you're happy with that, run these commands :
mkdir -p ~/.local/src cd ~/.local/src
First, get the dependencies for building and don't ask me why build-dep linux-base doesn't include flex, bison or bc!
apt build-dep -y linux-base apt install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu git flex bison bc
Then fetch the kernel tree for the device you're using, in our case for the pinenote we're getting smauel's fine work :
git clone https://github.com/smaeul/linux.git git checkout rk356x-ebc-dev
Okay, so here's another step you'll want to customize for another device, we build the defconfig into a valid .config for the pinenote:
make ARCH=arm64 CROSSCOMPILE=aarch64-linux-gnu- pinenotedefconfig
then we can go ahead and build the base kernel and modules:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- all
Now, so we have an obvious place to get to the files (and to avoid needing root, and saving you from polluting your amd64 device with arm64 files outside of your build tree), we make a pack directory and install the dtbs and modules there :
mkdir pack make ARCH=arm64 CROSSCOMPILE=aarch64-linux-gnu- INSTALLMODPATH=${PWD}/pack modulesinstall make ARCH=arm64 CROSSCOMPILE=aarch64-linux-gnu- INSTALLPATH=${PWD}/pack dtbs_install
That's it! All the modules you need are in pack/lib/modules/{kernel-version} so you'll want to copy those to /var/lib/modules/{kernel-version} on your pinenote's linux partition, your kernel image is in arch/arm64/boot/Image (this is the first file you give u-boot) and the dtb (the other file u-boot needs) is in pack/dtbs/{kernel-version}/rockchip/rk3566-pinenote.dtb {kernel-version} at the time of writing this document is 5.16.0-rc8-00002-g6c7fc21536f3 but just look in pack/lib/modules/ after you've run to be sure what your version is.