1 en Compiling the Kernel
JackA1ltman edited this page 2026-04-04 23:24:57 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Compiling the Kernel

Local Build · Step 3

This example uses the Xiaomi Mix2s kernel for the custom ROM Evolution X 10:

  • Source: https://github.com/Evolution-X-Devices/kernel_xiaomi_sdm845
  • Branch: vic

Toolchain: AOSP Clang 12 + Google GCC 4.9. Assumed directory layout:

/home/username/
├── Clang/clang_aosp_12/bin/
├── Gcc/
│   ├── google_gcc_arm/bin/
│   └── google_gcc_arm64/bin/
└── Kernel/evox_mix2s_a15/

Step 1: Find the defconfig File

The defconfig file lives under arch/arm64/configs/ in the kernel source. Common naming patterns:

  • <device_codename>_defconfig
  • <kernel_name>_defconfig
  • The most recently modified defconfig file in that directory

This example: two config files need to be merged:

  • vendor/mi845_defconfig — base Xiaomi config
  • vendor/polaris.config — Mix2s-specific driver config

Step 2: Generate the .config File

export PATH=/home/username/Clang/clang_aosp_12/bin:$PATH

make ARCH=arm64 O=out CC="clang" \
  CROSS_COMPILE="/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android-" \
  CROSS_COMPILE_ARM32="/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi-" \
  CLANG_TRIPLE=aarch64-linux-gnu- LD=ld.lld \
  vendor/mi845_defconfig vendor/polaris.config
Flag Description
ARCH=arm64 Target architecture
O=out Output directory, keeps build artifacts separate from source
CROSS_COMPILE Cross-compiler path (GCC ARM64)
CROSS_COMPILE_ARM32 Cross-compiler path (GCC ARM)
CLANG_TRIPLE Fallback Clang target triple, used if the primary Clang fails
LD=ld.lld Use Clang's built-in linker instead of the system default

On success, out/.config will be generated.

Step 3: Start the Build

make -j$(nproc --all) ARCH=arm64 O=out CC="clang" \
  CROSS_COMPILE="/home/username/Gcc/google_gcc_arm64/bin/aarch64-linux-android-" \
  CROSS_COMPILE_ARM32="/home/username/Gcc/google_gcc_arm/bin/arm-linux-androideabi-" \
  CLANG_TRIPLE=aarch64-linux-gnu- LD=ld.lld \
  vendor/mi845_defconfig vendor/polaris.config 2>&1 | tee error.log
Flag Description
-j$(nproc --all) Use all available CPU cores; or specify e.g. -j4
2>&1 | tee error.log Save build output to error.log for debugging

Build time is roughly 530 minutes (1+ hour on a 2-core machine). A successful build ends with a line like:

OBJCOPY arch/arm64/boot/Image.gz

If there is no Error 2 in the output and the OBJCOPY line is present, the build succeeded. The kernel image is at out/arch/arm64/boot/.