Hacking:Kernel patches

From ParabolaWiki
Jump to: navigation, search

The purpose of this page is to document my process of how I do the kernel patching of our official packages. For instance, linux-libre and linux-libre-pck.

1 Arch Linux kernel patches

Since the Arch kernel git repository is based on the upstream Linux kernel, to gather the patches simply clone the official Linux repository and add the Arch repository as a remote, which I'll call 'arch':

$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/
$ cd linux
$ git remote add arch https://git.archlinux.org/linux.git
$ git fetch arch
$ git fetch --tags arch # we will use the tags to get the patches

Let's say we want patches for Linux v5.17.8 from Arch's v5.17.8-arch1. Since v5.17.8-arch1 is built on top of v5.17.8, you'll notice that it's the same but with some more commits ahead, and the latest one is (commonly) just a change to the root Makefile which sets EXTRAVERSION to -arch1. So, let's save these patches, excepting the latest one.

$ git format-patch v5.17.8..v5.17.8-arch1~1 # ~1 means to skip the last patch
Tip: The -o $DIRECTORY flag let you save the patches in another directory

Summarizing, this the general command I use to get the patches:

$ git format-patch -o $DIRECTORY $VERSION..$ARCH_VERSION~1

2 PCK patches

The Parabola Community Kernel patches are listed in PCK. Simply download the patches and apply them, then create a diff. Here I will explain special cases.

2.1 AUFS

Clone the aufs5-standalone git repo. Apply these patches, in this order:

  1. aufs5-kbuild.patch
  2. aufs5-base.patch
  3. aufs5-mmap.patch
  4. aufs5-standalone.patch

Now, copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your kernel source tree. Never copy include/uapi/linux/Kbuild. Read the README file for more information.

2.2 Zen patch

Similar to what we did in #Arch Linux kernel patches, in the linux git add the zen kernel remote.

$ git remote add zen https://github.com/zen-kernel/zen-kernel
$ git fetch zen

And save a diff between the corresponding tags:

$ git diff $VERSION $ZEN_VERSION > patch-$ZEN_VERSION.diff

Before applying it, you'll need to modify it a bit as the root Makefile change adds -zen in EXTRAVERSION. You can "rebrand" it to PCK:

$ sed -e '/^+EXTRAVERSION = -zen/s/-zen[0-9]/-pck1/' -e '/^[-+]EXTRAVERSION =/s/= */= -gnu/' -i patch-$ZEN_VERSION.diff

Change pck1 with the corresponding PCK release.

3 RCN patch

Robert C. Nelson (RCN) patch is used by Arch Linux ARM to add extra features to the vanilla kernel. We are interested in adding compatibility for more devices only, not really on backporting patches or downstream things. Clone the repo, the only directory we will work with is patches/.

$ git clone https://github.com/RobertCNelson/armv7-multiplatform

Download the corresponding patch. You can find them in the RCN http server.

And apply it with git apply in your linux-libre source. You can either download the tarball or clone the git repo jxself and lxo are kindly maintaining. I'll explain how to do it with the git repo, which is what I use. First of all, create a branch based on the version you will work with:

$ git clone https://jxself.org/git/releases.git linux-libre
$ cd linux-libre
$ git checkout -b rcn-libre-$VERSION $VERSION_TAG # VERSION_TAG in releases.git are named sources/v$LINUX_VERSION

Now apply the RCN patch and clean the crap.

$ git apply $RCN_PATCH
$ rm arch/arm/configs/rcn-ee_defconfig
$ git apply --revert ../armv7-multiplatform/patches/drivers/ti/firmware/0001-Add-AM335x-CM3-Power-Managment-Firmware.patch # Change the path if needed

Follow the same process of reverting patches from patches/aufs, patches/wireless_regdb and any other bloatware/blobs you find. The example above is from a known blob (TI licensed), but there may be others. Then, create a tag and do a diff:

$ git add -A
$ git commit -m $MESSAGE
$ git tag -a $TAG_NAME -m $MESSAGE
$ git diff $VERSION_TAG $TAG_NAME > ../rcn-libre-$VERSION-$RCN_RELEASE.patch # RCN_RELEASE commonly is armv7-xN

Just in case, check the patch with deblob-check:

$ ./deblob-check -B rcn-libre-$VERSION-$RCN_RELEASE.patch

Beware of false positives, which can be safely ignored. However, if blobs are found and cannot be removed by simply reverting a patch, you'll have to create a deblob script to clean it. You can see examples of these here (named deblob-$KERNEL_GENERATION). I've made some for old versions here.

Note: There's an old guide I wrote in GitLab about debblobing the RCN patch, which is more exhaustive.