Upgrade kernel aports

From postmarketOS Wiki

This article is a step-by-step guide for upgrading kernel aports in postmarketOS, where we have postmarketOS specific patches on top of the package. linux-postmarketos-allwinner is used as example.

Clone the repository

Clone the Linux source (if you don't have it already) and add the source of the kernel you are about to update as remote repository.

$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git linux
$ cd linux
$ git remote add megi https://github.com/megous/linux.git

Fetch new patches

$ git fetch megi

Find the new upstream version

Either find the branch or tag scheme where the new version to package can be found by looking at the APKBUILD. In case of megi's kernel, we have tags and can list them with:

$ git tag | grep orange-pi
orange-pi-2020-10-19
orange-pi-5.10-20201102-0305
orange-pi-5.9-20201019-1553
orange-pi-5.9-20201031-1727
orange-pi-5.9-20201101-2057

The new tag needs to be inserted into the APKBUILD. If the kernel doesn't have tags, find the latest commit of the relevant branch with git log BRANCHNAME.

Checkout the new version

Checkout a branch called postmarketos-upgrade and reset it to the new upstream tag or branch:

$ git checkout -b postmarketos-upgrade
Switched to a new branch 'postmarketos-upgrade'
$ git reset --hard orange-pi-5.9-20201101-2057
Updating files: 100% (1234/1234), done.
HEAD is now at 8504203b708b usb: musb: Fix runtime PM race in musb_queue_resume_work

Apply existing patches

Apply the patches from the package to the newer Linux tree

$ git am $(pmbootstrap -q config work)/cache_git/pmaports/device/main/linux-postmarketos-allwinner/*.patch
Applying: dts: add dontbeevil (pinephone devkit)

Patch doesn't apply

If a patch does not apply, it looks like this:

$ git am /tmp/p/0010*.patch
Applying: usb: musb: avoid the hang in musb_pm_runtime_check_session
error: patch failed: drivers/usb/musb/musb_core.c:2005
error: drivers/usb/musb/musb_core.c: patch does not apply
Patch failed at 0001 usb: musb: avoid the hang in musb_pm_runtime_check_session
hint: Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Use git am --show-current-patch to look at the patch and use git log or git log -p to verify if it was already applied to the source tree. In that case, you can skip the patch (git am --skip).

Update the patch files

In the linux source tree:

$ git checkout orange-pi-5.9-20201101-2057
$ for patch in ~/path-to-the-aport/*.patch; do git am "$patch"; done
$ rm -r /tmp/p
$ git format-patch orange-pi-5.9-20201101-2057 -N -o /tmp/p
/tmp/p/0001-dts-add-dontbeevil-pinephone-devkit.patch
/tmp/p/0002-dts-add-pinetab-dev-old-display-panel.patch
/tmp/p/0003-Disable-8723cs-power-saving.patch
/tmp/p/0004-media-gc2145-Added-BGGR-bayer-mode.patch
/tmp/p/0005-dts-pinephone-Disable-flash-led-in-OV5640-node.patch
/tmp/p/0006-dts-pinetab-add-missing-bma223-ohci1.patch
/tmp/p/0007-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
/tmp/p/0008-arm64-dts-allwinner-Add-bluetooth-node-to-the-PineTa.patch
/tmp/p/0009-dts-pinephone-remove-bt-firmware-suffix.patch

In the pmaport dir:

$ rm *.patch
$ cp /tmp/p/*.patch .
$ ls -1 *.patch
0001-dts-add-dontbeevil-pinephone-devkit.patch
0002-dts-add-pinetab-dev-old-display-panel.patch
0003-Disable-8723cs-power-saving.patch
0004-media-gc2145-Added-BGGR-bayer-mode.patch
0005-dts-pinephone-Disable-flash-led-in-OV5640-node.patch
0006-dts-pinetab-add-missing-bma223-ohci1.patch
0007-dts-pinetab-make-audio-routing-consistent-with-pinep.patch
0008-arm64-dts-allwinner-Add-bluetooth-node-to-the-PineTa.patch
0009-dts-pinephone-remove-bt-firmware-suffix.patch

Update the source= in the APKBUILD and run pmbootstrap checksum.