| <html devsite><head> |
| <title>编译和验证</title> |
| <meta name="project_path" value="/_project.yaml"/> |
| <meta name="book_path" value="/_book.yaml"/> |
| </head> |
| |
| <body> |
| |
| <!-- |
| Copyright 2017 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <p>您可以使用设备树编译器 (DTC) 来编译设备树源文件。不过,在将叠加层 DT 应用于目标主 DT 之前,您还应该通过模拟 DTO 的行为来验证结果。</p> |
| |
| <h2 id="compile">通过 DTC 进行编译</h2> |
| |
| <p>使用 <code>dtc</code> 编译 <code>.dts</code> 时,您必须添加选项 <code>-@</code> 以在生成的 <code>.dtbo</code> 中添加 <code>__symbols__</code> 节点。<code>__symbols__</code> 节点包含带标签的所有节点的列表,DTO 库可使用这个列表作为参考。</p> |
| |
| <p>编译主 <code>.dts</code> 的示例命令:</p> |
| |
| <pre class="devsite-terminal"> |
| dtc -@ -O dtb -o my_main_dt.dtb my_main_dt.dts |
| </pre> |
| |
| <p>编译叠加层 DT <code>.dts</code> 的示例命令:</p> |
| |
| <pre class="devsite-terminal"> |
| dtc -@ -O dtb -o my_overlay_dt.dtbo my_overlay_dt.dts |
| </pre> |
| |
| <aside class="note"><strong>注意</strong>:如果您遇到 DTC 编译错误:<code>invalid option --'@'</code>,则可能需要更新 DTC 版本。在 AOSP 上游,官方 DTC 对 DTO 的支持从<a href="https://github.com/dgibson/dtc/tree/v1.4.4" class="external">版本 1.4.4</a> 开始,而且大部分补丁程序在 2016 年 12 月后就完成了合并。为了支持 DTO,建议您使用 AOSP 中的 <code><a href="https://android.googlesource.com/platform/external/dtc/" class="external">external/dtc</a></code>,它已与最新的 DTC 同步(已视需要合并 DTO 补丁程序)。</aside> |
| |
| <h2 id="verify">在主机上验证 DTO 结果</h2> |
| |
| <p>验证流程可以帮助您识别将叠加层 DT 放在主 DT 上时可能发生的错误。更新目标之前,您可以通过在 <code>.dts</code> 中使用 <code>/include/</code> 来模拟 DTO 行为,从而在主机上验证叠加 DT 的结果。</p> |
| |
| <aside class="note"><strong>注意</strong>:<code>/include/</code> 不支持在叠加层 DT 源中使用 <code>__overlay__</code>。</aside> |
| |
| <p><img src="../images/treble_dto_simulate.png"/> |
| </p> |
| |
| <figcaption><strong>图 1.</strong> 使用语法 <code>/include/</code> 来模拟主机上的 DTO</figcaption> |
| |
| <ol> |
| <li>创建叠加层 <code>.dts</code> 的副本。在副本中,移除第一行头文件。示例: |
| |
| <pre> |
| /dts-v1/; |
| /plugin/; |
| </pre>将文件另存为 <code>my_overlay_dt_wo_header.dts</code>(或您希望的任何文件名)。 |
| </li> |
| |
| <li>创建主 <code>.dts</code> 的副本。在副本中的最后一行后,为您在第 1 步中创建的文件附加 include 语法。例如: |
| |
| <pre> |
| /include/ "my_overlay_dt_wo_header.dts" |
| </pre>将文件另存为 <code>my_main_dt_with_include.dts</code>(或您希望的任何文件名)。 |
| </li> |
| |
| <li>使用 <code>dtc</code> 编译 <code>my_main_dt_with_include.dts</code> 以获得合并的 DT,这应该与使用 DTO 进行编译所得到的结果相同。例如: |
| |
| <pre class="devsite-terminal"> |
| dtc -@ -O dtb -o my_merged_dt.dtb my_main_dt_with_include.dts |
| </pre> |
| </li> |
| |
| <li>使用 <code>dtc</code> 转储 <code>my_merged_dt.dto</code>。 |
| |
| <pre class="devsite-terminal"> |
| dtc -O dts -o my_merged_dt.dts my_merged_dt.dtb |
| </pre> |
| </li> |
| </ol> |
| |
| <h2 id="verifying-DTO-in-p">在 Android 9 中验证 DTO</h2> |
| |
| <p>Android 9 需要具有设备树 Blob 叠加层 (DTBO) 分区。要在 SoC DT 中添加节点或更改属性,引导加载程序必须在 SoC DT 之上动态叠加设备专用的 DT。</p> |
| |
| <h3 id="indicating-applied-overlays">指示已应用的叠加层</h3> |
| |
| <p>要使<a href="/compatibility/vts/">供应商测试套件 (VTS)</a> 能够评估叠加层应用的准确性,供应商必须添加新的内核命令行参数 <code>androidboot.dtbo_idx</code>,用于指示从 DTBO 分区中选择哪些叠加层。例如,参数 <code>androidboot. |
| dtbo_idx=x,y,z</code> 将 <code>x</code>、<code>y</code> 和 <code>z</code> 报告为 DTBO 分区中已由引导加载程序按相同顺序应用于基础设备树 (DT) 的设备树叠加层 (DTO) 的索引,这些索引以零为起点。</p> |
| |
| <p>叠加层可以应用于主设备树中的节点,也可以添加新节点,但<strong>不能</strong>引用之前叠加层中添加的节点。这种限制是必要的,因为叠加层应用不会将叠加层符号表与主 DT 符号表合并(不合并的做法既可避免符号名称出现冲突,也可避免叠加层之间的依赖关系复杂化)。</p> |
| |
| <h4 id="example-invalid-overlays">示例:无效叠加层</h4> |
| |
| <p>在此示例中,<code>overlay_2.dts</code> 引用了由 <code>overlay_1.dts</code> 添加的节点 <strong><code>e</code></strong>。在将 <code>overlay_1</code> 应用于主 DT 之后,如果尝试将 <code>overlay_2</code> 应用于生成的 DT,则叠加层应用将发生故障,并出现基础 DT 的符号表中不存在符号 <strong><code>e</code></strong> 的错误。</p> |
| |
| <table> |
| <tbody><tr> |
| <th width="33%">main.dts</th> |
| |
| <th>overlay_1.dts</th> |
| |
| <th>overlay_2.dts</th> |
| |
| </tr> |
| <tr> |
| <td> |
| <pre> |
| |
| <strong>[main.dts]</strong> |
| |
| /dts-v1/; |
| |
| / { |
| a: a {}; |
| b: b {}; |
| c: c {}; |
| }; |
| </pre> |
| </td> |
| |
| <td> |
| <pre> |
| |
| <strong>[overlay_1.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| &b { ref1 = <&a>; |
| e: e { |
| prop = <0x0a>; |
| phandle = <0x04>; |
| }; |
| }; |
| </pre> |
| </td> |
| |
| <td> |
| <pre> |
| |
| <strong>[overlay_2.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| /* invalid! */ |
| <font color="red">&e</font> { |
| prop = <0x0b>; |
| }; |
| </pre> |
| </td> |
| </tr> |
| </tbody></table> |
| |
| <h4 id="example-valid-overlays">示例:有效叠加层</h4> |
| |
| <p>在此示例中,<code>overlay_2.dts</code> 仅引用了主 DTS 中的节点 <strong><code>b</code></strong>。将 <code>overlay_1</code> 和 <code>overlay_2</code> 依次应用于基础 DT 之后,节点 <strong><code>e</code></strong> 的属性 <strong><code>prop</code></strong> 的值(由 <code>overlay_1.dts</code> 设置)将被 <code>overlay_2.dts</code> 设置的值覆盖。</p> |
| |
| <table> |
| <tbody><tr> |
| <th width="33%">main.dts</th> |
| |
| <th>overlay_1.dts</th> |
| |
| <th>overlay_2.dts</th> |
| |
| </tr> |
| |
| <tr> |
| <td> |
| <pre> |
| |
| <strong>[final.dts]</strong> |
| |
| /dts-v1/; |
| |
| / { |
| a: a {}; |
| b: b {}; |
| c: c {}; |
| }; |
| </pre> |
| </td> |
| |
| <td> |
| <pre> |
| |
| <strong>[overlay_1.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| &b { ref1 = <&a>; |
| e { |
| prop = <0x0c>; |
| }; |
| }; |
| </pre> |
| </td> |
| |
| <td> |
| <pre> |
| |
| <strong>[overlay_2.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| /* valid */ |
| <font color="blue">&b</font> { ref1 = <&c>; |
| e { |
| prop = <0x0d>; |
| }; |
| }; |
| </pre> |
| </td> |
| </tr> |
| </tbody></table> |
| |
| <h3 id="implementing-the-dtbo-partition">实现 DTBO 分区</h3> |
| |
| <p>要实现所需的 DTBO 分区,请确保引导加载程序可以执行以下操作:</p> |
| |
| <ol> |
| <li>识别它正在哪个开发板上运行,并选择要应用的相应叠加层。</li> |
| |
| <li>将 <code>androidboot.dtbo_idx</code> 参数附加到内核命令行。 |
| |
| <ul> |
| <li>该参数必须指示 DTBO 分区映像中由引导加载程序按相同顺序应用于基础 DT 的 DTO 的索引,这些索引以零为起点。</li> |
| |
| <li>这些索引必须引用叠加层在 DTBO 分区中的位置。</li> |
| </ul> |
| </li> |
| </ol> |
| |
| <p>要详细了解 DTBO 分区结构,请访问 source.android.com 上的<a href="https://source.android.com/devices/architecture/dto/">设备树叠加层</a>。</p> |
| |
| <h3 id="validating-the-dtbo-partition">验证 DTBO 分区</h3> |
| |
| <p>您可以使用 VTS 来验证以下内容:</p> |
| |
| <ul> |
| <li>内核命令行参数 <code>androidboot.dtbo_idx</code> 是否存在(方法:检查 <code>Init</code> 是否已自动设置相应的 <code>ro.boot.dtbo_idx</code> 系统属性)。</li> |
| |
| <li><code>ro.boot.dtbo_idx</code> 系统属性的有效性(方法:检查该属性是否至少指定了一个有效的 DTBO 映像索引)。</li> |
| |
| <li>DTBO 分区的有效性(还应验证 DTBO 分区中应用于基础 DT 的叠加层的有效性)。</li> |
| |
| <li>生成的 DT 中的其他节点或属性更改是否已呈现给 Linux 内核。</li> |
| </ul> |
| |
| <p>例如,在以下叠加层和最终 DT 中,将 <code>androidboot.dtbo_idx=5,3</code> 添加到内核命令行可通过验证,而将 <code>androidboot.dtbo_idx=3,5</code> 添加到内核命令行则不能通过验证。</p> |
| |
| <table> |
| <tbody><tr> |
| <th width="50%">索引 3 处的叠加层 DT</th> |
| |
| <th>索引 5 处的叠加层 DT</th> |
| |
| </tr><tr> |
| <td> |
| <pre> |
| |
| <strong>[overlay_1.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| &c <strong>{ prop = <0xfe>; }</strong>; |
| </pre> |
| </td> |
| |
| <td> |
| <pre> |
| |
| <strong>[overlay_2.dts]</strong> |
| |
| /dts-v1/; |
| /plugin/; |
| |
| &c { prop = <0xff>; }; |
| </pre> |
| </td> |
| </tr> |
| |
| </tbody></table><table> |
| <tbody><tr> |
| <th>最终 DT</th> |
| |
| </tr><tr> |
| <td> |
| <pre> |
| |
| /dts-v1/; |
| / { |
| |
| a { |
| phandle = <0x1>; |
| }; |
| |
| b { |
| phandle = <0x2>; |
| }; |
| |
| c { |
| phandle = <0x3>; |
| <strong>prop = <0xfe></strong>; |
| }; |
| |
| __symbols__ { |
| a = "/a"; |
| b = "/b"; |
| c = "/c"; |
| }; |
| }; |
| |
| </pre></td></tr></tbody></table> |
| |
| </body></html> |