自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
恢复映像
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在非 A/B 设备上,恢复映像应包含设备树 blob (DTB) 或高级配置与电源接口 (ACPI) 叠加层映像的信息。当此类设备启动进入恢复模式时,引导加载程序可以加载与恢复映像兼容的叠加层映像。支持 A/B(无缝)更新的设备应将恢复用作启动,而非单独的恢复分区(如需了解详情,请参阅实现 A/B 更新)。
在不同的 Android 版本中,用于将恢复 DTBO/ACPIO 作为启动/恢复映像的一部分的选项有所不同。
版本 |
更新方案 |
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) |
是 |
* 搭载 Android 11 或更高版本并使用通用内核映像 (GKI) 的 A/B 设备必须使用主启动头文件版本 3,才能与供应商启动分区相兼容。
要点:
A/B 设备不需要指定恢复映像,因为 A/B 更新使用两组分区(包括 boot
和 dtbo
),且在更新期间在两者间切换,从而无需恢复映像。A/B 设备仍然可以使用专用恢复映像。
发布时搭载 Android 11 或更高版本且使用启动头文件版本 3 的非 A/B 设备必须单独为恢复映像显式指定启动头文件版本 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 |
恢复 DTBO 或 ACPIO(o 页) |
o = (recovery_[dtbo|acpio]_size + page_size - 1) / page_size |
如需详细了解用于指定启动映像头文件版本和叠加层映像路径的 mkbootimg
工具参数,请参阅启动映像头文件版本编号。
实现 DTBO
搭载 9 或更高版本的非 A/B 设备可以填充恢复映像的 recovery_dtbo
部分。如需在 BoardConfig.mk
设备的 recovery.img
中添加 recovery_dtbo
映像,请执行以下操作:
将 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 构建系统会将变量 BOARD_PREBUILT_DTBOIMAGE
指定的 DTBO 添加到 recovery.img
中。
实现 ACPIO
搭载 Android 9 或更高版本的非 A/B 设备可以使用 ACPIO 叠加层映像(而不是 DTBO 映像),并且可以填充恢复映像的 recovery_acpio
部分(而不是 recovery_dtbo
部分)。如需在 BoardConfig.mk
设备的 recovery.img
中添加 recovery_acpio
映像,请执行以下操作:
将 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 构建系统会将变量 BOARD_RECOVERY_ACPIO
指定的 ACPIO 添加到 recovery.img
中。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-04。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-04-04。"],[],[],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`."]]