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