自 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.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 boot-debug.img
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 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/subscribed/7840830/aosp_arm64-user/latest下載。使用
userdebug_plat_sepolicy.cil
更新設備boot-debug.img
或vendor_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
新增 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