自 Android 10 起,用于运行CTS-on-GSI/VTS合规性测试的通用系统映像(GSI) 从 userdebug 更改为用户构建类型,以便进行发布签名。这对于 VTS 测试来说是一个问题,因为 VTS 需要adb root
才能运行,但adb root
在用户构建设备上不可用。
引入调试 ramdisk(或调试启动映像)以在引导加载程序未锁定的用户构建设备上启用adb root
。通过对 CTS-on-GSI 和 VTS-on-GSI 使用相同的用户构建 GSI system.img
,这简化了测试流程。对于STS设置,仍然需要使用另一个userdebug OEM system.img
。
下表显示了 Android 10 中合规性测试的映像和构建类型更改。
测试套件 | 测试用 | 建造 | 调试虚拟磁盘 | 亚行根? | Android 9 -> 10 构建变体更改 |
---|---|---|---|---|---|
CTS | OEM系统 | 用户 | 氮 | 氮 | 不用找了 |
GSI上的CTS | GSI | 用户 | 氮 | 氮 | userdebug -> 用户 GSI 发布签名 |
超导系统 | OEM系统 | 用户调试 | 氮 | 是 | Q 中的新功能 |
虚拟交通系统 | GSI | 用户 | 是 | 是 | userdebug -> 用户 GSI 发布签名 |
概述
这些附加图像文件在构建文件夹 ( ${ANDROID_PRODUCT_OUT}
) 下生成:
-
boot-debug.img
-
vendor_boot-debug.img
当boot-debug.img
刷新到设备的boot
分区时,系统 sepolicy 文件的 userdebug 版本和附加属性文件adb_debug.prop
会被加载。这允许adb root
使用用户构建system.img
(GSI 或 OEM)。
对于使用具有供应vendor_boot
分区的设备的通用内核映像 (GKI) ,不得刷新boot-debug.img
,因为必须使用经过认证的 GKI 映像boot
启动分区。相反, vendor_boot-debug.img
应该闪存到vendor_boot
分区上,以便于调试ramdisk。
使用调试 ramdisk 的先决条件
调试 ramdisk 由运行合规性测试的 OEM 提供。它不得经过发布签名,并且只有在设备解锁时才能使用。
不会生成或使用调试 ramdisk 来升级具有以下功能的设备:
-
BOARD_BUILD_SYSTEM_ROOT_IMAGE
true - 内核命令行中的
skip_initramfs
安卓 12 GSI
无需额外说明即可将调试 ramdisk 与 Android 12 GSI 结合使用。
从 2021 年 9 月 29 日开始,调试 ramdis 不再需要使用repack_bootimg
工具进行更新。 SGR1.210929.001 (7777720)
之后的 Android 12 GSI 版本将最新的userdebug_plat_sepolicy.cil
文件合并到其system.img
中,并忽略调试 ramdisk 中的userdebug_plat_sepolicy.cil
。有关详细信息,请参阅CL 。
安卓 11 GSI
使用boot-debug.img
或vendor_boot-debug.img
时,系统sepolicy 将从boot-debug.img
或vendor_boot-debug.img
的调试ramdisk 中的userdebug_plat_sepolicy.cil
文件加载。为了启动 GSI 映像,请始终合并android11-gsi
分支中的最新 sepolicy 更改来重建boot-debug.img
或vendor_boot-debug.img
。
或者,可以使用repack_bootimg
工具通过更新的 GSI sepolicy 重建boot-debug.img
或vendor_boot-debug.img
。
重新打包调试 ramdisk
合作伙伴可以使用repack_bootimg
将 GSI sepolicy 文件更新到boot-debug.img
boot-debug.img
如果设备使用 GKI,则为vendor_boot-debug.img
),而不是合并 sepolicy 更改来重建 boot-debug.img 。
步骤如下:
从https://ci.android.com下载
otatools.zip
。我们建议从aosp-master
上的aosp_arm64-userdebug
的构建工件下载。设置
repack_bootimg
的执行环境:unzip otatools.zip -d otatools
export PATH="${PWD}/otatools/bin:${PATH}"
repack_bootimg --help
从您正在使用的 GSI 版本下载
userdebug_plat_sepolicy.cil
或boot-with-debug-ramdisk-${KERNEL_VERSION}.img
。例如,如果您使用RJR1.211020.001 (7840830)
中的arm64 GSI,则从https://ci.android.com/builds/subscribed/7840830/aosp_arm64-user/latest下载。使用
userdebug_plat_sepolicy.cil
更新设备boot-debug.img
或vendor_boot-debug.img
:repack_bootimg --local --dst_bootimg boot-debug.img \ --ramdisk_add userdebug_plat_sepolicy.cil:userdebug_plat_sepolicy.cil \ --ramdisk_add userdebug_plat_sepolicy.cil:first_stage_ramdisk/userdebug_plat_sepolicy.cil
# If using GKI
repack_bootimg --local --dst_bootimg vendor_boot-debug.img \ --ramdisk_add userdebug_plat_sepolicy.cil:userdebug_plat_sepolicy.cil \ --ramdisk_add userdebug_plat_sepolicy.cil:first_stage_ramdisk/userdebug_plat_sepolicy.cil
使用
boot-with-debug-ramdisk-${KERNEL_VERSION}.img
:repack_bootimg --src_bootimg boot-with-debug-ramdisk-5.4.img \ --dst_bootimg boot-debug.img \ --ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:userdebug_plat_sepolicy.cil \ --ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:first_stage_ramdisk/userdebug_plat_sepolicy.cil
# If using GKI
repack_bootimg --src_bootimg boot-with-debug-ramdisk-5.4.img \ --dst_bootimg vendor_boot-debug.img \ --ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:userdebug_plat_sepolicy.cil \ --ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:first_stage_ramdisk/userdebug_plat_sepolicy.cil
--ramdisk_add
的参数可以根据设备配置进行调整。请参阅下一节以获取详细说明。
userdebug sepolicy 的路径
上面的repack_bootimg
将文件userdebug_plat_sepolicy.cil
从--src_bootimg
的 ramdisk 复制到--dst_bootimg
的 ramdisk 。但是,调试 ramdisk 中的路径在不同的 Android 版本中可能会有所不同。在 Android 10 和 11 中,对于内核命令行中具有androidboot.force_normal_boot=1
的设备,路径为first_stage_ramdisk/userdebug_plat_sepolicy.cil
。否则,路径为userdebug_plat_sepolicy.cil
。
执行以下命令查看内核命令行中是否有androidboot.force_normal_boot
:
adb root
adb shell cat /proc/cmdline | grep force_normal_boot
从 Android 12 开始,调试 ramdisk 内的路径始终为userdebug_plat_sepolicy.cil
,无论内核命令行中是否存在androidboot.force_normal_boot=1
。下表显示了不同 Android 版本中调试 ramdisk 内的路径。
调试图像 | 安卓10 | 安卓11 | 安卓12 |
---|---|---|---|
GKI boot-with-debug-ramdisk-${KERNEL_VERSION}.img | 不适用 | first_stage_ramdisk/userdebug_plat_sepolicy.cil | userdebug_plat_sepolicy.cil |
设备特定的 boot-debug.img | 取决于force_normal_boot | 取决于force_normal_boot | userdebug_plat_sepolicy.cil |
设备特定的vendor_boot-debug.img | 不适用 | 取决于force_normal_boot | userdebug_plat_sepolicy.cil |
您可以指定--ramdisk_add
使用src_path:dst_path
对列表将文件从不同路径复制到不同路径。例如,以下命令将文件first_stage_ramdisk/userdebug_plat_sepolicy.cil
从Android 11 boot-with-debug-ramdisk-5.4.img
到Android 11vendor_boot vendor_boot-debug.img
内的first_stage_ramdisk/userdebug_plat_sepolicy.cil
。
repack_bootimg \
--src_bootimg boot-with-debug-ramdisk-5.4.img \
--dst_bootimg vendor_boot-debug.img \
--ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:first_stage_ramdisk/userdebug_plat_sepolicy.cil
如果内核命令行中没有androidboot.force_normal_boot=1
,则应如下调整命令,将目标路径更改为userdebug_plat_sepolicy.cil
。
repack_bootimg \
--src_bootimg boot-with-debug-ramdisk-5.4.img \
--dst_bootimg vendor_boot-debug.img \
--ramdisk_add first_stage_ramdisk/userdebug_plat_sepolicy.cil:userdebug_plat_sepolicy.cil
添加 AVB 页脚
如果传递给--dst_bootimg
映像配置为AVB 链接分区,则需要在运行repack_bootimg
命令后添加 AVB 页脚。
例如,在运行repack_bootimg
之前,运行以下命令来检查vendor_boot-debug.img
是否具有链接的 AVB 页脚。
avbtool info_image --image vendor_boot-debug.img
如果原来有链式 AVB 页脚,则需要在运行repack_bootimg
命令后添加 AVB 页脚。使用任何测试密钥对vendor_boot-debug.img
进行签名都可以,因为调试ramdisk只能在设备解锁时使用,这允许在boot
或vendor_boot
分区上使用非发布密钥签名的映像。
avbtool add_hash_footer --partition_name vendor_boot \
--partition_size 100663296 \
--algorithm SHA256_RSA4096 \
--key otatools/external/avb/test/data/testkey_rsa4096.pem \
--image vendor_boot-debug.img