TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 1 | ####################################################### |
| 2 | TF-M Internal Trusted Storage Service Integration Guide |
| 3 | ####################################################### |
| 4 | |
| 5 | ************ |
| 6 | Introduction |
| 7 | ************ |
| 8 | TF-M Internal Trusted Storage (ITS) service implements PSA Internal Trusted |
| 9 | Storage APIs. |
| 10 | |
| 11 | The service is backed by hardware isolation of the flash access domain and |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 12 | relies on hardware to isolate the flash area from access by the Non-secure |
| 13 | Processing Environment, as well as the Application Root of Trust at higher |
| 14 | levels of isolation. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 15 | |
| 16 | The current ITS service design relies on hardware abstraction provided by TF-M. |
| 17 | The ITS service provides a non-hierarchical storage model, as a filesystem, |
| 18 | where all the assets are managed by a linearly indexed list of metadata. |
| 19 | |
| 20 | The design addresses the following high level requirements as well: |
| 21 | |
| 22 | - **Confidentiality** - Resistance to unauthorised accesses through |
| 23 | hardware/software attacks. Assumed to be provided by the internal flash |
| 24 | device, backed by hardware isolation. |
| 25 | |
| 26 | - **Access Authentication** - Mechanism to establish requester's identity (a |
| 27 | non-secure entity, secure entity, or a remote server). |
| 28 | |
| 29 | - **Integrity** - Resistance to tampering by attackers with physical access is |
| 30 | assumed to be provided by the internal flash device itself, while resistance |
| 31 | to tampering by Non-secure or App RoT attackers also requires hardware |
| 32 | isolation. |
| 33 | |
| 34 | - **Reliability** - Resistance to power failure scenarios and incomplete write |
| 35 | cycles. |
| 36 | |
| 37 | - **Configurability** - High level of configurability to scale up/down memory |
| 38 | footprint to cater for a variety of devices with varying requirements. |
| 39 | |
| 40 | - **Performance** - Optimized to be used for resource constrained devices with |
| 41 | very small silicon footprint, the PPA (power, performance, area) should be |
| 42 | optimal. |
| 43 | |
| 44 | ******************************* |
| 45 | Current ITS Service Limitations |
| 46 | ******************************* |
| 47 | - **Fragmentation** - The current design does not support fragmentation, as an |
| 48 | asset is stored in a contiguous space in a block. This means that the maximum |
| 49 | asset size can only be up-to a block size. Each block can potentially store |
| 50 | multiple assets. |
| 51 | A delete operation implicitly moves all the assets towards the top of the |
| 52 | block to avoid fragmentation within block. However, this may also result in |
| 53 | unutilized space at the end of each block. |
| 54 | |
| 55 | - **Non-hierarchical storage model** - The current design uses a |
| 56 | non-hierarchical storage model, as a filesystem, where all the assets are |
| 57 | managed by a linearly indexed list of metadata. This model locates the |
| 58 | metadata in blocks which are always stored in the same flash location. That |
| 59 | increases the number of writes in a specific flash location as every change in |
| 60 | the storage area requires a metadata update. |
| 61 | |
| 62 | - **Protection against physical storage medium failure** - Complete handling of |
| 63 | inherent failures of storage mediums (e.g. bad blocks in a NAND based device) |
| 64 | is not supported by the current design. |
| 65 | |
| 66 | - **Lifecycle management** - Currently, it does not support any subscription |
| 67 | based keys and certificates required in a secure lifecycle management. Hence, |
| 68 | an asset's validity time-stamp can not be invalidated based on the system |
| 69 | time. |
| 70 | |
| 71 | - **Provisioning vs user/device data** - In the current design, all assets are |
| 72 | treated in the same manner. In an alternative design, it may be required to |
| 73 | create separate partitions for provisioning content and user/device generated |
| 74 | content. This is to allow safe update of provisioning data during firmware |
| 75 | updates without the need to wipe out the user/device generated data. |
| 76 | |
| 77 | ************** |
| 78 | Code Structure |
| 79 | ************** |
| 80 | TF-M Internal Trusted Storage service code is located in |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 81 | ``secure_fw/partitions/internal_trusted_storage/`` and is divided as follows: |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 82 | |
| 83 | - Core files |
| 84 | - Flash filesystem interfaces |
| 85 | - Flash interfaces |
| 86 | |
| 87 | The PSA ITS interfaces for the TF-M ITS service are located in |
| 88 | ``interface/include/psa``. |
| 89 | |
| 90 | PSA Internal Trusted Storage Interfaces |
| 91 | ======================================= |
| 92 | |
| 93 | The TF-M ITS service exposes the following mandatory PSA ITS interfaces |
| 94 | version 1.0: |
| 95 | |
| 96 | .. code-block:: c |
| 97 | |
| 98 | psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, psa_storage_create_flags_t create_flags); |
| 99 | psa_status_t psa_its_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length); |
| 100 | psa_status_t psa_its_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info); |
| 101 | psa_status_t psa_its_remove(psa_storage_uid_t uid); |
| 102 | |
| 103 | These PSA ITS interfaces and TF-M ITS types are defined and documented in |
| 104 | ``interface/include/psa/storage_common.h``, |
| 105 | ``interface/include/psa/internal_trusted_storage.h``, and |
| 106 | ``interface/include/tfm_its_defs.h`` |
| 107 | |
| 108 | Core Files |
| 109 | ========== |
| 110 | - ``tfm_its_req_mngr.c`` - Contains the ITS request manager implementation which |
| 111 | handles all requests which arrive to the service. This layer extracts the |
| 112 | arguments from the input and output vectors, and it calls the internal trusted |
| 113 | storage layer with the provided parameters. |
| 114 | |
| 115 | - ``tfm_internal_trusted_storage.c`` - Contains the TF-M internal trusted |
| 116 | storage API implementations which are the entry points to the ITS service. |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 117 | Allocates a filesystem context for ITS and makes appropriate fs calls. Also |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 118 | handles requests from the PS partition with a separate fs context. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 119 | |
| 120 | - ``its_utils.c`` - Contains common and basic functionalities used across the |
| 121 | ITS service code. |
| 122 | |
| 123 | Flash Filesystem Interface |
| 124 | ========================== |
| 125 | - ``flash_fs/its_flash_fs.h`` - Abstracts the flash filesystem operations used |
| 126 | by the internal trusted storage service. The purpose of this abstraction is to |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 127 | have the ability to plug-in other filesystems or filesystem proxies |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 128 | (supplicant). |
| 129 | |
| 130 | - ``flash_fs/its_flash_fs.c`` - Contains the ``its_flash_fs`` implementation for |
| 131 | the required interfaces. |
| 132 | |
| 133 | - ``flash_fs/its_flash_fs_mbloc.c`` - Contains the metadata block manipulation |
| 134 | functions required to implement the ``its_flash_fs`` interfaces in |
| 135 | ``flash_fs/its_flash_fs.c``. |
| 136 | |
| 137 | - ``flash_fs/its_flash_fs_dbloc.c`` - Contains the data block manipulation |
| 138 | functions required to implement the ``its_flash_fs`` interfaces in |
| 139 | ``flash_fs/its_flash_fs.c``. |
| 140 | |
| 141 | The system integrator **may** replace this implementation with its own |
| 142 | flash filesystem implementation or filesystem proxy (supplicant). |
| 143 | |
| 144 | Flash Interface |
| 145 | =============== |
| 146 | - ``flash/its_flash.h`` - Abstracts the flash operations for the internal |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 147 | trusted storage service. Defines the ``struct its_flash_info_t`` type, which |
| 148 | is used as a parameter to the filesystem to provide information about the |
| 149 | flash device in use, such as the block size and number of blocks available. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 150 | |
Jamie Fox | 9fb2838 | 2019-11-26 17:03:18 +0000 | [diff] [blame] | 151 | - ``flash/its_flash.c`` - Contains the ``its_flash`` implementations common to |
| 152 | all flash types. |
| 153 | |
Jamie Fox | d70da21 | 2019-11-28 14:41:45 +0000 | [diff] [blame] | 154 | - ``flash/its_flash_nand.c`` - Implements the ITS flash interface for a NAND |
| 155 | flash device, on top of the CMSIS flash interface implemented by the target. |
| 156 | This implementation writes entire block updates in one-shot, so the CMSIS |
| 157 | flash implementation **must** be able to detect incomplete writes and return |
| 158 | an error the next time the block is read. |
| 159 | |
Jamie Fox | 9fb2838 | 2019-11-26 17:03:18 +0000 | [diff] [blame] | 160 | - ``flash/its_flash_nor.c`` - Implements the ITS flash interface for a NOR flash |
| 161 | device, on top of the CMSIS flash interface implemented by the target. |
| 162 | |
| 163 | - ``flash/its_flash_ram.c`` - Implements the ITS flash interface for an emulated |
| 164 | flash device using RAM, on top of the CMSIS flash interface implemented by the |
| 165 | target. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 166 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 167 | - ``flash/its_flash_info_internal.c`` - Defines an instance of the |
| 168 | ``struct its_flash_info_t`` type for the internal flash device based on |
| 169 | target-specific definitions. |
| 170 | |
| 171 | - ``flash/its_flash_info_external.c`` - Defines an instance of the |
| 172 | ``struct its_flash_info_t`` type for the external flash device, used only to |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 173 | handle requests from the PS partition. |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 174 | |
Jamie Fox | 9fb2838 | 2019-11-26 17:03:18 +0000 | [diff] [blame] | 175 | The CMSIS flash interface **must** be implemented for each target based on its |
| 176 | flash controller. |
| 177 | |
David Hu | 74977d2 | 2019-10-22 10:26:03 +0800 | [diff] [blame] | 178 | The ITS flash interface depends on target-specific definitions from |
| 179 | ``platform/ext/target/<TARGET_NAME>/partition/flash_layout.h``. |
| 180 | Please see the `Internal Trusted Storage Service Definitions` section for |
| 181 | details. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 182 | |
| 183 | ***************************** |
| 184 | ITS Service Integration Guide |
| 185 | ***************************** |
| 186 | This section describes mandatory (i.e. **must** implement) or optional |
| 187 | (i.e. **may** implement) interfaces which the system integrator has to take in |
| 188 | to account in order to integrate the internal trusted storage service in a new |
| 189 | platform. |
| 190 | |
| 191 | Maximum Asset Size |
| 192 | ================== |
| 193 | An asset is stored in a contiguous space in a block/sector. The maximum size of |
| 194 | an asset can be up-to the size of the data block/sector. |
| 195 | |
| 196 | Internal Trusted Storage Service Definitions |
| 197 | ============================================ |
| 198 | The ITS service requires the following platform definitions: |
| 199 | |
| 200 | - ``ITS_FLASH_AREA_ADDR`` - Defines the flash address where the internal trusted |
| 201 | storage area starts. |
David Hu | 74977d2 | 2019-10-22 10:26:03 +0800 | [diff] [blame] | 202 | - ``ITS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area for |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 203 | internal trusted storage in bytes. |
| 204 | - ``ITS_SECTOR_SIZE`` - Defines the size of the flash sectors (the smallest |
| 205 | erasable unit) in bytes. |
David Hu | 74977d2 | 2019-10-22 10:26:03 +0800 | [diff] [blame] | 206 | - ``ITS_SECTORS_PER_BLOCK`` - Defines the number of contiguous ITS_SECTOR_SIZE |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 207 | to form a logical block in the filesystem. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 208 | - ``ITS_FLASH_DEV_NAME`` - Specifies the flash device used by ITS to store the |
| 209 | data. |
| 210 | - ``ITS_FLASH_PROGRAM_UNIT`` - Defines the smallest flash programmable unit in |
Jamie Fox | d70da21 | 2019-11-28 14:41:45 +0000 | [diff] [blame] | 211 | bytes. Valid values are powers of two between 1 and ``ITS_SECTOR_SIZE`` |
| 212 | inclusive. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 213 | - ``ITS_MAX_ASSET_SIZE`` - Defines the maximum asset size to be stored in the |
| 214 | ITS area. This size is used to define the temporary buffers used by ITS to |
| 215 | read/write the asset content from/to flash. The memory used by the temporary |
| 216 | buffers is allocated statically as ITS does not use dynamic memory allocation. |
| 217 | - ``ITS_NUM_ASSETS`` - Defines the maximum number of assets to be stored in the |
| 218 | ITS area. This number is used to dimension statically the filesystem metadata |
| 219 | tables in RAM (fast access) and flash (persistent storage). The memory used by |
| 220 | the filesystem metadata tables is allocated statically as ITS does not use |
| 221 | dynamic memory allocation. |
| 222 | |
David Hu | 74977d2 | 2019-10-22 10:26:03 +0800 | [diff] [blame] | 223 | The sectors reserved to be used as internal trusted storage **must** be |
| 224 | contiguous sectors starting at ``ITS_FLASH_AREA_ADDR``. |
| 225 | |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 226 | Target must provide a header file, called ``flash_layout.h``, which defines the |
| 227 | information explained above. The defines must be named as they are specified |
| 228 | above. |
| 229 | |
| 230 | More information about the ``flash_layout.h`` content, not ITS related, is |
| 231 | available in :doc:`platform readme </platform/ext/readme>` along with other |
| 232 | platform information. |
| 233 | |
Jamie Fox | f7a8229 | 2019-11-18 17:39:50 +0000 | [diff] [blame] | 234 | The following optional platform definitions may also be defined in |
| 235 | ``flash_layout.h`` or set at build time in ``platform/ext/<TARGET_NAME>.cmake``: |
| 236 | |
| 237 | - ``ITS_BUF_SIZE``- Defines the size of the partition's internal data transfer |
| 238 | buffer. If not provided, then ``ITS_MAX_ASSET_SIZE`` is used to allow asset |
| 239 | data to be copied between the client and the filesystem in one iteration. |
| 240 | Reducing the buffer size will decrease the RAM usage of the partition at the |
| 241 | expense of latency, as data will be copied in multiple iterations. *Note:* |
| 242 | when data is copied in multiple iterations, the atomicity property of the |
| 243 | filesystem is lost in the case of an asynchronous power failure. |
Chris Brand | 2603c29 | 2020-02-05 16:44:11 -0800 | [diff] [blame] | 244 | - ``ITS_MAX_BLOCK_DATA_COPY`` - Defines the buffer size used when copying data |
| 245 | between blocks, in bytes. If not provided, defaults to 256. Increasing this |
| 246 | value will increase the memory footprint of the service. |
Jamie Fox | f7a8229 | 2019-11-18 17:39:50 +0000 | [diff] [blame] | 247 | |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 248 | Flash Interface |
| 249 | =============== |
| 250 | For ITS service operations, a contiguous set of blocks must be earmarked for |
| 251 | the internal trusted storage area. The design requires either 2 blocks, or any |
| 252 | number of blocks greater than or equal to 4. Total number of blocks can not be |
| 253 | 0, 1 or 3. This is a design choice limitation to provide power failure safe |
| 254 | update operations. |
| 255 | |
| 256 | For API specification, please check: |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 257 | ``secure_fw/partitions/internal_trusted_storage/flash/its_flash.h`` |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 258 | |
| 259 | ITS Service Features Flags |
| 260 | ========================== |
| 261 | ITS service defines a set of flags that can be used to compile in/out certain |
| 262 | ITS service features. The ``CommonConfig.cmake`` file sets the default values |
| 263 | of those flags. However, those flags values can be overwritten by setting them |
| 264 | in ``platform/ext/<TARGET_NAME>.cmake`` based on the target capabilities or |
| 265 | needs. The list of ITS services flags are: |
| 266 | |
| 267 | - ``ITS_CREATE_FLASH_LAYOUT``- this flag indicates that it is required |
| 268 | to create an ITS flash layout. If this flag is set, ITS service will |
| 269 | generate an empty and valid ITS flash layout to store assets. It will |
| 270 | erase all data located in the assigned ITS memory area before generating |
| 271 | the ITS layout. This flag is required to be set if the ITS memory area |
| 272 | is located in a non-persistent memory. This flag can be set if the ITS |
| 273 | memory area is located in a persistent memory without a valid ITS flash |
| 274 | layout in it. That is the case when it is the first time in the device |
| 275 | life that the ITS service is executed. |
| 276 | - ``ITS_VALIDATE_METADATA_FROM_FLASH``- this flag allows to |
| 277 | enable/disable the validation mechanism to check the metadata store in flash |
| 278 | every time the flash data is read from flash. This validation is required |
| 279 | if the flash is not hardware protected against data corruption. |
Jamie Fox | f58bd22 | 2020-06-12 18:21:25 +0100 | [diff] [blame] | 280 | - ``ITS_RAM_FS``- setting this flag to ``ON`` enables the use of RAM instead of |
| 281 | the persistent storage device to store the FS in the Internal Trusted Storage |
| 282 | service. This flag is ``OFF`` by default. The ITS regression tests write/erase |
| 283 | storage multiple time, so enabling this flag can increase the life of flash |
| 284 | memory when testing. |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 285 | |
Soby Mathew | 728a20a | 2020-03-25 13:33:35 +0000 | [diff] [blame] | 286 | .. Note:: |
Jamie Fox | f58bd22 | 2020-06-12 18:21:25 +0100 | [diff] [blame] | 287 | If this flag is disabled when running the regression tests, then it is |
| 288 | recommended that the persistent storage area is erased before running the |
| 289 | tests to ensure that all tests can run to completion. The type of persistent |
| 290 | storage area is platform specific (eFlash, MRAM, etc.) and it is described |
| 291 | in corresponding flash_layout.h |
Soby Mathew | 728a20a | 2020-03-25 13:33:35 +0000 | [diff] [blame] | 292 | |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 293 | -------------- |
| 294 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 295 | *Copyright (c) 2019-2020, Arm Limited. All rights reserved.* |
Chris Brand | 2603c29 | 2020-02-05 16:44:11 -0800 | [diff] [blame] | 296 | *Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.* |