blob: 634a10616fc071dd1aab0b227f77fbc28c4435ab [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassbbb0b122011-10-15 05:48:21 +00002#
3# Copyright (c) 2011 The Chromium OS Authors.
Simon Glassbbb0b122011-10-15 05:48:21 +00004
5Device Tree Control in U-Boot
6=============================
7
8This feature provides for run-time configuration of U-Boot via a flat
9device tree (fdt). U-Boot configuration has traditionally been done
10using CONFIG options in the board config file. This feature aims to
11make it possible for a single U-Boot binary to support multiple boards,
12with the exact configuration of each board controlled by a flat device
13tree (fdt). This is the approach recently taken by the ARM Linux kernel
14and has been used by PowerPC for some time.
15
16The fdt is a convenient vehicle for implementing run-time configuration
17for three reasons. Firstly it is easy to use, being a simple text file.
18It is extensible since it consists of nodes and properties in a nice
19hierarchical format.
20
21Finally, there is already excellent infrastructure for the fdt: a
22compiler checks the text file and converts it to a compact binary
23format, and a library is already available in U-Boot (libfdt) for
24handling this format.
25
26The dts directory contains a Makefile for building the device tree blob
27and embedding it in your U-Boot image. This is useful since it allows
28U-Boot to configure itself according to what it finds there. If you have
29a number of similar boards with different peripherals, you can describe
30the features of each board in the device tree file, and have a single
31generic source base.
32
33To enable this feature, add CONFIG_OF_CONTROL to your board config file.
34
35
36What is a Flat Device Tree?
37---------------------------
38
39An fdt can be specified in source format as a text file. To read about
40the fdt syntax, take a look at the specification here:
41
42https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
43
44You also might find this section of the Linux kernel documentation
45useful: (access this in the Linux kernel source code)
46
47 Documentation/devicetree/booting-without-of.txt
48
49There is also a mailing list:
50
51 http://lists.ozlabs.org/listinfo/devicetree-discuss
52
53In case you are wondering, OF stands for Open Firmware.
54
55
56Tools
57-----
58
59To use this feature you will need to get the device tree compiler here:
60
Jon Loeliger5f658262014-05-27 09:12:48 -050061 git://git.kernel.org/pub/scm/utils/dtc/dtc.git
Simon Glassbbb0b122011-10-15 05:48:21 +000062
63For example:
64
Jon Loeliger5f658262014-05-27 09:12:48 -050065 $ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
Simon Glassbbb0b122011-10-15 05:48:21 +000066 $ cd dtc
67 $ make
68 $ sudo make install
69
70Then run the compiler (your version will vary):
71
72 $ dtc -v
73 Version: DTC 1.2.0-g2cb4b51f
74 $ make tests
75 $ cd tests
76 $ ./run_tests.sh
77 ********** TEST SUMMARY
78 * Total testcases: 1371
79 * PASS: 1371
80 * FAIL: 0
81 * Bad configuration: 0
82 * Strange test result: 0
83
Simon Glass134a6512013-05-07 06:11:46 +000084You will also find a useful fdtdump utility for decoding a binary file, as
85well as fdtget/fdtput for reading and writing properties in a binary file.
Simon Glassbbb0b122011-10-15 05:48:21 +000086
87
88Where do I get an fdt file for my board?
89----------------------------------------
90
91You may find that the Linux kernel has a suitable file. Look in the
92kernel source in arch/<arch>/boot/dts.
93
94If not you might find other boards with suitable files that you can
95modify to your needs. Look in the board directories for files with a
96.dts extension.
97
98Failing that, you could write one from scratch yourself!
99
100
101Configuration
102-------------
103
104Use:
105
106#define CONFIG_DEFAULT_DEVICE_TREE "<name>"
107
108to set the filename of the device tree source. Then put your device tree
109file into
110
111 board/<vendor>/dts/<name>.dts
112
113This should include your CPU or SOC's device tree file, placed in
Stephen Warren06520282013-07-24 10:09:22 -0700114arch/<arch>/dts, and then make any adjustments required.
Simon Glassbbb0b122011-10-15 05:48:21 +0000115
116If CONFIG_OF_EMBED is defined, then it will be picked up and built into
Simon Glass63b4b5b2014-06-02 22:04:50 -0600117the U-Boot image (including u-boot.bin). This is suitable for debugging
118and development only and is not recommended for production devices.
Simon Glassbbb0b122011-10-15 05:48:21 +0000119
120If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
121a u-boot.dtb file alongside u-boot.bin. A common approach is then to
122join the two:
123
124 cat u-boot.bin u-boot.dtb >image.bin
125
Simon Glass63b4b5b2014-06-02 22:04:50 -0600126and then flash image.bin onto your board. Note that U-Boot creates
127u-boot-dtb.bin which does the above step for you also. If you are using
128CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
129tree binary.
Simon Glassbbb0b122011-10-15 05:48:21 +0000130
Alex Deymo82f766d2017-04-02 01:25:20 -0700131If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
132device tree at runtime, for example if an earlier bootloader stage creates
133it and passes it to U-Boot.
134
Simon Glassf828bf22013-04-20 08:42:41 +0000135If 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.
Simon Glassbbb0b122011-10-15 05:48:21 +0000140
Simon Glass63b4b5b2014-06-02 22:04:50 -0600141To use a device tree file that you have compiled yourself, pass
Simon Glassd18926a2014-06-12 07:24:43 -0600142EXT_DTB=<filename> to 'make', as in:
Simon Glass63b4b5b2014-06-02 22:04:50 -0600143
Simon Glassd18926a2014-06-12 07:24:43 -0600144 make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
Simon Glass63b4b5b2014-06-02 22:04:50 -0600145
146Then U-Boot will copy that file to u-boot.dtb, put it in the .img file
147if used, and u-boot-dtb.bin.
148
Simon Glasseea63e02011-10-24 19:15:34 +0000149If you wish to put the fdt at a different address in memory, you can
150define the "fdtcontroladdr" environment variable. This is the hex
151address of the fdt binary blob, and will override either of the options.
152Be aware that this environment variable is checked prior to relocation,
153when only the compiled-in environment is available. Therefore it is not
154possible to define this variable in the saved SPI/NAND flash
Thomas Chou545dfd12015-10-16 08:44:51 +0800155environment, for example (it will be ignored). After relocation, this
156variable will be set to the address of the newly relocated fdt blob.
157It is read-only and cannot be changed. It can optionally be used to
158control the boot process of Linux with bootm/bootz commands.
Simon Glasseea63e02011-10-24 19:15:34 +0000159
160To use this, put something like this in your board header file:
161
162#define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0"
163
Jagannadha Sutradharudu Teki74de8c92013-02-28 10:20:18 +0000164Build:
165
166After board configuration is done, fdt supported u-boot can be build in two ways:
1671) build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
168 $ make
1692) build the user specified dts file
170 $ make DEVICE_TREE=<dts-file-name>
171
Simon Glassbbb0b122011-10-15 05:48:21 +0000172
Simon Glassbbb0b122011-10-15 05:48:21 +0000173Limitations
174-----------
175
176U-Boot is designed to build with a single architecture type and CPU
177type. So for example it is not possible to build a single ARM binary
178which runs on your AT91 and OMAP boards, relying on an fdt to configure
179the various features. This is because you must select one of
180the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
181time. Similarly you cannot build for multiple cpu types or
182architectures.
183
184That said the complexity reduction by using fdt to support variants of
185boards which use the same SOC / CPU can be substantial.
186
187It is important to understand that the fdt only selects options
188available in the platform / drivers. It cannot add new drivers (yet). So
189you must still have the CONFIG option to enable the driver. For example,
190you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
191but can use the fdt to specific the UART clock, peripheral address, etc.
192In very broad terms, the CONFIG options in general control *what* driver
193files are pulled in, and the fdt controls *how* those files work.
194
195--
196Simon Glass <sjg@chromium.org>
1971-Sep-11