xref: /openbmc/u-boot/doc/README.fdt-control (revision 64bd89e4)
1#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
4# SPDX-License-Identifier:	GPL-2.0+
5#
6
7Device Tree Control in U-Boot
8=============================
9
10This feature provides for run-time configuration of U-Boot via a flat
11device tree (fdt). U-Boot configuration has traditionally been done
12using CONFIG options in the board config file. This feature aims to
13make it possible for a single U-Boot binary to support multiple boards,
14with the exact configuration of each board controlled by a flat device
15tree (fdt). This is the approach recently taken by the ARM Linux kernel
16and has been used by PowerPC for some time.
17
18The fdt is a convenient vehicle for implementing run-time configuration
19for three reasons. Firstly it is easy to use, being a simple text file.
20It is extensible since it consists of nodes and properties in a nice
21hierarchical format.
22
23Finally, there is already excellent infrastructure for the fdt: a
24compiler checks the text file and converts it to a compact binary
25format, and a library is already available in U-Boot (libfdt) for
26handling this format.
27
28The dts directory contains a Makefile for building the device tree blob
29and embedding it in your U-Boot image. This is useful since it allows
30U-Boot to configure itself according to what it finds there. If you have
31a number of similar boards with different peripherals, you can describe
32the features of each board in the device tree file, and have a single
33generic source base.
34
35To enable this feature, add CONFIG_OF_CONTROL to your board config file.
36It is currently supported on ARM, x86 and Microblaze - other architectures
37will need to add code to their arch/xxx/lib/board.c file to locate the
38FDT. Alternatively you can enable generic board support on your board
39(with CONFIG_SYS_GENERIC_BOARD) if this is available (as it is for
40PowerPC). For ARM, Tegra and Exynos5 have device trees available for
41common devices.
42
43
44What is a Flat Device Tree?
45---------------------------
46
47An fdt can be specified in source format as a text file. To read about
48the fdt syntax, take a look at the specification here:
49
50https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
51
52You also might find this section of the Linux kernel documentation
53useful: (access this in the Linux kernel source code)
54
55	Documentation/devicetree/booting-without-of.txt
56
57There is also a mailing list:
58
59	http://lists.ozlabs.org/listinfo/devicetree-discuss
60
61In case you are wondering, OF stands for Open Firmware.
62
63
64Tools
65-----
66
67To use this feature you will need to get the device tree compiler here:
68
69	git://jdl.com/software/dtc.git
70
71For example:
72
73	$ git clone git://jdl.com/software/dtc.git
74	$ cd dtc
75	$ make
76	$ sudo make install
77
78Then run the compiler (your version will vary):
79
80	$ dtc -v
81	Version: DTC 1.2.0-g2cb4b51f
82	$ make tests
83	$ cd tests
84	$ ./run_tests.sh
85	********** TEST SUMMARY
86	*     Total testcases:	1371
87	*                PASS:	1371
88	*                FAIL:	0
89	*   Bad configuration:	0
90	* Strange test result:	0
91
92You will also find a useful fdtdump utility for decoding a binary file, as
93well as fdtget/fdtput for reading and writing properties in a binary file.
94
95
96Where do I get an fdt file for my board?
97----------------------------------------
98
99You may find that the Linux kernel has a suitable file. Look in the
100kernel source in arch/<arch>/boot/dts.
101
102If not you might find other boards with suitable files that you can
103modify to your needs. Look in the board directories for files with a
104.dts extension.
105
106Failing that, you could write one from scratch yourself!
107
108
109Configuration
110-------------
111
112Use:
113
114#define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
115
116to set the filename of the device tree source. Then put your device tree
117file into
118
119	board/<vendor>/dts/<name>.dts
120
121This should include your CPU or SOC's device tree file, placed in
122arch/<arch>/dts, and then make any adjustments required.
123
124If CONFIG_OF_EMBED is defined, then it will be picked up and built into
125the U-Boot image (including u-boot.bin).
126
127If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
128a u-boot.dtb file alongside u-boot.bin. A common approach is then to
129join the two:
130
131	cat u-boot.bin u-boot.dtb >image.bin
132
133and then flash image.bin onto your board.
134
135If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
136startup. This is only useful for sandbox. Use the -d flag to U-Boot to
137specify the file to read.
138
139You cannot use more than one of these options at the same time.
140
141If you wish to put the fdt at a different address in memory, you can
142define the "fdtcontroladdr" environment variable. This is the hex
143address of the fdt binary blob, and will override either of the options.
144Be aware that this environment variable is checked prior to relocation,
145when only the compiled-in environment is available. Therefore it is not
146possible to define this variable in the saved SPI/NAND flash
147environment, for example (it will be ignored).
148
149To use this, put something like this in your board header file:
150
151#define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
152
153Build:
154
155After board configuration is done, fdt supported u-boot can be build in two ways:
1561)  build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
157    $ make
1582)  build the user specified dts file
159    $ make DEVICE_TREE=<dts-file-name>
160
161
162Limitations
163-----------
164
165U-Boot is designed to build with a single architecture type and CPU
166type. So for example it is not possible to build a single ARM binary
167which runs on your AT91 and OMAP boards, relying on an fdt to configure
168the various features. This is because you must select one of
169the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
170time. Similarly you cannot build for multiple cpu types or
171architectures.
172
173That said the complexity reduction by using fdt to support variants of
174boards which use the same SOC / CPU can be substantial.
175
176It is important to understand that the fdt only selects options
177available in the platform / drivers. It cannot add new drivers (yet). So
178you must still have the CONFIG option to enable the driver. For example,
179you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
180but can use the fdt to specific the UART clock, peripheral address, etc.
181In very broad terms, the CONFIG options in general control *what* driver
182files are pulled in, and the fdt controls *how* those files work.
183
184--
185Simon Glass <sjg@chromium.org>
1861-Sep-11
187