Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2011 The Chromium OS Authors. |
| 3 | # |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 5 | # |
| 6 | |
| 7 | Device Tree Control in U-Boot |
| 8 | ============================= |
| 9 | |
| 10 | This feature provides for run-time configuration of U-Boot via a flat |
| 11 | device tree (fdt). U-Boot configuration has traditionally been done |
| 12 | using CONFIG options in the board config file. This feature aims to |
| 13 | make it possible for a single U-Boot binary to support multiple boards, |
| 14 | with the exact configuration of each board controlled by a flat device |
| 15 | tree (fdt). This is the approach recently taken by the ARM Linux kernel |
| 16 | and has been used by PowerPC for some time. |
| 17 | |
| 18 | The fdt is a convenient vehicle for implementing run-time configuration |
| 19 | for three reasons. Firstly it is easy to use, being a simple text file. |
| 20 | It is extensible since it consists of nodes and properties in a nice |
| 21 | hierarchical format. |
| 22 | |
| 23 | Finally, there is already excellent infrastructure for the fdt: a |
| 24 | compiler checks the text file and converts it to a compact binary |
| 25 | format, and a library is already available in U-Boot (libfdt) for |
| 26 | handling this format. |
| 27 | |
| 28 | The dts directory contains a Makefile for building the device tree blob |
| 29 | and embedding it in your U-Boot image. This is useful since it allows |
| 30 | U-Boot to configure itself according to what it finds there. If you have |
| 31 | a number of similar boards with different peripherals, you can describe |
| 32 | the features of each board in the device tree file, and have a single |
| 33 | generic source base. |
| 34 | |
| 35 | To enable this feature, add CONFIG_OF_CONTROL to your board config file. |
Simon Glass | 0618f98 | 2013-05-07 06:11:46 +0000 | [diff] [blame] | 36 | It is currently supported on ARM, x86 and Microblaze - other architectures |
| 37 | will need to add code to their arch/xxx/lib/board.c file to locate the |
| 38 | FDT. Alternatively you can enable generic board support on your board |
| 39 | (with CONFIG_SYS_GENERIC_BOARD) if this is available (as it is for |
| 40 | PowerPC). For ARM, Tegra and Exynos5 have device trees available for |
| 41 | common devices. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | What is a Flat Device Tree? |
| 45 | --------------------------- |
| 46 | |
| 47 | An fdt can be specified in source format as a text file. To read about |
| 48 | the fdt syntax, take a look at the specification here: |
| 49 | |
| 50 | https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf |
| 51 | |
| 52 | You also might find this section of the Linux kernel documentation |
| 53 | useful: (access this in the Linux kernel source code) |
| 54 | |
| 55 | Documentation/devicetree/booting-without-of.txt |
| 56 | |
| 57 | There is also a mailing list: |
| 58 | |
| 59 | http://lists.ozlabs.org/listinfo/devicetree-discuss |
| 60 | |
| 61 | In case you are wondering, OF stands for Open Firmware. |
| 62 | |
| 63 | |
| 64 | Tools |
| 65 | ----- |
| 66 | |
| 67 | To use this feature you will need to get the device tree compiler here: |
| 68 | |
Jon Loeliger | b88a6ba | 2014-05-27 09:12:48 -0500 | [diff] [blame] | 69 | git://git.kernel.org/pub/scm/utils/dtc/dtc.git |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 70 | |
| 71 | For example: |
| 72 | |
Jon Loeliger | b88a6ba | 2014-05-27 09:12:48 -0500 | [diff] [blame] | 73 | $ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 74 | $ cd dtc |
| 75 | $ make |
| 76 | $ sudo make install |
| 77 | |
| 78 | Then run the compiler (your version will vary): |
| 79 | |
| 80 | $ dtc -v |
| 81 | Version: DTC 1.2.0-g2cb4b51f |
| 82 | $ make tests |
| 83 | $ cd tests |
| 84 | $ ./run_tests.sh |
| 85 | ********** TEST SUMMARY |
| 86 | * Total testcases: 1371 |
| 87 | * PASS: 1371 |
| 88 | * FAIL: 0 |
| 89 | * Bad configuration: 0 |
| 90 | * Strange test result: 0 |
| 91 | |
Simon Glass | 0618f98 | 2013-05-07 06:11:46 +0000 | [diff] [blame] | 92 | You will also find a useful fdtdump utility for decoding a binary file, as |
| 93 | well as fdtget/fdtput for reading and writing properties in a binary file. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | Where do I get an fdt file for my board? |
| 97 | ---------------------------------------- |
| 98 | |
| 99 | You may find that the Linux kernel has a suitable file. Look in the |
| 100 | kernel source in arch/<arch>/boot/dts. |
| 101 | |
| 102 | If not you might find other boards with suitable files that you can |
| 103 | modify to your needs. Look in the board directories for files with a |
| 104 | .dts extension. |
| 105 | |
| 106 | Failing that, you could write one from scratch yourself! |
| 107 | |
| 108 | |
| 109 | Configuration |
| 110 | ------------- |
| 111 | |
| 112 | Use: |
| 113 | |
| 114 | #define CONFIG_DEFAULT_DEVICE_TREE "<name>" |
| 115 | |
| 116 | to set the filename of the device tree source. Then put your device tree |
| 117 | file into |
| 118 | |
| 119 | board/<vendor>/dts/<name>.dts |
| 120 | |
| 121 | This should include your CPU or SOC's device tree file, placed in |
Stephen Warren | 9215e0b | 2013-07-24 10:09:22 -0700 | [diff] [blame] | 122 | arch/<arch>/dts, and then make any adjustments required. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 123 | |
| 124 | If CONFIG_OF_EMBED is defined, then it will be picked up and built into |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 125 | the U-Boot image (including u-boot.bin). This is suitable for debugging |
| 126 | and development only and is not recommended for production devices. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 127 | |
| 128 | If CONFIG_OF_SEPARATE is defined, then it will be built and placed in |
| 129 | a u-boot.dtb file alongside u-boot.bin. A common approach is then to |
| 130 | join the two: |
| 131 | |
| 132 | cat u-boot.bin u-boot.dtb >image.bin |
| 133 | |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 134 | and then flash image.bin onto your board. Note that U-Boot creates |
| 135 | u-boot-dtb.bin which does the above step for you also. If you are using |
| 136 | CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device |
| 137 | tree binary. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 138 | |
Simon Glass | 1539343 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 139 | If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on |
| 140 | startup. This is only useful for sandbox. Use the -d flag to U-Boot to |
| 141 | specify the file to read. |
| 142 | |
| 143 | You cannot use more than one of these options at the same time. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 144 | |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 145 | To use a device tree file that you have compiled yourself, pass |
Simon Glass | c3b0de4 | 2014-06-12 07:24:43 -0600 | [diff] [blame] | 146 | EXT_DTB=<filename> to 'make', as in: |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 147 | |
Simon Glass | c3b0de4 | 2014-06-12 07:24:43 -0600 | [diff] [blame] | 148 | make EXT_DTB=boot/am335x-boneblack-pubkey.dtb |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 149 | |
| 150 | Then U-Boot will copy that file to u-boot.dtb, put it in the .img file |
| 151 | if used, and u-boot-dtb.bin. |
| 152 | |
Simon Glass | dc6fa64 | 2011-10-24 19:15:34 +0000 | [diff] [blame] | 153 | If you wish to put the fdt at a different address in memory, you can |
| 154 | define the "fdtcontroladdr" environment variable. This is the hex |
| 155 | address of the fdt binary blob, and will override either of the options. |
| 156 | Be aware that this environment variable is checked prior to relocation, |
| 157 | when only the compiled-in environment is available. Therefore it is not |
| 158 | possible to define this variable in the saved SPI/NAND flash |
| 159 | environment, for example (it will be ignored). |
| 160 | |
| 161 | To use this, put something like this in your board header file: |
| 162 | |
| 163 | #define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0" |
| 164 | |
Jagannadha Sutradharudu Teki | 79e63a4 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 165 | Build: |
| 166 | |
| 167 | After board configuration is done, fdt supported u-boot can be build in two ways: |
| 168 | 1) build the default dts which is defined from CONFIG_DEFAULT_DEVICE_TREE |
| 169 | $ make |
| 170 | 2) build the user specified dts file |
| 171 | $ make DEVICE_TREE=<dts-file-name> |
| 172 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 173 | |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame^] | 174 | Configuration Options |
| 175 | --------------------- |
| 176 | |
| 177 | A number of run-time configuration options are provided in the /config node |
| 178 | of the control device tree. You can access these using fdtdec_get_config_int(), |
| 179 | fdtdec_get_config_bool() and fdtdec_get_config_string(). |
| 180 | |
| 181 | Available options are: |
| 182 | |
| 183 | silent-console |
| 184 | If present and non-zero, the console is silenced by default on boot. |
| 185 | |
| 186 | no-keyboard |
| 187 | Tells U-Boot not to expect an attached keyboard with a VGA console |
| 188 | |
| 189 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 190 | Limitations |
| 191 | ----------- |
| 192 | |
| 193 | U-Boot is designed to build with a single architecture type and CPU |
| 194 | type. So for example it is not possible to build a single ARM binary |
| 195 | which runs on your AT91 and OMAP boards, relying on an fdt to configure |
| 196 | the various features. This is because you must select one of |
| 197 | the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build |
| 198 | time. Similarly you cannot build for multiple cpu types or |
| 199 | architectures. |
| 200 | |
| 201 | That said the complexity reduction by using fdt to support variants of |
| 202 | boards which use the same SOC / CPU can be substantial. |
| 203 | |
| 204 | It is important to understand that the fdt only selects options |
| 205 | available in the platform / drivers. It cannot add new drivers (yet). So |
| 206 | you must still have the CONFIG option to enable the driver. For example, |
| 207 | you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver, |
| 208 | but can use the fdt to specific the UART clock, peripheral address, etc. |
| 209 | In very broad terms, the CONFIG options in general control *what* driver |
| 210 | files are pulled in, and the fdt controls *how* those files work. |
| 211 | |
| 212 | -- |
| 213 | Simon Glass <sjg@chromium.org> |
| 214 | 1-Sep-11 |