从 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 构建变体更改 |
---|---|---|---|---|---|
中旅 | OEM系统 | 用户 | ñ | ñ | 没变 |
CTS-on-GSI | GSI | 用户 | ñ | ñ | 用户调试 -> 用户 GSI 发布签名 |
STS | OEM系统 | 用户调试 | ñ | 是 | Q中的新功能 |
VTS | GSI | 用户 | 是 | 是 | 用户调试 -> 用户 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
真 - 内核命令行中的
skip_initramfs
安卓 12 GSI
使用带有 Android 12 GSI 的调试 ramdisk 不需要额外的说明。
从 09/29/2021 开始,调试 ramdisk 不再需要使用repack_bootimg
工具进行更新。在SGR1.210929.001 (7777720)
之后构建的 Android 12 GSI 在其system.img
中合并了最新的userdebug_plat_sepolicy.cil
文件,并忽略了调试 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
debug.img。
重新打包调试 ramdisk
合作伙伴可以使用repack_bootimg
将 GSI sepolicy 文件更新为boot-debug.img
(或vendor_boot-debug.img
,如果设备使用 GKI),而不是合并 sepolicy 更改来重建boot-debug.img
。
步骤如下:
从https://ci.android.com下载
otatools.zip
。我们建议从 aosp-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/submitted/ 7840830 /aosp_arm64-user/latest下载。使用 userdebug_plat_sepolicy.cil 更新设备
boot-debug.img
或vendor_boot-debug.img
userdebug_plat_sepolicy.cil
: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
从--dst_bootimg
的 ramdisk 复制到--src_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 开始,无论内核命令行中是否存在androidboot.force_normal_boot=1
,调试 ramdisk 中的路径始终为userdebug_plat_sepolicy.cil
。下表显示了不同 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 11 vendor_boot-debug.img
中的first_stage_ramdisk/userdebug_plat_sepolicy.cil
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