Build upstream Ubuntu Kernel for Arm64 Raspberry-Pi

Whole processes, git cloning the right codebase from a repository, installing all the packages, kernel configuration, and finally go building are such a challenge for beginners like me. Fortunately, Ubuntu Kernel Team provides an easy system for building kernel though.

In this article, we are going to look at some requirements. In more detail, try installing build tools, get ready, and building :-)

Get ready for upstream kernel and environment

Canonical, a company mainly supports Ubuntu distro maintains its Kernel sources at Launchpad, but for Raspberry Pi, it's maintained at this repository.

I'm currently running Kinetic release on my raspberry pi but wanna switch to an upstream kernel of master-next branch. Launchpad page has an instruction such as what to do in each branch of each repository in more detail but all I need now is the following address to clone,

1$ mkdir linux; cd linux
2$ git clone -b master-next \
3    https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux-raspi/+git/kinetic \
4    ./ubuntu-upstream-kernel
5$ cd ubuntu-upstream-kernel

also, we have to install the following packages but keep in mind that some of them aren't supported in older releases or needs. This article is based on 22.04.1 LTS.

1$ sudo apt build-dep linux linux-image-$(uname -r)
2$ sudo apt install libncurses-dev gawk flex bison openssl libssl-dev dkms \
3    libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm curl \
4    gcc-12-aarch64-linux-gnu gcc-12-aarch64-linux-gnu-base gcc-12 g++-12 \
5    linux-tools-common fakeroot debhelper gcc-aarch64-linux-gnu

Let's go!

Most of the branches for Ubuntu kernel have extra directories, debian, debian.master, and debian.raspi which have special files such as basic scripts, configs, and target info respectively. In my case, raspberry pi configs are in the latter one.

All we need to do is run scripts in debian but others are nothing care.

1# Now we are in 'ubuntu-upstream-kernel'
2
3$ export $(dpkg-architecture -aarm64)
4$ export CROSS_COMPILE=aarch64-linux-gnu-
5
6$ LANG=C fakeroot debian/rules clean            # cleaning any garbages
7$ LANG=C fakeroot debian/rules editconfigs      # menuconfig if you need
8$ LANG=C fakeroot debian/rules binary-headers binary binary-perarch

It will take a long and long time even though you are done with having meals, and going for a walk... so forget it at least for 2 hours.

Then you have some deb packages in the parents' directory like these,

1linux-buildinfo-5.19.0-1006-raspi_5.19.0-1006.13_arm64.deb
2linux-modules-extra-5.19.0-1006-raspi_5.19.0-1006.13_arm64.deb
3linux-headers-5.19.0-1006-raspi_5.19.0-1006.13_arm64.deb
4linux-raspi-headers-5.19.0-1006_5.19.0-1006.13_arm64.deb
5linux-image-5.19.0-1006-raspi_5.19.0-1006.13_arm64.deb
6linux-modules-5.19.0-1006-raspi_5.19.0-1006.13_arm64.deb

It's all up to you what to do with them, cheers :-)