自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
復原映像檔
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在非 A/B 裝置上,復原映像檔應包含裝置樹狀結構 blob (DTB) 或進階設定和電源介面 (ACPI) 重疊映像檔的資訊。當這類裝置啟動至復原模式時,系統啟動載入程式就能載入與復原映像相容的疊加層圖片。支援 A/B (無縫) 更新的裝置應使用復原功能做為啟動功能,而非使用獨立的復原分區 (詳情請參閱「實作 A/B 更新」)。
將復原 DTBO/ACPIO 納入啟動/復原映像檔的選項,在不同 Android 版本之間有所差異。
發布 |
更新配置 |
GKI 法規遵循 |
啟動標頭版本 (啟動裝置) |
啟動標頭版本 (升級裝置) |
需要專用復原映像檔 |
11 |
A/B、 虛擬 A/B |
是 |
3* |
無 |
否 |
A/B、 虛擬 A/B |
否 |
2、3 |
0、1、2、3 |
否 |
非 A/B |
是 |
3 |
無 |
是 |
非 A/B |
否 |
2、3 |
0、1、2、3 |
是 |
10 (Q) |
A/B |
無 |
2 |
0、1、2 |
否 |
非 A/B |
無 |
2 |
0、1、2 |
是 |
9 (P) |
A/B |
無 |
1 |
0、1 |
否 |
非 A/B |
無 |
1 |
0、1 |
是 |
8 (O) |
A/B |
無 |
不適用 (視為 0) |
不適用 (視為 0) |
否 |
非 A/B |
無 |
不適用 (視為 0) |
不適用 (視為 0) |
是 |
* 如果 A/B 裝置搭載 Android 11 以上版本,並使用通用核心映像檔 (GKI),則必須使用主要 3 版的啟動序號,才能與供應商啟動區分區相容。
重點:
A/B 裝置不需要指定復原映像檔,因為 A/B 更新會使用兩組分區 (包括 boot
和 dtbo
),並在更新期間切換分區,因此不需要復原映像檔。A/B 裝置仍可使用專屬的復原映像檔。
非 A/B 裝置若要使用 Android 11 以上版本,並使用版本 3 的啟動標頭,則必須另外明確指定復原映像檔的啟動標頭版本 2。例如:
BOARD_RECOVERY_MKBOOTIMG_ARGS := --header_version 2
對於不支援裝置樹狀結構的架構,復原映像檔可以包含 ACPIO 映像檔,而非 DTBO 映像檔。
關於 OTA 失敗和復原映像檔
為避免非 A/B 裝置發生無線更新 (OTA) 失敗,復原映像檔應是自給自足且不依賴其他映像檔。在 OTA 更新期間,如果在覆蓋映像檔更新後 (但尚未完成完整更新) 發生問題,裝置會嘗試啟動至復原模式,以便完成 OTA 更新。不過,由於覆蓋分區已更新,因此可能會與復原映像檔 (尚未更新) 不符。
為了避免復原程序在更新期間依賴 DTBO/ACPIO 分割區,執行 Android 9 以上版本的非 A/B 裝置可在啟動映像格式中,將復原程序 DTBO/ACPIO 圖像指定為包含重疊圖像的資訊,做為個別的部分 (必須使用啟動標頭版本 1 或 2)。
開機映像檔變更
如要在搭載 Android 9 以上版本的非 A/B 裝置上,讓復原映像檔包含復原 DTBO 或 ACPIO,請按照下列方式更新啟動映像檔結構。
開機映像檔區段 |
頁數 |
開機頁首 (1 頁) |
1 |
核心 (l 頁面) |
l = (kernel_size + page_size -
1) / page_size |
Ramdisk (m 頁面) |
m = (ramdisk_size + page_size -
1) / page_size |
第二階段啟動載入程式 (n 個頁面) |
n = (second_size + page_size -
1) / page_size |
Recovery DTBO 或 ACPIO (o 頁面) |
o = (recovery_[dtbo|acpio]_size + page_size -
1) / page_size |
如要進一步瞭解用於指定開機映像檔標頭版本和疊加圖像路徑的 mkbootimg
工具引數,請參閱「開機映像檔標頭版本管理」。
實作 DTBO
搭載 Android 9 以上版本的非 A/B 裝置,可以填入復原映像檔的 recovery_dtbo
區段。如要在 recovery.img
中加入 recovery_dtbo
圖片,請在裝置 BoardConfig.mk
中執行以下操作:
將設定 BOARD_INCLUDE_RECOVERY_DTBO
設為 true
:
BOARD_INCLUDE_RECOVERY_DTBO := true
擴充 BOARD_MKBOOTIMG_ARGS
變數,指定開機映像檔標頭版本:
BOARD_MKBOOTIMG_ARGS := --ramdisk_offset $(BOARD_RAMDISK_OFFSET) --tags_offset $(BOARD_KERNEL_TAGS_OFFSET) --header_version $(BOARD_BOOTIMG_HEADER_VERSION)
請確認 BOARD_PREBUILT_DTBOIMAGE
變數已設為 DTBO 圖片的路徑。Android 建構系統會在建立復原映像檔時,使用該變數設定 mkbootimg
工具的 recovery_dtbo
引數。
如果 BOARD_INCLUDE_RECOVERY_DTBO
、BOARD_MKBOOTIMG_ARGS
和 BOARD_PREBUILT_DTBOIMAGE
變數設定正確,Android 建構系統會納入 recovery.img
中 BOARD_PREBUILT_DTBOIMAGE
變數指定的 DTBO。
導入 ACPIO
執行 Android 9 以上版本的非 A/B 裝置可以使用 ACPIO 重疊映像檔 (而非 DTBO 映像檔),並填入復原映像檔的 recovery_acpio
區段 (而非 recovery_dtbo
區段)。如要在 recovery.img
中加入 recovery_acpio
圖片,請在裝置 BoardConfig.mk
中執行以下操作:
將設定 BOARD_INCLUDE_RECOVERY_ACPIO
設為 true
:
BOARD_INCLUDE_RECOVERY_ACPIO := true
擴充 BOARD_MKBOOTIMG_ARGS
變數,指定引導映像檔標頭版本。變數必須大於或等於 1,才能支援復原 ACPIO。
BOARD_MKBOOTIMG_ARGS += --header_version $(BOARD_BOOTIMG_HEADER_VERSION)
請確認 BOARD_RECOVERY_ACPIO
變數已設為 ACPIO 映像檔的路徑。Android 建構系統會在建立復原映像檔時,使用這個變數設定 mkbootimg
工具的 recovery_acpio
引數。
如果 BOARD_INCLUDE_RECOVERY_ACPIO
、BOARD_MKBOOTIMG_ARGS
和 BOARD_RECOVERY_ACPIO
變數設定正確,Android 建構系統就會納入 recovery.img
中 BOARD_RECOVERY_ACPIO
變數指定的 ACPIO。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Recovery images\n\nOn non-A/B devices, the recovery image should contain information from a\n[device tree blob (DTB)](/docs/core/architecture/bootloader/dtb-images) or\n[Advanced Configuration and Power Interface\n(ACPI)](https://uefi.org/acpi/specs) overlay image. When such\ndevices boot into recovery, the bootloader can then load the overlay image that\nis compatible with the recovery image. Devices that support [A/B (seamless)\nupdates](/docs/core/ota/ab) should use recovery as boot instead of a\nseparate recovery partition (for details, see [Implementing A/B\nUpdates](/docs/core/ota/ab/ab_implement)).\n\nThe options for including a recovery DTBO/ACPIO as part of the boot/recovery\nimage differ between Android releases.\n\n| Release | Update scheme | GKI compliance | Boot header version (launching devices) | Boot header version (upgrading devices) | Dedicated recovery image required |\n|---------|------------------|----------------|-----------------------------------------|-----------------------------------------|-----------------------------------|\n| 11 | A/B, Virtual A/B | Yes | 3^\\*^ | N/A | No |\n| 11 | A/B, Virtual A/B | No | 2, 3 | 0, 1, 2, 3 | No |\n| 11 | non-A/B | Yes | 3 | N/A | Yes |\n| 11 | non-A/B | No | 2, 3 | 0, 1, 2, 3 | Yes |\n| 10 (Q) | A/B | N/A | 2 | 0, 1, 2 | No |\n| 10 (Q) | non-A/B | N/A | 2 | 0, 1, 2 | Yes |\n| 9 (P) | A/B | N/A | 1 | 0, 1 | No |\n| 9 (P) | non-A/B | N/A | 1 | 0, 1 | Yes |\n| 8 (O) | A/B | N/A | N/A (considered 0) | N/A (considered 0) | No |\n| 8 (O) | non-A/B | N/A | N/A (considered 0) | N/A (considered 0) | Yes |\n\n**\\*** *A/B devices running Android\n11 or higher and using the [Generic Kernel Image\n(GKI)](/docs/core/architecture/kernel/generic-kernel-image) must use a\nprimary [boot header version of\n3](/docs/core/architecture/bootloader/boot-image-header#header-v3) to be\ncompatible with the [vendor boot\npartition](/docs/core/architecture/bootloader/partitions/vendor-boot-partitions).*\n\nKey points:\n\n- A/B devices don't need to specify a recovery image as A/B updates use two sets\n of partitions (including `boot` and `dtbo`) and switch between them during\n updates, removing the need for a recovery image. A/B devices can\n still use a dedicated recovery image.\n\n- Non-A/B devices launching with Android 11 or higher\n and using a boot header version of 3 must explicitly specify a [boot header\n version of 2](/docs/core/architecture/bootloader/boot-image-header#header-v2)\n for the recovery image separately. For example:\n\n BOARD_RECOVERY_MKBOOTIMG_ARGS := --header_version 2\n\n- For architectures that don't support device trees, the recovery image can\n include an ACPIO image instead of a DTBO image.\n\nAbout OTA failures and recovery images\n--------------------------------------\n\nTo prevent over-the-air (OTA) failures on non-A/B devices, the recovery image\nshould be self-sufficient and independent of other images. During an OTA update,\nif a problem occurs after the overlay image has been updated (but prior to\ncompleting the full update), the device tries to boot into recovery mode to\ncomplete the OTA update. However, because the overlay partition has already been\nupdated, a mismatch could occur with the recovery image (which hasn't been\nupdated yet).\n\nTo prevent recovery from depending on the DTBO/ACPIO partition during an\nupdate, non-A/B devices running Android 9 or higher\ncan specify a recovery DTBO/ACPIO image containing information from the overlay\nimage as a separate section in the boot image format (must use a boot header\nversion of 1 or 2).\n\nBoot image changes\n------------------\n\nTo allow the recovery image to contain the recovery DTBO or ACPIO on non-A/B\ndevices running Android 9 or higher, update the boot\nimage structure as follows.\n\n| Boot image section | Number of pages |\n|-----------------------------------|--------------------------------------------------------------------|\n| Boot header (1 page) | 1 |\n| Kernel (l pages) | l = (`kernel_size` + `page_size` - 1) / `page_size` |\n| Ramdisk (m pages) | m = (`ramdisk_size` + `page_size` - 1) / `page_size` |\n| Second stage bootloader (n pages) | n = (`second_size` + `page_size` - 1) / `page_size` |\n| Recovery DTBO or ACPIO (o pages) | o = (`recovery_[dtbo|acpio]_size` + `page_size` - 1) / `page_size` |\n\nFor details on the `mkbootimg` tool arguments for specifying the boot image\nheader version and overlay image paths, see [Boot Image Header\nVersioning](/docs/core/architecture/bootloader/boot-image-header#implementing-versioning).\n\nImplement DTBO\n--------------\n\nNon-A/B devices running 9 or higher can populate the\n`recovery_dtbo` section of the recovery image. To include the `recovery_dtbo`\nimage in `recovery.img`, in the device `BoardConfig.mk`:\n\n- Set the config `BOARD_INCLUDE_RECOVERY_DTBO` to `true`:\n\n BOARD_INCLUDE_RECOVERY_DTBO := true\n\n- Extend the `BOARD_MKBOOTIMG_ARGS` variable to specify the boot image header\n version:\n\n BOARD_MKBOOTIMG_ARGS := --ramdisk_offset $(BOARD_RAMDISK_OFFSET) --tags_offset $(BOARD_KERNEL_TAGS_OFFSET) --header_version $(BOARD_BOOTIMG_HEADER_VERSION)\n\n- Ensure that the `BOARD_PREBUILT_DTBOIMAGE` variable is set to the path of the\n DTBO image. The Android build system uses the variable to set the\n `recovery_dtbo` argument of the `mkbootimg` tool during the creation of\n recovery image.\n\nIf the `BOARD_INCLUDE_RECOVERY_DTBO`, `BOARD_MKBOOTIMG_ARGS`, and\n`BOARD_PREBUILT_DTBOIMAGE` variables are set correctly, the Android build system\nincludes the DTBO specified by the `BOARD_PREBUILT_DTBOIMAGE` variable in\n`recovery.img`.\n\nImplement ACPIO\n---------------\n\nNon-A/B devices running Android 9 or higher can use\nan ACPIO overlay image (instead of a DTBO image) and can populate the\n`recovery_acpio` section (instead of the `recovery_dtbo` section) of the\nrecovery image. To include the `recovery_acpio` image in `recovery.img`, in the\ndevice `BoardConfig.mk`:\n\n- Set the config `BOARD_INCLUDE_RECOVERY_ACPIO` to `true`:\n\n BOARD_INCLUDE_RECOVERY_ACPIO := true\n\n- Extend the `BOARD_MKBOOTIMG_ARGS` variable to specify the boot image header\n version. The variable must be greater than or equal to 1 to support recovery\n ACPIO.\n\n BOARD_MKBOOTIMG_ARGS += --header_version $(BOARD_BOOTIMG_HEADER_VERSION)\n\n- Ensure that the `BOARD_RECOVERY_ACPIO` variable is set to the path of the\n ACPIO image. The Android build system uses the variable to set the\n `recovery_acpio` argument of the `mkbootimg` tool during the creation of the\n recovery image.\n\nIf the `BOARD_INCLUDE_RECOVERY_ACPIO`, `BOARD_MKBOOTIMG_ARGS`, and\n`BOARD_RECOVERY_ACPIO` variables are set correctly, the Android build system\nincludes the ACPIO specified by the `BOARD_RECOVERY_ACPIO` variable in\n`recovery.img`."]]