xref: /openbmc/u-boot/doc/README.fdt-control (revision 63b4b5bae52e48528876e13e858ef934ac2e4a3b)
1bbb0b128SSimon Glass#
2bbb0b128SSimon Glass# Copyright (c) 2011 The Chromium OS Authors.
3bbb0b128SSimon Glass#
41a459660SWolfgang Denk# SPDX-License-Identifier:	GPL-2.0+
5bbb0b128SSimon Glass#
6bbb0b128SSimon Glass
7bbb0b128SSimon GlassDevice Tree Control in U-Boot
8bbb0b128SSimon Glass=============================
9bbb0b128SSimon Glass
10bbb0b128SSimon GlassThis feature provides for run-time configuration of U-Boot via a flat
11bbb0b128SSimon Glassdevice tree (fdt). U-Boot configuration has traditionally been done
12bbb0b128SSimon Glassusing CONFIG options in the board config file. This feature aims to
13bbb0b128SSimon Glassmake it possible for a single U-Boot binary to support multiple boards,
14bbb0b128SSimon Glasswith the exact configuration of each board controlled by a flat device
15bbb0b128SSimon Glasstree (fdt). This is the approach recently taken by the ARM Linux kernel
16bbb0b128SSimon Glassand has been used by PowerPC for some time.
17bbb0b128SSimon Glass
18bbb0b128SSimon GlassThe fdt is a convenient vehicle for implementing run-time configuration
19bbb0b128SSimon Glassfor three reasons. Firstly it is easy to use, being a simple text file.
20bbb0b128SSimon GlassIt is extensible since it consists of nodes and properties in a nice
21bbb0b128SSimon Glasshierarchical format.
22bbb0b128SSimon Glass
23bbb0b128SSimon GlassFinally, there is already excellent infrastructure for the fdt: a
24bbb0b128SSimon Glasscompiler checks the text file and converts it to a compact binary
25bbb0b128SSimon Glassformat, and a library is already available in U-Boot (libfdt) for
26bbb0b128SSimon Glasshandling this format.
27bbb0b128SSimon Glass
28bbb0b128SSimon GlassThe dts directory contains a Makefile for building the device tree blob
29bbb0b128SSimon Glassand embedding it in your U-Boot image. This is useful since it allows
30bbb0b128SSimon GlassU-Boot to configure itself according to what it finds there. If you have
31bbb0b128SSimon Glassa number of similar boards with different peripherals, you can describe
32bbb0b128SSimon Glassthe features of each board in the device tree file, and have a single
33bbb0b128SSimon Glassgeneric source base.
34bbb0b128SSimon Glass
35bbb0b128SSimon GlassTo enable this feature, add CONFIG_OF_CONTROL to your board config file.
36134a6512SSimon GlassIt is currently supported on ARM, x86 and Microblaze - other architectures
37134a6512SSimon Glasswill need to add code to their arch/xxx/lib/board.c file to locate the
38134a6512SSimon GlassFDT. Alternatively you can enable generic board support on your board
39134a6512SSimon Glass(with CONFIG_SYS_GENERIC_BOARD) if this is available (as it is for
40134a6512SSimon GlassPowerPC). For ARM, Tegra and Exynos5 have device trees available for
41134a6512SSimon Glasscommon devices.
42bbb0b128SSimon Glass
43bbb0b128SSimon Glass
44bbb0b128SSimon GlassWhat is a Flat Device Tree?
45bbb0b128SSimon Glass---------------------------
46bbb0b128SSimon Glass
47bbb0b128SSimon GlassAn fdt can be specified in source format as a text file. To read about
48bbb0b128SSimon Glassthe fdt syntax, take a look at the specification here:
49bbb0b128SSimon Glass
50bbb0b128SSimon Glasshttps://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
51bbb0b128SSimon Glass
52bbb0b128SSimon GlassYou also might find this section of the Linux kernel documentation
53bbb0b128SSimon Glassuseful: (access this in the Linux kernel source code)
54bbb0b128SSimon Glass
55bbb0b128SSimon Glass	Documentation/devicetree/booting-without-of.txt
56bbb0b128SSimon Glass
57bbb0b128SSimon GlassThere is also a mailing list:
58bbb0b128SSimon Glass
59bbb0b128SSimon Glass	http://lists.ozlabs.org/listinfo/devicetree-discuss
60bbb0b128SSimon Glass
61bbb0b128SSimon GlassIn case you are wondering, OF stands for Open Firmware.
62bbb0b128SSimon Glass
63bbb0b128SSimon Glass
64bbb0b128SSimon GlassTools
65bbb0b128SSimon Glass-----
66bbb0b128SSimon Glass
67bbb0b128SSimon GlassTo use this feature you will need to get the device tree compiler here:
68bbb0b128SSimon Glass
695f65826bSJon Loeliger	git://git.kernel.org/pub/scm/utils/dtc/dtc.git
70bbb0b128SSimon Glass
71bbb0b128SSimon GlassFor example:
72bbb0b128SSimon Glass
735f65826bSJon Loeliger	$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
74bbb0b128SSimon Glass	$ cd dtc
75bbb0b128SSimon Glass	$ make
76bbb0b128SSimon Glass	$ sudo make install
77bbb0b128SSimon Glass
78bbb0b128SSimon GlassThen run the compiler (your version will vary):
79bbb0b128SSimon Glass
80bbb0b128SSimon Glass	$ dtc -v
81bbb0b128SSimon Glass	Version: DTC 1.2.0-g2cb4b51f
82bbb0b128SSimon Glass	$ make tests
83bbb0b128SSimon Glass	$ cd tests
84bbb0b128SSimon Glass	$ ./run_tests.sh
85bbb0b128SSimon Glass	********** TEST SUMMARY
86bbb0b128SSimon Glass	*     Total testcases:	1371
87bbb0b128SSimon Glass	*                PASS:	1371
88bbb0b128SSimon Glass	*                FAIL:	0
89bbb0b128SSimon Glass	*   Bad configuration:	0
90bbb0b128SSimon Glass	* Strange test result:	0
91bbb0b128SSimon Glass
92134a6512SSimon GlassYou will also find a useful fdtdump utility for decoding a binary file, as
93134a6512SSimon Glasswell as fdtget/fdtput for reading and writing properties in a binary file.
94bbb0b128SSimon Glass
95bbb0b128SSimon Glass
96bbb0b128SSimon GlassWhere do I get an fdt file for my board?
97bbb0b128SSimon Glass----------------------------------------
98bbb0b128SSimon Glass
99bbb0b128SSimon GlassYou may find that the Linux kernel has a suitable file. Look in the
100bbb0b128SSimon Glasskernel source in arch/<arch>/boot/dts.
101bbb0b128SSimon Glass
102bbb0b128SSimon GlassIf not you might find other boards with suitable files that you can
103bbb0b128SSimon Glassmodify to your needs. Look in the board directories for files with a
104bbb0b128SSimon Glass.dts extension.
105bbb0b128SSimon Glass
106bbb0b128SSimon GlassFailing that, you could write one from scratch yourself!
107bbb0b128SSimon Glass
108bbb0b128SSimon Glass
109bbb0b128SSimon GlassConfiguration
110bbb0b128SSimon Glass-------------
111bbb0b128SSimon Glass
112bbb0b128SSimon GlassUse:
113bbb0b128SSimon Glass
114bbb0b128SSimon Glass#define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
115bbb0b128SSimon Glass
116bbb0b128SSimon Glassto set the filename of the device tree source. Then put your device tree
117bbb0b128SSimon Glassfile into
118bbb0b128SSimon Glass
119bbb0b128SSimon Glass	board/<vendor>/dts/<name>.dts
120bbb0b128SSimon Glass
121bbb0b128SSimon GlassThis should include your CPU or SOC's device tree file, placed in
12206520280SStephen Warrenarch/<arch>/dts, and then make any adjustments required.
123bbb0b128SSimon Glass
124bbb0b128SSimon GlassIf CONFIG_OF_EMBED is defined, then it will be picked up and built into
125*63b4b5baSSimon Glassthe U-Boot image (including u-boot.bin). This is suitable for debugging
126*63b4b5baSSimon Glassand development only and is not recommended for production devices.
127bbb0b128SSimon Glass
128bbb0b128SSimon GlassIf CONFIG_OF_SEPARATE is defined, then it will be built and placed in
129bbb0b128SSimon Glassa u-boot.dtb file alongside u-boot.bin. A common approach is then to
130bbb0b128SSimon Glassjoin the two:
131bbb0b128SSimon Glass
132bbb0b128SSimon Glass	cat u-boot.bin u-boot.dtb >image.bin
133bbb0b128SSimon Glass
134*63b4b5baSSimon Glassand then flash image.bin onto your board. Note that U-Boot creates
135*63b4b5baSSimon Glassu-boot-dtb.bin which does the above step for you also. If you are using
136*63b4b5baSSimon GlassCONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
137*63b4b5baSSimon Glasstree binary.
138bbb0b128SSimon Glass
139f828bf25SSimon GlassIf CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
140f828bf25SSimon Glassstartup. This is only useful for sandbox. Use the -d flag to U-Boot to
141f828bf25SSimon Glassspecify the file to read.
142f828bf25SSimon Glass
143f828bf25SSimon GlassYou cannot use more than one of these options at the same time.
144bbb0b128SSimon Glass
145*63b4b5baSSimon GlassTo use a device tree file that you have compiled yourself, pass
146*63b4b5baSSimon GlassDEV_TREE_BIN=<filename> to 'make', as in:
147*63b4b5baSSimon Glass
148*63b4b5baSSimon Glass	make DEV_TREE_BIN=boot/am335x-boneblack-pubkey.dtb
149*63b4b5baSSimon Glass
150*63b4b5baSSimon GlassThen U-Boot will copy that file to u-boot.dtb, put it in the .img file
151*63b4b5baSSimon Glassif used, and u-boot-dtb.bin.
152*63b4b5baSSimon Glass
153eea63e05SSimon GlassIf you wish to put the fdt at a different address in memory, you can
154eea63e05SSimon Glassdefine the "fdtcontroladdr" environment variable. This is the hex
155eea63e05SSimon Glassaddress of the fdt binary blob, and will override either of the options.
156eea63e05SSimon GlassBe aware that this environment variable is checked prior to relocation,
157eea63e05SSimon Glasswhen only the compiled-in environment is available. Therefore it is not
158eea63e05SSimon Glasspossible to define this variable in the saved SPI/NAND flash
159eea63e05SSimon Glassenvironment, for example (it will be ignored).
160eea63e05SSimon Glass
161eea63e05SSimon GlassTo use this, put something like this in your board header file:
162eea63e05SSimon Glass
163eea63e05SSimon Glass#define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
164eea63e05SSimon Glass
16574de8c9aSJagannadha Sutradharudu TekiBuild:
16674de8c9aSJagannadha Sutradharudu Teki
16774de8c9aSJagannadha Sutradharudu TekiAfter board configuration is done, fdt supported u-boot can be build in two ways:
16874de8c9aSJagannadha Sutradharudu Teki1)  build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
16974de8c9aSJagannadha Sutradharudu Teki    $ make
17074de8c9aSJagannadha Sutradharudu Teki2)  build the user specified dts file
17174de8c9aSJagannadha Sutradharudu Teki    $ make DEVICE_TREE=<dts-file-name>
17274de8c9aSJagannadha Sutradharudu Teki
173bbb0b128SSimon Glass
174bbb0b128SSimon GlassLimitations
175bbb0b128SSimon Glass-----------
176bbb0b128SSimon Glass
177bbb0b128SSimon GlassU-Boot is designed to build with a single architecture type and CPU
178bbb0b128SSimon Glasstype. So for example it is not possible to build a single ARM binary
179bbb0b128SSimon Glasswhich runs on your AT91 and OMAP boards, relying on an fdt to configure
180bbb0b128SSimon Glassthe various features. This is because you must select one of
181bbb0b128SSimon Glassthe CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
182bbb0b128SSimon Glasstime. Similarly you cannot build for multiple cpu types or
183bbb0b128SSimon Glassarchitectures.
184bbb0b128SSimon Glass
185bbb0b128SSimon GlassThat said the complexity reduction by using fdt to support variants of
186bbb0b128SSimon Glassboards which use the same SOC / CPU can be substantial.
187bbb0b128SSimon Glass
188bbb0b128SSimon GlassIt is important to understand that the fdt only selects options
189bbb0b128SSimon Glassavailable in the platform / drivers. It cannot add new drivers (yet). So
190bbb0b128SSimon Glassyou must still have the CONFIG option to enable the driver. For example,
191bbb0b128SSimon Glassyou need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
192bbb0b128SSimon Glassbut can use the fdt to specific the UART clock, peripheral address, etc.
193bbb0b128SSimon GlassIn very broad terms, the CONFIG options in general control *what* driver
194bbb0b128SSimon Glassfiles are pulled in, and the fdt controls *how* those files work.
195bbb0b128SSimon Glass
196bbb0b128SSimon Glass--
197bbb0b128SSimon GlassSimon Glass <sjg@chromium.org>
198bbb0b128SSimon Glass1-Sep-11
199