1 Device Tree Compiler Manual
2 ===========================
4 I - "dtc", the device tree compiler
11 4.3) Labels and References
13 II - The DT block format
15 2) Device tree generalities
16 3) Device tree "structure" block
17 4) Device tree "strings" block
23 1) convert-dtsv0 -- Conversion to Version 1
27 I - "dtc", the device tree compiler
28 ===================================
32 Source code for the Device Tree Compiler can be found at jdl.com.
33 The gitweb interface is:
35 http://git.jdl.com/gitweb/
37 The repository is here:
39 git://www.jdl.com/software/dtc.git
40 http://www.jdl.com/software/dtc.git
42 Tarballs of the 1.0.0 and latest releases are here:
44 http://www.jdl.com/software/dtc-v1.2.0.tgz
45 http://www.jdl.com/software/dtc-latest.tgz
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.
55 The currently supported Input Formats are:
57 - "dtb": "blob" format. A flattened device-tree block with
58 header in one binary blob.
60 - "dts": "source" format. A text file containing a "source"
63 - "fs" format. A representation equivalent to the output of
64 /proc/device-tree where nodes are directories and
67 The currently supported Output Formats are:
69 - "dtb": "blob" format
71 - "dts": "source" format
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.
81 The syntax of the dtc command line is:
83 dtc [options] [<input_filename>]
88 The name of the input source file. If no <input_filename>
89 or "-" is given, stdin is used.
92 Set the physical boot cpu.
95 Force. Try to produce output even if the input tree has errors.
98 Emit a brief usage and help message.
101 The source input format, as listed above.
104 The name of the generated output file. Use "-" for stdout.
107 The generated output format, as listed above.
110 Quiet: -q suppress warnings, -qq errors, -qqq all
113 Make space for <number> reserve map entries
114 Relevant for dtb and asm output only.
117 Ensure the blob at least <bytes> long, adding additional
121 Print DTC version and exit.
124 Generate output conforming to the given <output_version>.
125 By default the most recent version is generated.
126 Relevant for dtb and asm output only.
129 The <output_version> defines what version of the "blob" format will be
130 generated. Supported versions are 1, 2, 3, 16 and 17. The default is
131 always the most recent version and is likely the highest number.
133 Additionally, dtc performs various sanity checks on the tree.
136 4) Device Tree Source file
140 Here is a very rough overview of the layout of a DTS source file:
143 sourcefile: list_of_memreserve devicetree
145 memreserve: label 'memreserve' ADDR ADDR ';'
146 | label 'memreserve' ADDR '-' ADDR ';'
148 devicetree: '/' nodedef
150 nodedef: '{' list_of_property list_of_subnode '}' ';'
152 property: label PROPNAME '=' propdata ';'
155 | '<' list_of_cells '>'
156 | '[' list_of_bytes ']'
158 subnode: label nodename nodedef
160 That structure forms a hierarchical layout of nodes and properties
161 rooted at an initial node as:
166 Both classic C style and C++ style comments are supported.
168 Source files may be directly included using the syntax:
175 Properties are named, possibly labeled, values. Each value
178 - A null-teminated C-like string,
179 - A numeric value fitting in 32 bits,
180 - A list of 32-bit values
183 Here are some example property definitions:
185 - A property containing a 0 terminated string
187 property1 = "string_value";
189 - A property containing a numerical 32-bit hexadecimal value
191 property2 = <1234abcd>;
193 - A property containing 3 numerical 32-bit hexadecimal values
195 property3 = <12345678 12345678 deadbeef>;
197 - A property whose content is an arbitrary array of bytes
199 property4 = [0a 0b 0c 0d de ea ad be ef];
202 Node may contain sub-nodes to obtain a hierarchical structure.
205 - A child node named "childnode" whose unit name is
206 "childnode at address". It it turn has a string property
210 childprop = "hello\n";
214 By default, all numeric values are hexadecimal. Alternate bases
215 may be specified using a prefix "d#" for decimal, "b#" for binary,
218 Strings support common escape sequences from C: "\n", "\t", "\r",
219 "\(octal value)", "\x(hex value)".
222 4.3) Labels and References
224 Labels may be applied to nodes or properties. Labels appear
225 before a node name, and are referenced using an ampersand: &label.
226 Absolute node path names are also allowed in node references.
228 In this exmaple, a node is labled "mpic" and then referenced:
230 mpic: interrupt-controller@40000 {
235 interrupt-parent = <&mpic>;
239 And used in properties, lables may appear before or after any value:
242 prop: string = data: "mystring\n" data_end: ;
248 II - The DT block format
249 ========================
251 This chapter defines the format of the flattened device-tree
252 passed to the kernel. The actual content of the device tree
253 are described in the kernel documentation in the file
255 linux-2.6/Documentation/powerpc/booting-without-of.txt
257 You can find example of code manipulating that format within
258 the kernel. For example, the file:
260 including arch/powerpc/kernel/prom_init.c
262 will generate a flattened device-tree from the Open Firmware
263 representation. Other utilities such as fs2dt, which is part of
264 the kexec tools, will generate one from a filesystem representation.
265 Some bootloaders such as U-Boot provide a bit more support by
266 using the libfdt code.
268 For booting the kernel, the device tree block has to be in main memory.
269 It has to be accessible in both real mode and virtual mode with no
270 mapping other than main memory. If you are writing a simple flash
271 bootloader, it should copy the block to RAM before passing it to
278 The kernel is entered with r3 pointing to an area of memory that is
279 roughly described in include/asm-powerpc/prom.h by the structure
282 struct boot_param_header {
283 u32 magic; /* magic word OF_DT_HEADER */
284 u32 totalsize; /* total size of DT block */
285 u32 off_dt_struct; /* offset to structure */
286 u32 off_dt_strings; /* offset to strings */
287 u32 off_mem_rsvmap; /* offset to memory reserve map */
288 u32 version; /* format version */
289 u32 last_comp_version; /* last compatible version */
291 /* version 2 fields below */
292 u32 boot_cpuid_phys; /* Which physical CPU id we're
294 /* version 3 fields below */
295 u32 size_dt_strings; /* size of the strings block */
297 /* version 17 fields below */
298 u32 size_dt_struct; /* size of the DT structure block */
301 Along with the constants:
303 /* Definitions used by the flattened device tree */
304 #define OF_DT_HEADER 0xd00dfeed /* 4: version,
306 #define OF_DT_BEGIN_NODE 0x1 /* Start node: full name
308 #define OF_DT_END_NODE 0x2 /* End node */
309 #define OF_DT_PROP 0x3 /* Property: name off,
311 #define OF_DT_END 0x9
313 All values in this header are in big endian format, the various
314 fields in this header are defined more precisely below. All "offset"
315 values are in bytes from the start of the header; that is from the
320 This is a magic value that "marks" the beginning of the
321 device-tree block header. It contains the value 0xd00dfeed and is
322 defined by the constant OF_DT_HEADER
326 This is the total size of the DT block including the header. The
327 "DT" block should enclose all data structures defined in this
328 chapter (who are pointed to by offsets in this header). That is,
329 the device-tree structure, strings, and the memory reserve map.
333 This is an offset from the beginning of the header to the start
334 of the "structure" part the device tree. (see 2) device tree)
338 This is an offset from the beginning of the header to the start
339 of the "strings" part of the device-tree
343 This is an offset from the beginning of the header to the start
344 of the reserved memory map. This map is a list of pairs of 64-
345 bit integers. Each pair is a physical address and a size. The
346 list is terminated by an entry of size 0. This map provides the
347 kernel with a list of physical memory areas that are "reserved"
348 and thus not to be used for memory allocations, especially during
349 early initialization. The kernel needs to allocate memory during
350 boot for things like un-flattening the device-tree, allocating an
351 MMU hash table, etc... Those allocations must be done in such a
352 way to avoid overriding critical things like, on Open Firmware
353 capable machines, the RTAS instance, or on some pSeries, the TCE
354 tables used for the iommu. Typically, the reserve map should
355 contain _at least_ this DT block itself (header,total_size). If
356 you are passing an initrd to the kernel, you should reserve it as
357 well. You do not need to reserve the kernel image itself. The map
358 should be 64-bit aligned.
362 This is the version of this structure. Version 1 stops
363 here. Version 2 adds an additional field boot_cpuid_phys.
364 Version 3 adds the size of the strings block, allowing the kernel
365 to reallocate it easily at boot and free up the unused flattened
366 structure after expansion. Version 16 introduces a new more
367 "compact" format for the tree itself that is however not backward
368 compatible. Version 17 adds an additional field, size_dt_struct,
369 allowing it to be reallocated or moved more easily (this is
370 particularly useful for bootloaders which need to make
371 adjustments to a device tree based on probed information). You
372 should always generate a structure of the highest version defined
373 at the time of your implementation. Currently that is version 17,
374 unless you explicitly aim at being backward compatible.
378 Last compatible version. This indicates down to what version of
379 the DT block you are backward compatible. For example, version 2
380 is backward compatible with version 1 (that is, a kernel build
381 for version 1 will be able to boot with a version 2 format). You
382 should put a 1 in this field if you generate a device tree of
383 version 1 to 3, or 16 if you generate a tree of version 16 or 17
384 using the new unit name format.
388 This field only exist on version 2 headers. It indicate which
389 physical CPU ID is calling the kernel entry point. This is used,
390 among others, by kexec. If you are on an SMP system, this value
391 should match the content of the "reg" property of the CPU node in
392 the device-tree corresponding to the CPU calling the kernel entry
393 point (see further chapters for more informations on the required
394 device-tree contents)
398 This field only exists on version 3 and later headers. It
399 gives the size of the "strings" section of the device tree (which
400 starts at the offset given by off_dt_strings).
404 This field only exists on version 17 and later headers. It gives
405 the size of the "structure" section of the device tree (which
406 starts at the offset given by off_dt_struct).
408 So the typical layout of a DT block (though the various parts don't
409 need to be in that order) looks like this (addresses go from top to
412 ------------------------------
413 r3 -> | struct boot_param_header |
414 ------------------------------
415 | (alignment gap) (*) |
416 ------------------------------
417 | memory reserve map |
418 ------------------------------
420 ------------------------------
422 | device-tree structure |
424 ------------------------------
426 ------------------------------
428 | device-tree strings |
430 -----> ------------------------------
435 (*) The alignment gaps are not necessarily present; their presence
436 and size are dependent on the various alignment requirements of
437 the individual data blocks.
440 2) Device tree generalities
441 ---------------------------
443 This device-tree itself is separated in two different blocks, a
444 structure block and a strings block. Both need to be aligned to a 4
447 First, let's quickly describe the device-tree concept before detailing
448 the storage format. This chapter does _not_ describe the detail of the
449 required types of nodes & properties for the kernel, this is done
450 later in chapter III.
452 The device-tree layout is strongly inherited from the definition of
453 the Open Firmware IEEE 1275 device-tree. It's basically a tree of
454 nodes, each node having two or more named properties. A property can
457 It is a tree, so each node has one and only one parent except for the
458 root node who has no parent.
460 A node has 2 names. The actual node name is generally contained in a
461 property of type "name" in the node property list whose value is a
462 zero terminated string and is mandatory for version 1 to 3 of the
463 format definition (as it is in Open Firmware). Version 16 makes it
464 optional as it can generate it from the unit name defined below.
466 There is also a "unit name" that is used to differentiate nodes with
467 the same name at the same level, it is usually made of the node
468 names, the "@" sign, and a "unit address", which definition is
469 specific to the bus type the node sits on.
471 The unit name doesn't exist as a property per-se but is included in
472 the device-tree structure. It is typically used to represent "path" in
473 the device-tree. More details about the actual format of these will be
476 The kernel powerpc generic code does not make any formal use of the
477 unit address (though some board support code may do) so the only real
478 requirement here for the unit address is to ensure uniqueness of
479 the node unit name at a given level of the tree. Nodes with no notion
480 of address and no possible sibling of the same name (like /memory or
481 /cpus) may omit the unit address in the context of this specification,
482 or use the "@0" default unit address. The unit name is used to define
483 a node "full path", which is the concatenation of all parent node
484 unit names separated with "/".
486 The root node doesn't have a defined name, and isn't required to have
487 a name property either if you are using version 3 or earlier of the
488 format. It also has no unit address (no @ symbol followed by a unit
489 address). The root node unit name is thus an empty string. The full
490 path to the root node is "/".
492 Every node which actually represents an actual device (that is, a node
493 which isn't only a virtual "container" for more nodes, like "/cpus"
494 is) is also required to have a "device_type" property indicating the
497 Finally, every node that can be referenced from a property in another
498 node is required to have a "linux,phandle" property. Real open
499 firmware implementations provide a unique "phandle" value for every
500 node that the "prom_init()" trampoline code turns into
501 "linux,phandle" properties. However, this is made optional if the
502 flattened device tree is used directly. An example of a node
503 referencing another node via "phandle" is when laying out the
504 interrupt tree which will be described in a further version of this
507 This "linux, phandle" property is a 32-bit value that uniquely
508 identifies a node. You are free to use whatever values or system of
509 values, internal pointers, or whatever to generate these, the only
510 requirement is that every node for which you provide that property has
511 a unique value for it.
513 Here is an example of a simple device-tree. In this example, an "o"
514 designates a node followed by the node unit name. Properties are
515 presented with their name followed by their content. "content"
516 represents an ASCII string (zero terminated) value, while <content>
517 represents a 32-bit hexadecimal value. The various nodes in this
518 example will be discussed in a later chapter. At this point, it is
519 only meant to give you a idea of what a device-tree looks like. I have
520 purposefully kept the "name" and "linux,phandle" properties which
521 aren't necessary in order to give you a better idea of what the tree
522 looks like in practice.
525 |- name = "device-tree"
526 |- model = "MyBoardName"
527 |- compatible = "MyBoardFamilyName"
528 |- #address-cells = <2>
530 |- linux,phandle = <0>
534 | | - linux,phandle = <1>
535 | | - #address-cells = <1>
536 | | - #size-cells = <0>
539 | |- name = "PowerPC,970"
540 | |- device_type = "cpu"
542 | |- clock-frequency = <5f5e1000>
544 | |- linux,phandle = <2>
548 | |- device_type = "memory"
549 | |- reg = <00000000 00000000 00000000 20000000>
550 | |- linux,phandle = <3>
554 |- bootargs = "root=/dev/sda2"
555 |- linux,phandle = <4>
557 This tree is almost a minimal tree. It pretty much contains the
558 minimal set of required nodes and properties to boot a linux kernel;
559 that is, some basic model informations at the root, the CPUs, and the
560 physical memory layout. It also includes misc information passed
561 through /chosen, like in this example, the platform type (mandatory)
562 and the kernel command line arguments (optional).
564 The /cpus/PowerPC,970@0/64-bit property is an example of a
565 property without a value. All other properties have a value. The
566 significance of the #address-cells and #size-cells properties will be
567 explained in chapter IV which defines precisely the required nodes and
568 properties and their content.
571 3) Device tree "structure" block
573 The structure of the device tree is a linearized tree structure. The
574 "OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
575 ends that node definition. Child nodes are simply defined before
576 "OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
577 bit value. The tree has to be "finished" with a OF_DT_END token
579 Here's the basic structure of a single node:
581 * token OF_DT_BEGIN_NODE (that is 0x00000001)
582 * for version 1 to 3, this is the node full path as a zero
583 terminated string, starting with "/". For version 16 and later,
584 this is the node unit name only (or an empty string for the
586 * [align gap to next 4 bytes boundary]
588 * token OF_DT_PROP (that is 0x00000003)
589 * 32-bit value of property value size in bytes (or 0 if no
591 * 32-bit value of offset in string block of property name
592 * property value data if any
593 * [align gap to next 4 bytes boundary]
594 * [child nodes if any]
595 * token OF_DT_END_NODE (that is 0x00000002)
597 So the node content can be summarized as a start token, a full path,
598 a list of properties, a list of child nodes, and an end token. Every
599 child node is a full node structure itself as defined above.
601 NOTE: The above definition requires that all property definitions for
602 a particular node MUST precede any subnode definitions for that node.
603 Although the structure would not be ambiguous if properties and
604 subnodes were intermingled, the kernel parser requires that the
605 properties come first (up until at least 2.6.22). Any tools
606 manipulating a flattened tree must take care to preserve this
609 4) Device tree "strings" block
611 In order to save space, property names, which are generally redundant,
612 are stored separately in the "strings" block. This block is simply the
613 whole bunch of zero terminated strings for all property names
614 concatenated together. The device-tree property definitions in the
615 structure block will contain offset values from the beginning of the
622 This library should be merged into dtc proper.
623 This library should likely be worked into U-Boot and the kernel.
629 1) convert-dtsv0 -- Conversion to Version 1
631 convert-dtsv0 is a small utility program which converts (DTS)
632 Device Tree Source from the obsolete version 0 to version 1.
634 Version 1 DTS files are marked by line "/dts-v1/;" at the top of the file.
636 The syntax of the convert-dtsv0 command line is:
638 convert-dtsv0 [<input_filename ... >]
640 Each file passed will be converted to the new /dts-v1/ version by creating
641 a new file with a "v1" appended the filename.
643 Comments, empty lines, etc. are preserved.
646 2) ftdump -- Flat Tree dumping utility
648 The ftdump program prints a readable version of a flat device tree file.
650 The syntax of the ftdump command line is:
652 ftdump <DTB-file-name>