Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 1 | Service Deployment Model |
| 2 | ======================== |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 3 | |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 4 | A goal of the Trusted Services project is to provide a toolbox of reusable service components |
| 5 | that can be deployed across a wide range of platforms. The project structure promotes reuse by |
| 6 | grouping related source files into subdirectories that represent reusable components. Components |
| 7 | may be configured and combined in different ways to meet the needs of platform integrators who |
| 8 | aim to create firmware with the right features and tradeoffs for their products. |
| 9 | |
| 10 | Within the TS project structure, build files that combine and configure components to create |
| 11 | deployable firmware images reside under the deployments top-level directory. Beneath the |
| 12 | deployments parent are sub-directories concerned with building and deploying different |
| 13 | applications. Applications can generally be classified as one of the following: |
| 14 | |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 15 | - Service providers (e.g. psa-crypto) |
| 16 | - Test suites (e.g. ts-service-test) |
| 17 | - Libraries (e.g. libts) |
| 18 | - Development support applications (e.g. fwu-tool) |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 19 | |
| 20 | This page is mainly concerned with describing the conventions used to enable service providers |
| 21 | to be deployed in different environments, on different platforms and with different capabilities. |
| 22 | The conventions aim to minimize build definition duplication between alternative deployments |
| 23 | while offering sufficient flexibility to customize capabilities and support different platforms. |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 24 | |
| 25 | Ports and Adapters Architecture |
| 26 | ------------------------------- |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 27 | |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 28 | An application is decoupled from any particular environment via a set of interfaces that reflect |
| 29 | the needs of the application. This model conforms to the ports and adapters architectural |
| 30 | pattern that aims to avoid tight coupling between application components and any particular |
| 31 | environment. This pattern, also known as the hexagonal architecture, is often illustrated as a |
| 32 | hexagonal cell with the application on the inside and the platform on the outside. |
| 33 | |
| 34 | The following diagram illustrates how ports and adapters is applied in the trusted services |
| 35 | project to provide a model for service provider deployment. |
| 36 | |
| 37 | .. image:: image/TSportabilityModel.svg |
| 38 | |
| 39 | This deployment model has the following characteristics: |
| 40 | |
| 41 | - The application is decoupled from the environment by a set of virtual interfaces (ports) |
| 42 | that reflect the needs of the application. |
| 43 | - Ports are realized by a set of adapters. An adapter may: |
| 44 | |
| 45 | * Use a service/device provided by the platform or environment. |
| 46 | * Communicate with another service provider. |
| 47 | * Provide a self-contained implementation. |
| 48 | - The set of adapters that the application depends on represents the infrastructure that is |
| 49 | needed to support the application. |
| 50 | - Different infrastructure realizations may be needed for different deployments of the same |
| 51 | service provider. |
| 52 | |
| 53 | Service Deployment Structure |
| 54 | ---------------------------- |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 55 | |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 56 | By convention, the directory structure for service provider deployments reflects the layers in |
| 57 | the ports and adapters architecture. The following dependency diagram illustrates the set of |
| 58 | relationships that exist for a fully defined deployment: |
| 59 | |
| 60 | .. uml:: uml/ServiceDeploymentDependencies.puml |
| 61 | |
| 62 | To avoid undesirable build definition duplication when adding new deployments of an application, |
| 63 | the directory structure used to organize files related to different deployments should reflect |
| 64 | the above model. The following table lists reusable build components that may be used across |
| 65 | different deployment definitions: |
| 66 | |
| 67 | .. list-table:: |
| 68 | :widths: 10 20 20 |
| 69 | :header-rows: 1 |
| 70 | |
| 71 | * - Build Component |
| 72 | - Defines |
| 73 | - Reuse Scope |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 74 | * - Deployment |
| 75 | - | Represents an application. Examples: a service provider, demo application, test application, |
| 76 | | some tool. |
| 77 | - | - |
| 78 | * - Infrastructure |
| 79 | - | A specific set of SW components that realize the ports that the application depends on. |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 80 | | An infrastructure definition may depend on: |
| 81 | |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 82 | * Drivers that conform to a driver model. |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 83 | - | Any deployment that uses the same infrastructure to support the application. |
| 84 | | This will depend on how specific the infrastructure is. An infrastructure |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 85 | | definition may allow for some level of configurability to enable a deployment |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 86 | | to impose a particular build configuration. Where an infrastructure includes |
| 87 | | adapters that use a well supported driver model (such as UEFI), the scope |
| 88 | | for reuse is large. |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 89 | * - Environment |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 90 | - | The set of environment specific components that are common across all |
| 91 | | deployments of an application for a particular environment. |
| 92 | - | All deployments of the application into a specific environment. There is |
| 93 | | scope to improve reuse of environment specific components across multiple |
| 94 | | deployments. |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 95 | * - Configuration |
| 96 | - | Build configuration variables together with a particular application, infrastructure |
| 97 | | and environment. Represents a specific build of the application. |
| 98 | - | None. |
| 99 | * - Platform |
| 100 | - | A specific set of hardware drivers and target platform specific settings. |
| 101 | | A platform definition may depend on: |
| 102 | |
| 103 | * Hardware driver ports defined by various components. |
| 104 | * Hardware specific resources. |
| 105 | * Target specific resource selection. |
| 106 | - | None. |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 107 | |
| 108 | Deployment Directory Structure |
| 109 | ------------------------------ |
| 110 | Using the block-storage deployment as an example, the deployment directory structure reflects |
| 111 | the service deployment model as follows:: |
| 112 | |
| 113 | deployments |
| 114 | |- block-storage |
| 115 | |- block-storage.cmake - Common application build definition |
| 116 | |- env - Environment specific build definitions |
| 117 | |- infra - Alternative infrastructures |
| 118 | |- config - Configurations for block-storage deployments |
| 119 | |
| 120 | Configuration Definitions |
| 121 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 122 | To build a particular configuration of the block-storage service provider (in this case, one |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 123 | that uses flash storage emulated with semihosting on the AEM FVP platform), use:: |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 124 | |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 125 | cd deployments/block-storage/config/semihosted-opteesp |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 126 | cmake -B build |
Gyorgy Szing | 21c6e00 | 2024-09-06 12:58:33 +0200 | [diff] [blame] | 127 | cmake --build build |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 128 | |
| 129 | The CMakeLists.txt file for the n1sdp-flash deployment of the block-storage service provider |
| 130 | includes: |
| 131 | |
| 132 | - Set TS_PLATFORM to n1sdp platform name |
| 133 | - Set any build configuration parameter overrides |
| 134 | - Include ``${DEPLOYMENT_ROOT}/env/opteesp.cmake`` |
| 135 | - Include ``${DEPLOYMENT_ROOT}/infra/edk2-flash.cmake`` |
| 136 | - Include ``${DEPLOYMENT_ROOT}/block-storage.cmake`` |
| 137 | |
| 138 | Each alternative deployment of the block-storage service provider is represented by a |
| 139 | subdirectory under ``${DEPLOYMENT_ROOT}/config``. The number of directories under config is |
| 140 | likely to grow to accommodate platform variability and different tradeoffs for how the infrastructure |
| 141 | for an application will be realized. |
| 142 | |
| 143 | To support test and to provide a starting point for new config definitions, a default config should |
| 144 | exist for each supported environment. |
| 145 | |
| 146 | Infrastructure Definitions |
| 147 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 148 | An infrastructure defines a set of adapter components that realize the ports that the application |
| 149 | depends on. For block-storage deployments, some possible infrastructures are: |
| 150 | |
| 151 | .. list-table:: |
| 152 | :header-rows: 1 |
| 153 | :widths: 10, 40 |
| 154 | |
| 155 | * - Infra Name |
| 156 | - Description |
| 157 | * - ref-ram |
| 158 | - Provides volatile storage using the reference partition configuration. Intended for test. |
| 159 | * - edk2-flash |
| 160 | - Provides persistent storage using a flash driver that conforms to the EDK2 driver model. |
| 161 | * - tfa-flash |
| 162 | - Provides persistent storage using a flash driver that conforms to the TF-A driver model. |
| 163 | * - rpmb |
| 164 | - Provides persistent storage using an RPMB partition, accessed via a Nwd agent. |
| 165 | |
| 166 | Platform Support |
| 167 | ---------------- |
| 168 | The Trusted Services project is not intended to be a home for platform specific code such as |
| 169 | device drivers. Ideally, device drivers and other platform specific code should be reused |
| 170 | from external upstream repos such as edk2-platforms. The ports and adapters pattern allows |
| 171 | alternative driver models to be accommodated so different upstream projects with different |
| 172 | driver models may be used without the need to modify driver code. Where driver reuse from |
| 173 | an external project is not possible, the platform directory structure can accommodate driver |
| 174 | components that reside within the TS project. |
| 175 | |
| 176 | The ability to accommodate third-party device drivers that conform to different driver models |
| 177 | is important for enabling TS components to be used across different segments. The EDK2 |
| 178 | project for example can provide a rich source of drivers that conform to the UEFI model. |
| 179 | UEFI is not however adopted in all product segments. |
| 180 | |
| 181 | All files related to supporting different platforms reside beneath the platform top-level |
| 182 | directory. |
| 183 | |
| 184 | Platform Providers |
| 185 | ^^^^^^^^^^^^^^^^^^ |
| 186 | Within the TS project, a platform provider is responsible for adding and maintaining the |
| 187 | glue that enables platform specific code to be used from a particular source. The platform |
| 188 | code will either be: |
| 189 | |
| 190 | - Fetched from an upstream repo (preferred) |
| 191 | - Added to the TS project. |
| 192 | |
| 193 | Each platform provider is represented by a subdirectory beneath ``platform/providers``. For |
| 194 | Arm provided platforms, the structure will look something like this:: |
| 195 | |
| 196 | platform |
| 197 | |-- providers |
| 198 | |--arm |
Gyorgy Szing | 7760ad0 | 2024-10-24 18:33:28 +0200 | [diff] [blame^] | 199 | |-- Corstone1000 |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 200 | |-- fvp |
| 201 | |-- fvp_base_aemva |
| 202 | |-- fvp_base_revc-2xaemv8a |
| 203 | |-- platform.cmake |
| 204 | |
| 205 | Under each platform leaf directory is a file called ``platform.cmake``. This file implements |
| 206 | the common configuration and build interface that will be used during the deployment build |
| 207 | process. How this interface is realized is entirely down to the platform provider. An |
| 208 | implementation will do things like setting configuration variables for SoC, board and driver |
| 209 | selection. Any additional files needed to support platform configuration and build may be |
| 210 | included within the platform provider's sub-tree. |
| 211 | |
| 212 | For product developers who want to define and maintain their own private platforms, it should |
| 213 | be possible to override the default ``platform/providers`` directory path to allow an |
| 214 | alternative sub-tree to be used. A product developer is free to organize a private sub-tree |
| 215 | in any way that suites their needs. |
| 216 | |
| 217 | Although the TS project structure doesn't mandate it, platform specific firmware is likely |
| 218 | to live outside of the TS project. The ability to reuse existing drivers and driver frameworks |
| 219 | is important for promoting adoption across hardware from different vendors. Board and silicon |
| 220 | vendors may reuse existing CI and project infrastructure for platform components that they |
| 221 | maintain. |
| 222 | |
| 223 | Platform support that depends on EDK2 platform components is represented by the edk2 platform |
| 224 | provider. Files related to the EDK2 platform provider are organized as follows:: |
| 225 | |
| 226 | platform |
| 227 | |- providers |
| 228 | |- edk2 |
| 229 | |- edk2-platforms.cmake - Fetches the upstream edk2-platforms repo |
| 230 | |- platform - Directory for platform definitions, organized by contributor |
| 231 | |- arm |
| 232 | |- n1sdp |
| 233 | |- platform.cmake |
| 234 | |
| 235 | Some special platforms are provided by the TS project itself. These are represented beneath |
| 236 | the ts provider. Current TS platforms are: |
| 237 | |
| 238 | .. list-table:: |
| 239 | :header-rows: 1 |
| 240 | :widths: 10, 90 |
| 241 | |
| 242 | * - TS Platform |
| 243 | - Purpose |
| 244 | * - ``ts/vanilla`` |
| 245 | - | A platform that never provides any drivers. The ``ts/vanilla`` platform should be used when an environment provides its own |
| 246 | | device framework and no additional drivers need to be provided by the platform. An attempt to build a deployment with |
| 247 | | platform dependencies on the vanilla platform will result in a build-time error. The vanilla platform is selected by |
| 248 | | default at build-time if no explicit platform has been specified. |
| 249 | * - ``ts/mock`` |
| 250 | - | A platform that provides a complete set of drivers that may be selected when building any deployment. The platform uses |
| 251 | | mock drivers that don't offer functionality suitable for production builds. The mock platform is useful for CI build |
| 252 | | testing of deployments with platform dependencies. You should always expect a deployment with platform dependencies to |
| 253 | | build when ``TS_PLATFORM=ts/mock``. |
| 254 | |
| 255 | Diver Models |
| 256 | ^^^^^^^^^^^^ |
| 257 | Alternative driver models are represented by subdirectories beneath ``platform/driver_model``. |
| 258 | Driver code imported from an external project, such as edk2-platforms, will also depend on |
| 259 | interface and other header files related to the driver model. For drivers reused from |
| 260 | edk2-platforms, the driver interface header files will define interface structures defined |
| 261 | by the UEFI specification. The following example illustrates two driver models, one for |
| 262 | UEFI drivers from the EDK2 project and another for bare-metal drivers that conform to TS |
| 263 | defined interfaces:: |
| 264 | |
| 265 | platform |
| 266 | |- driver_model |
| 267 | |- edk2 |
| 268 | |- baremetal |
| 269 | |
| 270 | Header files under the driver_model/edk2 directory will either explicitly provide definitions for |
| 271 | the EDK2 driver model or include definitions from an external component. To maintain compatibility |
| 272 | with driver code imported from edk2-platforms, sub-directories beneath platform/driver_model/edk2 |
| 273 | should conform to the EDK2 directory structure and naming conventions. The following illustrates |
| 274 | how UEFI driver model files are organized:: |
| 275 | |
| 276 | platform |
| 277 | |- driver_model |
| 278 | |- edk2 |
| 279 | |- interface |
| 280 | |- Protocol |
| 281 | | |- BlockIo.h |
| 282 | | |- DiskIo.h |
| 283 | | |- FirmwareVolumeBlock.h |
| 284 | | |
| 285 | |- Library |
| 286 | | |- IoLib.h |
| 287 | | |- DebugLib.h |
| 288 | |
| 289 | Drivers |
| 290 | ^^^^^^^ |
| 291 | The platforms/drivers directory provides a home for CMake files that enable driver code to be built |
| 292 | as part of the the deployment build process. Source files will either have been fetched from an |
| 293 | upstream repo or will live under the ``platform/drivers`` parent. |
| 294 | |
| 295 | -------------- |
| 296 | |
| 297 | *Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.* |
| 298 | |
| 299 | SPDX-License-Identifier: BSD-3-Clause |