README.fdt-control 6.2 KB

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