自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
实现 DTO
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
实现设备树叠加层 (DTO) 涉及分割设备树 (DT)、构建、分区和运行。在实现可以正常工作之后,您还必须保持两个 DT 之间的兼容性,并确定用于确保每个 DT 分区安全性的策略。
分割 DT
首先将 DT 分割成两部分:
- 主 DT。由 SoC 供应商提供的仅限 SoC 访问的部分和默认配置。
- 叠加 DT。由原始设计制造商 (ODM)/原始设备制造商 (OEM) 提供的设备专用配置。
分割 DT 之后,您必须确保主 DT 和叠加 DT 之间的兼容性,以便通过合并主 DT 和叠加 DT 为设备生成完整的 DT。有关 DTO 格式和规则的详细信息,请参阅 DTO 语法。如需详细了解多个 DT,请参阅使用多个 DT。
构建主 DT 和叠加 DT
如需构建主 DT,请执行以下操作:
- 将主 DT
.dts
编译为 .dtb
文件。
- 将
.dtb
文件刷写到引导加载程序在运行时可访问的分区(详见 [对 DT 进行分区](#partition))。
如需构建叠加 DT,请执行以下操作:
- 将叠加 DT
.dts
编译为 .dtbo
文件。虽然此文件格式与格式设为扁平化 DT 的 .dtb
文件相同,但是用不同的文件扩展名可以将其与主 DT 区分开来。
- 将
.dtbo
文件刷写到引导加载程序在运行时可访问的分区(详见 [对 DT 进行分区](#partition))。
如需详细了解如何使用 DTC 进行编译以及如何在主机上验证 DTO 结果,请参阅编译和验证。
对 DT 进行分区
在闪存中确定引导加载程序在运行时可访问和可信任的位置以放入 .dtb
和 .dtbo
。
主 DT 的示例位置:
- 启动分区的一部分,已附加到内核 (
image.gz
)
- 单独的 DT blob (
.dtb
),位于专用分区 (dtb
)
叠加 DT 的示例位置:

图 1. 将 .dtbo 放入 odm 分区中(仅当引导加载程序能够从 odm 分区的文件系统加载数据时才这样做)。

图 2. 将 .dtbo 放在独一无二的分区中,例如 dtbo 分区。
注意:叠加 DT 分区的大小取决于设备和主 DT blob 上所需的更改量。通常,8 MB 已足够当前使用并已为未来扩展留出了空间(如果需要的话)。
对于支持无缝 (A/B) 更新的设备,请用 A/B 来标识主 DT 和叠加 DT 分区:

图 3. DTBO 分区 A/B,示例 1。

图 4. DTBO 分区 A/B,示例 2。
在引导加载程序中运行
如需运行,请执行以下操作:

图 5. 引导加载程序中 DTO 的典型运行时实现。
- 将
.dtb
从存储空间加载到内存中。
- 将
.dtbo
从存储空间加载到内存中。
- 用
.dtb
叠加 .dtbo
以形成合并的 DT。
- 启动内核(已给定合并 DT 的内存地址)。
保持兼容性
主 DTB(来自 SoC 供应商)会被视为 DTBO 的 API 表面。将 DT 分离为 SoC 通用部件和设备专用部件后,您必须确保这两个部件以后相互兼容,包括:
- 主 DT 中的 DT 定义。例如节点、属性、标签。主 DT 中的任何定义更改都可能会触发叠加 DT 中的更改。例如,如需更正主 DT 中的某个节点名称,请定义映射到原始节点名称的“别名”标签(以免更改叠加 DT)。
- 叠加 DT 的存储位置。例如分区名称、存储格式。
确保安全
引导加载程序必须确保 DTB 或 DTBO 安全无虞、未被修改且未被损坏。您可以使用任何解决方案来保护 DTB 或 DTBO,例如,VBoot 1.0 中的启动映像签名或 AVB 哈希页脚 (VBoot 2.0)。
- 如果 DTB 或 DTBO 位于专属的分区中,您可以将该分区添加到 AVB 的信任链。信任链从硬件保护的信任根开始,并进入引导加载程序,从而验证 DTB 或 DTBO 分区的完整性和真实性。
- 如果 DTB 或 DTBO 位于现有分区(如
odm
分区)中,该分区应位于 AVB 的信任链中。(DTBO 分区可以与 odm
分区共享一个公钥)。
如需了解详情,请参阅启动时验证。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-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-03-04。"],[],[],null,["# Implement DTOs\n\nImplementing device tree overlays (DTOs) involves dividing the device tree (DT), building,\npartitioning, and running. After you have a working implementation, you must also maintain\ncompatibility between the two DTs and determine a strategy for ensuring the\nsecurity of each DT partition.\n\nDivide the DT\n-------------\n\nStart by dividing the DT into two parts:\n\n- **Main DT**. The SoC-only part and the default configurations, provided by SoC vendor.\n- **Overlay DT**. The device-specific configurations, provided by ODM/OEM.\n\nAfter dividing the DTs, you must ensure compatibility between main\nDT and overlay DT so that merging main DT and overlay DT results in a complete\nDT for the device. For details on DTO format and rules, see\n[DTO syntax](/docs/core/architecture/dto/syntax). For details on\nmultiple DTs, see\n[Use multiple DTs](/docs/core/architecture/dto/multiple).\n\nBuild main and overlay DTs\n--------------------------\n\nTo build the main DT:\n\n1. Compile the main DT `.dts` into a `.dtb` file.\n2. Flash the `.dtb` file into a bootloader runtime-accessible partition (detailed in \\[Partition DTs\\](#partition)).\n\nTo build the overlay DT:\n\n1. Compile the overlay DT `.dts` into a `.dtbo` file. While this file format is the same as the `.dtb` file formatted as a flattened DT, the different file extension distinguishes it from the main DT.\n2. Flash the `.dtbo` file into a bootloader runtime-accessible partition (detailed in \\[Partition DTs\\](#partition)).\n\nFor details on compiling with DTC and verifying DTO results on the host, see\n[Compile and verify](/docs/core/architecture/dto/compile).\n\nPartition DTs\n-------------\n\nDetermine a bootloader runtime-accessible and trusted location in flash\nmemory to put `.dtb` and `.dtbo`.\n\nExample locations for the main DT:\n\n- Part of boot partition, appended to the kernel (`image.gz`)\n- Separate DT blobs (`.dtb`) in dedicated partition (`dtb`)\n\nExample locations for the overlay DT: \n\n**Figure 1.** Put .dtbo into an odm partition (do this only if your bootloader has\nthe capability to load data from the filesystem of an odm partition). \n\n**Figure 2.** Put .dtbo into a unique partition, such as a dtbo partition.\n\n**Note:** The size of the\noverlay DT partition depends on the device and the amount of changes needed on\ntop of the main DT blob. Typically, 8 MB is more than enough and allows room to\ngrow in the future if required.\n\nFor devices that support\n[seamless (A/B) updates](/docs/core/ota/ab_updates), A/B the\nmain DT and overlay DT partitions: \n\n**Figure 3.** DTBO partition A/B, example 1. \n\n**Figure 4.** DTBO partition A/B, example 2.\n\nRun in bootloader\n-----------------\n\nTo run:\n\n**Figure 5.** Typical runtime implementation for DTO in bootloader.\n\n1. Load `.dtb` from storage into memory.\n2. Load `.dtbo` from storage into memory.\n3. Overlay `.dtb` with `.dtbo` to be a merged DT.\n4. Start kernel given the memory address of the merged DT.\n\nMaintain compatibility\n----------------------\n\nThe main DTB (from SoC vendor) is treated as an API surface for DTBOs. After\nseparating the DT into a SoC-common part and a device-specific part,\nyou must keep the two parts mutually compatible in the future, including:\n\n- **DT definition in main DT.** For example, nodes, properties, labels. Any definition change in main DT could trigger changes in overlay DT. For example, to correct a node name in main DT, define an \"alias\" label that maps to the original node name (to avoid the change of overlay DT).\n- **Overlay DT store location.** For example, partition name, store format.\n\nEnsure security\n---------------\n\nBootloader must ensure the DTB or DTBO is secure, unmodified, and uncorrupted.\nYou could use any solution to secure DTB or DTBO, for example,\n[Boot image\nsignature](/docs/security/features/verifiedboot/verified-boot#signature_format) in VBoot 1.0 or\n[AVB\nHASH footer](https://android.googlesource.com/platform/external/avb/+/android16-release/README.md#The-VBMeta-struct) (VBoot 2.0).\n\n- If DTB or DTBO is in a unique partition, you can add that partition to the trust chain of AVB. The trust chain starts from a hardware-protected root of trust and goes to the bootloader, which verifies the integrity and authenticity of DTB or DTBO partition.\n- If DTB or DTBO is in an existing partition (such as the `odm` partition), that partition should be in the trust chain of AVB. (DTBO partition could share a public key with `odm` partition).\n\nFor details, refer to [Verified\nBoot](/docs/security/features/verifiedboot)."]]