aboutsummaryrefslogtreecommitdiff
path: root/en/devices/architecture/dto/compile.html
blob: aea2f3bcbb6a6bf2acc2444b0fa78022af837427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<html devsite="">
<head>
  <title>Compiling & Verifying</title>
  <meta name="project_path" value="/_project.yaml">
  <meta name="book_path" value="/_book.yaml">
</head>

<body>
   {% include "_versions.html" %}
  <!--
      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>You can use Device Tree Compiler (DTC) to compile the Device Tree Source
  files. However, before applying the overlay DT on the target main DT, you
  should also verify the result by simulating the behavior of DTO.</p>


  <h2 id="compile">Compiling with DTC</h2>


  <p>When using <code>dtc</code> to compile <code>.dts</code>, you must add
  option <code>-@</code> to add a <code>__symbols__</code> node in the
  resulting <code>.dtbo</code>. The <code>__symbols__</code> node contains a
  list of all nodes that are marked with a label, which the DTO library can use
  for references.</p>


  <p>Sample command to build main DT <code>.dts</code>:</p>

  <pre class="devsite-terminal">
dtc -@ -O dtb -o my_main_dt.dtb my_main_dt.dts
</pre>

  <p>Sample command to build the overlay 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>Note:</strong> If you encounter the DTC build error:
  <code>invalid option --'@'</code>, you might need to update your DTC version.
  Upstream of AOSP, the official DTC supports DTO as of <a href=
  "https://github.com/dgibson/dtc/tree/v1.4.4" class="external">version
  1.4.4</a> and most patches are merged after December 2016. For DTO support,
  we recommend using the <code><a href=
  "https://android.googlesource.com/platform/external/dtc/" class=
  "external">external/dtc</a></code> in AOSP, which is synced with the latest DTC
  (with DTO patches merged as needed).</aside>


  <h2 id="verify">Verify DTO results on the host</h2>


  <p>Verification can help you identify errors that might occur when placing
  the overlay DT on the main DT. Before updating the target, you can verify the
  result of overlaying DT on the host by simulating the behavior of DTO using
  <code>/include/</code> in <code>.dts</code>.</p>


  <aside class="note"><strong>Note:</strong> <code>/include/</code> does NOT
  support the use of <code>__overlay__</code> in overlay DT sources.</aside>


  <p><img src="../images/treble_dto_simulate.png">
  </p>


  <figcaption><strong>Figure 1.</strong> Use syntax <code>/include/</code> to simulate
  DTO on the host</figcaption>


  <ol>
    <li>Create a copy of the overlay <code>.dts</code>. In the copy, remove the
    first line header. Example:

      <pre>
/dts-v1/;
/plugin/;
</pre>Save the file as <code>my_overlay_dt_wo_header.dts</code> (or any
filename you want).
    </li>


    <li>Create a copy of the main <code>.dts</code>. In the copy, after the
    last line, append the include syntax for the file you created in step 1.
    For example:

      <pre>
/include/ "my_overlay_dt_wo_header.dts"
</pre>Save the file as <code>my_main_dt_with_include.dts</code> (or any
filename you want).
    </li>


    <li>Use <code>dtc</code> to compile
    <code>my_main_dt_with_include.dts</code> to get the merged DT, which should
    be the same result as DTO. For example:

      <pre class="devsite-terminal">
dtc -@ -O dtb -o my_merged_dt.dtb my_main_dt_with_include.dts
</pre>
    </li>


    <li>Use <code>dtc</code> to dump <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">Verifying DTO in Android {{ androidPVersionNumber }}</h2>


  <p>Android {{ androidPVersionNumber}} requires a Device Tree Blob Overlay
  (DTBO) partition. To add nodes or make changes to the properties in the SoC
  DT, the bootloader must dynamically overlay a device specific DT over
  the SoC DT.</p>


  <h3 id="indicating-applied-overlays">Indicating applied overlays</h3>


  <p>To enable the <a href="/compatibility/vts/">
  Vendor Test Suite (VTS)</a> to assess the correctness of overlay
  application, vendors must add a new kernel command line parameter
  <code>androidboot.dtbo_idx</code> that indicates the overlays selected from
  the DTBO partition. For example, the parameter <code>androidboot.
  dtbo_idx=x,y,z</code> reports <code>x</code>, <code>y</code> and
  <code>z</code> as the zero-based indices of the Device Tree Overlays (DTOs)
  from the DTBO partition applied (in that order) by the bootloader to the base
  Device Tree (DT).</p>


  <p>Overlays can apply to nodes from the main device tree or add new nodes,
  but <strong>cannot</strong> refer to a node added in a previous overlay. This
  restriction is necessary because the overlay application does not merge the
  overlay symbol table with the main DT symbol table (not merging avoids
  conflicts in symbol names and complication of dependencies between
  overlays).</p>


  <h4 id="example-invalid-overlays">Example: Invalid overlays</h4>


  <p>In this example, <code>overlay_2.dts</code> refers to node
  <strong><code>e</code></strong> , which was added by
  <code>overlay_1.dts</code>. After <code>overlay_1</code> is applied to the
  main DT, if an attempt is made to apply <code>overlay_2</code> to the
  resultant DT, the overlay application will fail with an error that the symbol
  <strong><code>e</code></strong> is not present in the symbol table for the
  base DT.</p>


  <table>
    <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/;

