blob: 6082e7369cec8444a9d1abe6a0924cfef88b9309 [file] [log] [blame]
TudorCretuc0e4bee2019-07-23 11:38:21 +01001#######################################################
2TF-M Internal Trusted Storage Service Integration Guide
3#######################################################
4
5************
6Introduction
7************
8TF-M Internal Trusted Storage (ITS) service implements PSA Internal Trusted
9Storage APIs.
10
11The service is backed by hardware isolation of the flash access domain and
Jamie Foxdd3de952019-11-25 17:45:40 +000012relies on hardware to isolate the flash area from access by the Non-secure
13Processing Environment, as well as the Application Root of Trust at higher
14levels of isolation.
TudorCretuc0e4bee2019-07-23 11:38:21 +010015
16The current ITS service design relies on hardware abstraction provided by TF-M.
17The ITS service provides a non-hierarchical storage model, as a filesystem,
18where all the assets are managed by a linearly indexed list of metadata.
19
20The 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*******************************
45Current 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**************
78Code Structure
79**************
80TF-M Internal Trusted Storage service code is located in
Ken Liu738a4b02020-06-04 14:52:38 +080081``secure_fw/partitions/internal_trusted_storage/`` and is divided as follows:
TudorCretuc0e4bee2019-07-23 11:38:21 +010082
83 - Core files
84 - Flash filesystem interfaces
85 - Flash interfaces
86
87The PSA ITS interfaces for the TF-M ITS service are located in
88``interface/include/psa``.
89
90PSA Internal Trusted Storage Interfaces
91=======================================
92
93The TF-M ITS service exposes the following mandatory PSA ITS interfaces
94version 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
103These 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
108Core 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 Foxa7e73b72021-01-15 13:39:31 +0000117 Constructs a filesystem configuration using information from the ITS HAL,
118 allocates a filesystem context for ITS and makes appropriate FS calls. Also
119 handles requests from the PS partition with a separate FS config and context.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100120
121- ``its_utils.c`` - Contains common and basic functionalities used across the
122 ITS service code.
123
124Flash Filesystem Interface
125==========================
126- ``flash_fs/its_flash_fs.h`` - Abstracts the flash filesystem operations used
127 by the internal trusted storage service. The purpose of this abstraction is to
Jamie Foxdd3de952019-11-25 17:45:40 +0000128 have the ability to plug-in other filesystems or filesystem proxies
TudorCretuc0e4bee2019-07-23 11:38:21 +0100129 (supplicant).
130
131- ``flash_fs/its_flash_fs.c`` - Contains the ``its_flash_fs`` implementation for
132 the required interfaces.
133
Jamie Foxa7e73b72021-01-15 13:39:31 +0000134- ``flash_fs/its_flash_fs_mblock.c`` - Contains the metadata block manipulation
TudorCretuc0e4bee2019-07-23 11:38:21 +0100135 functions required to implement the ``its_flash_fs`` interfaces in
136 ``flash_fs/its_flash_fs.c``.
137
Jamie Foxa7e73b72021-01-15 13:39:31 +0000138- ``flash_fs/its_flash_fs_dblock.c`` - Contains the data block manipulation
TudorCretuc0e4bee2019-07-23 11:38:21 +0100139 functions required to implement the ``its_flash_fs`` interfaces in
140 ``flash_fs/its_flash_fs.c``.
141
142The system integrator **may** replace this implementation with its own
143flash filesystem implementation or filesystem proxy (supplicant).
144
145Flash Interface
146===============
Jamie Foxa7e73b72021-01-15 13:39:31 +0000147The ITS filesystem flash interface is defined by ``struct its_flash_fs_ops_t``
148in ``flash_fs/its_flash_fs.h``.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100149
Jamie Foxa7e73b72021-01-15 13:39:31 +0000150Implementations of the ITS filesystem flash interface for different types of
151storage can be found in the ```internal_trusted_storage/flash`` directory.
152
153- ``flash/its_flash.h`` - Helper header that includes the correct ITS flash
154 interface implementation for the target, and abstracts the allocation of
155 different flash device types.
Jamie Fox9fb28382019-11-26 17:03:18 +0000156
Jamie Foxd70da212019-11-28 14:41:45 +0000157- ``flash/its_flash_nand.c`` - Implements the ITS flash interface for a NAND
158 flash device, on top of the CMSIS flash interface implemented by the target.
159 This implementation writes entire block updates in one-shot, so the CMSIS
160 flash implementation **must** be able to detect incomplete writes and return
161 an error the next time the block is read.
162
Jamie Fox9fb28382019-11-26 17:03:18 +0000163- ``flash/its_flash_nor.c`` - Implements the ITS flash interface for a NOR flash
164 device, on top of the CMSIS flash interface implemented by the target.
165
166- ``flash/its_flash_ram.c`` - Implements the ITS flash interface for an emulated
167 flash device using RAM, on top of the CMSIS flash interface implemented by the
168 target.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100169
Jamie Fox9fb28382019-11-26 17:03:18 +0000170The CMSIS flash interface **must** be implemented for each target based on its
171flash controller.
172
David Hu74977d22019-10-22 10:26:03 +0800173The ITS flash interface depends on target-specific definitions from
174``platform/ext/target/<TARGET_NAME>/partition/flash_layout.h``.
Jamie Foxa7e73b72021-01-15 13:39:31 +0000175Please see the `Internal Trusted Storage Service HAL` section for details.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100176
177*****************************
178ITS Service Integration Guide
179*****************************
180This section describes mandatory (i.e. **must** implement) or optional
181(i.e. **may** implement) interfaces which the system integrator has to take in
182to account in order to integrate the internal trusted storage service in a new
183platform.
184
TudorCretuc0e4bee2019-07-23 11:38:21 +0100185Flash Interface
186===============
187For ITS service operations, a contiguous set of blocks must be earmarked for
188the internal trusted storage area. The design requires either 2 blocks, or any
189number of blocks greater than or equal to 4. Total number of blocks can not be
1900, 1 or 3. This is a design choice limitation to provide power failure safe
191update operations.
192
Jamie Foxa7e73b72021-01-15 13:39:31 +0000193Maximum Asset Size
194==================
195An asset is stored in a contiguous space in a logical filesystem block. The
196maximum size of an asset can be up-to the size of the data block. Typically,
197each logical block corresponds to one physical flash erase sector (the smallest
198unit that can erased), but the ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` configuration
199below allows a number of contiguous erase sectors to form one logical block.
200
201Internal Trusted Storage Service HAL
202====================================
203The ITS service requires the platform to implement the ITS HAL, defined in
204``platform/include/tfm_hal_its.h``.
205
206The following C definitions in the HAL are mandatory, and must be defined by the
207platform in a header named ``flash_layout.h``:
208
209- ``TFM_HAL_ITS_FLASH_DRIVER`` - Defines the identifier of the CMSIS Flash
210 ARM_DRIVER_FLASH object to use for ITS. It must have been allocated by the
211 platform and will be declared extern in the HAL header.
212
213- ``TFM_HAL_ITS_PROGRAM_UNIT`` - Defines the size of the ITS flash device's
214 physical program unit (the smallest unit of data that can be individually
215 programmed to flash). It must be equal to
216 ``TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit``, but made available at
217 compile time so that filesystem structures can be statically sized. Valid
218 values are powers of two between 1 and the flash sector size, inclusive.
219
220The following C definitions in the HAL may optionally be defined by the platform
221in the ``flash_layout.h`` header:
222
223- ``TFM_HAL_ITS_FLASH_AREA_ADDR`` - Defines the base address of the dedicated
224 flash area for ITS.
225
226- ``TFM_HAL_ITS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area
227 for ITS in bytes.
228
229- ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` - Defines the number of contiguous physical
230 flash erase sectors that form a logical erase block in the filesystem. The
231 typical value is ``1``, but it may be increased so that the maximum required
232 asset size will fit in one logical block.
233
234If any of the above definitions are not provided by the platform, then the
235``tfm_hal_its_fs_info()`` HAL API must be implemented instead. This function is
236documented in ``tfm_hal_its.h``.
237
238The sectors reserved to be used for Internal Trusted Storage **must** be
239contiguous.
240
241Internal Trusted Storage Service Optional Platform Definitions
242==============================================================
243The following optional platform definitions may be defined in
244``flash_layout.h``:
245
246- ``ITS_RAM_FS_SIZE`` - Defines the size of the RAM FS buffer when using the
247 RAM FS emulated flash implementation. The buffer must be at least as large as
248 the area earmarked for the filesystem by the HAL.
249- ``ITS_FLASH_NAND_BUF_SIZE`` - Defines the size of the write buffer when using
250 the NAND flash implementation. The buffer must be at least as large as a
251 logical filesystem block.
252- ``ITS_MAX_BLOCK_DATA_COPY`` - Defines the buffer size used when copying data
253 between blocks, in bytes. If not provided, defaults to 256. Increasing this
254 value will increase the memory footprint of the service.
255
256More information about the ``flash_layout.h`` content, not ITS related, is
257available in :doc:`platform readme </platform/ext/readme>` along with other
258platform information.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100259
Jamie Fox865778b2020-10-23 19:52:51 +0100260ITS Service Build Definitions
261=============================
262The ITS service uses a set of C definitions to compile in/out certain features,
263as well as to configure certain service parameters. When using the TF-M build
264system, these definitions are controlled by build flags of the same name. The
265``config/config_default.cmake`` file sets the default values of those flags, but
266they can be overwritten based on platform capabilities by setting them in
267``platform/ext/target/<TARGET_NAME>/config.cmake``. The list of ITS service
268build definitions is:
TudorCretuc0e4bee2019-07-23 11:38:21 +0100269
270- ``ITS_CREATE_FLASH_LAYOUT``- this flag indicates that it is required
271 to create an ITS flash layout. If this flag is set, ITS service will
272 generate an empty and valid ITS flash layout to store assets. It will
273 erase all data located in the assigned ITS memory area before generating
274 the ITS layout. This flag is required to be set if the ITS memory area
275 is located in a non-persistent memory. This flag can be set if the ITS
276 memory area is located in a persistent memory without a valid ITS flash
277 layout in it. That is the case when it is the first time in the device
278 life that the ITS service is executed.
279- ``ITS_VALIDATE_METADATA_FROM_FLASH``- this flag allows to
280 enable/disable the validation mechanism to check the metadata store in flash
281 every time the flash data is read from flash. This validation is required
282 if the flash is not hardware protected against data corruption.
Jamie Foxf58bd222020-06-12 18:21:25 +0100283- ``ITS_RAM_FS``- setting this flag to ``ON`` enables the use of RAM instead of
284 the persistent storage device to store the FS in the Internal Trusted Storage
285 service. This flag is ``OFF`` by default. The ITS regression tests write/erase
286 storage multiple time, so enabling this flag can increase the life of flash
287 memory when testing.
Chris Brandc47d7102020-02-20 11:12:18 -0800288 If this flag is set to ``ON``, ITS_RAM_FS_SIZE must also be provided. This
289 specifies the size of the block of RAM to be used to simulate the flash.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100290
Soby Mathew728a20a2020-03-25 13:33:35 +0000291 .. Note::
Jamie Foxf58bd222020-06-12 18:21:25 +0100292 If this flag is disabled when running the regression tests, then it is
293 recommended that the persistent storage area is erased before running the
294 tests to ensure that all tests can run to completion. The type of persistent
295 storage area is platform specific (eFlash, MRAM, etc.) and it is described
296 in corresponding flash_layout.h
Soby Mathew728a20a2020-03-25 13:33:35 +0000297
Jamie Fox865778b2020-10-23 19:52:51 +0100298- ``ITS_MAX_ASSET_SIZE`` - Defines the maximum asset size to be stored in the
299 ITS area. This size is used to define the temporary buffers used by ITS to
300 read/write the asset content from/to flash. The memory used by the temporary
301 buffers is allocated statically as ITS does not use dynamic memory allocation.
302- ``ITS_NUM_ASSETS`` - Defines the maximum number of assets to be stored in the
303 ITS area. This number is used to dimension statically the filesystem metadata
304 tables in RAM (fast access) and flash (persistent storage). The memory used by
305 the filesystem metadata tables is allocated statically as ITS does not use
306 dynamic memory allocation.
307- ``ITS_BUF_SIZE``- Defines the size of the partition's internal data transfer
308 buffer. If not provided, then ``ITS_MAX_ASSET_SIZE`` is used to allow asset
309 data to be copied between the client and the filesystem in one iteration.
310 Reducing the buffer size will decrease the RAM usage of the partition at the
311 expense of latency, as data will be copied in multiple iterations. *Note:*
312 when data is copied in multiple iterations, the atomicity property of the
313 filesystem is lost in the case of an asynchronous power failure.
314
TudorCretuc0e4bee2019-07-23 11:38:21 +0100315--------------
316
Jamie Foxa7e73b72021-01-15 13:39:31 +0000317*Copyright (c) 2019-2021, Arm Limited. All rights reserved.*
Chris Brand2603c292020-02-05 16:44:11 -0800318*Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.*