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