使用調試 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