en Compiling the Kernel - JackA1ltman/NonGKI_Kernel_Build_2nd GitHub Wiki
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 configvendor/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 5โ30 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 2in the output and theOBJCOPYline is present, the build succeeded. The kernel image is atout/arch/arm64/boot/.