]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/dtc/Documentation/manual.txt
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / dtc / Documentation / manual.txt
1 Device Tree Compiler Manual
2 ===========================
3
4 I - "dtc", the device tree compiler
5     1) Obtaining Sources
6     2) Description
7     3) Command Line
8     4) Source File
9     4.1) Overview
10     4.2) Properties
11     4.3) Labels and References
12
13 II - The DT block format
14     1) Header
15     2) Device tree generalities
16     3) Device tree "structure" block
17     4) Device tree "strings" block
18
19
20 III - libfdt
21
22 IV - Utility Tools
23     1) convert-dtsv0 -- Conversion to Version 1
24     1) fdtdump
25
26
27 I - "dtc", the device tree compiler
28 ===================================
29
30 1) Sources
31
32 Source code for the Device Tree Compiler can be found at jdl.com.
33 The gitweb interface is:
34
35     http://git.jdl.com/gitweb/
36
37 The repository is here:
38
39     git://www.jdl.com/software/dtc.git
40     http://www.jdl.com/software/dtc.git
41
42 Tarballs of the 1.0.0 and latest releases are here:
43
44     http://www.jdl.com/software/dtc-v1.2.0.tgz
45     http://www.jdl.com/software/dtc-latest.tgz
46
47
48 2) Description
49
50 The Device Tree Compiler, dtc, takes as input a device-tree in
51 a given format and outputs a device-tree in another format.
52 Typically, the input format is "dts", a human readable source
53 format, and creates a "dtb", or binary format as output.
54
55 The currently supported Input Formats are:
56
57     - "dtb": "blob" format.  A flattened device-tree block with
58         header in one binary blob.
59
60     - "dts": "source" format.  A text file containing a "source"
61         for a device-tree.
62
63     - "fs" format.  A representation equivalent to the output of
64         /proc/device-tree  where nodes are directories and
65         properties are files.
66
67 The currently supported Output Formats are:
68
69      - "dtb": "blob" format
70
71      - "dts": "source" format
72
73      - "asm": assembly language file.  A file that can be sourced
74         by gas to generate a device-tree "blob".  That file can
75         then simply be added to your Makefile.  Additionally, the
76         assembly file exports some symbols that can be used.
77
78
79 3) Command Line
80
81 The syntax of the dtc command line is:
82
83     dtc [options] [<input_filename>]
84
85 Options:
86
87     <input_filename>
88         The name of the input source file.  If no <input_filename>
89         or "-" is given, stdin is used.
90
91     -b <number>
92         Set the physical boot cpu.
93
94     -f
95         Force.  Try to produce output even if the input tree has errors.
96
97     -h
98         Emit a brief usage and help message.
99
100     -I <input_format>
101         The source input format, as listed above.
102
103     -o <output_filename>
104         The name of the generated output file.  Use "-" for stdout.
105
106     -O <output_format>
107         The generated output format, as listed above.
108
109     -d <dependency_filename>
110         Generate a dependency file during compilation.
111
112     -q
113         Quiet: -q suppress warnings, -qq errors, -qqq all
114
115     -R <number>
116         Make space for <number> reserve map entries
117         Relevant for dtb and asm output only.
118
119     -S <bytes>
120         Ensure the blob at least <bytes> long, adding additional
121         space if needed.
122
123     -v
124         Print DTC version and exit.
125
126     -V <output_version>
127         Generate output conforming to the given <output_version>.
128         By default the most recent version is generated.
129         Relevant for dtb and asm output only.
130
131
132 The <output_version> defines what version of the "blob" format will be
133 generated.  Supported versions are 1, 2, 3, 16 and 17.  The default is
134 always the most recent version and is likely the highest number.
135
136 Additionally, dtc performs various sanity checks on the tree.
137
138
139 4) Device Tree Source file
140
141 4.1) Overview
142
143 Here is a very rough overview of the layout of a DTS source file:
144
145
146     sourcefile:   list_of_memreserve devicetree
147
148     memreserve:   label 'memreserve' ADDR ADDR ';'
149                 | label 'memreserve' ADDR '-' ADDR ';'
150
151     devicetree:   '/' nodedef
152
153     nodedef:      '{' list_of_property list_of_subnode '}' ';'
154
155     property:     label PROPNAME '=' propdata ';'
156
157     propdata:     STRING
158                 | '<' list_of_cells '>'
159                 | '[' list_of_bytes ']'
160
161     subnode:      label nodename nodedef
162
163 That structure forms a hierarchical layout of nodes and properties
164 rooted at an initial node as:
165
166     / {
167     }
168
169 Both classic C style and C++ style comments are supported.
170
171 Source files may be directly included using the syntax:
172
173     /include/ "filename"
174
175
176 4.2) Properties
177
178 Properties are named, possibly labeled, values.  Each value
179 is one of:
180
181     - A null-teminated C-like string,
182     - A numeric value fitting in 32 bits,
183     - A list of 32-bit values
184     - A byte sequence
185
186 Here are some example property definitions:
187
188     - A property containing a 0 terminated string
189
190         property1 = "string_value";
191
192     - A property containing a numerical 32-bit hexadecimal value
193
194         property2 = <1234abcd>;
195
196     - A property containing 3 numerical 32-bit hexadecimal values
197
198         property3 = <12345678 12345678 deadbeef>;
199
200     - A property whose content is an arbitrary array of bytes
201
202         property4 = [0a 0b 0c 0d de ea ad be ef];
203
204
205 Node may contain sub-nodes to obtain a hierarchical structure.
206 For example:
207
208     - A child node named "childnode" whose unit name is
209       "childnode at address".  It it turn has a string property
210       called "childprop".
211
212         childnode@addresss {
213             childprop = "hello\n";
214         };
215
216
217 By default, all numeric values are hexadecimal.  Alternate bases
218 may be specified using a prefix "d#" for decimal, "b#" for binary,
219 and "o#" for octal.
220
221 Strings support common escape sequences from C: "\n", "\t", "\r",
222 "\(octal value)", "\x(hex value)".
223
224
225 4.3) Labels and References
226
227 Labels may be applied to nodes or properties.  Labels appear
228 before a node name, and are referenced using an ampersand: &label.
229 Absolute node path names are also allowed in node references.
230
231 In this exmaple, a node is labled "mpic" and then referenced:
232
233     mpic:  interrupt-controller@40000 {
234         ...
235     };
236
237     ethernet-phy@3 {
238         interrupt-parent = <&mpic>;
239         ...
240     };
241
242 And used in properties, lables may appear before or after any value:
243
244     randomnode {
245         prop: string = data: "mystring\n" data_end: ;
246         ...
247     };
248
249
250
251 II - The DT block format
252 ========================
253
254 This chapter defines the format of the flattened device-tree
255 passed to the kernel. The actual content of the device tree
256 are described in the kernel documentation in the file
257
258     linux-2.6/Documentation/powerpc/booting-without-of.txt
259
260 You can find example of code manipulating that format within
261 the kernel.  For example, the file:
262
263         including arch/powerpc/kernel/prom_init.c
264
265 will generate a flattened device-tree from the Open Firmware
266 representation.  Other utilities such as fs2dt, which is part of
267 the kexec tools, will generate one from a filesystem representation.
268 Some bootloaders such as U-Boot provide a bit more support by
269 using the libfdt code.
270
271 For booting the kernel, the device tree block has to be in main memory.
272 It has to be accessible in both real mode and virtual mode with no
273 mapping other than main memory.  If you are writing a simple flash
274 bootloader, it should copy the block to RAM before passing it to
275 the kernel.
276
277
278 1) Header
279 ---------
280
281 The kernel is entered with r3 pointing to an area of memory that is
282 roughly described in include/asm-powerpc/prom.h by the structure
283 boot_param_header:
284
285     struct boot_param_header {
286         u32     magic;                  /* magic word OF_DT_HEADER */
287         u32     totalsize;              /* total size of DT block */
288         u32     off_dt_struct;          /* offset to structure */
289         u32     off_dt_strings;         /* offset to strings */
290         u32     off_mem_rsvmap;         /* offset to memory reserve map */
291         u32     version;                /* format version */
292         u32     last_comp_version;      /* last compatible version */
293
294         /* version 2 fields below */
295         u32     boot_cpuid_phys;        /* Which physical CPU id we're
296                                            booting on */
297         /* version 3 fields below */
298         u32     size_dt_strings;        /* size of the strings block */
299
300         /* version 17 fields below */
301         u32     size_dt_struct;         /* size of the DT structure block */
302     };
303
304 Along with the constants:
305
306     /* Definitions used by the flattened device tree */
307     #define OF_DT_HEADER            0xd00dfeed      /* 4: version,
308                                                        4: total size */
309     #define OF_DT_BEGIN_NODE        0x1             /* Start node: full name
310                                                        */
311     #define OF_DT_END_NODE          0x2             /* End node */
312     #define OF_DT_PROP              0x3             /* Property: name off,
313                                                        size, content */
314     #define OF_DT_END               0x9
315
316 All values in this header are in big endian format, the various
317 fields in this header are defined more precisely below.  All "offset"
318 values are in bytes from the start of the header; that is from the
319 value of r3.
320
321    - magic
322
323      This is a magic value that "marks" the beginning of the
324      device-tree block header. It contains the value 0xd00dfeed and is
325      defined by the constant OF_DT_HEADER
326
327    - totalsize
328
329      This is the total size of the DT block including the header. The
330      "DT" block should enclose all data structures defined in this
331      chapter (who are pointed to by offsets in this header). That is,
332      the device-tree structure, strings, and the memory reserve map.
333
334    - off_dt_struct
335
336      This is an offset from the beginning of the header to the start
337      of the "structure" part the device tree. (see 2) device tree)
338
339    - off_dt_strings
340
341      This is an offset from the beginning of the header to the start
342      of the "strings" part of the device-tree
343
344    - off_mem_rsvmap
345
346      This is an offset from the beginning of the header to the start
347      of the reserved memory map. This map is a list of pairs of 64-
348      bit integers. Each pair is a physical address and a size. The
349      list is terminated by an entry of size 0. This map provides the
350      kernel with a list of physical memory areas that are "reserved"
351      and thus not to be used for memory allocations, especially during
352      early initialization. The kernel needs to allocate memory during
353      boot for things like un-flattening the device-tree, allocating an
354      MMU hash table, etc... Those allocations must be done in such a
355      way to avoid overriding critical things like, on Open Firmware
356      capable machines, the RTAS instance, or on some pSeries, the TCE
357      tables used for the iommu. Typically, the reserve map should
358      contain _at least_ this DT block itself (header,total_size). If
359      you are passing an initrd to the kernel, you should reserve it as
360      well. You do not need to reserve the kernel image itself. The map
361      should be 64-bit aligned.
362
363    - version
364
365      This is the version of this structure. Version 1 stops
366      here. Version 2 adds an additional field boot_cpuid_phys.
367      Version 3 adds the size of the strings block, allowing the kernel
368      to reallocate it easily at boot and free up the unused flattened
369      structure after expansion. Version 16 introduces a new more
370      "compact" format for the tree itself that is however not backward
371      compatible. Version 17 adds an additional field, size_dt_struct,
372      allowing it to be reallocated or moved more easily (this is
373      particularly useful for bootloaders which need to make
374      adjustments to a device tree based on probed information). You
375      should always generate a structure of the highest version defined
376      at the time of your implementation. Currently that is version 17,
377      unless you explicitly aim at being backward compatible.
378
379    - last_comp_version
380
381      Last compatible version. This indicates down to what version of
382      the DT block you are backward compatible. For example, version 2
383      is backward compatible with version 1 (that is, a kernel build
384      for version 1 will be able to boot with a version 2 format). You
385      should put a 1 in this field if you generate a device tree of
386      version 1 to 3, or 16 if you generate a tree of version 16 or 17
387      using the new unit name format.
388
389    - boot_cpuid_phys
390
391      This field only exist on version 2 headers. It indicate which
392      physical CPU ID is calling the kernel entry point. This is used,
393      among others, by kexec. If you are on an SMP system, this value
394      should match the content of the "reg" property of the CPU node in
395      the device-tree corresponding to the CPU calling the kernel entry
396      point (see further chapters for more informations on the required
397      device-tree contents)
398
399    - size_dt_strings
400
401      This field only exists on version 3 and later headers.  It
402      gives the size of the "strings" section of the device tree (which
403      starts at the offset given by off_dt_strings).
404
405    - size_dt_struct
406
407      This field only exists on version 17 and later headers.  It gives
408      the size of the "structure" section of the device tree (which
409      starts at the offset given by off_dt_struct).
410
411 So the typical layout of a DT block (though the various parts don't
412 need to be in that order) looks like this (addresses go from top to
413 bottom):
414
415              ------------------------------
416        r3 -> |  struct boot_param_header  |
417              ------------------------------
418              |      (alignment gap) (*)   |
419              ------------------------------
420              |      memory reserve map    |
421              ------------------------------
422              |      (alignment gap)       |
423              ------------------------------
424              |                            |
425              |    device-tree structure   |
426              |                            |
427              ------------------------------
428              |      (alignment gap)       |
429              ------------------------------
430              |                            |
431              |     device-tree strings    |
432              |                            |
433       -----> ------------------------------
434       |
435       |
436       --- (r3 + totalsize)
437
438   (*) The alignment gaps are not necessarily present; their presence
439       and size are dependent on the various alignment requirements of
440       the individual data blocks.
441
442
443 2) Device tree generalities
444 ---------------------------
445
446 This device-tree itself is separated in two different blocks, a
447 structure block and a strings block. Both need to be aligned to a 4
448 byte boundary.
449
450 First, let's quickly describe the device-tree concept before detailing
451 the storage format. This chapter does _not_ describe the detail of the
452 required types of nodes & properties for the kernel, this is done
453 later in chapter III.
454
455 The device-tree layout is strongly inherited from the definition of
456 the Open Firmware IEEE 1275 device-tree. It's basically a tree of
457 nodes, each node having two or more named properties. A property can
458 have a value or not.
459
460 It is a tree, so each node has one and only one parent except for the
461 root node who has no parent.
462
463 A node has 2 names. The actual node name is generally contained in a
464 property of type "name" in the node property list whose value is a
465 zero terminated string and is mandatory for version 1 to 3 of the
466 format definition (as it is in Open Firmware). Version 16 makes it
467 optional as it can generate it from the unit name defined below.
468
469 There is also a "unit name" that is used to differentiate nodes with
470 the same name at the same level, it is usually made of the node
471 names, the "@" sign, and a "unit address", which definition is
472 specific to the bus type the node sits on.
473
474 The unit name doesn't exist as a property per-se but is included in
475 the device-tree structure. It is typically used to represent "path" in
476 the device-tree. More details about the actual format of these will be
477 below.
478
479 The kernel powerpc generic code does not make any formal use of the
480 unit address (though some board support code may do) so the only real
481 requirement here for the unit address is to ensure uniqueness of
482 the node unit name at a given level of the tree. Nodes with no notion
483 of address and no possible sibling of the same name (like /memory or
484 /cpus) may omit the unit address in the context of this specification,
485 or use the "@0" default unit address. The unit name is used to define
486 a node "full path", which is the concatenation of all parent node
487 unit names separated with "/".
488
489 The root node doesn't have a defined name, and isn't required to have
490 a name property either if you are using version 3 or earlier of the
491 format. It also has no unit address (no @ symbol followed by a unit
492 address). The root node unit name is thus an empty string. The full
493 path to the root node is "/".
494
495 Every node which actually represents an actual device (that is, a node
496 which isn't only a virtual "container" for more nodes, like "/cpus"
497 is) is also required to have a "device_type" property indicating the
498 type of node .
499
500 Finally, every node that can be referenced from a property in another
501 node is required to have a "linux,phandle" property. Real open
502 firmware implementations provide a unique "phandle" value for every
503 node that the "prom_init()" trampoline code turns into
504 "linux,phandle" properties. However, this is made optional if the
505 flattened device tree is used directly. An example of a node
506 referencing another node via "phandle" is when laying out the
507 interrupt tree which will be described in a further version of this
508 document.
509
510 This "linux, phandle" property is a 32-bit value that uniquely
511 identifies a node. You are free to use whatever values or system of
512 values, internal pointers, or whatever to generate these, the only
513 requirement is that every node for which you provide that property has
514 a unique value for it.
515
516 Here is an example of a simple device-tree. In this example, an "o"
517 designates a node followed by the node unit name. Properties are
518 presented with their name followed by their content. "content"
519 represents an ASCII string (zero terminated) value, while <content>
520 represents a 32-bit hexadecimal value. The various nodes in this
521 example will be discussed in a later chapter. At this point, it is
522 only meant to give you a idea of what a device-tree looks like. I have
523 purposefully kept the "name" and "linux,phandle" properties which
524 aren't necessary in order to give you a better idea of what the tree
525 looks like in practice.
526
527   / o device-tree
528       |- name = "device-tree"
529       |- model = "MyBoardName"
530       |- compatible = "MyBoardFamilyName"
531       |- #address-cells = <2>
532       |- #size-cells = <2>
533       |- linux,phandle = <0>
534       |
535       o cpus
536       | | - name = "cpus"
537       | | - linux,phandle = <1>
538       | | - #address-cells = <1>
539       | | - #size-cells = <0>
540       | |
541       | o PowerPC,970@0
542       |   |- name = "PowerPC,970"
543       |   |- device_type = "cpu"
544       |   |- reg = <0>
545       |   |- clock-frequency = <5f5e1000>
546       |   |- 64-bit
547       |   |- linux,phandle = <2>
548       |
549       o memory@0
550       | |- name = "memory"
551       | |- device_type = "memory"
552       | |- reg = <00000000 00000000 00000000 20000000>
553       | |- linux,phandle = <3>
554       |
555       o chosen
556         |- name = "chosen"
557         |- bootargs = "root=/dev/sda2"
558         |- linux,phandle = <4>
559
560 This tree is almost a minimal tree. It pretty much contains the
561 minimal set of required nodes and properties to boot a linux kernel;
562 that is, some basic model informations at the root, the CPUs, and the
563 physical memory layout.  It also includes misc information passed
564 through /chosen, like in this example, the platform type (mandatory)
565 and the kernel command line arguments (optional).
566
567 The /cpus/PowerPC,970@0/64-bit property is an example of a
568 property without a value. All other properties have a value. The
569 significance of the #address-cells and #size-cells properties will be
570 explained in chapter IV which defines precisely the required nodes and
571 properties and their content.
572
573
574 3) Device tree "structure" block
575
576 The structure of the device tree is a linearized tree structure. The
577 "OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
578 ends that node definition. Child nodes are simply defined before
579 "OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
580 bit value. The tree has to be "finished" with a OF_DT_END token
581
582 Here's the basic structure of a single node:
583
584      * token OF_DT_BEGIN_NODE (that is 0x00000001)
585      * for version 1 to 3, this is the node full path as a zero
586        terminated string, starting with "/". For version 16 and later,
587        this is the node unit name only (or an empty string for the
588        root node)
589      * [align gap to next 4 bytes boundary]
590      * for each property:
591         * token OF_DT_PROP (that is 0x00000003)
592         * 32-bit value of property value size in bytes (or 0 if no
593           value)
594         * 32-bit value of offset in string block of property name
595         * property value data if any
596         * [align gap to next 4 bytes boundary]
597      * [child nodes if any]
598      * token OF_DT_END_NODE (that is 0x00000002)
599
600 So the node content can be summarized as a start token, a full path,
601 a list of properties, a list of child nodes, and an end token. Every
602 child node is a full node structure itself as defined above.
603
604 NOTE: The above definition requires that all property definitions for
605 a particular node MUST precede any subnode definitions for that node.
606 Although the structure would not be ambiguous if properties and
607 subnodes were intermingled, the kernel parser requires that the
608 properties come first (up until at least 2.6.22).  Any tools
609 manipulating a flattened tree must take care to preserve this
610 constraint.
611
612 4) Device tree "strings" block
613
614 In order to save space, property names, which are generally redundant,
615 are stored separately in the "strings" block. This block is simply the
616 whole bunch of zero terminated strings for all property names
617 concatenated together. The device-tree property definitions in the
618 structure block will contain offset values from the beginning of the
619 strings block.
620
621
622 III - libfdt
623 ============
624
625 This library should be merged into dtc proper.
626 This library should likely be worked into U-Boot and the kernel.
627
628
629 IV - Utility Tools
630 ==================
631
632 1) convert-dtsv0 -- Conversion to Version 1
633
634 convert-dtsv0 is a small utility program which converts (DTS)
635 Device Tree Source from the obsolete version 0 to version 1.
636
637 Version 1 DTS files are marked by line "/dts-v1/;" at the top of the file.
638
639 The syntax of the convert-dtsv0 command line is:
640
641     convert-dtsv0 [<input_filename ... >]
642
643 Each file passed will be converted to the new /dts-v1/ version by creating
644 a new file with a "v1" appended the filename.
645
646 Comments, empty lines, etc. are preserved.
647
648
649 2) fdtdump -- Flat Device Tree dumping utility
650
651 The fdtdump program prints a readable version of a flat device tree file.
652
653 The syntax of the fdtdump command line is:
654
655     fdtdump <DTB-file-name>