Android通用内核编译
https://source.android.google.cn/docs/setup/build/building-kernels
AOSP源码
查找对应版本:
https://android.googlesource.com/kernel/common/+refs
下载源码:
mkdir android-kernel && cd android-kernel
repo init -u https://android.googlesource.com/kernel/manifest -b common-android13-5.10
repo sync
坑:ubuntu 20.04 官方源里没有repo
mkdir -p ~/.bin
PATH="${HOME}/.bin:${PATH}"
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+rx ~/.bin/repo
或者直接用git
git clone https://android.googlesource.com/kernel/common -b android13-5.10-2023-02
交叉编译工具
#内核版本查看
https://android.googlesource.com/kernel/common/+/refs/heads/android13-5.10/build.config.common
或者去源代码Makefile头部查看
#clang
https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/master-kernel-build-2022/clang-r416183b.tar.gz
#gcc
https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/refs/tags/android-12.1.0_r27.tar.gz
build脚本
export PATH=/root/project/android_kernel/xaga-s/toolchain/clang-r416183b/bin:$PATH
#make clean
#make -j$(nproc --all) O=out ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=/root/project/android_kernel/xaga-s/toolchain/android-12.1.0_r27/bin/aarch64-linux-android- CC=clang LD=ld.lld gki_defconfig
#make -j$(nproc --all) O=out ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=/root/project/android_kernel/xaga-s/toolchain/android-12.1.0_r27/bin/aarch64-linux-android- CC=clang LD=ld.lld
make -j$(nproc --all) CC=clang ARCH=arm64 LLVM=1 LLVM_IAS=1 O=out gki_defconfig
make -j$(nproc --all) CC=clang ARCH=arm64 LLVM=1 LLVM_IAS=1 O=out CONFIG_LTO_CLANG=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y CONFIG_LTO_CLANG_FULL=n prepare
make -j$(nproc --all) CC=clang ARCH=arm64 LLVM=1 LLVM_IAS=1 O=out CONFIG_LTO_CLANG=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y CONFIG_LTO_CLANG_FULL=n scripts
make -j$(nproc --all) CC=clang ARCH=arm64 LLVM=1 LLVM_IAS=1 O=out CONFIG_LTO_CLANG=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y CONFIG_LTO_CLANG_FULL=n modules_prepare
make -j$(nproc --all) CC=clang ARCH=arm64 LLVM=1 LLVM_IAS=1 O=out CONFIG_LTO_CLANG=y CONFIG_LTO_NONE=n CONFIG_LTO_CLANG_THIN=y CONFIG_LTO_CLANG_FULL=n modules