blob: b4919ad76934c4e574ccd28dc17429e061983cd1 [file] [log] [blame]
Joakim Bech8e5c5b32018-10-25 08:18:32 +02001.. _device_tree:
2
3###########
4Device Tree
5###########
6OP-TEE core can use the device tree format to inject platform configuration
7information during platform initialization and possibly some run time contexts.
8
9Device Tree technology allows to describe platforms from ASCII source files
10so-called DTS files. These can be used to generate a platform description binary
11image, so-called DTB, embedded in the platform boot media for applying expected
12configuration settings during the platform initializations.
13
14This scheme relaxes design constraints on the OP-TEE core implementation as most
15of the platform specific hardware can be tuned without modifying C source files
16or adding configuration directives in the build environments.
17
18Secure and Non-Secure Device Trees
19**********************************
20There can be several device trees embedded in the target system and some can be
21shared 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 Carrierefa410462019-03-11 10:17:43 +010026 memory. Secure world may use its content during OP-TEE core
27 initialization.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020028
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 Carrierefa410462019-03-11 10:17:43 +010031 located in secure memory. Secure world could use its content but this
32 is currently not implemented in the latest OP-TEE release.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020033
34 - OP-TEE core can also embedded a device tree structure to describe the
35 platform.
36
Etienne Carrierefa410462019-03-11 10:17:43 +010037 - 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 Bech8e5c5b32018-10-25 08:18:32 +020040
41Obviously the non-secure world will not be able to access a device tree image
Etienne Carrierefa410462019-03-11 10:17:43 +010042located in a secure memory which non-secure world has no access to.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020043
Etienne Carrierefa410462019-03-11 10:17:43 +010044When OP-TEE core is built with ``CFG_DT=y``, non-secure and secure device trees
45can be accessed by OP-TEE core to get some platform configuration information.
46
47.. _generic_boot_and_dtbs:
48
49Generic boot and DTBs
50*********************
51Generic boot sequence gets discovers main memory address ranges from
52preferrably embedded DTB (section :ref:`embedded_dtb`), defaulting to
53early boot external DTB (section :ref:`external_dtb`).
54
55Generic boot uses early boot external DTB (section :ref:`external_dtb`)
56to share platform configuration information with the non-secure world.
57
58Plaform and drivers can call OP-TEE DT API (``core/include/kernel/dt.h``)
59to access embedded and/or external DTBs.
60
61.. _external_dtb:
62
63Early boot external device tree
Joakim Bech8e5c5b32018-10-25 08:18:32 +020064*******************************
Etienne Carrierefa410462019-03-11 10:17:43 +010065The bootloader provides arguments to OP-TEE core when it boots it. Among
66those, the physical memory base address of a non-secure device tree image
67accessible to OP-TEE core, or a null address value in absence of such DTB.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020068
Etienne Carrierefa410462019-03-11 10:17:43 +010069Platform configuration may statically define such DTB location using the
70build configuration directive ``CFG_DT_ADDR``.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020071
Etienne Carrierefa410462019-03-11 10:17:43 +010072When an external DTB is referred, OP-TEE core gets the console configuration
73if the platform has registered a compatible driver by adding attribute
74``__dt_driver`` to a defined ``const struct dt_driver`` instance.
75
76When an external DTB is referred, OP-TEE core adds into this DTB the
77description of some OP-TEE resources. These information can be used
78by the non-secure world to properly communicate with OP-TEE. This scheme
79assumes the image is located in non-secure memory.
Joakim Bech8e5c5b32018-10-25 08:18:32 +020080
81Modifications made by OP-TEE core on the non-secure device tree image provided
82by 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 Carrierefa410462019-03-11 10:17:43 +010091Early boot DTB can be accessed by OP-TEE core only during its initialization,
92before non-secure world boots as it is expected the DTB memory location has
93likely been replaced with runtime contexts content.
94
95Assuming there is no embedded DTB (section :ref:`embedded_dtb`) OP-TEE core
96discovers the main memory address ranges from the non-secure DTB.
97
98.. _external_dtb_overlay:
99
100Early boot device tree overlay
101******************************
102There are two possibilities for OP-TEE core to provide a device tree
103overlay 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
110In the later case, memory referred by configuration directive ``CFG_DT_ADDR``
111shall not contain a valid DTB image when OP-TEE core is booted. A subsequent
112non-secure boot stage should merge the OP-TEE DTB overlay image into
113another DTB.
114
115A typical bootflow for this would be Trusted Firmware-A -> OP-TEE -> U-Boot
116with U-Boot in charge of merging OP-TEE DTB overlay located at ``CFG_DT_ADDR``
117into a DTB U-Boot has loaded from elsewhere.
118
119This functionality is enabled when ``CFG_EXTERNAL_DTB_OVERLAY=y``.
120
121.. _embedded_dtb:
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200122
123Embedded Secure Device Tree
124***************************
Etienne Carrierefa410462019-03-11 10:17:43 +0100125When OP-TEE core is built with configuration directive ``CFG_EMBED_DTB=y``,
Joakim Bech8e5c5b32018-10-25 08:18:32 +0200126directive ``CFG_EMBED_DTB_SOURCE_FILE`` shall provide the relative path of the
127DTS file inside directory ``core/arch/$(ARCH)/dts`` from which a DTB is
128generated and embedded in a read-only section of OP-TEE core.
129
Etienne Carrierefa410462019-03-11 10:17:43 +0100130Refer to ``core/include/kernel/dt.h`` for API to access embedded DTB.
131
132Section :ref:`generic_boot_and_dtbs` documents the generic boot sequence
133against embedded DTB.