blob: 8305cb23796a26f376463886302e258a9b5abf01 [file] [log] [blame]
Julian Halle76ade82020-11-25 03:07:21 +01001Portability Model
2=================
3
4Within the Trusted Services project, an environment represents the execution environment for an application such
5as a trusted service provider. Some example environments are:
6
7 - *opteesp* - Secure partition managed by OP-TEE.
8 - *opteeta* - TA running under OP-TEE with access to the Global Platform internal API.
9 - *hfsp* - Secure partition managed by Hafnium.
10
11An underlying TEE or SPM that manages a secure processing environment will have its own model for porting to different hardware.
12For example, OP-TEE has its own driver model that allows for alternative hardware drivers. In some cases, a secure processing
13environment will not provide native support for all hardware that an application depends on. To address this, the TS
14portability model allows:
15
16 - Application interfaces to be adapted to services natively provided by a secure processing environment if they are available.
17 - Adapting to platform provided drivers when no native environment support is available.
18
19Ports and Adapters Architecture
20-------------------------------
21
22An application is decoupled from any particular environment via a set of interfaces that reflect the needs of the application.
23This model conforms to the *ports and adapters* architectural pattern that aims to avoid tight coupling between application
24components and any particular environment. This pattern, also known as the *hexagonal architecture*, is often illustrated as
25a hexagonal cell with the application on the inside and the platform on the outside.
26
27The following diagram illustrates how ports and adapters is applied in the trusted services project to provide a model for
28application portability.
29
30.. image:: image/TSportabilityModel.svg
31
32The portability model has the following characteristics:
33
34 - The application is decoupled from the environment by a set of virtual interfaces (ports) that reflect the needs of the
35 application.
36 - Those interfaces are realized by a set of adapters that either use native environment services or platform provided
37 services.
38 - For a given environment, the set of adapters that realize interfaces used by an application will always be the same,
39 independent of the platform.
40 - A platform presents interfaces that conform to conventional driver and middleware abstractions such as block drivers and
41 filesystems.
42 - The set of platform interfaces that an application depends on is defined by the set of adapters used for a deployment of an
43 application in a particular environment. This can form the basis for a platform configuration.
44
45The need to use platform provided components will depend on the native features provided by an environment. For example, the
46*opteeta* environment represents the TA environment provided by OP-TEE. In its role as a trusted OS, OP-TEE provides access to
47an implementation of the Global Platform Internal Core API that provides services such as secure storage. Usage of any back-end
48hardware is handled by OP-TEE and its own OS components so no additional provision is needed. Bare metal environments such as
49secure partitions offer few native facilities so it may be necessary to map application interfaces to platform provided drivers.
50Mapping application interfaces to platform drivers is a way of extending the native services provided by an environment.
51
52The portability model allows for an arbitrary partitioning of hardware-backed services between native environment services and
53platform drivers.
54
55Portability Model Example
56-------------------------
57
58To illustrate usage of the portability model, consider deployments of the following two trusted services:
59
60 - fTPM based on the Microsoft TPM2.0 reference implementation.
61 - trustedfirmware.org Crypto service based on the Mbed TLS library.
62
63The Microsoft TPM2.0 reference and Mbed TLS both define their own platform interfaces to allow for platform specific
64implementations of features such as roll-back protected storage and entropy. Although some interfaces are similar between the
65two implementations, they are not the same. These interfaces are classed as ports within the ports and adapters architecture.
66To simplify the example, just the entropy platform dependency is considered. Both fTPM and Crypto service providers need access
67to a cryptographic grade RNG to support key generation. How the RNG is realized will depend on:
68
69 - What facilities the environment natively provides.
70 - What other trusted services are available on the device.
71 - Whether the environment allows for platform specific access to hardware.
72 - Availability of a spare hardware TRNG instance.
73
74Adapters will be responsible for adapting both fTPM and Crypto views of an entropy source to a suitable realization.
75Some example adapters:
76
77fTPM adapters that realize MS entropy interface (port)
78''''''''''''''''''''''''''''''''''''''''''''''''''''''
79 - *Adapts to crypto service* - Uses crypto service generate_random operation
80 - *Adapts to TEE API* - Uses native TEE OS
81 - *Adapts to TRNG* - Uses platform TRNG hardware
82
83Crypto adapters that realize Mbed TLS entropy source interface (port)
84'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
85 - *Adapts to fTPM* - Uses TPM2 getrandom command
86 - *TEE API* - Uses native TEE OS
87 - *TRNG* - Uses platform TRNG hardware
88
89The above examples reveal that for a given environment, a port may be realized by more than one type of adapter. For example, an
90fTPM deployed within a secure partition could source entropy from either TRNG hardware or from the Crypto service. This
91ambiguity may be resolved by various strategies such as:
92
93 1. Allow a service profile to be applied at build time that defines a core set of mandatory trusted services. A build-time
94 selection of alternative adapters is made, based on available core services.
95 2. A built image for a trusted service deployment to a particular environment includes the superset of adapters that could be
96 used. A runtime configuration is applied, that specifies which adapters to use.
97
98Providing Platform Firmware
99---------------------------
100
101A goal of the TS project is to reduce barriers to deploying trusted services on different hardware platforms. To this end,
102build-time and run-time coupling between TS project and platform components should be minimized. Platform providers should be
103free to make any of the following choices:
104
105 - Reuse existing drivers and driver frameworks (e.g. from tf-a, an RTOS, CMSIS).
106 - Provide platform components as part of a BSP.
107 - Maintain platform components in separate repos.
108 - Operate independent test, bug reporting and release processes for platform components.
109 - Control the logical organization and naming of different platforms within the TS project.
110 - Maintain whatever platform configuration files that are needed within the provider's sub-tree within the TS project.
111
112The platform top-level directory within the TS project provides a structure that allows platform specific components to be
113contributed by different providers. Different providers are represented beneath the platform/providers directory. The virtual
114platform interfaces used by some adapters are defined under platform/interface. The directory structure beneath a platform
115provider's parent is organized to reflect the provider's own naming scheme for different hardware. Supported platforms are each
116represented by a leaf sub-directory within the provider's subtree.
117
118For Arm provided platforms, the structure will look something like this::
119
120 platform
121 |-- interface
122 |-- providers
123 |--arm
124 |-- corstone700
125 |-- fvp
126 |-- fvp_base_aemva
127 |-- fvp_base_revc-2xaemv8a
128 |-- platform.cmake
129
130Under each platform leaf directory is a file called *platform.cmake*. This file implements the common configuration and build
131interface that will be used during the deployment build process. How this interface is realized is entirely down to the
132platform provider. An implementation will do things like setting configuration variables for SoC, board and driver selection.
133Any additional files needed to support platform configuration and build may be included within the platform provider's sub-tree.
134
135For product developers who want to define and maintain their own private platforms, it should be possible to override the
136default platform/providers directory path to allow an alternative sub-tree to be used. A product developer is free to organize
137a private sub-tree in any way that suites their needs.
138
139Although the TS project structure doesn't mandate it, platform specific firmware is likely to live outside of the TS project.
140The ability to reuse existing drivers and driver frameworks is important for promoting adoption across hardware from different
141vendors. Board and silicon vendors may reuse existing CI and project infrastructure for platform components that they maintain.
142
143Some special platforms are provided by the TS project itself. These are represented beneath the *ts* provider.
144Current TS platforms are:
145
146.. list-table::
147 :header-rows: 1
148 :widths: 10, 90
149
150 * - TS Platform
151 - Purpose
152 * - ts/vanilla
153 - | A platform that never provides any drivers. The ts/vanilla platform should be used when an environment provides its own
154 | device framework and no additional drivers need to be provided by the platform. An attempt to build a deployment with
155 | platform dependencies on the vanilla platform will result in a build-time error. The vanilla platform is selected by
156 | default at build-time if no explicit platform has been specified.
157 * - ts/mock
158 - | A platform that provides a complete set of drivers that may be selected when building any deployment. The platform uses
159 | mock drivers that don't offer functionality suitable for production builds. The mock platform is useful for CI build
160 | testing of deployments with platform dependencies. You should always expect a deployment with platform dependencies to
161 | build when TS_PLATFORM=ts/mock.
162
163Determining a Platform Configuration for a Deployment
164-----------------------------------------------------
165
166The TS project supports building and installing an application image into different environments that could be hosted on
167different hardware platforms. A platform is characterized by SoC and board-level hardware and possibly by OS type components
168such as device drivers and middleware. To deploy an application that depends on platform drivers, you need to tie-down:
169
170 - *Application name* - such as the name of the service e.g. crypto, secure-storage, attestation, tpm.
171 - *Environment* - the environment in which the application will run e.g. bare metal secure partition, Global Platform TEE,
172 Trusty TEE, microcontroller RTOS.
173 - *Platform* - the hardware platform that hosts the environment.
174
175The following example illustrates how these parameters are specified via the deployment build command line::
176
177 cd trusted-services/deployments/crypto/opteesp
178 cmake -S . -B build -DTS_PLATFORM=arm/fvp/fvp_base_revc-2xaemv8a
179
180The combination of <application name> + <environment> allows a set of build-time platform dependencies to be generated, based on
181the set of adapter components used for the deployment. This information is passed via the platform build interface to the
182platform.cmake file for the specified platform via a CMake target property called TS_PLATFORM_DRIVER_DEPENDENCIES. The
183translation of the platform dependency information to a suitable build configuration is handled by the platform.cmake file for
184the selected platform. This separation gives a platform provider the freedom to use their own configuration conventions when
185reusing existing drivers.
186
187To allow for out-of-tree platform definitions, the root path for platform definitions may be modified by providing an
188alternative value for TS_PLATFORM_ROOT. Both TS_PLATFORM and TS_PLATFORM_ROOT may be set via the CMake command line or using
189environment variables.
190
191Adapters
192--------
193
194As described above, the role of an adapter conforms to the Ports and Adapters pattern. With reference to the hexagonal cell
195representation, an adapter implements an application defined inside interface and adapts it to either an environment interface
196or an outside platform interface. Within the TS project, adapters are treated like any other software component and may be
197reused whenever appropriate. However, because an adapter implements an application defined interface, adapter implementations
198will tend to be tied to a particular application or component. The complexity of adapter implementations can vary a lot and
199will depend on how closely an inside interface matches either an outside interface or an environment interface.
200
201The collection of adapters used for a deployment is defined by the environment specific build file for a deployment. Deployment
202of the same service into a different environment may result in a different set of adapters being used. As each adapter is
203treated as a separate component, a separate component.cmake file exists for each adapter. When an adapter depends on one or
204more platform interfaces, the dependency must be declared in the adapter's component.cmake file. This information forms the
205basis for the platform build configuration.
206
207--------------
208
209*Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.*
210
211SPDX-License-Identifier: BSD-3-Clause