Upgrade kernel aports

From postmarketOS
Revision as of 23:19, 23 February 2021 by MartijnBraam (talk | contribs) (→‎Update the patch files)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

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

Copy existing patches to a temp dir:

$ cd $(pmbootstrap -q config work)/cache_git/pmaports
$ mkdir -p /tmp/p
$ cp main/linux-postmarketos-allwinner/*.patch /tmp/p

Then go back to the linux source and try to apply them one after another

$ git am /tmp/p/0001*.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

In the pmaport dir:

$ rm *.patch
$ cp /tmp/p/*.patch .
$ ls -1 *.patch

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