Rebuilding the Certified Ubuntu for AMD ARM Devices Linux Kernel from Source
This page describes the steps to download the source code files for the Linux kernel used in the Certified Ubuntu for AMD ARM devices 20.04 LTS release.
The following steps are also applicable to 22.04 - use jammy
where focal
is referenced below.
Table of Contents
- 1 Introduction
- 2 Configure the Build Environment
- 3 Clone the Linux Kernel Source Code
- 4 Configure the Build Environment
- 5 Edit the Linux Kernel Configuration
- 6 Build the Linux Kernel
- 7 Install the Linux Kernel Packages
- 8 Upgrading & Downgrading the Linux Kernel Image
- 9 Build the Kernel (Advanced)
- 9.1 Rebase Kernel
- 9.1.1 Interactive Rebase
- 9.1.2 Ours/Theirs Rebase
- 9.2 Configure the Kernel
- 9.3 Build the Kernel Packages
- 9.1 Rebase Kernel
Introduction
The Certified Ubuntu for AMD ARM Devices release provides a robust and stable Linux kernel image that covers many use cases. It is possible that a particular application may require a feature in the Linux kernel that is not enabled by default in the Certified Ubuntu for AMD ARM Devices kernel.
This wiki page documents how to clone the AMD-specific Linux kernel tree for ARM devices from the Canonical Ubuntu servers and rebuild it using standard Debian best practices.
Configure the Build Environment
Before fetching the Linux kernel sources, first configure the build environment with tools such as git
, Aarch64 gcc
, and fakeroot
.
First, configure the Ubuntu sources package repository for Ubuntu 20.04 LTS.
$ echo "deb-src http://archive.ubuntu.com/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/focal.list
After configuring the new repository, update the apt metadata cache.
$ sudo apt-get update
Once the package repository is updated, configure all of the build dependencies for the Linux kernel
$ sudo apt-get build-dep linux
Native Build: Recommend having at least 8 GB of free space on your SD card or use an external HDD Using the Certified Ubuntu on Xilinx Devices image with a SATA hard disk
Once the Linux kernel build dependencies are configured, install the remaining tools required for the build process.
$ sudo apt-get install git fakeroot libncurses-dev gcc-aarch64-linux-gnu linux-tools-common
The gcc-aarch64-linux-gnu
package is only required when cross compiling the kernel.
Clone the Linux Kernel Source Code
The Certified Ubuntu for Xilinx Devices Linux kernel repository can be found on Launchpad at https://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-xilinx-zynqmp/+git/focal
In order to get started, first clone the source code.
$ git clone https://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-xilinx-zynqmp/+git/focal
After cloning the source code, switch to the latest tag. To check for the latest tag, look at the Git history with
$ cd focal
$ git tag
To check out a specific tag, name it explicitly.
$ git checkout Ubuntu-xilinx-zynqmp-5.4.0-1017.20
Configure the Build Environment
Prior to building the Linux kernel there are some environment variables that need to be set. Some are universal but others are only required if building in a cross-compile environment.
First, set the target architecture for the Linux kernel
$ export ARCH=arm64
Also, export the dpkg
variables required for packaging Debian packages for the target (arm64) architecture
$ export $(dpkg-architecture -aarm64)
Finally, if compiling in a cross-compilation environment set the CROSS_COMPILE
variable
$ export CROSS_COMPILE=aarch64-linux-gnu-
Edit the Linux Kernel Configuration
First lets make a quick edit to distinguish our kernel build from the binaries installed from Canonical. Here we just added the +local
to the version in the changelog
to distinguish it from the running kernel.
$ fakeroot debian/rules clean
$ vi debian.zynqmp/changelog
linux-xilinx-zynqmp (5.4.0-1017.20+local) focal; urgency=medium
If the Linux kernel configuration requires modification the standard Linux kernel menuconfig can be accessed with the standard Debian editconfigs
rule. This is the place in the process where new drivers, modules, or features of the Linux kernel can be enabled. If there are no edits required this section can be skipped.
$ fakeroot debian/rules clean
$ fakeroot debian/rules editconfigs
After the kernel options have been configured, select <Exit>
from the bottom menu and then proceed to build the kernel.
Build the Linux Kernel
To build the Linux kernel, use the standard Debian rules system with the binary
target. The output of this process will be a series of standard .deb
Debian packages.
$ fakeroot debian/rules clean
$ do_tools=false fakeroot debian/rules binary
The generated .deb
packages are located one directory higher than the Linux kernel source directory.
If you are making changes to the configuration that may impact modules and/or the abi, then you may need to skip those checks as shown below.
$ do_tools=false skipmodule=true skipconfig=true skipabi=true fakeroot debian/rules binary
Install the Linux Kernel Packages
If the kernel was compiled on the target, installing the new kernel is simple. First, change to the directory where the build process placed the Debian packages and install them with the dpkg
tool.
$ cd .. (or to wherever the .deb packages are located)
$ sudo dpkg -i *.deb
If the kernel was compiled in a cross-compilation environment, first copy the .deb packages to some kind of external media such as a USB stick in order to transport them to the Ubuntu target machine. Alternatively, they can be placed in the FAT32 partition of the Ubuntu SD card (mounted at /boot/firmware
in the running Ubuntu system). Then, they can be installed using the dpkg
tool as described above.
After installing the kernel update packages, reboot the system
$ sudo reboot
If cross-compiling the kernel, you can “scp” the Debian packages to the target and install them.
Upgrading & Downgrading the Linux Kernel Image
If a newer or older version of the Linux kernel is required, the same process is appropriate. Simply, choose the appropriate tag and build using it.
NOTE: If a newer version of the Linux kernel appears in the package repositories, the Linux kernel image will be updated to it automatically. It may need to be rebuilt manually to re-enable special features from the kernel configuration above.
Build the Kernel (Advanced)
This section is EXPERIMENTAL and intended for advanced kernel developers.
This section shows how to rebase the Xilinx branch against the mainline Ubuntu branch. This way you can upgrade the kernel and pick up the required commits to support Xilinx devices.
Rebase Kernel
$ git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal
$ git remote add xlnx git://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-xilinx-zynqmp/+git/focal
$ git fetch --tags xlnx
$ git checkout -b Ubuntu-xilinx-zynqmp-5.4.0-1017.20.rebase Ubuntu-xilinx-zynqmp-5.4.0-1017.20
OPTIONAL: Find number of commits in <c1> that aren’t reachable from <c2> you may use git rev-list --count <c1>..<c2>
$ git rev-list --count Ubuntu-5.4.0-98.111..Ubuntu-xilinx-zynqmp-5.4.0-1017.20
Interactive Rebase
The recommended rebase process is to manually go through each commit using the interactive mode and keep only the commits related to AMD platforms.
git rebase -i Ubuntu-5.4.0-98.111
Make any changes to the rebase commands or commits if needed from the menu. Then hit Ctrl-X to exit the menu and start rebasing against “Ubuntu-xilinx-zynqmp-5.4.0-1017.20”. Here you will need to address each conflict individually before you can proceed.
Ours/Theirs Rebase
We will take the lazy approach to resolving conflicts by using the ours/theirs strategy. Here we will use the “theirs” strategy, which is saying that we will automatically accept the changes in the feature branch (Ubuntu-xilinx-zynqmp-5.4.0-1017.20) when there is a conflict.
$ git rebase -Xtheirs Ubuntu-5.4.0-98.111
This will rebase without any conflicts. However, the gadget driver does not resolve properly. If you were to try to build the kernel as this point, you will get a compiler error flagging the gadget driver. So we will checkout the entire driver from the base branch (Ubuntu-5.4.0-98.111) as shown below using the “ours” option.
$ git checkout --ours drivers/usb/dwc3/gadget.c
$ git commit -a -m'usb: dwc3: gadget: keep driver commits from ubuntu branch'
NOTE: We chose the base branch because the gadget driver has more recent commits.
Configure the Kernel
Recommend modifying the debian.zynqmp/changelog
to add a local version, +rebase
, to the upstream kernel version. This will help distinguish the rebased kernel packages from the upstream kernel.
$ fakeroot debian/rules clean
$ vi debian.zynqmp/changelog
linux (5.4.0-91.102+rebase) focal; urgency=medium
OPTIONAL: You may manually populate the config fragment file OVERRIDES
, which will override any of the default kernel configs.
$ touch debian.zynqmp/config/OVERRIDES
Clean and configure the build environment.
$ fakeroot debian/rules clean
Configure the kernel. Required if you made an OVERRIDES
file.
$ fakeroot debian/rules editconfigs
Hit <return> on the keyboard to enter the config menu. Then from the config menu click <exit>.
Build the Kernel Packages
$ fakeroot debian/rules clean
Build the kernel, but skip the modules, config and abi checks since we have made significant changes.
$ do_tools=false skipmodule=true skipconfig=true skipabi=true fakeroot debian/rules binary
Install the packages and reboot.
Related content
© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy