Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 1 | ####################### |
| 2 | Adding Secure Partition |
| 3 | ####################### |
| 4 | |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 5 | *********************** |
| 6 | Terms and abbreviations |
| 7 | *********************** |
| 8 | This document uses the following terms and abbreviations. |
| 9 | |
| 10 | .. table:: term table |
| 11 | :widths: auto |
| 12 | |
| 13 | ================== ================================== |
| 14 | **Term** **Meaning** |
| 15 | ================== ================================== |
| 16 | FF Firmware Framework |
| 17 | ID Identifier |
| 18 | IPC Interprocess communication |
| 19 | IPC model The secure IPC framework |
| 20 | irqs Interrupt requests |
| 21 | Library model The secure function call framework |
| 22 | MMIO Memory Mapped I/O |
| 23 | PSA Platform Security Architecture |
| 24 | RoT Root of Trust |
| 25 | SID RoT Service ID |
| 26 | SP Secure Partition |
| 27 | SPM Secure Partition Manager |
| 28 | TF-M Trusted firmware M |
| 29 | ================== ================================== |
| 30 | |
| 31 | ************ |
| 32 | Introduction |
| 33 | ************ |
| 34 | Secure Partition is an execution environment that provides the following |
| 35 | functions to Root of Trust (RoT) Services: |
| 36 | |
| 37 | - Access to resources, protection of its own code and data. |
| 38 | - Mechanisms to interact with other components in the system. |
| 39 | |
| 40 | Each Secure Partition is a single thread of execution and the smallest unit of |
| 41 | isolation. |
| 42 | |
| 43 | This document mainly describes how to add a secure partition in TF-M and |
| 44 | focuses on the configuration, manifest, implement rules. The actual |
| 45 | source-level implementation is not included in this document. |
| 46 | |
| 47 | .. Note:: |
| 48 | If not otherwise specified, the steps are identical for library and IPC |
| 49 | model. |
| 50 | |
| 51 | The IPC model conforms the *PSA Firmware Framework (FF) v 1.0.0*. Refer to |
| 52 | `PSA Firmware Framework specification`_ for details. |
| 53 | |
| 54 | ******* |
| 55 | Process |
| 56 | ******* |
| 57 | The main steps to add a secure partition are as follows: |
| 58 | |
| 59 | - `Add source folder`_ |
| 60 | - `Add manifest`_ |
| 61 | - `Add configuration`_ |
| 62 | - `Generate files`_ |
| 63 | - `Implement the RoT services`_ |
| 64 | |
| 65 | Add source folder |
| 66 | ================= |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 67 | Add a source folder under ``<TF-M base folder>/secure_fw/partitions`` for the new |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 68 | secure partition (Let's take EXAMPLE as the folder name): |
| 69 | |
| 70 | This folder should include those parts: |
| 71 | |
| 72 | - Manifest file: EXAMPLE.yaml |
| 73 | - CMake configuration files |
| 74 | - Source code files |
| 75 | |
| 76 | Add manifest |
| 77 | ============ |
| 78 | Each Secure Partition must have resource requirements declared in a manifest |
| 79 | file. The Secure Partition Manager (SPM) uses the manifest file to assemble and |
| 80 | allocate resources within the SPE. The manifest includes the following: |
| 81 | |
| 82 | - A Secure Partition name. |
| 83 | - A list of implemented RoT Services. |
| 84 | - Access to other RoT Services. |
| 85 | - Memory requirements. |
| 86 | - Scheduling hints. |
| 87 | - Peripheral memory-mapped I/O regions and interrupts. |
| 88 | |
| 89 | .. Note:: |
| 90 | The current manifest format in TF-M is "yaml" which is different from the |
| 91 | requirement of PSA FF. |
| 92 | |
| 93 | Here is a manifest reference example for the IPC model, please refer to |
| 94 | `Library model support`_ for the library extend: |
| 95 | |
| 96 | .. code-block:: yaml |
| 97 | |
| 98 | { |
| 99 | "psa_framework_version": 1.0, |
| 100 | "name": "TFM_SP_EXAMPLE", |
| 101 | "type": "PSA-ROT", |
| 102 | "priority": "HIGH", |
| 103 | "entry_point": "EXAMPLE_main", |
| 104 | "stack_size": "0x0200", |
| 105 | "services" : [ |
| 106 | { |
| 107 | "name": "ROT_A", |
| 108 | "sid": "0x0000F000", |
| 109 | "non_secure_clients": true, |
| 110 | "version": 1, |
| 111 | "version_policy": "STRICT" |
| 112 | } |
| 113 | ], |
| 114 | "mmio_regions": [ |
| 115 | { |
| 116 | "name": "TFM_PERIPHERAL_A", |
| 117 | "permission": "READ-WRITE" |
| 118 | } |
| 119 | ], |
| 120 | "irqs": [ |
| 121 | { |
| 122 | "source": "TFM_A_IRQ", |
| 123 | "signal": "SPM_CORE_A_IRQ", |
| 124 | "tfm_irq_priority": 64, |
| 125 | } |
| 126 | ], |
| 127 | "linker_pattern": { |
| 128 | "object_list": [ |
| 129 | "*EXAMPLE.*" |
| 130 | ] |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | Secure Partition ID Distribution |
| 135 | -------------------------------- |
| 136 | Every Secure Partition has an identifier (ID). TF-M will generate a header file |
| 137 | that includes definitions of the Secure Partition IDs. The header file is |
| 138 | ``<TF-M base folder>/interface/include/psa_manifest/pid.h``. Each definition |
| 139 | uses the ``name`` attribute in the manifest as its name and the value is |
| 140 | allocated by SPM. |
| 141 | |
| 142 | .. code-block:: c |
| 143 | |
| 144 | #define name id-value |
| 145 | |
| 146 | Here is the Secure Partition ID table used in TF-M. |
| 147 | |
| 148 | .. table:: PID table |
| 149 | :widths: auto |
| 150 | |
| 151 | =============================== ================= |
| 152 | **Partition name** **Partition ID** |
| 153 | =============================== ================= |
| 154 | Reserved 0-255 |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 155 | TFM_SP_PS 256 |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 156 | TFM_SP_ITS 257 |
| 157 | TFM_SP_AUDIT_LOG 258 |
| 158 | TFM_SP_CRYPTO 259 |
| 159 | TFM_SP_PLATFORM 260 |
| 160 | TFM_SP_INITIAL_ATTESTATION 261 |
| 161 | TFM_SP_CORE_TEST 262 |
| 162 | TFM_SP_CORE_TEST_2 263 |
| 163 | TFM_SP_SECURE_TEST_PARTITION 264 |
| 164 | TFM_SP_IPC_SERVICE_TEST 265 |
| 165 | TFM_SP_IPC_CLIENT_TEST 266 |
| 166 | TFM_IRQ_TEST_1 267 |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 167 | TFM_SP_PS_TEST 268 |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 168 | =============================== ================= |
| 169 | |
| 170 | About where to add the definition, please refer to the chapter `Add |
| 171 | configuration`_. |
| 172 | |
| 173 | RoT Service ID (SID) Distribution |
| 174 | --------------------------------- |
| 175 | An RoT Service is identified by its RoT Service ID (SID). A SID is a 32-bit |
| 176 | number that is associated with a symbolic name in the Secure Partition |
| 177 | manifest. The bits [31:12] uniquely identify the vendor of the RoT Service. |
| 178 | The remaining bits [11:0] can be used at the discretion of the vendor. |
| 179 | |
| 180 | Here is the RoT Service ID table used in TF-M. |
| 181 | |
| 182 | .. table:: SID table |
| 183 | :widths: auto |
| 184 | |
| 185 | =========================== ====================== ======================== |
| 186 | **Services** **Vendor ID(20 bits)** **Function ID(12 bits)** |
| 187 | =========================== ====================== ======================== |
| 188 | audit_logging 0x00000 0x000-0x01F |
| 189 | initial_attestation 0x00000 0x020-0x03F |
| 190 | platform 0x00000 0x040-0x05F |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 191 | protected_storage 0x00000 0x060-0x07F |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 192 | crypto 0x00000 0x080-0x09F |
| 193 | internal_trusted_storage 0x00000 0x0A0-0x0BF |
| 194 | test_secure_service 0x0000F 0x000-0x01F |
| 195 | core_test 0x0000F 0x020-0x03F |
| 196 | core_test_2 0x0000F 0x040-0x05F |
| 197 | tfm_ipc_client 0x0000F 0x060-0x07F |
| 198 | tfm_ipc_service 0x0000F 0x080-0x09F |
| 199 | tfm_irq_test_service_1 0x0000F 0x0A0-0x0BF |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 200 | tfm_ps_test_service 0x0000F 0x0C0-0x0DF |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 201 | =========================== ====================== ======================== |
| 202 | |
| 203 | mmio_regions |
| 204 | ------------ |
| 205 | This attribute is a list of MMIO region objects which the Secure Partition |
| 206 | needs access to. TF-M only supports the ``named_region`` current. Please refer |
| 207 | to PSA FF for more details about it. The user needs to provide a name macro to |
| 208 | indicate the variable of the memory region. |
| 209 | |
| 210 | TF-M uses the below structure to indicate a peripheral memory. |
| 211 | |
| 212 | .. code-block:: c |
| 213 | |
| 214 | struct tfm_spm_partition_platform_data_t { |
| 215 | uint32_t periph_start; |
| 216 | uint32_t periph_limit; |
| 217 | int16_t periph_ppc_bank; |
| 218 | int16_t periph_ppc_loc; |
| 219 | }; |
| 220 | |
| 221 | .. Note:: |
| 222 | This structure is not expected by TF-M, it's only that the current |
| 223 | implementations are using. Other peripherals that need different information |
| 224 | to create isolation need to define a different structure with the same name. |
| 225 | |
| 226 | Here is a example for it: |
| 227 | |
| 228 | .. code-block:: c |
| 229 | |
| 230 | struct tfm_spm_partition_platform_data_t tfm_peripheral_A; |
| 231 | #define TFM_PERIPHERAL_A (&tfm_peripheral_A) |
| 232 | |
| 233 | linker_pattern |
| 234 | -------------- |
| 235 | ``linker_pattern`` is a legacy region which contains the minimum information |
| 236 | required to link a Secure Partition’s compiled static objects. Now, it is |
| 237 | required as 'IMPLEMENTATION DEFINED' in PSA FF 1.0.0. |
| 238 | |
| 239 | Library model support |
| 240 | --------------------- |
| 241 | For the library model, the user needs to add a ``secure_functions`` item. The |
| 242 | main difference between ``secure_function`` and ``services`` is the extra |
| 243 | ``signal`` key for secure function entry. |
| 244 | |
| 245 | The ``signal`` must be the upper case of the secure function name. |
| 246 | |
| 247 | .. code-block:: yaml |
| 248 | |
| 249 | "secure_functions": [ |
| 250 | { |
| 251 | "name": "TFM_EXAMPLE_A", |
| 252 | "signal": "EXAMPLE_A_FUNC", |
| 253 | "sid": "0x00000000", |
| 254 | "non_secure_clients": true, |
| 255 | "version": 1, |
| 256 | "version_policy": "STRICT" |
| 257 | }, |
| 258 | |
| 259 | Add configuration |
| 260 | ================= |
| 261 | The following configuration tasks are required for the newly added secure |
| 262 | partition: |
| 263 | |
| 264 | Add CMake configure files |
| 265 | ------------------------- |
| 266 | Two CMake configure files need to be added: |
| 267 | |
| 268 | - CMakeLists.inc, which is used to add the definition of what files are needed |
| 269 | to build. |
| 270 | - CMakeLists.txt, which is the compilation configuration for this module. |
| 271 | |
| 272 | .. Note:: |
| 273 | The CMakeLists.inc is not mandatory, the user can put everything in |
| 274 | CMakeLists.txt. |
| 275 | |
| 276 | Please refer to the source code of TF-M for more detail. |
| 277 | |
| 278 | Update manifest list |
| 279 | -------------------- |
| 280 | The ``<TF-M base folder>/tools/tfm_manifest_list.yaml`` is used to collect |
| 281 | necessary information of secure partition. |
| 282 | |
| 283 | - ``name``: The name string of the secure partition. |
| 284 | - ``short_name``: should be the same as the ``name`` in the secure partition |
| 285 | manifest file. |
| 286 | - ``manifest``: the relative path of the manifest file to TF-M root. |
| 287 | - ``tfm_partition_ipc``: indicate if this partition is compatible with the IPC |
| 288 | model. |
| 289 | - ``conditional``: Optional. Configure control macro for this partition. |
| 290 | - ``version_major``: major version the partition manifest. |
| 291 | - ``version_minor``: minor version the partition manifest. |
| 292 | - ``pid``: Secure Partition ID value distributed in chapter `Secure Partition |
| 293 | ID Distribution`_. |
| 294 | |
| 295 | Reference configuration example: |
| 296 | |
| 297 | .. code-block:: yaml |
| 298 | |
| 299 | { |
| 300 | "name": "Example Service", |
| 301 | "short_name": "TFM_SP_EXAMPLE", |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 302 | "manifest": "secure_fw/partitions/EXAMPLE/tfm_example.yaml", |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 303 | "tfm_partition_ipc": true, |
| 304 | "conditional": "TFM_PARTITION_EXAMPLE_ENABLE", |
| 305 | "version_major": 0, |
| 306 | "version_minor": 1, |
| 307 | "pid": 256 |
| 308 | } |
| 309 | |
| 310 | Generate files |
| 311 | ============== |
| 312 | After finishing the configuration works, the user needs to generate necessary |
| 313 | files from manifest by using TF-M tools. |
| 314 | |
| 315 | .. code-block:: bash |
| 316 | |
Leonardo Sandoval | d7f72d5 | 2020-07-28 18:02:34 -0500 | [diff] [blame] | 317 | cd <base folder> |
Edison Ai | 1b7e845 | 2019-12-16 10:03:52 +0800 | [diff] [blame] | 318 | cd trusted-firmware-m |
| 319 | python ./tools/tfm_parse_manifest_list.py |
| 320 | |
| 321 | Implement the RoT services |
| 322 | ========================== |
| 323 | The following not-binding rules, as currently implemented, can be used as |
| 324 | guidelines: |
| 325 | |
| 326 | - In the IPC model, Use PSA FF proposed memory accessing mechanism. SPM |
| 327 | provides APIs and checking between isolation boundaries, a free accessing |
| 328 | of memory can cause program panic. |
| 329 | - In the IPC model, the memory checking inside partition runtime is |
| 330 | unnecessary. SPM handles the checking while memory accessing APIs are |
| 331 | called. |
| 332 | - In the IPC model, the client ID had been included in the message structure |
| 333 | and secure partition can get it when calling psa_get() function. The secure |
| 334 | partition does not need to call ``tfm_core_get_caller_client_id()`` to get |
| 335 | the caller client ID anymore. |
| 336 | - In the IPC model, SPM will check the security policy and partition |
| 337 | dependence between client and service. So the service does not need to |
| 338 | validate the secure caller anymore. |
| 339 | |
| 340 | ********* |
| 341 | Reference |
| 342 | ********* |
| 343 | |
| 344 | | `PSA Firmware Framework specification`_ |
| 345 | |
| 346 | .. _PSA Firmware Framework specification: https://pages.arm.com/psa- |
| 347 | resources-ff.html?_ga=2.156169596.61580709.1542617040-1290528876.1541647333 |
| 348 | |
| 349 | -------------- |
| 350 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 351 | *Copyright (c) 2019-2020, Arm Limited. All rights reserved.* |