使用调试 ramdisk 进行 VTS 测试

使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。

从 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.imgvendor_boot-debug.img时,系统 sepolicy 从boot-debug.imgvendor_boot-debug.img的调试 ramdisk 中的userdebug_plat_sepolicy.cil文件加载。为了启动 GSI 映像,请始终合并来自android11-gsi分支的最新 sepolicy 更改以重建您的boot-debug.imgvendor_boot-debug.img

或者, repack_bootimg工具可用于使用更新的 GSI sepolicy 重建boot-debug.imgvendor_boot-debug.img debug.img。

重新打包调试 ramdisk

合作伙伴可以使用repack_bootimg将 GSI sepolicy 文件更新为boot-debug.img (或vendor_boot-debug.img ,如果设备使用 GKI),而不是合并 sepolicy 更改来重建boot-debug.img

步骤如下:

  1. https://ci.android.com下载otatools.zip 。我们建议从 aosp- aosp-master上的aosp_arm64-userdebug构建工件下载。

  2. 设置repack_bootimg的执行环境:

    unzip otatools.zip -d otatools
    export PATH="${PWD}/otatools/bin:${PATH}"
    repack_bootimg --help
    
  3. 从您正在使用的 GSI 构建中下载userdebug_plat_sepolicy.cilboot-with-debug-ramdisk-${KERNEL_VERSION}.img 。例如,如果您使用RJR1.211020.001 (7840830)中的 arm64 GSI,则从https://ci.android.com/builds/submitted/ 7840830 /aosp_arm64-user/latest下载。

  4. 使用 userdebug_plat_sepolicy.cil 更新设备boot-debug.imgvendor_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

如果传递给--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 只能在设备解锁时使用,这允许在bootvendor_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