自 Android 10 起,用于运行 CTS-on-GSI/VTS 一致性测试的 通用系统映像 (GSI) 从 userdebug 版本更改为 user 版本类型,以便进行发布签名。这对 VTS 测试来说是个问题,因为 VTS 需要 adb root 才能运行,但 adb root 在 user 版本设备上不可用。
引入了调试 ramdisk(或调试启动映像),以在启动加载程序已解锁的 user 版本设备上启用 adb root。这通过对 CTS-on-GSI 和 VTS-on-GSI 使用相同的 user 版本 GSI system.img 简化了测试流程。对于 STS 设置,仍然需要使用另一个 userdebug OEM system.img。
下表显示了 Android 10 中一致性测试的映像和版本类型更改。
| 测试套件 | 测试所用映像 | 构建 | 调试 ramdisk | adb root? | Android 9 -> 10 版本变体更改 |
|---|---|---|---|---|---|
| CTS | OEM 的系统 | user | 否 | 否 | 无更改 |
| CTS-on-GSI | GSI | user | 否 | 否 | userdebug -> user GSI 发布签名 |
| STS | OEM 的系统 | userdebug | 否 | 是 | Q 版本新增功能 |
| VTS | GSI | user | 是 | 是 | userdebug -> user GSI 发布签名 |
概览
这些额外的映像文件在构建文件夹 (${ANDROID_PRODUCT_OUT}) 下生成
boot-debug.imgvendor_boot-debug.img
当 boot-debug.img 刷写到设备的 boot 分区时,将加载 userdebug 版本的系统 sepolicy 文件和一个额外的属性文件 adb_debug.prop。这允许使用 user 版本 system.img(GSI 或 OEM 的)执行 adb root。
对于使用具有 vendor_boot 分区的设备的 通用内核映像 (GKI),不得刷写 boot-debug.img,因为 boot 分区必须刷写经过认证的 GKI 映像。相反,应将 vendor_boot-debug.img 刷写到 vendor_boot 分区,以便于调试 ramdisk。
使用调试 ramdisk 的先决条件
调试 ramdisk 由运行一致性测试的 OEM 提供。它不得进行发布签名,并且只能在设备解锁的情况下使用。
调试 ramdisk 不会为具有以下配置的升级设备生成或使用:
BOARD_BUILD_SYSTEM_ROOT_IMAGE为 true- 内核命令行中包含
skip_initramfs
Android 12 GSI
使用 Android 12 GSI 时,无需额外的指令即可使用调试 ramdisk。
从 2021 年 9 月 29 日开始,调试 ramdisk 不再需要使用 repack_bootimg 工具进行更新。在 SGR1.210929.001 (7777720) 之后的 Android 12 GSI 构建版本在其 system.img 中合并了最新的 userdebug_plat_sepolicy.cil 文件,并忽略来自调试 ramdisk 的 userdebug_plat_sepolicy.cil。有关详细信息,请参阅 CL。
Android 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(或设备使用 GKI 时更新到 vendor_boot-debug.img),而不是合并 sepolicy 更改来重建 boot-debug.img。
步骤如下:
从 https://ci.android.com 下载
otatools.zip。我们建议从aosp-main上的aosp_arm64-userdebug的构建工件下载。设置
repack_bootimg的执行环境unzip otatools.zip -d otatoolsexport 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.imgrepack_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 GKIrepack_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}.imgrepack_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 GKIrepack_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 rootadb shell cat /proc/cmdline | grep force_normal_boot
从 Android 12 开始,调试 ramdisk 中的路径始终为 userdebug_plat_sepolicy.cil,无论内核命令行中是否存在 androidboot.force_normal_boot=1。下表显示了不同 Android 版本中调试 ramdisk 中的路径。
| 调试映像 | Android 10 | Android 11 | Android 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。
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