README.fdt-control 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #
  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. Device Tree Control in U-Boot
  23. =============================
  24. This feature provides for run-time configuration of U-Boot via a flat
  25. device tree (fdt). U-Boot configuration has traditionally been done
  26. using CONFIG options in the board config file. This feature aims to
  27. make it possible for a single U-Boot binary to support multiple boards,
  28. with the exact configuration of each board controlled by a flat device
  29. tree (fdt). This is the approach recently taken by the ARM Linux kernel
  30. and has been used by PowerPC for some time.
  31. The fdt is a convenient vehicle for implementing run-time configuration
  32. for three reasons. Firstly it is easy to use, being a simple text file.
  33. It is extensible since it consists of nodes and properties in a nice
  34. hierarchical format.
  35. Finally, there is already excellent infrastructure for the fdt: a
  36. compiler checks the text file and converts it to a compact binary
  37. format, and a library is already available in U-Boot (libfdt) for
  38. handling this format.
  39. The dts directory contains a Makefile for building the device tree blob
  40. and embedding it in your U-Boot image. This is useful since it allows
  41. U-Boot to configure itself according to what it finds there. If you have
  42. a number of similar boards with different peripherals, you can describe
  43. the features of each board in the device tree file, and have a single
  44. generic source base.
  45. To enable this feature, add CONFIG_OF_CONTROL to your board config file.
  46. It is currently supported on ARM, x86 and Microblaze - other architectures
  47. will need to add code to their arch/xxx/lib/board.c file to locate the
  48. FDT. Alternatively you can enable generic board support on your board
  49. (with CONFIG_SYS_GENERIC_BOARD) if this is available (as it is for
  50. PowerPC). For ARM, Tegra and Exynos5 have device trees available for
  51. common devices.
  52. What is a Flat Device Tree?
  53. ---------------------------
  54. An fdt can be specified in source format as a text file. To read about
  55. the fdt syntax, take a look at the specification here:
  56. https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
  57. You also might find this section of the Linux kernel documentation
  58. useful: (access this in the Linux kernel source code)
  59. Documentation/devicetree/booting-without-of.txt
  60. There is also a mailing list:
  61. http://lists.ozlabs.org/listinfo/devicetree-discuss
  62. In case you are wondering, OF stands for Open Firmware.
  63. Tools
  64. -----
  65. To use this feature you will need to get the device tree compiler here:
  66. git://jdl.com/software/dtc.git
  67. For example:
  68. $ git clone git://jdl.com/software/dtc.git
  69. $ cd dtc
  70. $ make
  71. $ sudo make install
  72. Then run the compiler (your version will vary):
  73. $ dtc -v
  74. Version: DTC 1.2.0-g2cb4b51f
  75. $ make tests
  76. $ cd tests
  77. $ ./run_tests.sh
  78. ********** TEST SUMMARY
  79. * Total testcases: 1371
  80. * PASS: 1371
  81. * FAIL: 0
  82. * Bad configuration: 0
  83. * Strange test result: 0
  84. You will also find a useful fdtdump utility for decoding a binary file, as
  85. well as fdtget/fdtput for reading and writing properties in a binary file.
  86. Where do I get an fdt file for my board?
  87. ----------------------------------------
  88. You may find that the Linux kernel has a suitable file. Look in the
  89. kernel source in arch/<arch>/boot/dts.
  90. If not you might find other boards with suitable files that you can
  91. modify to your needs. Look in the board directories for files with a
  92. .dts extension.
  93. Failing that, you could write one from scratch yourself!
  94. Configuration
  95. -------------
  96. Use:
  97. #define CONFIG_DEFAULT_DEVICE_TREE "<name>"
  98. to set the filename of the device tree source. Then put your device tree
  99. file into
  100. board/<vendor>/dts/<name>.dts
  101. This should include your CPU or SOC's device tree file, placed in
  102. arch/<arch>/dts, and then make any adjustments required. The name of this
  103. is CONFIG_ARCH_DEVICE_TREE.dts.
  104. If CONFIG_OF_EMBED is defined, then it will be picked up and built into
  105. the U-Boot image (including u-boot.bin).
  106. If CONFIG_OF_SEPARATE is defined, then it will be built and placed in
  107. a u-boot.dtb file alongside u-boot.bin. A common approach is then to
  108. join the two:
  109. cat u-boot.bin u-boot.dtb >image.bin
  110. and then flash image.bin onto your board.
  111. If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
  112. startup. This is only useful for sandbox. Use the -d flag to U-Boot to
  113. specify the file to read.
  114. You cannot use more than one of these options at the same time.
  115. If you wish to put the fdt at a different address in memory, you can
  116. define the "fdtcontroladdr" environment variable. This is the hex
  117. address of the fdt binary blob, and will override either of the options.
  118. Be aware that this environment variable is checked prior to relocation,
  119. when only the compiled-in environment is available. Therefore it is not
  120. possible to define this variable in the saved SPI/NAND flash
  121. environment, for example (it will be ignored).
  122. To use this, put something like this in your board header file:
  123. #define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0"
  124. Build:
  125. After board configuration is done, fdt supported u-boot can be build in two ways:
  126. 1) build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE
  127. $ make
  128. 2) build the user specified dts file
  129. $ make DEVICE_TREE=<dts-file-name>
  130. Limitations
  131. -----------
  132. U-Boot is designed to build with a single architecture type and CPU
  133. type. So for example it is not possible to build a single ARM binary
  134. which runs on your AT91 and OMAP boards, relying on an fdt to configure
  135. the various features. This is because you must select one of
  136. the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
  137. time. Similarly you cannot build for multiple cpu types or
  138. architectures.
  139. That said the complexity reduction by using fdt to support variants of
  140. boards which use the same SOC / CPU can be substantial.
  141. It is important to understand that the fdt only selects options
  142. available in the platform / drivers. It cannot add new drivers (yet). So
  143. you must still have the CONFIG option to enable the driver. For example,
  144. you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver,
  145. but can use the fdt to specific the UART clock, peripheral address, etc.
  146. In very broad terms, the CONFIG options in general control *what* driver
  147. files are pulled in, and the fdt controls *how* those files work.
  148. --
  149. Simon Glass <sjg@chromium.org>
  150. 1-Sep-11