Jump to content

Patching

From postmarketOS Wiki
Revision as of 20:34, 8 September 2017 by Ollieparanoid (talk | contribs) (Workflow)

Introduction

The most common use-case is, that you want to package an Android kernel. But it does not compile with our GCC6, so you need to patch the kernel. Unlike in the Android world, we do not fork the kernel repository and apply our patches there. Instead we ship our custom patches with the package build recipe in the aport folder.

This guide assumes, that you already know what to patch - if you don't know what to patch and only have the error, try to search the web for that error message. More often than not, there is a patch already available, that will fix it. If you don't have any luck, ask in the chat.

As everywhere else in the wiki, please expand this guide wherever information is missing that would have helped you!


Workflow

  1. Try to compile your program with pmbootstrap build my-package. Note in which chroot it will actually build, it is the start of the building message. When it starts with (native) for example, the chroot is the "native" chroot (which is the default).
  2. Wait until it fails or runs through (it works in both cases)
  3. The sources of the kernel are now extracted in /home/user/build/src in the chroot where it was building.
  4. Use pmbootstrap chroot to enter the chroot and to create the patch. It will enter the native chroot by default, if you need another chroot, then look at pmbootstrap chroot --help. Then do the following inside the chroot shell:
    1. Install git and an editor such as nano with: apk add git nano
    2. Switch from root to user: su - user
    3. Go into the source folder: cd ~/build/src/
    4. Patches get applied in the builddir, so usually there is another folder inside src, that you need to enter. You can check with ls which folders/files are inside the src folder. Enter that subfolder if necessary.
    5. We'll be using git to create a patch file, so we will initialize a new repository and add everything:
      1. git init . (it will say: "Initialized empty Git repository in /home/user/build/src/.git/")
      2. git add -A
      3. git commit -m "initial"
    6. Now it's time to edit the file you want to edit.
      1. export TERM=xterm
      2. nano Makefile (or whichever file you want to edit)
      3. NOTE: nano is glitchy when used like that. If it is unusable for you, run chmod 777 Makefile and then edit the file from outside the chroot with your favorite editor (a graphical one works, too!). The path is similar to: ~/.local/var/pmbootstrap/chroot_native/home/user/build/src/(optional builddir)/Makefile.
    7. (in the chroot again) run git diff to get a patch file generated to the screen. You can save it to a file by redirecting it: git diff > /tmp/mypatch.patch.
    8. Quit the chroot by pressing ^D (CTRL+D) twice (typing exit also works).
  5. Copy the patch file you have created to your aport folder (adjust the work path, that you have given pmbootstrap init and the chroot suffix native if necessary):
    1. cp ~/.local/var/pmbootstrap/chroot_native/tmp/mypatch.patch ~/code/pmbootstrap/aports/device/linux-my-cool-kernel/mypatch.patch
  6. Rename the mypatch.patch file to give it a meaningful name!
  7. You can add arbitrary text at the top of the patch file. Use this to paste the error message that you got during compilation there, with a note that this will be fixed by this patch.