1 Device Tree Compiler Manual
2 ===========================
4 I - "dtc", the device tree compiler
6 1.1) Submitting Patches
12 4.3) Labels and References
14 II - The DT block format
16 2) Device tree generalities
17 3) Device tree "structure" block
18 4) Device tree "strings" block
24 1) convert-dtsv0 -- Conversion to Version 1
28 I - "dtc", the device tree compiler
29 ===================================
33 Source code for the Device Tree Compiler can be found at jdl.com.
34 The gitweb interface is:
36 http://git.jdl.com/gitweb/
38 The repository is here:
40 git://www.jdl.com/software/dtc.git
41 http://www.jdl.com/software/dtc.git
43 Tarballs of the 1.0.0 and latest releases are here:
45 http://www.jdl.com/software/dtc-v1.2.0.tgz
46 http://www.jdl.com/software/dtc-latest.tgz
48 1.1) Submitting Patches
50 Patches should be sent to jdl@jdl.com, and CC'ed to
51 devicetree-discuss@lists.ozlabs.org.
55 The Device Tree Compiler, dtc, takes as input a device-tree in
56 a given format and outputs a device-tree in another format.
57 Typically, the input format is "dts", a human readable source
58 format, and creates a "dtb", or binary format as output.
60 The currently supported Input Formats are:
62 - "dtb": "blob" format. A flattened device-tree block with
63 header in one binary blob.
65 - "dts": "source" format. A text file containing a "source"
68 - "fs" format. A representation equivalent to the output of
69 /proc/device-tree where nodes are directories and
72 The currently supported Output Formats are:
74 - "dtb": "blob" format
76 - "dts": "source" format
78 - "asm": assembly language file. A file that can be sourced
79 by gas to generate a device-tree "blob". That file can
80 then simply be added to your Makefile. Additionally, the
81 assembly file exports some symbols that can be used.
86 The syntax of the dtc command line is:
88 dtc [options] [<input_filename>]
93 The name of the input source file. If no <input_filename>
94 or "-" is given, stdin is used.
97 Set the physical boot cpu.
100 Force. Try to produce output even if the input tree has errors.
103 Emit a brief usage and help message.
106 The source input format, as listed above.
109 The name of the generated output file. Use "-" for stdout.
112 The generated output format, as listed above.
114 -d <dependency_filename>
115 Generate a dependency file during compilation.
118 Quiet: -q suppress warnings, -qq errors, -qqq all
121 Make space for <number> reserve map entries
122 Relevant for dtb and asm output only.
125 Ensure the blob at least <bytes> long, adding additional
129 Print DTC version and exit.
132 Generate output conforming to the given <output_version>.
133 By default the most recent version is generated.
134 Relevant for dtb and asm output only.
137 The <output_version> defines what version of the "blob" format will be
138 generated. Supported versions are 1, 2, 3, 16 and 17. The default is
139 always the most recent version and is likely the highest number.
141 Additionally, dtc performs various sanity checks on the tree.
144 4) Device Tree Source file
148 Here is a very rough overview of the layout of a DTS source file:
151 sourcefile: list_of_memreserve devicetree
153 memreserve: label 'memreserve' ADDR ADDR ';'
154 | label 'memreserve' ADDR '-' ADDR ';'
156 devicetree: '/' nodedef
158 nodedef: '{' list_of_property list_of_subnode '}' ';'
160 property: label PROPNAME '=' propdata ';'
163 | '<' list_of_cells '>'
164 | '[' list_of_bytes ']'
166 subnode: label nodename nodedef
168 That structure forms a hierarchical layout of nodes and properties
169 rooted at an initial node as:
174 Both classic C style and C++ style comments are supported.
176 Source files may be directly included using the syntax:
183 Properties are named, possibly labeled, values. Each value
186 - A null-teminated C-like string,
187 - A numeric value fitting in 32 bits,
188 - A list of 32-bit values
191 Here are some example property definitions:
193 - A property containing a 0 terminated string
195 property1 = "string_value";
197 - A property containing a numerical 32-bit hexadecimal value
199 property2 = <1234abcd>;
201 - A property containing 3 numerical 32-bit hexadecimal values
203 property3 = <12345678 12345678 deadbeef>;
205 - A property whose content is an arbitrary array of bytes
207 property4 = [0a 0b 0c 0d de ea ad be ef];
210 Node may contain sub-nodes to obtain a hierarchical structure.
213 - A child node named "childnode" whose unit name is
214 "childnode at address". It it turn has a string property
218 childprop = "hello\n";
222 By default, all numeric values are hexadecimal. Alternate bases
223 may be specified using a prefix "d#" for decimal, "b#" for binary,
226 Strings support common escape sequences from C: "\n", "\t", "\r",
227 "\(octal value)", "\x(hex value)".
230 4.3) Labels and References
232 Labels may be applied to nodes or properties. Labels appear
233 before a node name, and are referenced using an ampersand: &label.
234 Absolute node path names are also allowed in node references.
236 In this exmaple, a node is labled "mpic" and then referenced:
238 mpic: interrupt-controller@40000 {
243 interrupt-parent = <&mpic>;
247 And used in properties, lables may appear before or after any value:
250 prop: string = data: "mystring\n" data_end: ;
256 II - The DT block format
257 ========================
259 This chapter defines the format of the flattened device-tree
260 passed to the kernel. The actual content of the device tree
261 are described in the kernel documentation in the file
263 linux-2.6/Documentation/powerpc/booting-without-of.txt
265 You can find example of code manipulating that format within
266 the kernel. For example, the file:
268 including arch/powerpc/kernel/prom_init.c
270 will generate a flattened device-tree from the Open Firmware
271 representation. Other utilities such as fs2dt, which is part of
272 the kexec tools, will generate one from a filesystem representation.
273 Some bootloaders such as U-Boot provide a bit more support by
274 using the libfdt code.
276 For booting the kernel, the device tree block has to be in main memory.
277 It has to be accessible in both real mode and virtual mode with no
278 mapping other than main memory. If you are writing a simple flash
279 bootloader, it should copy the block to RAM before passing it to
286 The kernel is entered with r3 pointing to an area of memory that is
287 roughly described in include/asm-powerpc/prom.h by the structure
290 struct boot_param_header {
291 u32 magic; /* magic word OF_DT_HEADER */
292 u32 totalsize; /* total size of DT block */
293 u32 off_dt_struct; /* offset to structure */
294 u32 off_dt_strings; /* offset to strings */
295 u32 off_mem_rsvmap; /* offset to memory reserve map */
296 u32 version; /* format version */
297 u32 last_comp_version; /* last compatible version */
299 /* version 2 fields below */
300 u32 boot_cpuid_phys; /* Which physical CPU id we're
302 /* version 3 fields below */
303 u32 size_dt_strings; /* size of the strings block */
305 /* version 17 fields below */
306 u32 size_dt_struct; /* size of the DT structure block */
309 Along with the constants:
311 /* Definitions used by the flattened device tree */
312 #define OF_DT_HEADER 0xd00dfeed /* 4: version,
314 #define OF_DT_BEGIN_NODE 0x1 /* Start node: full name
316 #define OF_DT_END_NODE 0x2 /* End node */
317 #define OF_DT_PROP 0x3 /* Property: name off,
319 #define OF_DT_END 0x9
321 All values in this header are in big endian format, the various
322 fields in this header are defined more precisely below. All "offset"
323 values are in bytes from the start of the header; that is from the
328 This is a magic value that "marks" the beginning of the
329 device-tree block header. It contains the value 0xd00dfeed and is
330 defined by the constant OF_DT_HEADER
334 This is the total size of the DT block including the header. The
335 "DT" block should enclose all data structures defined in this
336 chapter (who are pointed to by offsets in this header). That is,
337 the device-tree structure, strings, and the memory reserve map.
341 This is an offset from the beginning of the header to the start
342 of the "structure" part the device tree. (see 2) device tree)
346 This is an offset from the beginning of the header to the start
347 of the "strings" part of the device-tree
351 This is an offset from the beginning of the header to the start
352 of the reserved memory map. This map is a list of pairs of 64-
353 bit integers. Each pair is a physical address and a size. The
354 list is terminated by an entry of size 0. This map provides the
355 kernel with a list of physical memory areas that are "reserved"
356 and thus not to be used for memory allocations, especially during
357 early initialization. The kernel needs to allocate memory during
358 boot for things like un-flattening the device-tree, allocating an
359 MMU hash table, etc... Those allocations must be done in such a
360 way to avoid overriding critical things like, on Open Firmware
361 capable machines, the RTAS instance, or on some pSeries, the TCE
362 tables used for the iommu. Typically, the reserve map should
363 contain _at least_ this DT block itself (header,total_size). If
364 you are passing an initrd to the kernel, you should reserve it as
365 well. You do not need to reserve the kernel image itself. The map
366 should be 64-bit aligned.
370 This is the version of this structure. Version 1 stops
371 here. Version 2 adds an additional field boot_cpuid_phys.
372 Version 3 adds the size of the strings block, allowing the kernel
373 to reallocate it easily at boot and free up the unused flattened
374 structure after expansion. Version 16 introduces a new more
375 "compact" format for the tree itself that is however not backward
376 compatible. Version 17 adds an additional field, size_dt_struct,
377 allowing it to be reallocated or moved more easily (this is
378 particularly useful for bootloaders which need to make
379 adjustments to a device tree based on probed information). You
380 should always generate a structure of the highest version defined
381 at the time of your implementation. Currently that is version 17,
382 unless you explicitly aim at being backward compatible.
386 Last compatible version. This indicates down to what version of
387 the DT block you are backward compatible. For example, version 2
388 is backward compatible with version 1 (that is, a kernel build
389 for version 1 will be able to boot with a version 2 format). You
390 should put a 1 in this field if you generate a device tree of
391 version 1 to 3, or 16 if you generate a tree of version 16 or 17
392 using the new unit name format.
396 This field only exist on version 2 headers. It indicate which
397 physical CPU ID is calling the kernel entry point. This is used,
398 among others, by kexec. If you are on an SMP system, this value
399 should match the content of the "reg" property of the CPU node in
400 the device-tree corresponding to the CPU calling the kernel entry
401 point (see further chapters for more informations on the required
402 device-tree contents)
406 This field only exists on version 3 and later headers. It
407 gives the size of the "strings" section of the device tree (which
408 starts at the offset given by off_dt_strings).
412 This field only exists on version 17 and later headers. It gives
413 the size of the "structure" section of the device tree (which
414 starts at the offset given by off_dt_struct).
416 So the typical layout of a DT block (though the various parts don't
417 need to be in that order) looks like this (addresses go from top to
420 ------------------------------
421 r3 -> | struct boot_param_header |
422 ------------------------------
423 | (alignment gap) (*) |
424 ------------------------------
425 | memory reserve map |
426 ------------------------------
428 ------------------------------
430 | device-tree structure |
432 ------------------------------
434 ------------------------------
436 | device-tree strings |
438 -----> ------------------------------
443 (*) The alignment gaps are not necessarily present; their presence
444 and size are dependent on the various alignment requirements of
445 the individual data blocks.
448 2) Device tree generalities
449 ---------------------------
451 This device-tree itself is separated in two different blocks, a
452 structure block and a strings block. Both need to be aligned to a 4
455 First, let's quickly describe the device-tree concept before detailing
456 the storage format. This chapter does _not_ describe the detail of the
457 required types of nodes & properties for the kernel, this is done
458 later in chapter III.
460 The device-tree layout is strongly inherited from the definition of
461 the Open Firmware IEEE 1275 device-tree. It's basically a tree of
462 nodes, each node having two or more named properties. A property can
465 It is a tree, so each node has one and only one parent except for the
466 root node who has no parent.
468 A node has 2 names. The actual node name is generally contained in a
469 property of type "name" in the node property list whose value is a
470 zero terminated string and is mandatory for version 1 to 3 of the
471 format definition (as it is in Open Firmware). Version 16 makes it
472 optional as it can generate it from the unit name defined below.
474 There is also a "unit name" that is used to differentiate nodes with
475 the same name at the same level, it is usually made of the node
476 names, the "@" sign, and a "unit address", which definition is
477 specific to the bus type the node sits on.
479 The unit name doesn't exist as a property per-se but is included in
480 the device-tree structure. It is typically used to represent "path" in
481 the device-tree. More details about the actual format of these will be
484 The kernel powerpc generic code does not make any formal use of the
485 unit address (though some board support code may do) so the only real
486 requirement here for the unit address is to ensure uniqueness of
487 the node unit name at a given level of the tree. Nodes with no notion
488 of address and no possible sibling of the same name (like /memory or
489 /cpus) may omit the unit address in the context of this specification,
490 or use the "@0" default unit address. The unit name is used to define
491 a node "full path", which is the concatenation of all parent node
492 unit names separated with "/".
494 The root node doesn't have a defined name, and isn't required to have
495 a name property either if you are using version 3 or earlier of the
496 format. It also has no unit address (no @ symbol followed by a unit
497 address). The root node unit name is thus an empty string. The full
498 path to the root node is "/".
500 Every node which actually represents an actual device (that is, a node
501 which isn't only a virtual "container" for more nodes, like "/cpus"
502 is) is also required to have a "device_type" property indicating the
505 Finally, every node that can be referenced from a property in another
506 node is required to have a "linux,phandle" property. Real open
507 firmware implementations provide a unique "phandle" value for every
508 node that the "prom_init()" trampoline code turns into
509 "linux,phandle" properties. However, this is made optional if the
510 flattened device tree is used directly. An example of a node
511 referencing another node via "phandle" is when laying out the
512 interrupt tree which will be described in a further version of this
515 This "linux, phandle" property is a 32-bit value that uniquely
516 identifies a node. You are free to use whatever values or system of
517 values, internal pointers, or whatever to generate these, the only
518 requirement is that every node for which you provide that property has
519 a unique value for it.
521 Here is an example of a simple device-tree. In this example, an "o"
522 designates a node followed by the node unit name. Properties are
523 presented with their name followed by their content. "content"
524 represents an ASCII string (zero terminated) value, while <content>
525 represents a 32-bit hexadecimal value. The various nodes in this
526 example will be discussed in a later chapter. At this point, it is
527 only meant to give you a idea of what a device-tree looks like. I have
528 purposefully kept the "name" and "linux,phandle" properties which
529 aren't necessary in order to give you a better idea of what the tree
530 looks like in practice.
533 |- name = "device-tree"
534 |- model = "MyBoardName"
535 |- compatible = "MyBoardFamilyName"
536 |- #address-cells = <2>
538 |- linux,phandle = <0>
542 | | - linux,phandle = <1>
543 | | - #address-cells = <1>
544 | | - #size-cells = <0>
547 | |- name = "PowerPC,970"
548 | |- device_type = "cpu"
550 | |- clock-frequency = <5f5e1000>
552 | |- linux,phandle = <2>
556 | |- device_type = "memory"
557 | |- reg = <00000000 00000000 00000000 20000000>
558 | |- linux,phandle = <3>
562 |- bootargs = "root=/dev/sda2"
563 |- linux,phandle = <4>
565 This tree is almost a minimal tree. It pretty much contains the
566 minimal set of required nodes and properties to boot a linux kernel;
567 that is, some basic model informations at the root, the CPUs, and the
568 physical memory layout. It also includes misc information passed
569 through /chosen, like in this example, the platform type (mandatory)
570 and the kernel command line arguments (optional).
572 The /cpus/PowerPC,970@0/64-bit property is an example of a
573 property without a value. All other properties have a value. The
574 significance of the #address-cells and #size-cells properties will be
575 explained in chapter IV which defines precisely the required nodes and
576 properties and their content.
579 3) Device tree "structure" block
581 The structure of the device tree is a linearized tree structure. The
582 "OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
583 ends that node definition. Child nodes are simply defined before
584 "OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
585 bit value. The tree has to be "finished" with a OF_DT_END token
587 Here's the basic structure of a single node:
589 * token OF_DT_BEGIN_NODE (that is 0x00000001)
590 * for version 1 to 3, this is the node full path as a zero
591 terminated string, starting with "/". For version 16 and later,
592 this is the node unit name only (or an empty string for the
594 * [align gap to next 4 bytes boundary]
596 * token OF_DT_PROP (that is 0x00000003)
597 * 32-bit value of property value size in bytes (or 0 if no
599 * 32-bit value of offset in string block of property name
600 * property value data if any
601 * [align gap to next 4 bytes boundary]
602 * [child nodes if any]
603 * token OF_DT_END_NODE (that is 0x00000002)
605 So the node content can be summarized as a start token, a full path,
606 a list of properties, a list of child nodes, and an end token. Every
607 child node is a full node structure itself as defined above.
609 NOTE: The above definition requires that all property definitions for
610 a particular node MUST precede any subnode definitions for that node.
611 Although the structure would not be ambiguous if properties and
612 subnodes were intermingled, the kernel parser requires that the
613 properties come first (up until at least 2.6.22). Any tools
614 manipulating a flattened tree must take care to preserve this
617 4) Device tree "strings" block
619 In order to save space, property names, which are generally redundant,
620 are stored separately in the "strings" block. This block is simply the
621 whole bunch of zero terminated strings for all property names
622 concatenated together. The device-tree property definitions in the
623 structure block will contain offset values from the beginning of the
630 This library should be merged into dtc proper.
631 This library should likely be worked into U-Boot and the kernel.
637 1) convert-dtsv0 -- Conversion to Version 1
639 convert-dtsv0 is a small utility program which converts (DTS)
640 Device Tree Source from the obsolete version 0 to version 1.
642 Version 1 DTS files are marked by line "/dts-v1/;" at the top of the file.
644 The syntax of the convert-dtsv0 command line is:
646 convert-dtsv0 [<input_filename ... >]
648 Each file passed will be converted to the new /dts-v1/ version by creating
649 a new file with a "v1" appended the filename.
651 Comments, empty lines, etc. are preserved.
654 2) fdtdump -- Flat Device Tree dumping utility
656 The fdtdump program prints a readable version of a flat device tree file.
658 The syntax of the fdtdump command line is:
660 fdtdump <DTB-file-name>