虚拟机中通过模拟器调试android kernel

  1. 配置虚拟机环境

虚拟机安装ubuntu(此处略),需要注意的是虚拟机要开启嵌套虚拟化(即在虚拟机中再次使能虚拟化功能)

  • Hyper-v

停止虚拟机后使用get-vm 获取虚拟机名字,然后通过

Set-VMProcessor -ExposeVirtualizationExtensions $true -VMName ubuntu20.04命令即可(ubuntu20.04是我们的虚拟机名字)
Set-VMProcessor -ExposeVirtualizationExtensions $true -VMName ubuntu20.04可以获取虚拟功能是否开启
  • VMware虚拟机在虚拟机设置界面就有配置(略)

  1. 配置并下载android代码

  1. 代码下载参考

https://blog.csdn.net/qq_26216519/article/details/128695630

https://blog.csdn.net/code_lyb/article/details/128285357?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-128285357-blog-128695630.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-128285357-blog-128695630.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=2

可使用国内镜像源替换android源(git config --global url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof https://android.googlesource.com)

  1. 切换分支

查看可切换的分支

cd .repo/manifests
git branch -a | cut -d / -f 3

以 android-12.1.0_r8 分支为例

repo init -b android-12.1.0_r8
repo sync -c --no-tags -j6   # 如果不需要与服务器数据一致,可以不运行该步
repo start android-12.1.0_r8 --all

查看切换结果

repo branches
  1. 编译

source ./build/envsetup.sh
lunch sdk_car_x86_64-eng   	
m all -j$(nproc)
emulator -verbose -show-kernel -selinux permissive -writable-system
  1. 内核下载和替换

https://source.android.google.cn/docs/setup/build/building-kernels?hl=zh-cn

https://www.codeinsideout.com/blog/android/build-aosp/

下载:

repo init -u https://android.googlesource.com/kernel/manifest -b BRANCH

【实际上用tsinghua AOSP源代替】:

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/kernel/manifest -b x
repo sync

修改内核配置:

当我们需要修改内核config的时候,在gki下使用以下步骤进行修改:

~/android_kernel/common$ make ARCH=x86 gki_defconfig
~/android_kernel/common$ make ARCH=x86 menuconfig
~/android_kernel/common$ make ARCH=x86 savedefconfig
~/android_kernel/common$ cp defconfig arch/x86/config/gki_defconfig

编译

https://source.android.google.cn/docs/setup/build/building-kernels?hl=zh-cn#customize-build

BUILD_CONFIG=common/build.config.gki.x86_64 LTO=none build/build.sh 
BUILD_CONFIG=common-modules/virtual-device/build.config.virtual_device.x86_64 build/build.sh  (android12构建virtual_device内核)
tools/bazel build //common-modules/virtual-device:virtual_device_x86_64_dist(android13构建virtual_device内核)
  1. 替换自己编译的kernel启动emulator

emulator -verbose -show-kernel -selinux permissive -writable-system -nocache -kernel out/android12-5.10/dist/bzImage  (不关闭cache则不会从kernel启动)
  • 也可以通过修改device\generic\goldfish\x86_64-kernel.mk文件中KERNEL_MODULES_PATH和 EMULATOR_KERNEL_FILE将kernel和kernel ko加入到emulator镜像中重新编译aosp系统,而无需定制emulator的启动命令。

3.调试代码

调试android kernel见:

https://blog.csdn.net/fightingup/article/details/128906416?spm=1001.2014.3001.5501

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值