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