Skip to content

Building

simplehima edited this page Dec 5, 2026 · 1 revision

What you need

  • Linux x86_64, or WSL2 on Windows (Ubuntu 22.04 or newer). Put the source inside the Linux filesystem (for example ~/kernel), not on /mnt/c: building from a Windows drive is many times slower and breaks symlinks.
  • About 15 GB free disk space and 8 GB RAM or more. A full ThinLTO build takes about 10 minutes on 16 threads.
  • AOSP clang r547379 (clang 20). Other Android clang versions may build, but only r547379 is tested. Mixing compilers changes nothing in the module CRCs; it is about known-good code generation.

Packages (Ubuntu):

sudo apt update
sudo apt install -y git bc bison flex make libssl-dev libelf-dev cpio kmod zip unzip python3 \
  build-essential lz4 rsync curl

Toolchain:

mkdir -p ~/kernel/toolchain/clang-r547379 && cd ~/kernel/toolchain/clang-r547379
curl -L https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/main/clang-r547379.tar.gz | tar xz
./bin/clang --version      # clang version 20.0.0

If that branch no longer has r547379, take it from an older prebuilts/clang/host/linux-x86 tag that does.

Get the source

cd ~/kernel
git clone --recurse-submodules https://github.com/simplehima/thanatos-kernel.git
cd thanatos-kernel

KernelSU-Next is a git submodule pinned to the tested version. build_thanatos.sh initializes it if you forgot --recurse-submodules.

Build

CLANG_DIR=~/kernel/toolchain/clang-r547379 ./build_thanatos.sh ksun      # root
CLANG_DIR=~/kernel/toolchain/clang-r547379 ./build_thanatos.sh vanilla   # no root

The Image lands in out/<variant>/arch/arm64/boot/Image. Check the version string:

strings out/ksun/arch/arm64/boot/Image | grep -m1 "Linux version"
# Linux version 6.1.177-Thanatos (...)

What the script does:

Step Detail
Config a55x_defconfig plus fragments: ksu.config thanatos.config (ksun) or thanatos.config vanilla.config (vanilla)
Make flags ARCH=arm64 LLVM=1 LLVM_IAS=1, LOCALVERSION= so the version is exactly 6.1.x-Thanatos with no +
Build user KBUILD_BUILD_USER=Hima KBUILD_BUILD_HOST=Thanatos; override them in the environment for your own builds

The fragments live in arch/arm64/configs/. Put Thanatos options in thanatos.config, not in a55x_defconfig, so rebasing on a new base tree stays simple.

Check vendor module compatibility (required)

Pull the phone's modules once:

mkdir -p ~/kernel/vendor_mods/{vendor_boot,system_dlkm,vendor_dlkm}
adb shell su -c "cp /system_dlkm/lib/modules/*.ko /vendor_dlkm/lib/modules/*.ko /sdcard/ 2>/dev/null"

Get the vendor_boot ramdisk modules from your firmware's vendor_boot.img: unpack it with magiskboot unpack and extract the vendor_ramdisk*.cpio. Then run the check:

export PATH=~/kernel/toolchain/clang-r547379/bin:$PATH
thanatos/tools/crcgate.sh out/ksun ~/kernel/vendor_mods/vendor_boot ~/kernel/vendor_mods/system_dlkm ~/kernel/vendor_mods/vendor_dlkm
# checked=16618 ok=16617 crc_mismatch=0 missing=1

crc_mismatch must be 0. The one known missing symbol (find_in_flight_task_in_one_workqueue, in sec_debug_ssld_info.ko) is fine: that module doesn't load on stock either. See Vendor Module Compatibility.

Pack a flashable zip

thanatos/tools/pack_ak3.sh ksun v1.2
thanatos/tools/pack_ak3.sh vanilla v1.2

The zips land in out/. The packer clones AnyKernel3 the first time, or uses a checkout you pass as the third argument. The device checks and the boot handling come from thanatos/anykernel.sh.

Rebuilding after a change

make is incremental. Run ./build_thanatos.sh ksun again. Changing a config fragment reruns the defconfig step. Header changes can rebuild most of the tree.

Troubleshooting

Error Fix
clang not found: set CLANG_DIR Set CLANG_DIR to the folder that has bin/clang
KernelSU-Next/kernel/Kconfig: No such file git submodule update --init KernelSU-Next
Version shows 6.1.x-Thanatos+ Build through build_thanatos.sh; it passes LOCALVERSION=
Vendor modules fail on the phone with disagrees about version of symbol Your change altered the KMI. Run crcgate.sh and revert the change that moves a CRC
Scripts fail with $'\r': command not found The files got Windows line endings: git config core.autocrlf false, then check out again

Clone this wiki locally