android-kernel-compile

1.设置环境变量

设置这个环境变量是因为Repo在使用过程中会访问Google更新自己,容易被墙

1
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

2.初始化仓库

(1)manifest.git

image2 原版链接

1
2
3
4
repo init -u https://android.googlesource.com/kernel/manifest
mv <kernel_manifest.xml> .repo/manifests
repo init -m manifest.xml
repo sync

使用清华源,不指定分支会报错,我也不知道为什么,不过没什么影响

1
repo init -u https://mirrors.ustc.edu.cn/aosp/kernel/manifest.git -b android-gs-pantah-5.10-android13-qpr2

(2)下载manifest.xml

然后找到对应的manifest.xml,放在.repo/manifests目录下 https://source.android.com/docs/core/architecture/kernel/gki-android13-5_10-release-builds?hl=zh-cn image1 如果找不到对应版本的话,可以在https://ci.android.com/builds/submitted/9750494/kernel_aarch64/latest?hl=zh-cn(9750494换成和你手机一样的编号,如下我的设备是9598324)

1
2
3
4
adb shell
panther:/ $ uname -a
Linux localhost 5.10.149-android13-4-00002-gca169caca7bb-ab9598324 #1 SMP PREEMPT Mon Feb 13 12:48:28 UTC 2023 aarch64 Toybox
panther:/ $

(3)更改fetch链接和分支

找到manifest_10208116.xml 后,拷贝到.repo/manifests目录下,需要修改两处 1.fetch="https://android.googlesource.com/"改为fetch="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP" 2.project path="common"中的upstream="android13-5.10-2023-02"改为upstream="deprecated/android13-5.10-2023-02"(分支被遗弃,较新的分支不需要这一步) 具体有没有废弃可以在https://android.googlesource.com/kernel/common/+refs上查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<manifest>
<remote name="aosp" fetch="https://android.googlesource.com/" review="https://android.googlesource.com/"/>
<default upstream="master-kernel-build-2022" dest-branch="master-kernel-build-2022" remote="aosp" sync-j="4"/>
<superproject name="kernel/superproject" remote="aosp" revision="common-android13-5.10-2023-02"/>
<project path="build/kernel" name="kernel/build" revision="92e8d0541d372646caca7d26fc4a1d7804db7420">
<linkfile dest="tools/bazel" src="kleaf/bazel.sh"/>
<linkfile dest="WORKSPACE" src="kleaf/bazel.WORKSPACE"/>
<linkfile dest="build/build.sh" src="build.sh"/>
<linkfile dest="build/build_abi.sh" src="build_abi.sh"/>
<linkfile dest="build/build_test.sh" src="build_test.sh"/>
<linkfile dest="build/build_utils.sh" src="build_utils.sh"/>
<linkfile dest="build/config.sh" src="config.sh"/>
<linkfile dest="build/envsetup.sh" src="envsetup.sh"/>
<linkfile dest="build/_setup_env.sh" src="_setup_env.sh"/>
<linkfile dest="build/multi-switcher.sh" src="multi-switcher.sh"/>
<linkfile dest="build/abi" src="abi"/>
<linkfile dest="build/static_analysis" src="static_analysis"/>
</project>
<project path="hikey-modules" name="kernel/hikey-modules" revision="a068c3379fab21a8719c03e661c7d9de97583244" upstream="android13-5.10" dest-branch="android13-5.10"/>
<project path="common" name="kernel/common" revision="776d0a76f6aa7c5a92c60afbe886a8e786953199" upstream="android13-5.10-2023-02" dest-branch="android13-5.10-2023-02">
<linkfile dest=".source_date_epoch_dir" src="."/>
</project>
<project path="kernel/tests" name="kernel/tests" revision="42a77670ce44d6e19a6fbb8b93fa0b06f009a3a4"/>
<project path="kernel/configs" name="kernel/configs" revision="b3cc2bc03dab303c54a9ce1f709f8ee315eb311d"/>
<project path="common-modules/virtual-device" name="kernel/common-modules/virtual-device" revision="d8e1867f2148aff332ebeeea93946277f3ebf83d" upstream="android13-5.10" dest-branch="android13-5.10"/>
<project path="prebuilts/clang/host/linux-x86" name="platform/prebuilts/clang/host/linux-x86" clone-depth="1" revision="4bb6424cb1615af408ae80871131f4da8c4ddadf"/>
<project path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8" clone-depth="1" revision="007101a451907c5369db5002ddf7b14dcefb7864"/>
<project path="prebuilts/build-tools" name="platform/prebuilts/build-tools" clone-depth="1" revision="f6813860e16b2fa1461a15e7b8a3127dfdee021a"/>
<project path="prebuilts/kernel-build-tools" name="kernel/prebuilts/build-tools" clone-depth="1" revision="0fb21fa343b2157c91e21b7ead1e99c1ea82125b"/>
<project path="tools/mkbootimg" name="platform/system/tools/mkbootimg" revision="2208a03d874255af1e4eaf6cf7c156fe1dc98943"/>
<project path="prebuilts/bazel/linux-x86_64" name="platform/prebuilts/bazel/linux-x86_64" clone-depth="1" revision="6162318e6458db65f94eed6671e302c3e894b1ac"/>
<project path="prebuilts/jdk/jdk11" name="platform/prebuilts/jdk/jdk11" clone-depth="1" revision="aee26c8cd89b9abb428f676caba168699cd8662f"/>
<project path="prebuilts/ndk-r23" name="toolchain/prebuilts/ndk/r23" clone-depth="1" revision="93532f3052c14fbb337ff57d5732128dc7481ee6"/>
<project path="external/bazel-skylib" name="platform/external/bazel-skylib" revision="f1fb8167b4ed64feb494fd1ea6a8a619bbb549de"/>
<project path="build/bazel_common_rules" name="platform/build/bazel_common_rules" revision="ddd2d82d10e21fb4137d2db3c1b848d6f1832acc"/>
<project path="external/stardoc" name="platform/external/stardoc" revision="b6ef2c6b6e39087f7396aaeb13c83464dfce4a19"/>
<project path="external/python/absl-py" name="platform/external/python/absl-py" revision="63f98de5b158481877489ca39158ed691f7551e1"/>
</manifest>

3.同步代码

1
repo sync -j12

4.编译

1
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh

编译结果存放在/home/showfaker/kernel/out/android13-5.10/dist下,pixel7使用的是boot-lz4.img

5.编译kernelSU

1
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -

然后再次在根目录下运行编译命令

1
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh

6.刷机

1
2
adb reboot bootloader
fastboot flash boot .\boot-lz4.img

然后开机启动,打开kernelSU的管理APP,可以看到已经可以正常工作 image3 tips:如果遇到循环启动那就是刷机失败了,建议刷回原版镜像重试


android-kernel-compile
http://showfaker.top/2024/02/24/android-kernel-compile/
作者
ShowFaker
发布于
2024年2月24日
许可协议