&amp;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">&amp;e</font> {
    prop = <0x0b>;
};
</pre>
      </td>
    </tr>
  </table>


  <h4 id="example-valid-overlays">Example: Valid overlays</h4>


  <p>In this example, <code>overlay_2.dts</code> refers only to node
  <strong><code>b</code></strong> from the main DTS. When
  <code>overlay_1</code> is applied to the base DT, then followed by the
  application of <code>overlay_2</code>, the value of property
  <strong><code>prop</code></strong> in node <strong><code>e</code></strong>
  (set by <code>overlay_1.dts</code>) is overwritten by the value set by
  <code>overlay_2.dts</code>.</p>


  <table>
    <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/;


&amp;b { ref1 =  <&a>;
     e {
          prop = <0x0c>;
      };
};
</pre>
        </td>

      <td>
      <pre>
<strong>[overlay_2.dts]</strong>

/dts-v1/;
/plugin/;

/* valid */
<font color="blue">&amp;b</font> { ref1 =  <&c>;
     e {
          prop = <0x0d>;
      };
};
</pre>
      </td>
    </tr>
  </table>


  <h3 id="implementing-the-dtbo-partition">Implementing the DTBO partition</h3>


  <p>To implement the required DTBO partition, ensure the bootloader can do the
  following:</p>


  <ol>
    <li>Identify the board it is running on and select the corresponding
    overlay(s) to be applied.</li>


    <li>Append the <code>androidboot.dtbo_idx</code> parameter to the kernel
    command line.

      <ul>
        <li>The parameter must indicate, the zero-based indices of the DTOs
        from the DTBO partition image it applied to the base DT (in the same
        order).</li>


        <li>The indices must refer to the position of the overlay in the DTBO
        partition.</li>
      </ul>
    </li>
  </ol>


  <p>For details on the structure of the DTBO partition, refer to <a href=
  "https://source.android.com/devices/architecture/dto/">Device Tree
  Overlays</a> on source.android.com.</p>


  <h3 id="validating-the-dtbo-partition">Validating the DTBO partition</h3>


  <p>You can use VTS to verify the following:</p>


  <ul>
    <li>Existence of the kernel command line parameter
    <code>androidboot.dtbo_idx</code> (by checking that <code>Init</code> has
    automatically set up the corresponding <code>ro.boot.dtbo_idx</code> system
    property).</li>


    <li>Validity of the <code>ro.boot.dtbo_idx</code> system property (by
    checking that the property specifies at least one valid DTBO image
    index).</li>


    <li>Validity of the DTBO partition (also verifies the overlays in the DTBO
    partition that are applied to the base DT).</li>


    <li>Additional nodes or property changes in the resulting DT are presented
    to the Linux kernel.</li>
  </ul>


  <p>For example, in the following overlays and final DT, adding
  <code>androidboot.dtbo_idx=5,3</code> to the kernel command line passes
  validation but adding <code>androidboot.dtbo_idx=3,5</code> to the kernel
  command line does not pass validation.</p>


  <table>
    <tr>
      <th width="50%">Overlay DT at index 3</th>


      <th>Overlay DT at index 5</th>

<tr>
<td>
<pre>
<strong>[overlay_1.dts]</strong>

/dts-v1/;
/plugin/;

&amp;c <strong>{ prop = <0xfe>; }</strong>;
</pre>
      </td>

      <td>
      <pre>
<strong>[overlay_2.dts]</strong>

/dts-v1/;
/plugin/;

&amp;c { prop = <0xff>; };
</pre>
        </td>
    </tr>

<table>
    <tr>
   <th>Final DT</th>

   <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";
	};
};

  </table>
</body>
</html>