postmarketOS

Troubleshooting:kernel

While porting pmOS to a new device you probably will find common pitfalls that others have already solved. Here is a set of them:

Patching a kernel is as simple as putting a .patch file in your aports/device/linux-vendor-flavor folder and adding the patch name to the source variable in your APKBUILD file.

Common configurations

First of all, make sure the following options are configured as you'll probably need them

CONFIG_DEVTMPFS=y
CONFIG_VT=y
CONFIG_DM_CRYPT=y

Note: CONFIG_DEVTMPFS_MOUNT is not needed but it doesn't hurt.

Also, we are compiling kernels using gcc6, which probably didn't exist when your manufacturers released the kernel sources for your device. You need the file compiler-gcc6.h. In your APKBUILD add it to source and copy it to the right location.

undefined reference to kgsl_iommu_sync_lock

drivers/built-in.o:(.data.rel+0x68c): undefined reference to kgsl_iommu_sync_lock'
drivers/built-in.o:(.data.rel+0x690): undefined reference to kgsl_iommu_sync_unlock'

You need to apply the gpu-msm-fix-gcc5-compile.patch patch.

How can I boot the kernel with some specific arguments?

You can configure CONFIG_CMDLINE so that the arguments are permanent or change it in boot time using fastboot or pmbootstrap, for example:

fastboot boot -c "console=ttyHSL0,115200,n8" ...

pmbootstrap flasher boot --cmdline "PMOS_NO_OUTPUT_REDIRECT"

MSM framebuffer doesn't work

We found out that removing the 3D driver support makes the MSM framebuffer. See #66.

CONFIG_MSM_KGSL=n

PTY allocation request failed

PTY allocation request failed on channel 0
-ash: a: unknown operand

Go to Common configurations, you have probably missed CONFIG_DEVTMPFS!

Kernel compilation: (some header file): No such file or directory

Busybox' zip implementation does not extract symlinks. There are two workarounds. One is to use another archive type (typically kernel sources are downloaded from GitHub, where you can also get the source as .tar.gz - simply by changing the extension in the URL).

The other workaround is to add unzip to the makedepends, so it uses the original unzip instead of the busybox version.

Kernel compilation: BusyBox lzma compression fails

In case you get the following output:

LZMA    arch/arm/boot/compressed/piggy.lzma
lzma: unrecognized option: 9
BusyBox v1.26.2 (2017-06-11 06:37:13 GMT) multi-call binary.

Usage: lzma -d [-cf] [FILE]...

Decompress FILE (or stdin)

        -d      Decompress
        -c      Write to stdout
        -f      Force

In the BusyBox version shipped with Alpine Linux, only lower compression levels are enabled (to reduce the binary size). The kernel you're building is configured to compress with LZMA at the highest compression level. Pick one of the following solutions: Add xz to the makedepends= line. Then the "real" lzma binary will be used instead of the Busybox version. This is recommended, because then your kernel will get built most similar to how it is built elsewhere, so you have the lowest risk of introducing a reason for the kernel not to boot (because the kernel is too big in size or something like that) Reduce the compression ratio by adding this patch. This will not introduce any dependency, but increase the kernel size. * Use another compression algorithm (run pmbootstrap menuconfig linux-... and change it there). Gzip should work, but will produce a big kernel, because pmbootstrap currently installs a workaround to always use the fastest compression method (-1), when the most compressing one (-9) is chosen. This will increase the kernel size the most.

Android Kernel compilation fails on warnings (not on errors) (-Werror)

Don't even bother fixing all those warnings, there are too many of them and we don't want the outdated Android kernels in the long run anyway! Write a patch, that removes -Werror from all Makefiles recursively instead (please expand on how to do that step by step, ask in the channel if you need help).

See this patch as example.

Building the kernel with Android's build system

It might be useful for debugging to build Android's kernel with Android's build system.

You can follow the LineageOS building guide for your device (see this for titan device as example).

The process should be similar for other devices:

# make some directories
mkdir -p ~/bin
mkdir -p ~/android/lineage

# download the 'repo' tool
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

# clone LineageOS
cd ~/android/lineage
~/bin/repo init -u https://github.com/LineageOS/android.git -b cm-14.1

# Download the rest of dependencies (this will take a while and about *TODO* GB of disk space)
~/bin/repo sync

# now prepare the build for your device (replace 'titan' with the device you want to for the kernel for)
source build/envsetup.sh
breakfast titan

# Now instead of following the rest of the guide (which will compile both Android and the kernel
#  for your device), simply compile the kernel:
mka kernel

# This command will also generate the device tree, initramfs and boot.img images
mka bootimage

You can check the $OUT environment variable and cd into it. In the case of titan the interesting generated files are:

The defconfig used is available at ~/android/lineage/kernel/motorola/msm8226/arch/arm/configs/titan_defconfig