使用调试 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 构建变体更改
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.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

重新打包调试 ramdisk

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

步骤如下:

  1. https://ci.android.com下载otatools.zip 。我们建议从aosp-main上的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/subscribed/7840830/aosp_arm64-user/latest下载。

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

如果传递给--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