Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | .. sectionauthor:: Copyright 2011 The Chromium OS Authors |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 3 | .. Copyright 2023-2024 Linaro Ltd. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 4 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 5 | Devicetree Control in U-Boot |
| 6 | ============================ |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 7 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 8 | This feature provides for run-time configuration of U-Boot via a flattened |
| 9 | devicetree (fdt). |
| 10 | |
| 11 | This feature aims to make it possible for a single U-Boot binary to support |
| 12 | multiple boards, with the exact configuration of each board controlled by |
| 13 | a flattened devicetree (fdt). This is the approach taken by Linux kernel for |
| 14 | ARM and RISC-V and has been used by PowerPC for some time. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 15 | |
| 16 | The fdt is a convenient vehicle for implementing run-time configuration |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 17 | for three reasons: |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 18 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 19 | - There is already excellent infrastructure for the fdt: a compiler checks |
| 20 | the text file and converts it to a compact binary format, and a library |
| 21 | is already available in U-Boot (libfdt) for handling this format |
| 22 | - It is extensible since it consists of nodes and properties in a nice |
| 23 | hierarchical format |
| 24 | - It is fairly efficient to read incrementally |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 25 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 26 | The U-Boot Makefile infrastructure allows for building the devicetree blob |
| 27 | and embedding it in the U-Boot image. This is useful since it allows U-Boot |
| 28 | to configure itself according to what it finds there. If you have a number |
| 29 | of similar boards with different peripherals, you can describe the features |
| 30 | of each board in the devicetree file, and have a single generic source base. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 31 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 32 | To enable this feature, select `OF_CONTROL` via Kconfig. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 33 | |
| 34 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 35 | What is a Flattened Devicetree? |
| 36 | ------------------------------- |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 37 | |
| 38 | An fdt can be specified in source format as a text file. To read about |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 39 | the fdt syntax, take a look at `the devicetree specification`_. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 40 | |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 41 | There is also a `devicetree compiler mailing list`_ for the compiler and |
| 42 | associated tools. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 43 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 44 | In case you are wondering, OF stands for Open Firmware. This follows the |
| 45 | convention used in Linux. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 46 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 47 | |
| 48 | Tools |
| 49 | ----- |
| 50 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 51 | To create flattened device trees the device tree compiler is used. This is |
Simon Glass | 9665f19 | 2018-10-01 12:22:16 -0600 | [diff] [blame] | 52 | provided by U-Boot automatically. If you have a system version of dtc |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 53 | (typically in the 'device-tree-compiler' package), that system version is |
| 54 | currently not used. |
Simon Glass | 9665f19 | 2018-10-01 12:22:16 -0600 | [diff] [blame] | 55 | |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 56 | If you want to build your own dtc, it is kept here:: |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 57 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 58 | git://git.kernel.org/pub/scm/utils/dtc/dtc.git |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 59 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 60 | You can decode a binary file with:: |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 61 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 62 | dtc -I dtb -O dts <filename.dtb> |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 63 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 64 | That repo also includes `fdtget`/`fdtput` for reading and writing properties in |
| 65 | a binary file. U-Boot adds its own `fdtgrep` for creating subsets of the file. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 66 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 67 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 68 | Where do I get a devicetree file for my board? |
| 69 | ---------------------------------------------- |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 70 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 71 | The devicetree files and devicetree bindings are maintained as part of the Linux |
| 72 | kernel git repository. Traditionally, U-Boot placed copies of devicetree source |
| 73 | files from the Linux kernel into `arch/<arch>/dts/<name>.dts`. However, this |
| 74 | required each board maintainer to manually keep their devicetree in sync with |
| 75 | the Linux kernel and often led to divergence between these copies. |
| 76 | |
| 77 | U-Boot rather maintains a Git subtree as `dts/upstream/` sub-directory. It is |
| 78 | regularly synced with the Linux kernel and hence no need for manual devicetree |
| 79 | sync. You may find that the `dts/upstream/` already has a suitable devicetree |
| 80 | file for your board. Look in `dts/upstream/src/<arch>/<vendor>`. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 81 | |
| 82 | If not you might find other boards with suitable files that you can |
| 83 | modify to your needs. Look in the board directories for files with a |
| 84 | .dts extension. |
| 85 | |
| 86 | Failing that, you could write one from scratch yourself! |
| 87 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 88 | |
| 89 | Resyncing with devicetree-rebasing |
| 90 | ---------------------------------- |
| 91 | |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 92 | The `devicetree-rebasing repository`_ maintains a fork cum mirror copy of |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 93 | devicetree files along with the bindings synced at every Linux kernel major |
| 94 | release or intermediate release candidates. The U-Boot maintainers regularly |
| 95 | sync the `dts/upstream/` subtree from the devicetree-rebasing repo whenever |
| 96 | the next branch opens (refer: :doc:`../release_cycle`) with the latest mainline |
| 97 | Linux kernel release. To sync the `dts/upstream/` subtree, run:: |
| 98 | |
| 99 | ./dts/update-dts-subtree.sh pull <devicetree-rebasing-release-tag> |
| 100 | |
| 101 | If required it is also possible to cherry-pick fixes from the |
| 102 | devicetree-rebasing repository prior to next sync, usage:: |
| 103 | |
| 104 | ./dts/update-dts-subtree.sh pick <devicetree-rebasing-commit-id> |
| 105 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 106 | |
| 107 | Configuration |
| 108 | ------------- |
| 109 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 110 | SoC/board maintainers are encouraged to migrate to use synced copies from |
| 111 | `dts/upstream/src/<arch>/<vendor>`. To do that add `imply OF_UPSTREAM` for the |
| 112 | SoC being used via Kconfig and set `DEFAULT_DEVICE_TREE=<vendor>/<name>` when |
| 113 | prompted by Kconfig. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 114 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 115 | However, if `dts/upstream/` hasn't yet received devicetree source file for your |
Tom Rini | 916f738 | 2024-05-17 11:49:30 -0600 | [diff] [blame] | 116 | newly added board support then one option is that you can add the corresponding |
| 117 | devicetree source file as `arch/<arch>/dts/<name>.dts`. To select that add `# |
| 118 | CONFIG_OF_UPSTREAM is not set` and set `DEFAULT_DEVICE_TREE=<name>` when |
| 119 | prompted by Kconfig. Another option is that you can use use the "pick" option of |
| 120 | `dts/update-dts-subtree.sh` mentioned above to bring in the commits that you |
| 121 | need. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 122 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 123 | This should include your CPU or SoC's devicetree file. On top of that any U-Boot |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 124 | specific tweaks (see: :ref:`dttweaks`) can be made for your board. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 125 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 126 | If `OF_EMBED` is selected by Kconfig, then it will be picked up and built into |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 127 | the U-Boot image (including u-boot.bin). This is suitable for debugging |
| 128 | and development only and is not recommended for production devices. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 129 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 130 | If `OF_SEPARATE` is selected by Kconfig, then it will be built and placed in |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 131 | a u-boot.dtb file alongside u-boot-nodtb.bin with the combined result placed |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 132 | in u-boot.bin so you can still just flash u-boot.bin onto your board. If Kconfig |
| 133 | option `SPL_FRAMEWORK` is enabled, then u-boot.img will be built to include the |
| 134 | device tree binary. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 135 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 136 | If `OF_BOARD` is selected by Kconfig, a board-specific routine will provide the |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 137 | devicetree at runtime, for example if an earlier bootloader stage creates |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 138 | it and passes it to U-Boot. |
| 139 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 140 | If `BLOBLIST` is selected by Kconfig, the devicetree may come from a bloblist |
| 141 | passed from a previous stage, if present. |
Simon Glass | 4a30a57 | 2024-01-03 18:49:19 -0700 | [diff] [blame] | 142 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 143 | If `SANDBOX` is selected by Kconfig, then it will be read from a file on |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 144 | startup. Use the -d flag to U-Boot to specify the file to read, -D for the |
| 145 | default and -T for the test devicetree, used to run sandbox unit tests. |
Simon Glass | 1539343 | 2013-04-20 08:42:41 +0000 | [diff] [blame] | 146 | |
| 147 | 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] | 148 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 149 | To use a devicetree file that you have compiled yourself, pass |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 150 | EXT_DTB=<filename> to 'make', as in:: |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 151 | |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 152 | make EXT_DTB=boot/am335x-boneblack-pubkey.dtb |
Simon Glass | 67bce6b | 2014-06-02 22:04:50 -0600 | [diff] [blame] | 153 | |
| 154 | Then U-Boot will copy that file to u-boot.dtb, put it in the .img file |
| 155 | if used, and u-boot-dtb.bin. |
| 156 | |
Simon Glass | dc6fa64 | 2011-10-24 19:15:34 +0000 | [diff] [blame] | 157 | If you wish to put the fdt at a different address in memory, you can |
| 158 | define the "fdtcontroladdr" environment variable. This is the hex |
| 159 | address of the fdt binary blob, and will override either of the options. |
| 160 | Be aware that this environment variable is checked prior to relocation, |
| 161 | when only the compiled-in environment is available. Therefore it is not |
| 162 | possible to define this variable in the saved SPI/NAND flash |
Thomas Chou | 4fda281 | 2015-10-16 08:44:51 +0800 | [diff] [blame] | 163 | environment, for example (it will be ignored). After relocation, this |
| 164 | variable will be set to the address of the newly relocated fdt blob. |
| 165 | It is read-only and cannot be changed. It can optionally be used to |
| 166 | control the boot process of Linux with bootm/bootz commands. |
Simon Glass | dc6fa64 | 2011-10-24 19:15:34 +0000 | [diff] [blame] | 167 | |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 168 | To use this, put something like this in your board header file:: |
Simon Glass | dc6fa64 | 2011-10-24 19:15:34 +0000 | [diff] [blame] | 169 | |
Tom Rini | c9edebe | 2022-12-04 10:03:50 -0500 | [diff] [blame] | 170 | #define CFG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0" |
Simon Glass | dc6fa64 | 2011-10-24 19:15:34 +0000 | [diff] [blame] | 171 | |
Jagannadha Sutradharudu Teki | 79e63a4 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 172 | Build: |
| 173 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 174 | After the board configuration is done, fdt supported u-boot can be built in two |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 175 | ways: |
| 176 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 177 | # build the default dts which is selected by DEFAULT_DEVICE_TREE Kconfig:: |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 178 | |
Jagannadha Sutradharudu Teki | 79e63a4 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 179 | $ make |
Simon Glass | ac35c2f | 2021-08-01 18:57:10 -0600 | [diff] [blame] | 180 | |
| 181 | # build the user specified dts file:: |
| 182 | |
Jagannadha Sutradharudu Teki | 79e63a4 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 183 | $ make DEVICE_TREE=<dts-file-name> |
| 184 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 185 | |
Simon Glass | c5f9e16 | 2021-08-01 18:57:12 -0600 | [diff] [blame] | 186 | .. _dttweaks: |
| 187 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 188 | Adding tweaks for U-Boot |
| 189 | ------------------------ |
| 190 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 191 | With `dts/upstream` Git subtree, it is ensured that devicetree files in U-Boot |
| 192 | are an exact copy of those in Linux kernel available under |
| 193 | `dts/upstream/src/<arch>/<vendor>`. |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 194 | |
| 195 | U-Boot is of course a very different project from Linux, e.g. it operates under |
| 196 | much more restrictive memory and code-size constraints. Where Linux may use a |
| 197 | full clock driver with Common Clock Format (CCF) to find the input clock to the |
| 198 | UART, U-Boot typically wants to output a banner as early as possible before too |
| 199 | much code has run. |
| 200 | |
| 201 | A second difference is that U-Boot includes different phases. For SPL, |
| 202 | constraints are even more extreme and the devicetree is shrunk to remove |
| 203 | unwanted nodes, or even turned into C code to avoid access overhead. |
| 204 | |
| 205 | U-Boot automatically looks for and includes a file with updates to the standard |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 206 | devicetree for your board, searching for them in `arch/<arch>/dts/` in this |
| 207 | order:: |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 208 | |
| 209 | <orig_filename>-u-boot.dtsi |
| 210 | <CONFIG_SYS_SOC>-u-boot.dtsi |
| 211 | <CONFIG_SYS_CPU>-u-boot.dtsi |
| 212 | <CONFIG_SYS_VENDOR>-u-boot.dtsi |
| 213 | u-boot.dtsi |
| 214 | |
| 215 | Only one of these is selected but of course you can #include another one within |
| 216 | that file, to create a hierarchy of shared files. |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 217 | |
Rasmus Villemoes | 303d98d | 2021-11-21 14:52:51 +0100 | [diff] [blame] | 218 | |
| 219 | External .dtsi fragments |
| 220 | ------------------------ |
| 221 | |
| 222 | Apart from describing the hardware present, U-Boot also uses its |
| 223 | control dtb for various configuration purposes. For example, the |
| 224 | public key(s) used for Verified Boot are embedded in a specific format |
| 225 | in a /signature node. |
| 226 | |
| 227 | As mentioned above, the U-Boot build system automatically includes a |
| 228 | `*-u-boot.dtsi` file, if found, containing U-Boot specific |
| 229 | quirks. However, some data, such as the mentioned public keys, are not |
| 230 | appropriate for upstream U-Boot but are better kept and maintained |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 231 | outside the U-Boot repository. You can use `DEVICE_TREE_INCLUDES` Kconfig |
| 232 | option to specify a list of .dtsi files that will also be included when |
Rasmus Villemoes | 303d98d | 2021-11-21 14:52:51 +0100 | [diff] [blame] | 233 | building .dtb files. |
| 234 | |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 235 | |
| 236 | Devicetree bindings schema checks |
| 237 | --------------------------------- |
| 238 | |
| 239 | With devicetee-rebasing Git subtree, the devicetree bindings are also regularly |
| 240 | synced with Linux kernel as `dts/upstream/Bindings/` sub-directory. This |
| 241 | allows U-Boot to run devicetree bindings schema checks which will bring |
| 242 | compliance to U-Boot core/drivers regarding usage of devicetree. |
| 243 | |
| 244 | Dependencies |
| 245 | ~~~~~~~~~~~~ |
| 246 | |
| 247 | The DT schema project must be installed in order to validate the DT schema |
| 248 | binding documents and validate DTS files using the DT schema. For installation |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 249 | instructions, refer to the `DT schema project page`_. |
Sumit Garg | 7a87a44 | 2024-02-22 15:06:04 +0530 | [diff] [blame] | 250 | |
| 251 | Several executables (dt-doc-validate, dt-mk-schema, dt-validate) will be |
| 252 | installed. Ensure they are in your PATH (~/.local/bin by default). |
| 253 | |
| 254 | You should also install yamllint (used by dtschema when present). On Debian/ |
| 255 | Ubuntu systems:: |
| 256 | |
| 257 | apt install yamllint |
| 258 | |
| 259 | Running checks |
| 260 | ~~~~~~~~~~~~~~ |
| 261 | |
| 262 | In order to perform validation of DTB files, use the ``dtbs_check`` target:: |
| 263 | |
| 264 | make dtbs_check |
| 265 | |
| 266 | It is also possible to run checks with a subset of matching schema files by |
| 267 | setting the ``DT_SCHEMA_FILES`` variable to 1 or more specific schema files or |
| 268 | patterns (partial match of a fixed string). Each file or pattern should be |
| 269 | separated by ':'. |
| 270 | |
| 271 | :: |
| 272 | |
| 273 | make dtbs_check DT_SCHEMA_FILES=trivial-devices.yaml:rtc.yaml |
| 274 | make dtbs_check DT_SCHEMA_FILES=/gpio/ |
| 275 | make dtbs_check DT_SCHEMA_FILES=trivial-devices.yaml |
| 276 | |
Rasmus Villemoes | 303d98d | 2021-11-21 14:52:51 +0100 | [diff] [blame] | 277 | |
Simon Glass | a31dc3d | 2018-10-01 12:22:17 -0600 | [diff] [blame] | 278 | Relocation, SPL and TPL |
| 279 | ----------------------- |
| 280 | |
| 281 | U-Boot can be divided into three phases: TPL, SPL and U-Boot proper. |
| 282 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 283 | The full devicetree is available to U-Boot proper, but normally only a subset |
Simon Glass | a31dc3d | 2018-10-01 12:22:17 -0600 | [diff] [blame] | 284 | (or none at all) is available to TPL and SPL. See 'Pre-Relocation Support' and |
Heinrich Schuchardt | c79f03c | 2020-02-25 21:35:39 +0100 | [diff] [blame] | 285 | 'SPL Support' in doc/driver-model/design.rst for more details. |
Simon Glass | a31dc3d | 2018-10-01 12:22:17 -0600 | [diff] [blame] | 286 | |
| 287 | |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 288 | Using several DTBs in the SPL (SPL_MULTI_DTB_FIT Kconfig option) |
| 289 | ---------------------------------------------------------------- |
Jean-Jacques Hiblot | 7c530e3 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 290 | In some rare cases it is desirable to let SPL be able to select one DTB among |
| 291 | many. This usually not very useful as the DTB for the SPL is small and usually |
| 292 | fits several platforms. However the DTB sometimes include information that do |
| 293 | work on several platforms (like IO tuning parameters). |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 294 | In this case it is possible to use SPL_MULTI_DTB_FIT Kconfig option. This option |
| 295 | appends to the SPL a FIT image containing several DTBs listed in SPL_OF_LIST. |
Jean-Jacques Hiblot | 7c530e3 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 296 | board_fit_config_name_match() is called to select the right DTB. |
| 297 | |
| 298 | If board_fit_config_name_match() relies on DM (DM driver to access an EEPROM |
| 299 | containing the board ID for example), it possible to start with a generic DTB |
| 300 | and then switch over to the right DTB after the detection. For this purpose, |
| 301 | the platform code must call fdtdec_resetup(). Based on the returned flag, the |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 302 | platform may have to re-initialise the DM subsystem using dm_uninit() and |
Jean-Jacques Hiblot | 7c530e3 | 2018-12-07 14:50:52 +0100 | [diff] [blame] | 303 | dm_init_and_scan(). |
| 304 | |
| 305 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 306 | Limitations |
| 307 | ----------- |
| 308 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 309 | Devicetrees can help reduce the complexity of supporting variants of boards |
| 310 | which use the same SOC / CPU. |
| 311 | |
| 312 | However U-Boot is designed to build for a single architecture type and CPU |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 313 | type. So for example it is not possible to build a single ARM binary |
| 314 | which runs on your AT91 and OMAP boards, relying on an fdt to configure |
| 315 | the various features. This is because you must select one of |
| 316 | the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 317 | time. Similarly U-Boot cannot be built for multiple cpu types or |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 318 | architectures. |
| 319 | |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 320 | It is important to understand that the fdt only selects options |
| 321 | available in the platform / drivers. It cannot add new drivers (yet). So |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 322 | you must still have the Kconfig option to enable the driver. For example, |
| 323 | you need to enable SYS_NS16550 Kconfig option to bring in the NS16550 driver, |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 324 | but can use the fdt to specific the UART clock, peripheral address, etc. |
Sumit Garg | 86f4ccc | 2024-02-22 15:06:03 +0530 | [diff] [blame] | 325 | In very broad terms, the Kconfig options in general control *what* driver |
Simon Glass | 38d6b8d | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 326 | files are pulled in, and the fdt controls *how* those files work. |
| 327 | |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 328 | History |
| 329 | ------- |
| 330 | |
| 331 | U-Boot configuration was previous done using CONFIG options in the board |
| 332 | config file. This eventually got out of hand with nearly 10,000 options. |
| 333 | |
| 334 | U-Boot adopted devicetrees around the same time as Linux and early boards |
| 335 | used it before Linux (e.g. snow). The two projects developed in parallel |
| 336 | and there are still some differences in the bindings for certain boards. |
| 337 | While there has been discussion of having a separate repository for devicetree |
| 338 | files, in practice the Linux kernel Git repository has become the place where |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 339 | these are stored, with U-Boot taking copies via |
| 340 | `devicetree-rebasing repository`_ and adding tweaks with u-boot.dtsi files. |
Simon Glass | b4fbaaf | 2021-08-01 18:57:11 -0600 | [diff] [blame] | 341 | |
Sumit Garg | 879c61c | 2024-03-01 18:54:53 +0530 | [diff] [blame] | 342 | .. _the devicetree specification: https://www.devicetree.org/specifications/ |
| 343 | .. _devicetree compiler mailing list: https://www.spinics.net/lists/devicetree-compiler/ |
| 344 | .. _devicetree-rebasing repository: https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git |
| 345 | .. _DT schema project page: https://github.com/devicetree-org/dt-schema/tree/main |