README.fdt-control 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # SPDX-License-Identifier: GPL-2.0+
  2. #
  3. # Copyright (c) 2011 The Chromium OS Authors.
  4. Device Tree Control in U-Boot
  5. =============================
  6. This feature provides for run-time configuration of U-Boot via a flat
  7. device tree (fdt). U-Boot configuration has traditionally been done
  8. using CONFIG options in the board config file. This feature aims to
  9. make it possible for a single U-Boot binary to support multiple boards,
  10. with the exact configuration of each board controlled by a flat device
  11. tree (fdt). This is the approach recently taken by the ARM Linux kernel
  12. and has been used by PowerPC for some time.
  13. The fdt is a convenient vehicle for implementing run-time configuration
  14. for three reasons. Firstly it is easy to use, being a simple text file.
  15. It is extensible since it consists of nodes and properties in a nice
  16. hierarchical format.
  17. Finally, there is already excellent infrastructure for the fdt: a
  18. compiler checks the text file and converts it to a compact binary
  19. format, and a library is already available in U-Boot (libfdt) for
  20. handling this format.
  21. The dts directory contains a Makefile for building the device tree blob
  22. and embedding it in your U-Boot image. This is useful since it allows
  23. U-Boot to configure itself according to what it finds there. If you have
  24. a number of similar boards with different peripherals, you can describe
  25. the features of each board in the device tree file, and have a single
  26. generic source base.
  27. To enable this feature, add CONFIG_OF_CONTROL to your board config file.
  28. What is a Flat Device Tree?
  29. ---------------------------
  30. An fdt can be specified in source format as a text file. To read about
  31. the fdt syntax, take a look at the specification here:
  32. https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
  33. You also might find this section of the Linux kernel documentation
  34. useful: (access this in the Linux kernel source code)
  35. Documentation/devicetree/booting-without-of.txt
  36. There is also a mailing list:
  37. http://lists.ozlabs.org/listinfo/devicetree-discuss
  38. In case you are wondering, OF stands for Open Firmware.
  39. Tools
  40. -----
  41. To use this feature you will need to get the device tree compiler. This is
  42. provided by U-Boot automatically. If you have a system version of dtc
  43. (typically in the 'device-tree-compiler' package), it is currently not used.
  44. If you want to build your own dtc, it is kept here:
  45. git://git.kernel.org/pub/scm/utils/dtc/dtc.git
  46. For example:
  47. $ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git
  48. $ cd dtc
  49. $ make
  50. $ sudo make install
  51. Then run the compiler (your version will vary):
  52. $ dtc -v
  53. Version: DTC 1.2.0-g2cb4b51f
  54. $ make tests
  55. $ cd tests
  56. $ ./run_tests.sh
  57. ********** TEST SUMMARY
  58. * Total testcases: 1371
  59. * PASS: 1371
  60. * FAIL: 0
  61. * Bad configuration: 0
  62. * Strange test result: 0
  63. You will also find a useful fdtdump utility for decoding a binary file, as
  64. well as fdtget/fdtput for reading and writing properties in a binary file.
  65. Where do I get an fdt file for my board?
  66. ----------------------------------------
  67. You may find that the Linux kernel has a suitable file. Look in the
  68. kernel source in arch/<arch>/boot/dts.
  69. If not you might find other boards with suitable files that you can
  70. modify to your needs. Look in the board directories for files with a
  71. .dts extension.
  72. Failing that, you could write one from scratch yourself!
  73. Configuration
  74. -------------
  75. Use:
  76. #define CONFIG_DEFAULT_DEVICE_TREE "<name>"
  77. to set the filename of the device tree source. Then put your device tree
  78. file into
  79. board/<vendor>/dts/<name>.dts
  80. This should include your CPU or SOC's device tree file, placed in
  81. arch/<arch>/dts, and then make any adjustments required.
  82. If CONFIG_OF_EMBED is defined, then it will be picked up and built into
  83. the U-Boot image (including u-boot.bin). This is suitable for debugging
  84. and development only and is not recommended for production devices.
  85. If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
  86. a u-boot.dtb file alongside u-boot-nodtb.bin. A common approach is then to
  87. join the two:
  88. cat u-boot-nodtb.bin u-boot.dtb >image.bin
  89. and then flash image.bin onto your board. Note that U-Boot creates
  90. u-boot-dtb.bin which does the above step for you also. Resulting
  91. u-boot.bin is a copy of u-boot-dtb.bin in this case. If you are using
  92. CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
  93. tree binary.
  94. If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
  95. device tree at runtime, for example if an earlier bootloader stage creates
  96. it and passes it to U-Boot.
  97. If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
  98. startup. This is only useful for sandbox. Use the -d flag to U-Boot to
  99. specify the file to read.
  100. You cannot use more than one of these options at the same time.
  101. To use a device tree file that you have compiled yourself, pass
  102. EXT_DTB=<filename> to 'make', as in:
  103. make EXT_DTB=boot/am335x-boneblack-pubkey.dtb
  104. Then U-Boot will copy that file to u-boot.dtb, put it in the .img file
  105. if used, and u-boot-dtb.bin.
  106. If you wish to put the fdt at a different address in memory, you can
  107. define the "fdtcontroladdr" environment variable. This is the hex
  108. address of the fdt binary blob, and will override either of the options.
  109. Be aware that this environment variable is checked prior to relocation,
  110. when only the compiled-in environment is available. Therefore it is not
  111. possible to define this variable in the saved SPI/NAND flash
  112. environment, for example (it will be ignored). After relocation, this
  113. variable will be set to the address of the newly relocated fdt blob.
  114. It is read-only and cannot be changed. It can optionally be used to
  115. control the boot process of Linux with bootm/bootz commands.
  116. To use this, put something like this in your board header file:
  117. #define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0"
  118. Build:
  119. After board configuration is done, fdt supported u-boot can be build in two ways:
  120. 1) build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
  121. $ make
  122. 2) build the user specified dts file
  123. $ make DEVICE_TREE=<dts-file-name>
  124. Relocation, SPL and TPL
  125. -----------------------
  126. U-Boot can be divided into three phases: TPL, SPL and U-Boot proper.
  127. The full device tree is available to U-Boot proper, but normally only a subset
  128. (or none at all) is available to TPL and SPL. See 'Pre-Relocation Support' and
  129. 'SPL Support' in doc/driver-model/README.txt for more details.
  130. Using several DTBs in the SPL (CONFIG_SPL_MULTI_DTB)
  131. ----------------------------------------------------
  132. In some rare cases it is desirable to let SPL be able to select one DTB among
  133. many. This usually not very useful as the DTB for the SPL is small and usually
  134. fits several platforms. However the DTB sometimes include information that do
  135. work on several platforms (like IO tuning parameters).
  136. In this case it is possible to use CONFIG_SPL_MULTI_DTB. This option appends to
  137. the SPL a FIT image containing several DTBs listed in SPL_OF_LIST.
  138. board_fit_config_name_match() is called to select the right DTB.
  139. If board_fit_config_name_match() relies on DM (DM driver to access an EEPROM
  140. containing the board ID for example), it possible to start with a generic DTB
  141. and then switch over to the right DTB after the detection. For this purpose,
  142. the platform code must call fdtdec_resetup(). Based on the returned flag, the
  143. platform may have to re-initiliaze the DM subusystem using dm_uninit() and
  144. dm_init_and_scan().
  145. Limitations
  146. -----------
  147. U-Boot is designed to build with a single architecture type and CPU
  148. type. So for example it is not possible to build a single ARM binary
  149. which runs on your AT91 and OMAP boards, relying on an fdt to configure
  150. the various features. This is because you must select one of
  151. the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
  152. time. Similarly you cannot build for multiple cpu types or
  153. architectures.
  154. That said the complexity reduction by using fdt to support variants of
  155. boards which use the same SOC / CPU can be substantial.
  156. It is important to understand that the fdt only selects options
  157. available in the platform / drivers. It cannot add new drivers (yet). So
  158. you must still have the CONFIG option to enable the driver. For example,
  159. you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
  160. but can use the fdt to specific the UART clock, peripheral address, etc.
  161. In very broad terms, the CONFIG options in general control *what* driver
  162. files are pulled in, and the fdt controls *how* those files work.
  163. --
  164. Simon Glass <sjg@chromium.org>
  165. 1-Sep-11