Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 1 | Project Structure |
| 2 | ================= |
| 3 | |
| 4 | This page describes the directory and repository structure for the trusted services project. |
| 5 | |
| 6 | Top-Level Project Organization |
| 7 | ------------------------------ |
| 8 | The project is organized under the following top-level directories:: |
| 9 | |
| 10 | project |
| 11 | |-- docs |
| 12 | |-- deployments |
| 13 | |-- environments |
| 14 | |-- platforms |
| 15 | |-- components |
| 16 | |-- external |
| 17 | |-- protocols |
| 18 | |-- tools |
| 19 | |
| 20 | Top-level directories are used to organize project files as follows: |
| 21 | |
| 22 | docs |
| 23 | '''' |
| 24 | |
| 25 | The home for project documentation source. |
| 26 | |
| 27 | deployments |
| 28 | ''''''''''' |
| 29 | |
| 30 | A deployment represents the build instance of a service (or in fact any unit of functionality) for a particular |
| 31 | environment. For each deployment, there is a single deployable output, usually a binary executable. The |
| 32 | deployment is concerned with configuring and building a particular set of components to run in a particular |
| 33 | environment. For each supported deployment, there is a leaf sub-directory that lives under a parent. The |
| 34 | parent directory identifies what's being deployed while the leaf sub-directory identifies where it is being |
| 35 | deployed. The following example illustrates how the 'what' and 'where' are combined to form fully defined |
| 36 | deployments:: |
| 37 | |
| 38 | deployment-name = <descriptive-name>/<environment> |
| 39 | |
| 40 | deployments |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 41 | |-- protected-storage/opteesp |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 42 | |-- crypto/opteesp |
Imre Kis | 3d6848d | 2023-01-04 15:36:19 +0100 | [diff] [blame] | 43 | |-- crypto/sp |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 44 | |-- ts-demo/arm-linux |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 45 | |-- component-test/linux-pc |
| 46 | |-- libts/linux-pc |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 47 | |
| 48 | The trusted services project uses CMake to configure and generate build files. A CMakeLists.txt file exists |
| 49 | for each deployment to define the set of components, any deployment specific configuration and anything |
| 50 | environment specific. Each deployment leaf directory also holds a source file that defines the main entry |
| 51 | point to allow a particular set of components to be initialized before entering the application that implements |
| 52 | the core functionality of software being deployed. |
| 53 | |
| 54 | The directory structure for deployments supports inheritance from the deployment parent to promote reuse of |
| 55 | common definitions and initialization code. For example, deployments of the secure-storage service for |
| 56 | different environments are likely to have similarities in terms of the set of components used and in subsystem |
| 57 | initialization code. To avoid duplication between deployments, common cmake and source files may be located |
| 58 | under the deployment parent. This is illustrated in the following:: |
| 59 | |
| 60 | deployments |
| 61 | |-- secure-storage |
| 62 | |-- common.cmake <-- Common cmake file |
| 63 | |-- service_init.c <-- Common initialization code |
| 64 | |-- opteesp |
Imre Kis | 3d6848d | 2023-01-04 15:36:19 +0100 | [diff] [blame] | 65 | | |-- CMakeLists.txt <-- Includes ../common.cmake to inherit common definitions |
| 66 | | |-- opteesp_service_init.c |
| 67 | |-- sp |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 68 | |-- CMakeLists.txt <-- Includes ../common.cmake to inherit common definitions |
| 69 | |-- opteesp_service_init.c |
| 70 | |
| 71 | environments |
| 72 | '''''''''''' |
| 73 | |
| 74 | An environment represents the execution context in which a built image runs. There are different environments |
| 75 | represented in the project structure, one for each supported isolated execution context. Files related to a |
| 76 | particular environment live under a sub-directory whose name describes the environment. For example: |
| 77 | |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 78 | - *opteesp* An S-EL0 secure partition hosted by OP-TEE |
Imre Kis | 3d6848d | 2023-01-04 15:36:19 +0100 | [diff] [blame] | 79 | - *sp* SPMC agnostic S-EL0 secure partition |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 80 | - *arm-linux* Linux user-space, cross compiled for Arm. |
| 81 | - *linux-pc* Native PC POSIX environment |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 82 | |
| 83 | Files related to an environment will tend to live outside of the project tree and will need to be imported |
| 84 | in some way. How this is handled will depend on the environment. An environment will generally provide the |
| 85 | following: |
| 86 | |
| 87 | - Environment specific libraries that have been externally built. |
| 88 | - Public header files for libraries. |
| 89 | - An install method that takes a deployment image and installs it in the environment. |
| 90 | - Compiler configuration |
| 91 | |
| 92 | A deployment will include an environment specific build file (see above) that defines the list of environment |
| 93 | specific components used for a deployment into a particular environment. |
| 94 | |
Imre Kis | 3d6848d | 2023-01-04 15:36:19 +0100 | [diff] [blame] | 95 | opteesp |
| 96 | """"""" |
| 97 | |
| 98 | The opteesp environment uses a very similar SP format to the OP-TEE Trusted Applications. It is an ELF file with an OP-TEE |
| 99 | specific header structure at its beginning. The SP image is relocatable and it is handled by the ELF loader (ldelf) component |
| 100 | of OP-TEE. Naturally this environment only works with OP-TEE in the role of the SPMC. |
| 101 | |
| 102 | sp |
| 103 | "" |
| 104 | |
| 105 | Deployments that use the sp environment can produce SPMC agnostic SP images. This environment generates SP images as flat |
| 106 | binaries that can be loaded without an ELF loader. The initialization of the stack and the handling of relocation must be done |
| 107 | in the startup code of the SP. Setting the memory access rights of different sections of the SP image can be either done |
| 108 | thought load relative memory regions in the manifest or by using the ``FFA_MEM_PERM_SET`` interface of the FF-A v1.1 |
| 109 | specification in the boot phase of the SP. |
| 110 | |
| 111 | Trusted Services first builds ELF files for the sp environment deployments and then it generates the memory region nodes of the |
| 112 | manifest based on the sections of the ELF file. The sections of the ELF is then copied into the flat binary image. The |
| 113 | environment provides the startup file so all the necessary initialization steps are done before the ``sp_main`` call. |
| 114 | |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 115 | platforms |
| 116 | ''''''''' |
| 117 | |
| 118 | For some deployments, an environment may not provide access to all hardware backed services needed by an |
| 119 | application. Files under the platforms directory are concerned with configuring and building platform specific |
| 120 | code that extends the capabilities of an environment. Details of how this works are described in the: |
Julian Hall | 86ae749 | 2022-09-02 15:56:00 +0100 | [diff] [blame] | 121 | :ref:`Service Deployment Model` |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 122 | |
| 123 | components |
| 124 | '''''''''' |
| 125 | |
| 126 | Source code lives under the components directory, organized as reusable groups of source files. A component |
| 127 | is the unit of reuse for code that may be combined with other components to realize the functionality needed |
| 128 | for a deployment. Creating a new deployment should be just a case of selecting the right set of components |
| 129 | to provide the required functionality for the target environment. Some components may depend on other |
| 130 | components and others may only make sense in a particular environment. |
| 131 | |
| 132 | The components sub-tree has an organization that reflects the layered model where service components are |
| 133 | kept separate from RPC components and so on. There is also a separation between client components and service |
| 134 | provider components. The following illustrates this:: |
| 135 | |
| 136 | components |
| 137 | |-- service |
| 138 | | |-- common |
| 139 | | | |-- test |
| 140 | | |-- secure-storage |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 141 | | | |-- frontend |
| 142 | | | |-- backend |
| 143 | | | |-- factory |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 144 | | | |-- test |
| 145 | | |-- crypto |
| 146 | | | |-- client |
| 147 | | | |- component.cmake |
| 148 | | | |-- provider |
| 149 | |-- rpc |
| 150 | | |-- common |
| 151 | | |-- ffarpc |
| 152 | | | |-- caller |
| 153 | | | |-- endpoint |
| 154 | |
| 155 | Each leaf directory under the components parent includes a cmake file called component.cmake. This is used to |
| 156 | define all files that make up the component and any special defines that are needed to build it. A deployment |
| 157 | CMakeLists.txt just needs to reference the required set of components. No details of the component internals |
| 158 | are reflected in the deployment CMakeLists.txt file. |
| 159 | |
| 160 | Test components |
| 161 | ''''''''''''''' |
| 162 | |
| 163 | Test code is treated in exactly the same as any other source code and is organized into components to achieve |
| 164 | the same reuse goals. To create a deployment intended for testing, you select an appropriate set of components |
| 165 | where some happen to be test components. By convention, test components live in sub-directories called test. |
| 166 | Test directories are located at the point in the components sub-tree that reflects the scope of tests. In the |
| 167 | above example, two test sub-directories are illustrated. The locations of the test component directories imply |
| 168 | the following about the scope of the tests:: |
| 169 | |
| 170 | components |
| 171 | |-- service |
| 172 | | |-- common |
| 173 | | | |-- test <-- Tests for the common service component |
| 174 | | |-- secure-storage |
Julian Hall | 2075a21 | 2021-03-24 10:11:29 +0000 | [diff] [blame] | 175 | | | |-- frontend |
| 176 | | | |-- backend |
| 177 | | | |-- factory |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 178 | | | |-- test <-- Service level tests for the secure-storage service |
| 179 | |
| 180 | If it is necessary to componentize tests further, sub-directories under the test directory may be used, say |
| 181 | for different classes of test. e.g:: |
| 182 | |
| 183 | components |
| 184 | |-- service |
| 185 | |-- common |
| 186 | |-- test |
| 187 | |-- unit |
| 188 | |-- fuzz |
| 189 | |
| 190 | external |
| 191 | '''''''' |
| 192 | |
| 193 | Code that originates from other open source projects that needs to be built as part of trusted service |
| 194 | deployments is represented by directories beneath the external top-level directory. External components |
| 195 | are generally fetched from the source repo during the CMake build process. During the build for a particular |
| 196 | deployment, a deployment specific configuration may be applied to an external component. A CMake file under |
| 197 | each external component directory is responsible for fetching and building the external component:: |
| 198 | |
| 199 | external |
| 200 | |-- CppUTest |
| 201 | | |-- CppUTest.cmake |
| 202 | | |-- cpputest-cmake-fix.patch |
| 203 | |-- mbed-crypto |
| 204 | |-- nanopb |
| 205 | |
| 206 | protocols |
| 207 | ''''''''' |
| 208 | |
| 209 | The protocols directory holds protocol definition files to allow clients to use trusted services. Ideally, |
| 210 | the service access protocol should be formally defined using an interface description language (IDL) that |
| 211 | provides a programming language neutral definition of the service interface. The protocols directory |
| 212 | structure accommodates protocol definitions using different definition methods. Where a service access |
| 213 | protocol has been defined using an IDL with language compilation support, code may be generated from the |
| 214 | interface description to allow RPC request and response parameters to be serialized and deserialized in a |
| 215 | compatible way between service clients and providers. The protocols sub-tree is organized as follows:: |
| 216 | |
| 217 | protocols |
| 218 | |-- service |
| 219 | | |-- common |
| 220 | | |-- crypto |
| 221 | | | |-- packed-c <-- C structure based definitions |
| 222 | | | |-- protobuf <-- Protocol Buffers definitions |
| 223 | | |-- secure-storage |
| 224 | | |-- packed-c |
| 225 | |
| 226 | tools |
| 227 | ''''' |
| 228 | |
| 229 | The project directory structure includes a tools directory for holding general purpose tools components |
| 230 | to support activities such as build and test. |
| 231 | |
| 232 | -------------- |
| 233 | |
Imre Kis | 3d6848d | 2023-01-04 15:36:19 +0100 | [diff] [blame] | 234 | *Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.* |
Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame] | 235 | |
| 236 | SPDX-License-Identifier: BSD-3-Clause |