Add qemu 2.4.0
[kvmfornfv.git] / qemu / dtc / Documentation / manual.txt
1 Device Tree Compiler Manual
2 ===========================
3
4 I - "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
14 II - 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
21 III - libfdt
22
23 IV - Utility Tools
24     1) convert-dtsv0 -- Conversion to Version 1
25     1) fdtdump
26
27
28 I - "dtc", the device tree compiler
29 ===================================
30
31 1) Sources
32
33 Source code for the Device Tree Compiler can be found at jdl.com.
34 The gitweb interface is:
35
36     http://git.jdl.com/gitweb/
37
38 The repository is here:
39
40     git://www.jdl.com/software/dtc.git
41     http://www.jdl.com/software/dtc.git
42
43 Tarballs of the 1.0.0 and latest releases are here:
44
45     http://www.jdl.com/software/dtc-v1.2.0.tgz
46     http://www.jdl.com/software/dtc-latest.tgz
47
48 1.1) Submitting Patches
49
50 Patches should be sent to jdl@jdl.com, and CC'ed to
51 devicetree-discuss@lists.ozlabs.org.
52
53 2) Description
54
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.
59
60 The currently supported Input Formats are:
61
62     - "dtb": "blob" format.  A flattened device-tree block with
63         header in one binary blob.
64
65     - "dts": "source" format.  A text file containing a "source"
66         for a device-tree.
67
68     - "fs" format.  A representation equivalent to the output of
69         /proc/device-tree  where nodes are directories and
70         properties are files.
71
72 The currently supported Output Formats are:
73
74      - "dtb": "blob" format
75
76      - "dts": "source" format
77
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.
82
83
84 3) Command Line
85
86 The syntax of the dtc command line is:
87
88     dtc [options] [<input_filename>]
89
90 Options:
91
92     <input_filename>
93         The name of the input source file.  If no <input_filename>
94         or "-" is given, stdin is used.
95
96     -b <number>
97         Set the physical boot cpu.
98
99     -f
100         Force.  Try to produce output even if the input tree has errors.
101
102     -h
103         Emit a brief usage and help message.
104
105     -I <input_format>
106         The source input format, as listed above.
107
108     -o <output_filename>
109         The name of the generated output file.  Use "-" for stdout.
110
111     -O <output_format>
112         The generated output format, as listed above.
113
114     -d <dependency_filename>
115         Generate a dependency file during compilation.
116
117     -q
118         Quiet: -q suppress warnings, -qq errors, -qqq all
119
120     -R <number>
121         Make space for <number> reserve map entries
122         Relevant for dtb and asm output only.
123
124     -S <bytes>
125         Ensure the blob at least <bytes> long, adding additional
126         space if needed.
127
128     -v
129         Print DTC version and exit.
130
131     -V <output_version>
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.
135
136
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.
140
141 Additionally, dtc performs various sanity checks on the tree.
142
143
144 4) Device Tree Source file
145
146 4.1) Overview
147
148 Here is a very rough overview of the layout of a DTS source file:
149
150
151     sourcefile:   list_of_memreserve devicetree
152
153     memreserve:   label 'memreserve' ADDR ADDR ';'
154                 | label 'memreserve' ADDR '-' ADDR ';'
155
156     devicetree:   '/' nodedef
157
158     nodedef:      '{' list_of_property list_of_subnode '}' ';'
159
160     property:     label PROPNAME '=' propdata ';'
161
162     propdata:     STRING
163                 | '<' list_of_cells '>'
164                 | '[' list_of_bytes ']'
165
166     subnode:      label nodename nodedef
167
168 That structure forms a hierarchical layout of nodes and properties
169 rooted at an initial node as:
170
171     / {
172     }
173
174 Both classic C style and C++ style comments are supported.
175
176 Source files may be directly included using the syntax:
177
178     /include/ "filename"
179
180
181 4.2) Properties
182
183 Properties are named, possibly labeled, values.  Each value
184 is one of:
185
186     - A null-teminated C-like string,
187     - A numeric value fitting in 32 bits,
188     - A list of 32-bit values
189     - A byte sequence
190
191 Here are some example property definitions:
192
193     - A property containing a 0 terminated string
194
195         property1 = "string_value";
196
197     - A property containing a numerical 32-bit hexadecimal value
198
199         property2 = <1234abcd>;
200
201     - A property containing 3 numerical 32-bit hexadecimal values
202
203         property3 = <12345678 12345678 deadbeef>;
204
205     - A property whose content is an arbitrary array of bytes
206
207         property4 = [0a 0b 0c 0d de ea ad be ef];
208
209
210 Node may contain sub-nodes to obtain a hierarchical structure.
211 For example:
212
213     - A child node named "childnode" whose unit name is
214       "childnode at address".  It it turn has a string property
215       called "childprop".
216
217         childnode@addresss {
218             childprop = "hello\n";
219         };
220
221
222 By default, all numeric values are hexadecimal.  Alternate bases
223 may be specified using a prefix "d#" for decimal, "b#" for binary,
224 and "o#" for octal.
225
226 Strings support common escape sequences from C: "\n", "\t", "\r",
227 "\(octal value)", "\x(hex value)".
228
229
230 4.3) Labels and References
231
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.
235
236 In this exmaple, a node is labled "mpic" and then referenced:
237
238     mpic:  interrupt-controller@40000 {
239         ...
240     };
241
242     ethernet-phy@3 {
243         interrupt-parent = <&mpic>;
244         ...
245     };
246
247 And used in properties, lables may appear before or after any value:
248
249     randomnode {
250         prop: string = data: "mystring\n" data_end: ;
251         ...
252     };
253
254
255
256 II - The DT block format
257 ========================
258
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
262
263     linux-2.6/Documentation/powerpc/booting-without-of.txt
264
265 You can find example of code manipulating that format within
266 the kernel.  For example, the file:
267
268         including arch/powerpc/kernel/prom_init.c
269
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.
275
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
280 the kernel.
281
282
283 1) Header
284 ---------
285
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
288 boot_param_header:
289
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 */
298
299         /* version 2 fields below */
300         u32     boot_cpuid_phys;        /* Which physical CPU id we're
301                                            booting on */
302         /* version 3 fields below */
303         u32     size_dt_strings;        /* size of the strings block */
304
305         /* version 17 fields below */
306         u32     size_dt_struct;         /* size of the DT structure block */
307     };
308
309 Along with the constants:
310
311     /* Definitions used by the flattened device tree */
312     #define OF_DT_HEADER            0xd00dfeed      /* 4: version,
313                                                        4: total size */
314     #define OF_DT_BEGIN_NODE        0x1             /* Start node: full name
315                                                        */
316     #define OF_DT_END_NODE          0x2             /* End node */
317     #define OF_DT_PROP              0x3             /* Property: name off,
318                                                        size, content */
319     #define OF_DT_END               0x9
320
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
324 value of r3.
325
326    - magic
327
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
331
332    - totalsize
333
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.
338
339    - off_dt_struct
340
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)
343
344    - off_dt_strings
345
346      This is an offset from the beginning of the header to the start
347      of the "strings" part of the device-tree
348
349    - off_mem_rsvmap
350
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.
367
368    - version
369
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.
383
384    - last_comp_version
385
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.
393
394    - boot_cpuid_phys
395
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)
403
404    - size_dt_strings
405
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).
409
410    - size_dt_struct
411
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).
415
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
418 bottom):
419
420              ------------------------------
421        r3 -> |  struct boot_param_header  |
422              ------------------------------
423              |      (alignment gap) (*)   |
424              ------------------------------
425              |      memory reserve map    |
426              ------------------------------
427              |      (alignment gap)       |
428              ------------------------------
429              |                            |
430              |    device-tree structure   |
431              |                            |
432              ------------------------------
433              |      (alignment gap)       |
434              ------------------------------
435              |                            |
436              |     device-tree strings    |
437              |                            |
438       -----> ------------------------------
439       |
440       |
441       --- (r3 + totalsize)
442
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.
446
447
448 2) Device tree generalities
449 ---------------------------
450
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
453 byte boundary.
454
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.
459
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
463 have a value or not.
464
465 It is a tree, so each node has one and only one parent except for the
466 root node who has no parent.
467
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.
473
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.
478
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
482 below.
483
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 "/".
493
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 "/".
499
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
503 type of node .
504
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
513 document.
514
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.
520
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.
531
532   / o device-tree
533       |- name = "device-tree"
534       |- model = "MyBoardName"
535       |- compatible = "MyBoardFamilyName"
536       |- #address-cells = <2>
537       |- #size-cells = <2>
538       |- linux,phandle = <0>
539       |
540       o cpus
541       | | - name = "cpus"
542       | | - linux,phandle = <1>
543       | | - #address-cells = <1>
544       | | - #size-cells = <0>
545       | |
546       | o PowerPC,970@0
547       |   |- name = "PowerPC,970"
548       |   |- device_type = "cpu"
549       |   |- reg = <0>
550       |   |- clock-frequency = <5f5e1000>
551       |   |- 64-bit
552       |   |- linux,phandle = <2>
553       |
554       o memory@0
555       | |- name = "memory"
556       | |- device_type = "memory"
557       | |- reg = <00000000 00000000 00000000 20000000>
558       | |- linux,phandle = <3>
559       |
560       o chosen
561         |- name = "chosen"
562         |- bootargs = "root=/dev/sda2"
563         |- linux,phandle = <4>
564
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).
571
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.
577
578
579 3) Device tree "structure" block
580
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
586
587 Here's the basic structure of a single node:
588
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
593        root node)
594      * [align gap to next 4 bytes boundary]
595      * for each property:
596         * token OF_DT_PROP (that is 0x00000003)
597         * 32-bit value of property value size in bytes (or 0 if no
598           value)
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)
604
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.
608
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
615 constraint.
616
617 4) Device tree "strings" block
618
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
624 strings block.
625
626
627 III - libfdt
628 ============
629
630 This library should be merged into dtc proper.
631 This library should likely be worked into U-Boot and the kernel.
632
633
634 IV - Utility Tools
635 ==================
636
637 1) convert-dtsv0 -- Conversion to Version 1
638
639 convert-dtsv0 is a small utility program which converts (DTS)
640 Device Tree Source from the obsolete version 0 to version 1.
641
642 Version 1 DTS files are marked by line "/dts-v1/;" at the top of the file.
643
644 The syntax of the convert-dtsv0 command line is:
645
646     convert-dtsv0 [<input_filename ... >]
647
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.
650
651 Comments, empty lines, etc. are preserved.
652
653
654 2) fdtdump -- Flat Device Tree dumping utility
655
656 The fdtdump program prints a readable version of a flat device tree file.
657
658 The syntax of the fdtdump command line is:
659
660     fdtdump <DTB-file-name>