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