Jump to content

Troubleshooting downstream kernel compilation: Difference between revisions

From postmarketOS Wiki
Intgr (talk | contribs)
Halamix2 (talk | contribs)
mNo edit summary
 
(27 intermediate revisions by 16 users not shown)
Line 1: Line 1:
Here are some common kernel compilation problems listed. For debugging a kernel that compiles, but does not boot, see [[Troubleshooting:boot]].
Here are some common kernel compilation problems listed. For debugging a kernel that compiles, but does not boot, see [[Troubleshooting:boot]].


== How to create a patch ==
== Patching the kernel ==
Patching a kernel is as simple as putting a <code>.patch</code> file in your <code>aports/device/linux-vendor-flavor</code> folder and adding the patch name to the <code>source</code> variable in your <code>APKBUILD</code> file. See also: [[How to create a patch when packaging software]].
{{See also|Patching}}


== undefined reference to kgsl_iommu_sync_lock ==
In many cases, the issue that you're experiencing with kernel compilation can be fixed by a patch. Sometimes, other kernels already in pmOS might've had the same issue; for example, if you get a specific error, you can look for patches that mention it in pmaports with <code>grep -iR "error message" ~/.local/var/pmbootstrap/cache_git/pmaports/device</code>.
<pre>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'</pre>
To apply a patch to a kernel, place the <code>.patch</code> file containing the patch in your <code>device/category/linux-vendor-flavor</code> folder and add the patch name to the <code>source</code> variable in your <code>APKBUILD</code> file.
You need to apply the [https://gitlab.com/postmarketOS/pmaports/blob/master/device/linux-lg-mako/02_gpu-msm-fix-gcc5-compile.patch gpu-msm-fix-gcc5-compile.patch] patch.
 
=== Making patches from commits ===
 
If you want to apply a commit from a git repository as a patch, you have multiple options:
 
* If it's a GitHub or GitLab commit, you can get a patch file by appending <code>.patch</code> to the URL of the commit.
** This also works with pull requests/merge requests.
* You can also clone the git repository, then run <code>git format-patch -1 &lt;commit&gt;</code> (replace <code>&lt;commit&gt;</code> with the commit ID; you can also get multiple patches preceeding the given patch by changing the number from <code>1</code>).
 
== Booting the kernel with specific arguments ==
You can configure <code>CONFIG_CMDLINE</code> so that the arguments are permanent (you may also need to set <code>CONFIG_CMDLINE_EXTEND</code> to append the cmdline to the one provided by the bootloader, or <code>CONFIG_CMDLINE_FORCE</code> to overwrite it (alternatively, unset <code>CONFIG_CMDLINE_FROM_BOOTLOADER</code>)).
 
On some devices, you can change it at boot time using fastboot or pmbootstrap, for example:
 
<syntaxhighlight lang="shell-session">
$ fastboot boot -c "console=ttyHSL0,115200,n8"
...
$ pmbootstrap flasher boot --cmdline "quiet"
</syntaxhighlight>


== How can I boot the kernel with some specific arguments? ==
== TLS (SSL/HTTPS) is broken! ==
You can configure <code>CONFIG_CMDLINE</code> so that the arguments are permanent or change it in boot time using fastboot or pmbootstrap, for example:
If you see messages like these, when trying to access HTTPS pages, read on:
<pre>
Connecting to pastebin.com (104.20.209.21:443)
ssl_client: pastebin.com: TLS connect failed
wget: error getting response: Connection reset by peer
</pre>


<pre>fastboot boot -c &quot;console=ttyHSL0,115200,n8&quot; ...
You are probably running an older kernel (pre 3.17), which does not yet have the "getrandom" syscall. This is required by modern openssl/libressl versions (Alpine was on libressl for a long time, then switched back to openssl). Check your kernel version, and if that is the case, and [[the Mainline Kernel|mainlining]] is not feasible for you, consider backporting the getrandom syscall like done in {{MR|69|pmaports}}. This issue was discussed in {{issue|107|pmaports}}.


pmbootstrap flasher boot --cmdline &quot;PMOS_NO_OUTPUT_REDIRECT&quot;</pre>
== Kernel compilation issues ==
== MSM framebuffer doesn't work ==
We found out that removing the 3D driver support makes the MSM framebuffer. See [https://github.com/postmarketOS/pmbootstrap/pull/66 #66].


<pre>CONFIG_MSM_KGSL=n</pre>
=== PTY allocation request failed ===
== PTY allocation request failed ==
<pre>PTY allocation request failed on channel 0
<pre>PTY allocation request failed on channel 0
-ash: a: unknown operand</pre>
-ash: a: unknown operand</pre>
Go to [https://github.com/postmarketOS/pmbootstrap/wiki/Troubleshooting%3Akernel#common-configurations Common configurations], you have probably missed <code>CONFIG_DEVTMPFS</code>!
Go to [[kernel configuration]], you have probably missed <code>CONFIG_DEVTMPFS</code>!


== Kernel compilation: (some header file): No such file or directory ==
=== CROSS_COMPILE_ARM32 not defined or empty, the compat vDSO will not be built ===
Busybox' <code>zip</code> 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 <code>.tar.gz</code> - simply by changing the extension in the URL).
Disable <code>CONFIG_COMPAT_VDSO</code> in the kernel config.
 
=== (some header file): No such file or directory ===
Busybox's <code>zip</code> 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 <code>.tar.gz</code> - simply by changing the extension in the URL).


The other workaround is to add <code>unzip</code> to the makedepends, so it uses the original unzip instead of the busybox version.
The other workaround is to add <code>unzip</code> to the makedepends, so it uses the original unzip instead of the busybox version.
Line 31: Line 54:
(This has been fixed in busybox in the meantime.)
(This has been fixed in busybox in the meantime.)


== Kernel compilation: thumb conditional instruction should be in IT block ==
=== linux/types.h: No such file or directory ===
Add <code>linux-headers</code> to makedepends of linux-* APKBUILD.
 
=== thumb conditional instruction should be in IT block ===
<pre>
<pre>
arch/arm/crypto/aesbs-core.S:449: Error: thumb conditional instruction should be in IT block -- `addeq r6,r6,#0x10'
arch/arm/crypto/aesbs-core.S:449: Error: thumb conditional instruction should be in IT block -- `addeq r6,r6,#0x10'
Line 38: Line 64:
</pre>
</pre>


You can fix it by disabling <code>CONFIG_CRYPTO_AES_ARM_BS</code>.
You can fix it by disabling <code>CONFIG_CRYPTO_AES_ARM_BS</code> with:
<syntaxhighlight lang="bash">pmbootstrap kconfig edit</syntaxhighlight>
Then go to <code>Cryptographic API</code> and disable <code>Bit sliced AES using NEON instructions</code>.


On some other devices, like Huawei P7, you might also need to disable all CRYPTO flags containing ARM (<code>CONFIG_CRYPTO_{algorithm name}_ARM</code>), which are ARM NEON optimizations.
On some other devices, like Huawei P7, you might also need to disable all CRYPTO flags containing ARM (<code>CONFIG_CRYPTO_{algorithm name}_ARM</code>), which are ARM NEON optimizations.
Line 44: Line 72:
This was first noticed in {{MR|144|pmaports}}.
This was first noticed in {{MR|144|pmaports}}.


== Kernel compilation: BusyBox lzma compression fails ==
=== BusyBox lzma compression fails ===
In case you get the following output:
In case you get the following output:


Line 61: Line 89:


* Add <code>xz</code> to the <code>makedepends=</code> line. Then the &quot;real&quot; 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)
* Add <code>xz</code> to the <code>makedepends=</code> line. Then the &quot;real&quot; 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 [https://github.com/postmarketOS/pmbootstrap/blob/b4c9f93f0d7be1272f6a67de2128558ce58e1077/aports/linux-samsung-i9070/02_reduce_lzo_compression.patch this patch]. This will not introduce any dependency, but increase the kernel size.
* Reduce the compression ratio by adding [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/blob/master/device/testing/linux-samsung-i9070/02_reduce_lzo_compression.patch this patch]. This will not introduce any dependency, but increase the kernel size.
* Use another compression algorithm (run <code>pmbootstrap menuconfig linux-...</code> 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 (<code>-1</code>), when the most compressing one (<code>-9</code>) is chosen. This will increase the kernel size the most.
* Use another compression algorithm (run <code>pmbootstrap menuconfig linux-...</code> 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 (<code>-1</code>), when the most compressing one (<code>-9</code>) is chosen. This will increase the kernel size the most.


== Android Kernel compilation fails on warnings (not on errors) (-Werror) ==
=== xz: not found ===
 
If you see something like this in the logs:
 
<pre>
  XZKERN  arch/arm/boot/compressed/piggy.xzkern
/home/pmos/build/src/android_kernel_samsung_msm8226-3fa1853ed5d6c3a8ef5a2fda9822705243bbc256/scripts/xz_wrap.sh: exec: line 23: xz: not found
</pre>
 
It's similar to the "BusyBox lzma compression fails" issue above: some things are compressed with LZMA and will need <code>xz</code> installed. Add it to the <code>makedepends</code> of your <code>APKBUILD</code>.
 
=== Error: .err encountered in assembler messages ===
If compilation errors out on something like this in logs:
<pre>
/tmp/ccmAkEIJ.s: Assembler messages:
/tmp/ccmAkEIJ.s:2280: Error: .err encountered
</pre>
Then [https://wiki.postmarketos.org/wiki/Downstream_kernel_specific_package#GCC_version older version of GCC] should be used for compilation.
 
=== 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! When you generate your kernel APKBUILD with <code>pmbootstrap init</code>, then you should have code in the <code>prepare()</code> that automatically removes the <code>-Werror</code> parameter in all Makefiles.
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! When you generate your kernel APKBUILD with <code>pmbootstrap init</code>, then you should have code in the <code>prepare()</code> that automatically removes the <code>-Werror</code> parameter in all Makefiles.
Example from [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/blob/master/device/testing/linux-asus-z00vd/APKBUILD linux-asus-z00vd]:
<syntaxhighlight lang="bash">
# Remove -Werror from all makefiles
local i
local makefiles="$(find . -type f -name Makefile)
    $(find . -type f -name Kbuild)"
for i in $makefiles; do
    sed -i 's/-Werror-/-W/g' "$i"
    sed -i 's/-Werror//g' "$i"
done
</syntaxhighlight>
=== Error: selected processor does not support ARM mode `smc #0' ===
Try this patch: https://github.com/imoseyon/leanKernel-galaxy-nexus/pull/6
== Downstream kernel issues by manufacturer ==
=== Mediatek ===
==== ../tools/dct/DrvGen: No such file or directory ====
This error is specific to Mediatek kernels and it occures when DrvGen tries to load libc6.so library it has been linked against but Alpine chroot doesn't support libc.
One of the solutions is to copy [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/blob/master/device/testing/linux-vernee-k506/python3dct.patch python3dct.patch] to your linux-... directory and activate it in the APKBUILD. This patch replaces precompiled DrvGen with a python3 version.
=== Qualcomm ===
==== undefined reference to kgsl_iommu_sync_lock ====
<pre>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'</pre>
You need to apply the [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/blob/master/device/testing/linux-lg-mako/02_gpu-msm-fix-gcc5-compile.patch gpu-msm-fix-gcc5-compile.patch] patch.
==== X11 does not work on Qualcomm devices ====
Try apply this [https://gitlab/postmarketOS/pmaports/-/blob/master/device/testing/linux-xiaomi-santoni/fix-xorg-mdss-update-fb-info.patch patch].
==== MSM framebuffer doesn't work ====
We found out that removing the 3D driver support makes the MSM framebuffer work. See {{MR|66}}.
<pre>CONFIG_MSM_KGSL=n</pre>


== Building the kernel with Android's build system ==
== Building the kernel with Android's build system ==
Line 74: Line 159:
The process should be similar for other devices:
The process should be similar for other devices:


<source lang="bash"># make some directories
<syntaxhighlight lang="bash"># make some directories
mkdir -p ~/bin
mkdir -p ~/bin
mkdir -p ~/android/lineage
mkdir -p ~/android/lineage
Line 98: Line 183:


# This command will also generate the device tree, initramfs and boot.img images
# This command will also generate the device tree, initramfs and boot.img images
mka bootimage</source>
mka bootimage</syntaxhighlight>
You can check the <code>$OUT</code> environment variable and cd into it. In the case of titan the interesting generated files are:
You can check the <code>$OUT</code> environment variable and cd into it. In the case of titan the interesting generated files are:


Line 107: Line 192:


The defconfig used is available at <code>~/android/lineage/kernel/motorola/msm8226/arch/arm/configs/titan_defconfig</code>
The defconfig used is available at <code>~/android/lineage/kernel/motorola/msm8226/arch/arm/configs/titan_defconfig</code>
== Error: selected processor does not support ARM mode `smc #0' ==
Try this patch: https://github.com/imoseyon/leanKernel-galaxy-nexus/pull/6
== TLS (SSL/HTTPS) is broken! ==
If you see messages like these, when trying to access HTTPS pages, read on:
<pre>
Connecting to pastebin.com (104.20.209.21:443)
ssl_client: pastebin.com: TLS connect failed
wget: error getting response: Connection reset by peer
</pre>
You are probably running an older kernel (pre 3.17), which does not yet have the "getrandom" syscall. This is required by modern openssl/libressl versions (Alpine was on libressl for a long time, then switched back to openssl). Check your kernel version, and if that is the case, and [[the Mainline Kernel|mainlining]] is not feasible for you, consider backporting the getrandom syscall like done in {{MR|69|pmaports}}. This issue was discussed in {{issue|107|pmaports}}.


== External resources ==
== External resources ==
*[http://docs.halium.org/en/latest/porting/common-kernel-build-errors.html Halium Docs]
*[http://docs.halium.org/en/latest/porting/common-kernel-build-errors.html Halium Docs]
[[Category:Troubleshooting|kernel]]

Latest revision as of 10:17, 1 February 2025

Here are some common kernel compilation problems listed. For debugging a kernel that compiles, but does not boot, see Troubleshooting:boot.

Patching the kernel

See also: Patching

In many cases, the issue that you're experiencing with kernel compilation can be fixed by a patch. Sometimes, other kernels already in pmOS might've had the same issue; for example, if you get a specific error, you can look for patches that mention it in pmaports with grep -iR "error message" ~/.local/var/pmbootstrap/cache_git/pmaports/device.

To apply a patch to a kernel, place the .patch file containing the patch in your device/category/linux-vendor-flavor folder and add the patch name to the source variable in your APKBUILD file.

Making patches from commits

If you want to apply a commit from a git repository as a patch, you have multiple options:

  • If it's a GitHub or GitLab commit, you can get a patch file by appending .patch to the URL of the commit.
    • This also works with pull requests/merge requests.
  • You can also clone the git repository, then run git format-patch -1 <commit> (replace <commit> with the commit ID; you can also get multiple patches preceeding the given patch by changing the number from 1).

Booting the kernel with specific arguments

You can configure CONFIG_CMDLINE so that the arguments are permanent (you may also need to set CONFIG_CMDLINE_EXTEND to append the cmdline to the one provided by the bootloader, or CONFIG_CMDLINE_FORCE to overwrite it (alternatively, unset CONFIG_CMDLINE_FROM_BOOTLOADER)).

On some devices, you can change it at boot time using fastboot or pmbootstrap, for example:

$ fastboot boot -c "console=ttyHSL0,115200,n8"
...
$ pmbootstrap flasher boot --cmdline "quiet"

TLS (SSL/HTTPS) is broken!

If you see messages like these, when trying to access HTTPS pages, read on:

Connecting to pastebin.com (104.20.209.21:443)
ssl_client: pastebin.com: TLS connect failed
wget: error getting response: Connection reset by peer

You are probably running an older kernel (pre 3.17), which does not yet have the "getrandom" syscall. This is required by modern openssl/libressl versions (Alpine was on libressl for a long time, then switched back to openssl). Check your kernel version, and if that is the case, and mainlining is not feasible for you, consider backporting the getrandom syscall like done in pmaports!69. This issue was discussed in pmaports#107.

Kernel compilation issues

PTY allocation request failed

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

Go to kernel configuration, you have probably missed CONFIG_DEVTMPFS!

CROSS_COMPILE_ARM32 not defined or empty, the compat vDSO will not be built

Disable CONFIG_COMPAT_VDSO in the kernel config.

(some header file): No such file or directory

Busybox's 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.

(This has been fixed in busybox in the meantime.)

linux/types.h: No such file or directory

Add linux-headers to makedepends of linux-* APKBUILD.

thumb conditional instruction should be in IT block

arch/arm/crypto/aesbs-core.S:449: Error: thumb conditional instruction should be in IT block -- `addeq r6,r6,#0x10'
arch/arm/crypto/aesbs-core.S:904: Error: thumb conditional instruction should be in IT block -- `addeq r6,r6,#0x10'
arch/arm/crypto/aesbs-core.S:2100: Error: thumb conditional instruction should be in IT block -- `subne r9,#0x10'

You can fix it by disabling CONFIG_CRYPTO_AES_ARM_BS with:

pmbootstrap kconfig edit

Then go to Cryptographic API and disable Bit sliced AES using NEON instructions.

On some other devices, like Huawei P7, you might also need to disable all CRYPTO flags containing ARM (CONFIG_CRYPTO_{algorithm name}_ARM), which are ARM NEON optimizations.

This was first noticed in pmaports!144.

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.

xz: not found

If you see something like this in the logs:

  XZKERN  arch/arm/boot/compressed/piggy.xzkern
/home/pmos/build/src/android_kernel_samsung_msm8226-3fa1853ed5d6c3a8ef5a2fda9822705243bbc256/scripts/xz_wrap.sh: exec: line 23: xz: not found

It's similar to the "BusyBox lzma compression fails" issue above: some things are compressed with LZMA and will need xz installed. Add it to the makedepends of your APKBUILD.

Error: .err encountered in assembler messages

If compilation errors out on something like this in logs:

/tmp/ccmAkEIJ.s: Assembler messages:
/tmp/ccmAkEIJ.s:2280: Error: .err encountered

Then older version of GCC should be used for compilation.

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! When you generate your kernel APKBUILD with pmbootstrap init, then you should have code in the prepare() that automatically removes the -Werror parameter in all Makefiles.

Example from linux-asus-z00vd:

# Remove -Werror from all makefiles
local i
local makefiles="$(find . -type f -name Makefile)
    $(find . -type f -name Kbuild)"
for i in $makefiles; do
    sed -i 's/-Werror-/-W/g' "$i"
    sed -i 's/-Werror//g' "$i"
done

Error: selected processor does not support ARM mode `smc #0'

Try this patch: https://github.com/imoseyon/leanKernel-galaxy-nexus/pull/6

Downstream kernel issues by manufacturer

Mediatek

../tools/dct/DrvGen: No such file or directory

This error is specific to Mediatek kernels and it occures when DrvGen tries to load libc6.so library it has been linked against but Alpine chroot doesn't support libc. One of the solutions is to copy python3dct.patch to your linux-... directory and activate it in the APKBUILD. This patch replaces precompiled DrvGen with a python3 version.

Qualcomm

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.

X11 does not work on Qualcomm devices

Try apply this patch.

MSM framebuffer doesn't work

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

CONFIG_MSM_KGSL=n

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:

  • ~/android/lineage/out/target/product/titan/boot.img (boot image ready to be flashed: kernel + initramfs)
  • ~/android/lineage/out/target/product/titan/dt.img (device trees)
  • ~/android/lineage/out/target/product/titan/kernel (linux image)
  • ~/android/lineage/out/target/product/titan/ramdisk.img (compressed initramfs)

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

External resources