Building a kernel for Mobian
Prerequisites
As super user :
apt-get update apt-get dist-upgrade apt-get install gcc-aarch64-linux-gnu build-essential git debootstrap u-boot-tools device-tree-compiler libncurses-dev flex bison libssl-dev rsync kmod fakeroot git-buildpackage debhelper
Mobian-maintained kernel
Get sources
git clone https://salsa.debian.org/Mobian-team/devices/kernels/sunxi64-linux.git pinephone-linux cd pinephone-linux/
Apply patches in debian/patches
gbp pq import
applies those patches listed in debian/patches/series to a patch-queue/BRANCH branch (man page). (quilt push is an alternative means to achive this)
Generate .config from known working config
env ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- debian/rules .config
Customization
env ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make menuconfig
Compilation
fakeroot env ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- debian/rules binary
Backup .config file
env ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make savedefconfig
Testing debian package
You can mount with NFS your host folder or copy the debian package over ssh using scp.
On the target, you might be able to install the package with
sudo apt install /path/to/linux-image-x.y-sunxi64_x.y+sunxi64-1_arm64.deb
And then use a hard reboot to test it.
Downstream kernel
TODO
Troubleshooting
In the case of a boot failure, you can follow this tutorial to re-enable the previous kernel by editing /boot/extlinux/extlinux.conf and change the default label to boot to the previous kernel.
Update Process
Rebasing is used over merging so we have all our commits on top of upstream and we're less likely to forget anything when rebasing over a newer kernel branch.
The following steps are used:
Pull the latest mobian-x.y branch and fetch from upstream
Create a new branch: git checkout -b mobian-x.y.z
Create the patch branch: gbp pq import
Switch back to the main branch: gbp pq switch
Rebase the main branch on latest upstream tag: git rebase vx.y.z
For major kernel versions: git rebase --onto <latest upstream tag> <old upstream tag> <your working branch> See https://git-scm.com/book/ms/v2/Git-Branching-Rebasing (figure 39).
Create the new Debian-formatted upstream tag (needed for CI): git tag upstream/x.y.z+<platform> vx.y.z^{}
<platform> can be sunxi64, librem5, sdm845, sm7225 or rockchip depending on the device(s) this kernel is targeting
Don't forget to push the new tag: git push origin upstream/x.y.z+<platform>
Rebase our patches on top of the main branch: gbp pq rebase
For major kernel versions: git rebase --onto <your working branch> <last commit of previous mobian version> patch-queue/<your working branch>
Update patch files: gbp pq export
- Check the changes and make sure it still builds; Discard cosmetic-only changes (commit hashes, line numbers...) as long as the patches still apply cleanly without fuzz, that brings only noise for future reviews
If some patches were dropped in the process, renumber patch files: gbp pq export --renumber
Tag the upstream release with git tag -f upstream/<version>+<platform> v<version>^{} and push the tag. This allows CI to extract the source before building.