mirror of
https://github.com/JackA1ltman/NonGKI_Kernel_Build_2nd.git
synced 2026-08-19 15:03:40 +08:00
Page:
编译内核
Pages
Fork 项目
Home
en Automated Release
en Choosing a Toolchain
en Compiling on a Mobile Device
en Compiling the Kernel
en Compiling the Stock Vendor Kernel
en Configuring the YML File
en Embedding KernelSU and Patching SuSFS
en Fork the Repository
en Hiding Root Common Methods
en Introduction
en Kernel Build FAQ
en Packaging and Flashing
en Requirements
en Running and Downloading Artifacts
en Setting Up the Environment
en Variable Reference
内核编译答疑
利用移动设备编译内核
变量参考
基础需求
嵌入KernelSU和SuSFS修补
序章
打包与刷入
搭建基础环境
编译内核
编译器选择
编译设备厂商原始内核
自动发布
运行与产物
配置 YML 文件
隐藏Root常规方式
No results
Table of contents
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.
编译内核
基础编译 · 第三步
以 小米 Mix2s 设备的第三方系统 Evolution X 10 内核为例:
- 源码地址:
https://github.com/Evolution-X-Devices/kernel_xiaomi_sdm845 - 分支:
vic
选用 AOSP Clang 12 与 Google GCC 4.9,假设目录结构如下:
/home/username/
├── Clang/clang_aosp_12/bin/
├── Gcc/
│ ├── google_gcc_arm/bin/
│ └── google_gcc_arm64/bin/
└── Kernel/evox_mix2s_a15/
第一步:确定 defconfig 文件
defconfig 文件位于内核源码的 arch/arm64/configs/ 目录下,通常命名规则为:
设备代号_defconfig内核命名_defconfig- 被修改时间最晚的 defconfig 文件
本例说明:需合并两个 config 文件:
vendor/mi845_defconfig:负责基础小米 config 项vendor/polaris.config:负责 Mix2s 专属驱动 config 项
第二步:生成 .config 文件
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
| 参数 | 说明 |
|---|---|
ARCH=arm64 |
编译目标架构 |
O=out |
编译输出目录,避免与源码混淆 |
CROSS_COMPILE |
交叉编译器(GCC ARM64)路径 |
CROSS_COMPILE_ARM32 |
交叉编译器(GCC ARM)路径 |
CLANG_TRIPLE |
备用 Clang,主 Clang 失败时回退 |
LD=ld.lld |
替换链接器为 Clang 自带链接器 |
执行成功后将在 out/ 目录下生成 .config 文件。
第三步:正式编译
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
| 参数 | 说明 |
|---|---|
-j$(nproc --all) |
调用全部核心,也可指定如 -j4 |
2>&1 | tee error.log |
将错误输出同步写入 error.log |
编译时间约 5–30 分钟(2 核心机器可能需要 1 小时以上)。出现以下输出则代表编译成功:
OBJCOPY arch/arm64/boot/Image.gz
若无
Error 2出现,并存在上述OBJCOPY行,则编译成功,内核文件位于out/arch/arm64/boot/。
🌐 Language / 语言
📖 English
Local Build
- Setting Up the Environment
- Choosing a Toolchain
- Compiling the Kernel
- Compiling on a Mobile Device
- Compiling the Stock Vendor Kernel
- Embedding KernelSU & Patching SuSFS
- Packaging and Flashing
- Kernel Build FAQ
Build with Actions
- Fork the Repository
- Configuring the YML File
- Variable Reference
- Running and Downloading Artifacts
- Automated Release
Hide Root Trace
📖 中文
基础编译
利用 Action 构建内核
隐藏Root痕迹