Ubuntu20编译Aosp内核
前言
目标机型:Pixel3 XL
AOSP版本:android-10.0.0_r2
内核版本:android-msm-crosshatch-4.9-android10
编译环境:Ubuntu20.04.5,CPU:8C,内存:8G,交换区:8G
问题记录:
官方在
android-msm-crosshatch-4.9-android10
内核代码中彻底删除了build/build.sh
编译,为给Pixel3 XL
编译Aosp10
的内核源码,本博客拷贝android-msm-crosshatch-4.9-android12
内核源码的build/build.sh
文件使用,能编译成功。
一、下载内核
-
根据官网链接 :https://source.android.google.cn/docs/setup/build/building-kernels?hl=zh-cn,目前
Pixel3 XL
支持推荐的内核版本是android-msm-crosshatch-4.9-android12
,低于该版本的内核,彻底删除了build/build.sh
编译。
-
按如下步骤下载
Aosp10
的内核源码:mkdir asop10-kernel & cd asop10-kernel curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > /usr/bin/repo chmod a+x /usr/bin/repo export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/' git config --global user.email "test@example.com" git config --global user.name "test" repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/kernel/manifest -b android-msm-crosshatch-4.9-android10-qpr1 repo sync
-
按上述步骤下载的
Aosp10
内核源码没有build/build.sh
编译文件,解决方法:先同步一份Aosp12
的内核源码,拷贝build/build.sh
文件到Aosp10
内核源码build
路径。# repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/kernel/manifest -b android-msm-crosshatch-4.9-android12 # repo sync # 拷贝一份 build/build.sh 文件到asop10-kernel/build
二、编译目标机型内核
-
查看目标机型内核版本,取g后的数字,版本号为:
fff483291c07
adb shell cat /proc/version
-
编译目标机型的
Aosp10
内核cd asop10-kernel/private/msm-google git checkout fff483291c07 # 修改内核为目标机型对应的版本 cd asop10-kernel build/build.sh # 开始编译
-
编译完成,编译结果在
out/android-msm-pixel-4.9/dist/
和out/android-msm-pixel-4.9/private/msm-google/arch/arm64/boot/
路径。
三、打包boot.img并刷入目标机型
-
感觉改内核代码太麻烦,此处采用源码编译的方式,参考博文:Ubuntu20编译Aosp10源码
-
设置临时环境变量,编译boot.img,编译结果在
/home/steptp/aosp1000r2/out/target/product/crosshatch/
下。cd /home/steptp/aosp1000r2 export TARGET_PREBUILT_KERNEL=/home/steptp/aosp10-kernel/out/android-msm-pixel-4.9/private/msm-google/arch/arm64/boot/Image.lz4-dtb source build/envsetup.sh lunch 14 # aosp_crosshatch-userdebug,目标机型是pixel3 xl make bootimage # 编译内核 cd out/target/product/crosshatch/ # 编译成功后,boot.img文件路径
-
刷入内核
adb reboot bootloader fastboot flash boot boot.img
四、解决触摸屏失灵问题
-
方法:将内核编译生成的所有
ko
文件拷贝到目标机型/vendor/lib/modules
下。# 解决触摸屏问题 adb root adb disable-verity # 解锁DM-verity adb reboot #手机会重启,不用关闭cmd窗口,手机可能需要拔掉数据写重新连接 adb root adb shell mount -o rw,remount /system # 部分机型需要使用:adb shell mount -o rw,remount / adb shell remount # 重新加载文件系统 adb push /home/steptp/aosp10-kernel/out/android-msm-pixel-4.9/dist/*.ko /vendor/lib/modules adb shell mount -o remount,ro /system #移动完之后记得把权限改回只读 # 同上,部分机型需要使用:adb shell mount -o remount,ro / adb reboot