Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 1 | Portability Model |
| 2 | ================= |
| 3 | |
| 4 | Within the Trusted Services project, an environment represents the execution environment for an application such |
| 5 | as 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 | |
| 11 | An underlying TEE or SPM that manages a secure processing environment will have its own model for porting to different hardware. |
| 12 | For example, OP-TEE has its own driver model that allows for alternative hardware drivers. In some cases, a secure processing |
| 13 | environment will not provide native support for all hardware that an application depends on. To address this, the TS |
| 14 | portability 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 | |
| 19 | Ports and Adapters Architecture |
| 20 | ------------------------------- |
| 21 | |
| 22 | An application is decoupled from any particular environment via a set of interfaces that reflect the needs of the application. |
| 23 | This model conforms to the *ports and adapters* architectural pattern that aims to avoid tight coupling between application |
| 24 | components and any particular environment. This pattern, also known as the *hexagonal architecture*, is often illustrated as |
| 25 | a hexagonal cell with the application on the inside and the platform on the outside. |
| 26 | |
| 27 | The following diagram illustrates how ports and adapters is applied in the trusted services project to provide a model for |
| 28 | application portability. |
| 29 | |
| 30 | .. image:: image/TSportabilityModel.svg |
| 31 | |
| 32 | The 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 | |
| 45 | The 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 |
| 47 | an implementation of the Global Platform Internal Core API that provides services such as secure storage. Usage of any back-end |
| 48 | hardware is handled by OP-TEE and its own OS components so no additional provision is needed. Bare metal environments such as |
| 49 | secure partitions offer few native facilities so it may be necessary to map application interfaces to platform provided drivers. |
| 50 | Mapping application interfaces to platform drivers is a way of extending the native services provided by an environment. |
| 51 | |
| 52 | The portability model allows for an arbitrary partitioning of hardware-backed services between native environment services and |
| 53 | platform drivers. |
| 54 | |
| 55 | Portability Model Example |
| 56 | ------------------------- |
| 57 | |
| 58 | To 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 | |
| 63 | The Microsoft TPM2.0 reference and Mbed TLS both define their own platform interfaces to allow for platform specific |
| 64 | implementations of features such as roll-back protected storage and entropy. Although some interfaces are similar between the |
| 65 | two implementations, they are not the same. These interfaces are classed as ports within the ports and adapters architecture. |
| 66 | To simplify the example, just the entropy platform dependency is considered. Both fTPM and Crypto service providers need access |
| 67 | to 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 | |
| 74 | Adapters will be responsible for adapting both fTPM and Crypto views of an entropy source to a suitable realization. |
| 75 | Some example adapters: |
| 76 | |
| 77 | fTPM 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 | |
| 83 | Crypto 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 | |
| 89 | The above examples reveal that for a given environment, a port may be realized by more than one type of adapter. For example, an |
| 90 | fTPM deployed within a secure partition could source entropy from either TRNG hardware or from the Crypto service. This |
| 91 | ambiguity 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 | |
| 98 | Providing Platform Firmware |
| 99 | --------------------------- |
| 100 | |
| 101 | A goal of the TS project is to reduce barriers to deploying trusted services on different hardware platforms. To this end, |
| 102 | build-time and run-time coupling between TS project and platform components should be minimized. Platform providers should be |
| 103 | free 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 | |
| 112 | The platform top-level directory within the TS project provides a structure that allows platform specific components to be |
| 113 | contributed by different providers. Different providers are represented beneath the platform/providers directory. The virtual |
| 114 | platform interfaces used by some adapters are defined under platform/interface. The directory structure beneath a platform |
| 115 | provider's parent is organized to reflect the provider's own naming scheme for different hardware. Supported platforms are each |
| 116 | represented by a leaf sub-directory within the provider's subtree. |
| 117 | |
| 118 | For 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 | |
| 130 | Under each platform leaf directory is a file called *platform.cmake*. This file implements the common configuration and build |
| 131 | interface that will be used during the deployment build process. How this interface is realized is entirely down to the |
| 132 | platform provider. An implementation will do things like setting configuration variables for SoC, board and driver selection. |
| 133 | Any additional files needed to support platform configuration and build may be included within the platform provider's sub-tree. |
| 134 | |
| 135 | For product developers who want to define and maintain their own private platforms, it should be possible to override the |
| 136 | default platform/providers directory path to allow an alternative sub-tree to be used. A product developer is free to organize |
| 137 | a private sub-tree in any way that suites their needs. |
| 138 | |
| 139 | Although the TS project structure doesn't mandate it, platform specific firmware is likely to live outside of the TS project. |
| 140 | The ability to reuse existing drivers and driver frameworks is important for promoting adoption across hardware from different |
| 141 | vendors. Board and silicon vendors may reuse existing CI and project infrastructure for platform components that they maintain. |
| 142 | |
| 143 | Some special platforms are provided by the TS project itself. These are represented beneath the *ts* provider. |
| 144 | Current 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 | |
| 163 | Determining a Platform Configuration for a Deployment |
| 164 | ----------------------------------------------------- |
| 165 | |
| 166 | The TS project supports building and installing an application image into different environments that could be hosted on |
| 167 | different hardware platforms. A platform is characterized by SoC and board-level hardware and possibly by OS type components |
| 168 | such 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 | |
| 175 | The 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 | |
| 180 | The combination of <application name> + <environment> allows a set of build-time platform dependencies to be generated, based on |
| 181 | the set of adapter components used for the deployment. This information is passed via the platform build interface to the |
| 182 | platform.cmake file for the specified platform via a CMake target property called TS_PLATFORM_DRIVER_DEPENDENCIES. The |
| 183 | translation of the platform dependency information to a suitable build configuration is handled by the platform.cmake file for |
| 184 | the selected platform. This separation gives a platform provider the freedom to use their own configuration conventions when |
| 185 | reusing existing drivers. |
| 186 | |
| 187 | To allow for out-of-tree platform definitions, the root path for platform definitions may be modified by providing an |
| 188 | alternative value for TS_PLATFORM_ROOT. Both TS_PLATFORM and TS_PLATFORM_ROOT may be set via the CMake command line or using |
| 189 | environment variables. |
| 190 | |
| 191 | Adapters |
| 192 | -------- |
| 193 | |
| 194 | As described above, the role of an adapter conforms to the Ports and Adapters pattern. With reference to the hexagonal cell |
| 195 | representation, an adapter implements an application defined inside interface and adapts it to either an environment interface |
| 196 | or an outside platform interface. Within the TS project, adapters are treated like any other software component and may be |
| 197 | reused whenever appropriate. However, because an adapter implements an application defined interface, adapter implementations |
| 198 | will tend to be tied to a particular application or component. The complexity of adapter implementations can vary a lot and |
| 199 | will depend on how closely an inside interface matches either an outside interface or an environment interface. |
| 200 | |
| 201 | The collection of adapters used for a deployment is defined by the environment specific build file for a deployment. Deployment |
| 202 | of the same service into a different environment may result in a different set of adapters being used. As each adapter is |
| 203 | treated as a separate component, a separate component.cmake file exists for each adapter. When an adapter depends on one or |
| 204 | more platform interfaces, the dependency must be declared in the adapter's component.cmake file. This information forms the |
| 205 | basis for the platform build configuration. |
| 206 | |
| 207 | -------------- |
| 208 | |
| 209 | *Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.* |
| 210 | |
| 211 | SPDX-License-Identifier: BSD-3-Clause |