Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 1 | .. _device_tree: |
| 2 | |
| 3 | ########### |
| 4 | Device Tree |
| 5 | ########### |
| 6 | OP-TEE core can use the device tree format to inject platform configuration |
| 7 | information during platform initialization and possibly some run time contexts. |
| 8 | |
| 9 | Device Tree technology allows to describe platforms from ASCII source files |
| 10 | so-called DTS files. These can be used to generate a platform description binary |
| 11 | image, so-called DTB, embedded in the platform boot media for applying expected |
| 12 | configuration settings during the platform initializations. |
| 13 | |
| 14 | This scheme relaxes design constraints on the OP-TEE core implementation as most |
| 15 | of the platform specific hardware can be tuned without modifying C source files |
| 16 | or adding configuration directives in the build environments. |
| 17 | |
| 18 | Secure and Non-Secure Device Trees |
| 19 | ********************************** |
| 20 | There can be several device trees embedded in the target system and some can be |
| 21 | shared across the boot stages. |
| 22 | |
| 23 | - Boot loader stages may load a device tree structure in memory for all boot |
| 24 | stage to get platform configuration from. If such device tree data are to |
| 25 | be accessed by the non-secure world, they shall be located in non-secure |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 26 | memory. Secure world may use its content during OP-TEE core |
| 27 | initialization. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 28 | |
| 29 | - Boot loader stages may load a device tree structure in secure memory for |
| 30 | the benefit of the secure world only. Such device tree blob shall be |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 31 | located in secure memory. Secure world could use its content but this |
| 32 | is currently not implemented in the latest OP-TEE release. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 33 | |
| 34 | - OP-TEE core can also embedded a device tree structure to describe the |
| 35 | platform. |
| 36 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 37 | - Non-secure world can embed its own device tree structure(s) and/or |
| 38 | rely on a device tree structure loaded by the secure world during |
| 39 | its initialization which happen before non-secure world is booted. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 40 | |
| 41 | Obviously the non-secure world will not be able to access a device tree image |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 42 | located in a secure memory which non-secure world has no access to. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 43 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 44 | When OP-TEE core is built with ``CFG_DT=y``, non-secure and secure device trees |
| 45 | can be accessed by OP-TEE core to get some platform configuration information. |
| 46 | |
| 47 | .. _generic_boot_and_dtbs: |
| 48 | |
| 49 | Generic boot and DTBs |
| 50 | ********************* |
| 51 | Generic boot sequence gets discovers main memory address ranges from |
| 52 | preferrably embedded DTB (section :ref:`embedded_dtb`), defaulting to |
| 53 | early boot external DTB (section :ref:`external_dtb`). |
| 54 | |
| 55 | Generic boot uses early boot external DTB (section :ref:`external_dtb`) |
| 56 | to share platform configuration information with the non-secure world. |
| 57 | |
| 58 | Plaform and drivers can call OP-TEE DT API (``core/include/kernel/dt.h``) |
| 59 | to access embedded and/or external DTBs. |
| 60 | |
| 61 | .. _external_dtb: |
| 62 | |
| 63 | Early boot external device tree |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 64 | ******************************* |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 65 | The bootloader provides arguments to OP-TEE core when it boots it. Among |
| 66 | those, the physical memory base address of a non-secure device tree image |
| 67 | accessible to OP-TEE core, or a null address value in absence of such DTB. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 68 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 69 | Platform configuration may statically define such DTB location using the |
| 70 | build configuration directive ``CFG_DT_ADDR``. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 71 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 72 | When an external DTB is referred, OP-TEE core gets the console configuration |
| 73 | if the platform has registered a compatible driver by adding attribute |
| 74 | ``__dt_driver`` to a defined ``const struct dt_driver`` instance. |
| 75 | |
| 76 | When an external DTB is referred, OP-TEE core adds into this DTB the |
| 77 | description of some OP-TEE resources. These information can be used |
| 78 | by the non-secure world to properly communicate with OP-TEE. This scheme |
| 79 | assumes the image is located in non-secure memory. |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 80 | |
| 81 | Modifications made by OP-TEE core on the non-secure device tree image provided |
| 82 | by early boot and passed to non-secure world are the following: |
| 83 | |
| 84 | - Add an OP-TEE node if none found with the related invocation parameters. |
| 85 | |
| 86 | - Add a reserved memory node for the few memory areas that shall be reserved |
| 87 | to the secure world and non accessed by the non-secure world. |
| 88 | |
| 89 | - Add a PSCI description node if none found. |
| 90 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 91 | Early boot DTB can be accessed by OP-TEE core only during its initialization, |
| 92 | before non-secure world boots as it is expected the DTB memory location has |
| 93 | likely been replaced with runtime contexts content. |
| 94 | |
| 95 | Assuming there is no embedded DTB (section :ref:`embedded_dtb`) OP-TEE core |
| 96 | discovers the main memory address ranges from the non-secure DTB. |
| 97 | |
| 98 | .. _external_dtb_overlay: |
| 99 | |
| 100 | Early boot device tree overlay |
| 101 | ****************************** |
| 102 | There are two possibilities for OP-TEE core to provide a device tree |
| 103 | overlay to the non-secure world. |
| 104 | |
| 105 | - Append OP-TEE nodes to an existing DTB overlay located in early boot DTB. |
| 106 | (``CFG_DT_ADDR`` or boot argument register ``R2``/``X2``). |
| 107 | |
| 108 | - Generate a new DTB overlay image at location defined by ``CFG_DT_ADDR``. |
| 109 | |
| 110 | In the later case, memory referred by configuration directive ``CFG_DT_ADDR`` |
| 111 | shall not contain a valid DTB image when OP-TEE core is booted. A subsequent |
| 112 | non-secure boot stage should merge the OP-TEE DTB overlay image into |
| 113 | another DTB. |
| 114 | |
| 115 | A typical bootflow for this would be Trusted Firmware-A -> OP-TEE -> U-Boot |
| 116 | with U-Boot in charge of merging OP-TEE DTB overlay located at ``CFG_DT_ADDR`` |
| 117 | into a DTB U-Boot has loaded from elsewhere. |
| 118 | |
| 119 | This functionality is enabled when ``CFG_EXTERNAL_DTB_OVERLAY=y``. |
| 120 | |
| 121 | .. _embedded_dtb: |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 122 | |
| 123 | Embedded Secure Device Tree |
| 124 | *************************** |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 125 | When OP-TEE core is built with configuration directive ``CFG_EMBED_DTB=y``, |
Joakim Bech | 8e5c5b3 | 2018-10-25 08:18:32 +0200 | [diff] [blame] | 126 | directive ``CFG_EMBED_DTB_SOURCE_FILE`` shall provide the relative path of the |
| 127 | DTS file inside directory ``core/arch/$(ARCH)/dts`` from which a DTB is |
| 128 | generated and embedded in a read-only section of OP-TEE core. |
| 129 | |
Etienne Carriere | fa41046 | 2019-03-11 10:17:43 +0100 | [diff] [blame] | 130 | Refer to ``core/include/kernel/dt.h`` for API to access embedded DTB. |
| 131 | |
| 132 | Section :ref:`generic_boot_and_dtbs` documents the generic boot sequence |
| 133 | against embedded DTB. |