xref: /openbmc/u-boot/doc/README.fdt-control (revision 49a97162ea573b8646ba29162b71fc2c29e9c5d4)
11a459660SWolfgang Denk# SPDX-License-Identifier: GPL-2.0+
2bbb0b128SSimon Glass#
383d290c5STom Rini# Copyright (c) 2011 The Chromium OS Authors.
4bbb0b128SSimon Glass
5bbb0b128SSimon GlassDevice Tree Control in U-Boot
6bbb0b128SSimon Glass=============================
7bbb0b128SSimon Glass
8bbb0b128SSimon GlassThis feature provides for run-time configuration of U-Boot via a flat
9bbb0b128SSimon Glassdevice tree (fdt). U-Boot configuration has traditionally been done
10bbb0b128SSimon Glassusing CONFIG options in the board config file. This feature aims to
11bbb0b128SSimon Glassmake it possible for a single U-Boot binary to support multiple boards,
12bbb0b128SSimon Glasswith the exact configuration of each board controlled by a flat device
13bbb0b128SSimon Glasstree (fdt). This is the approach recently taken by the ARM Linux kernel
14bbb0b128SSimon Glassand has been used by PowerPC for some time.
15bbb0b128SSimon Glass
16bbb0b128SSimon GlassThe fdt is a convenient vehicle for implementing run-time configuration
17bbb0b128SSimon Glassfor three reasons. Firstly it is easy to use, being a simple text file.
18bbb0b128SSimon GlassIt is extensible since it consists of nodes and properties in a nice
19bbb0b128SSimon Glasshierarchical format.
20bbb0b128SSimon Glass
21bbb0b128SSimon GlassFinally, there is already excellent infrastructure for the fdt: a
22bbb0b128SSimon Glasscompiler checks the text file and converts it to a compact binary
23bbb0b128SSimon Glassformat, and a library is already available in U-Boot (libfdt) for
24bbb0b128SSimon Glasshandling this format.
25bbb0b128SSimon Glass
26bbb0b128SSimon GlassThe dts directory contains a Makefile for building the device tree blob
27bbb0b128SSimon Glassand embedding it in your U-Boot image. This is useful since it allows
28bbb0b128SSimon GlassU-Boot to configure itself according to what it finds there. If you have
29bbb0b128SSimon Glassa number of similar boards with different peripherals, you can describe
30bbb0b128SSimon Glassthe features of each board in the device tree file, and have a single
31bbb0b128SSimon Glassgeneric source base.
32bbb0b128SSimon Glass
33bbb0b128SSimon GlassTo enable this feature, add CONFIG_OF_CONTROL to your board config file.
34bbb0b128SSimon Glass
35bbb0b128SSimon Glass
36bbb0b128SSimon GlassWhat is a Flat Device Tree?
37bbb0b128SSimon Glass---------------------------
38bbb0b128SSimon Glass
39bbb0b128SSimon GlassAn fdt can be specified in source format as a text file. To read about
40bbb0b128SSimon Glassthe fdt syntax, take a look at the specification here:
41bbb0b128SSimon Glass
42bbb0b128SSimon Glasshttps://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
43bbb0b128SSimon Glass
44bbb0b128SSimon GlassYou also might find this section of the Linux kernel documentation
45bbb0b128SSimon Glassuseful: (access this in the Linux kernel source code)
46bbb0b128SSimon Glass
47bbb0b128SSimon Glass	Documentation/devicetree/booting-without-of.txt
48bbb0b128SSimon Glass
49bbb0b128SSimon GlassThere is also a mailing list:
50bbb0b128SSimon Glass
51bbb0b128SSimon Glass	http://lists.ozlabs.org/listinfo/devicetree-discuss
52bbb0b128SSimon Glass
53bbb0b128SSimon GlassIn case you are wondering, OF stands for Open Firmware.
54bbb0b128SSimon Glass
55bbb0b128SSimon Glass
56bbb0b128SSimon GlassTools
57bbb0b128SSimon Glass-----
58bbb0b128SSimon Glass
59343864afSSimon GlassTo use this feature you will need to get the device tree compiler. This is
60343864afSSimon Glassprovided by U-Boot automatically. If you have a system version of dtc
61343864afSSimon Glass(typically in the 'device-tree-compiler' package), it is currently not used.
62343864afSSimon Glass
63343864afSSimon GlassIf you want to build your own dtc, it is kept here:
64bbb0b128SSimon Glass
655f65826bSJon Loeliger	git://git.kernel.org/pub/scm/utils/dtc/dtc.git
66bbb0b128SSimon Glass
67bbb0b128SSimon GlassFor example:
68bbb0b128SSimon Glass
695f65826bSJon Loeliger	$ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
70bbb0b128SSimon Glass	$ cd dtc
71bbb0b128SSimon Glass	$ make
72bbb0b128SSimon Glass	$ sudo make install
73bbb0b128SSimon Glass
74bbb0b128SSimon GlassThen run the compiler (your version will vary):
75bbb0b128SSimon Glass
76bbb0b128SSimon Glass	$ dtc -v
77bbb0b128SSimon Glass	Version: DTC 1.2.0-g2cb4b51f
78bbb0b128SSimon Glass	$ make tests
79bbb0b128SSimon Glass	$ cd tests
80bbb0b128SSimon Glass	$ ./run_tests.sh
81bbb0b128SSimon Glass	********** TEST SUMMARY
82bbb0b128SSimon Glass	*     Total testcases:	1371
83bbb0b128SSimon Glass	*                PASS:	1371
84bbb0b128SSimon Glass	*                FAIL:	0
85bbb0b128SSimon Glass	*   Bad configuration:	0
86bbb0b128SSimon Glass	* Strange test result:	0
87bbb0b128SSimon Glass
88134a6512SSimon GlassYou will also find a useful fdtdump utility for decoding a binary file, as
89134a6512SSimon Glasswell as fdtget/fdtput for reading and writing properties in a binary file.
90bbb0b128SSimon Glass
91bbb0b128SSimon Glass
92bbb0b128SSimon GlassWhere do I get an fdt file for my board?
93bbb0b128SSimon Glass----------------------------------------
94bbb0b128SSimon Glass
95bbb0b128SSimon GlassYou may find that the Linux kernel has a suitable file. Look in the
96bbb0b128SSimon Glasskernel source in arch/<arch>/boot/dts.
97bbb0b128SSimon Glass
98bbb0b128SSimon GlassIf not you might find other boards with suitable files that you can
99bbb0b128SSimon Glassmodify to your needs. Look in the board directories for files with a
100bbb0b128SSimon Glass.dts extension.
101bbb0b128SSimon Glass
102bbb0b128SSimon GlassFailing that, you could write one from scratch yourself!
103bbb0b128SSimon Glass
104bbb0b128SSimon Glass
105bbb0b128SSimon GlassConfiguration
106bbb0b128SSimon Glass-------------
107bbb0b128SSimon Glass
108bbb0b128SSimon GlassUse:
109bbb0b128SSimon Glass
110bbb0b128SSimon Glass#define CONFIG_DEFAULT_DEVICE_TREE	"<name>"
111bbb0b128SSimon Glass
112bbb0b128SSimon Glassto set the filename of the device tree source. Then put your device tree
113bbb0b128SSimon Glassfile into
114bbb0b128SSimon Glass
115bbb0b128SSimon Glass	board/<vendor>/dts/<name>.dts
116bbb0b128SSimon Glass
117bbb0b128SSimon GlassThis should include your CPU or SOC's device tree file, placed in
11806520280SStephen Warrenarch/<arch>/dts, and then make any adjustments required.
119bbb0b128SSimon Glass
120bbb0b128SSimon GlassIf CONFIG_OF_EMBED is defined, then it will be picked up and built into
12163b4b5baSSimon Glassthe U-Boot image (including u-boot.bin). This is suitable for debugging
12263b4b5baSSimon Glassand development only and is not recommended for production devices.
123bbb0b128SSimon Glass
124bbb0b128SSimon GlassIf CONFIG_OF_SEPARATE is defined, then it will be built and placed in
125*2436396aSAndy Shevchenkoa u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is then to
126bbb0b128SSimon Glassjoin the two:
127bbb0b128SSimon Glass
128*2436396aSAndy Shevchenko	cat u-boot-nodtb.bin u-boot.dtb >image.bin
129bbb0b128SSimon Glass
13063b4b5baSSimon Glassand then flash image.bin onto your board. Note that U-Boot creates
131*2436396aSAndy Shevchenkou-boot-dtb.bin which does the above step for you also. Resulting
132*2436396aSAndy Shevchenkou-boot.bin is a copy of u-boot-dtb.bin in this case. If you are using
13363b4b5baSSimon GlassCONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
13463b4b5baSSimon Glasstree binary.
135bbb0b128SSimon Glass
13682f766d1SAlex DeymoIf CONFIG_OF_BOARD is defined, a board-specific routine will provide the
13782f766d1SAlex Deymodevice tree at runtime, for example if an earlier bootloader stage creates
13882f766d1SAlex Deymoit and passes it to U-Boot.
13982f766d1SAlex Deymo
140f828bf25SSimon GlassIf CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
141f828bf25SSimon Glassstartup. This is only useful for sandbox. Use the -d flag to U-Boot to
142f828bf25SSimon Glassspecify the file to read.
143f828bf25SSimon Glass
144f828bf25SSimon GlassYou cannot use more than one of these options at the same time.
145bbb0b128SSimon Glass
14663b4b5baSSimon GlassTo use a device tree file that you have compiled yourself, pass
147d18926afSSimon GlassEXT_DTB=<filename> to 'make', as in:
14863b4b5baSSimon Glass
149d18926afSSimon Glass	make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
15063b4b5baSSimon Glass
15163b4b5baSSimon GlassThen U-Boot will copy that file to u-boot.dtb, put it in the .img file
15263b4b5baSSimon Glassif used, and u-boot-dtb.bin.
15363b4b5baSSimon Glass
154eea63e05SSimon GlassIf you wish to put the fdt at a different address in memory, you can
155eea63e05SSimon Glassdefine the "fdtcontroladdr" environment variable. This is the hex
156eea63e05SSimon Glassaddress of the fdt binary blob, and will override either of the options.
157eea63e05SSimon GlassBe aware that this environment variable is checked prior to relocation,
158eea63e05SSimon Glasswhen only the compiled-in environment is available. Therefore it is not
159eea63e05SSimon Glasspossible to define this variable in the saved SPI/NAND flash
160545dfd10SThomas Chouenvironment, for example (it will be ignored). After relocation, this
161545dfd10SThomas Chouvariable will be set to the address of the newly relocated fdt blob.
162545dfd10SThomas ChouIt is read-only and cannot be changed. It can optionally be used to
163545dfd10SThomas Choucontrol the boot process of Linux with bootm/bootz commands.
164eea63e05SSimon Glass
165eea63e05SSimon GlassTo use this, put something like this in your board header file:
166eea63e05SSimon Glass
167eea63e05SSimon Glass#define CONFIG_EXTRA_ENV_SETTINGS	"fdtcontroladdr=10000\0"
168eea63e05SSimon Glass
16974de8c9aSJagannadha Sutradharudu TekiBuild:
17074de8c9aSJagannadha Sutradharudu Teki
17174de8c9aSJagannadha Sutradharudu TekiAfter board configuration is done, fdt supported u-boot can be build in two ways:
17274de8c9aSJagannadha Sutradharudu Teki1)  build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
17374de8c9aSJagannadha Sutradharudu Teki    $ make
17474de8c9aSJagannadha Sutradharudu Teki2)  build the user specified dts file
17574de8c9aSJagannadha Sutradharudu Teki    $ make DEVICE_TREE=<dts-file-name>
17674de8c9aSJagannadha Sutradharudu Teki
177bbb0b128SSimon Glass
178a15a7aa4SSimon GlassRelocation, SPL and TPL
179a15a7aa4SSimon Glass-----------------------
180a15a7aa4SSimon Glass
181a15a7aa4SSimon GlassU-Boot can be divided into three phases: TPL, SPL and U-Boot proper.
182a15a7aa4SSimon Glass
183a15a7aa4SSimon GlassThe full device tree is available to U-Boot proper, but normally only a subset
184a15a7aa4SSimon Glass(or none at all) is available to TPL and SPL. See 'Pre-Relocation Support' and
185a15a7aa4SSimon Glass'SPL Support' in doc/driver-model/README.txt for more details.
186a15a7aa4SSimon Glass
187a15a7aa4SSimon Glass
188f1d2bc90SJean-Jacques HiblotUsing several DTBs in the SPL (CONFIG_SPL_MULTI_DTB)
189f1d2bc90SJean-Jacques Hiblot----------------------------------------------------
190f1d2bc90SJean-Jacques HiblotIn some rare cases it is desirable to let SPL be able to select one DTB among
191f1d2bc90SJean-Jacques Hiblotmany. This usually not very useful as the DTB for the SPL is small and usually
192f1d2bc90SJean-Jacques Hiblotfits several platforms. However the DTB sometimes include information that do
193f1d2bc90SJean-Jacques Hiblotwork on several platforms (like IO tuning parameters).
194f1d2bc90SJean-Jacques HiblotIn this case it is possible to use CONFIG_SPL_MULTI_DTB. This option appends to
195f1d2bc90SJean-Jacques Hiblotthe SPL a FIT image containing several DTBs listed in SPL_OF_LIST.
196f1d2bc90SJean-Jacques Hiblotboard_fit_config_name_match() is called to select the right DTB.
197f1d2bc90SJean-Jacques Hiblot
198f1d2bc90SJean-Jacques HiblotIf board_fit_config_name_match() relies on DM (DM driver to access an EEPROM
199f1d2bc90SJean-Jacques Hiblotcontaining the board ID for example), it possible to start with a generic DTB
200f1d2bc90SJean-Jacques Hiblotand then switch over to the right DTB after the detection. For this purpose,
201f1d2bc90SJean-Jacques Hiblotthe platform code must call fdtdec_resetup(). Based on the returned flag, the
202f1d2bc90SJean-Jacques Hiblotplatform may have to re-initiliaze the DM subusystem using dm_uninit() and
203f1d2bc90SJean-Jacques Hiblotdm_init_and_scan().
204f1d2bc90SJean-Jacques Hiblot
205f1d2bc90SJean-Jacques Hiblot
206bbb0b128SSimon GlassLimitations
207bbb0b128SSimon Glass-----------
208bbb0b128SSimon Glass
209bbb0b128SSimon GlassU-Boot is designed to build with a single architecture type and CPU
210bbb0b128SSimon Glasstype. So for example it is not possible to build a single ARM binary
211bbb0b128SSimon Glasswhich runs on your AT91 and OMAP boards, relying on an fdt to configure
212bbb0b128SSimon Glassthe various features. This is because you must select one of
213bbb0b128SSimon Glassthe CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
214bbb0b128SSimon Glasstime. Similarly you cannot build for multiple cpu types or
215bbb0b128SSimon Glassarchitectures.
216bbb0b128SSimon Glass
217bbb0b128SSimon GlassThat said the complexity reduction by using fdt to support variants of
218bbb0b128SSimon Glassboards which use the same SOC / CPU can be substantial.
219bbb0b128SSimon Glass
220bbb0b128SSimon GlassIt is important to understand that the fdt only selects options
221bbb0b128SSimon Glassavailable in the platform / drivers. It cannot add new drivers (yet). So
222bbb0b128SSimon Glassyou must still have the CONFIG option to enable the driver. For example,
223bbb0b128SSimon Glassyou need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
224bbb0b128SSimon Glassbut can use the fdt to specific the UART clock, peripheral address, etc.
225bbb0b128SSimon GlassIn very broad terms, the CONFIG options in general control *what* driver
226bbb0b128SSimon Glassfiles are pulled in, and the fdt controls *how* those files work.
227bbb0b128SSimon Glass
228bbb0b128SSimon Glass--
229bbb0b128SSimon GlassSimon Glass <sjg@chromium.org>
230bbb0b128SSimon Glass1-Sep-11
231