blob: 230117edf283b52d622a23580ddafb1c62834fcb [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 Foxdd3de952019-11-25 17:45:40 +0000117 Allocates a filesystem context for ITS and makes appropriate fs calls. Also
Kevin Pengc6d74502020-03-04 16:55:37 +0800118 handles requests from the PS partition with a separate fs context.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100119
120- ``its_utils.c`` - Contains common and basic functionalities used across the
121 ITS service code.
122
123Flash 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 Foxdd3de952019-11-25 17:45:40 +0000127 have the ability to plug-in other filesystems or filesystem proxies
TudorCretuc0e4bee2019-07-23 11:38:21 +0100128 (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
141The system integrator **may** replace this implementation with its own
142flash filesystem implementation or filesystem proxy (supplicant).
143
144Flash Interface
145===============
146- ``flash/its_flash.h`` - Abstracts the flash operations for the internal
Jamie Foxdd3de952019-11-25 17:45:40 +0000147 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.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100150
Jamie Fox9fb28382019-11-26 17:03:18 +0000151- ``flash/its_flash.c`` - Contains the ``its_flash`` implementations common to
152 all flash types.
153
Jamie Foxd70da212019-11-28 14:41:45 +0000154- ``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 Fox9fb28382019-11-26 17:03:18 +0000160- ``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.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100166
Jamie Foxdd3de952019-11-25 17:45:40 +0000167- ``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 Pengc6d74502020-03-04 16:55:37 +0800173 handle requests from the PS partition.
Jamie Foxdd3de952019-11-25 17:45:40 +0000174
Jamie Fox9fb28382019-11-26 17:03:18 +0000175The CMSIS flash interface **must** be implemented for each target based on its
176flash controller.
177
David Hu74977d22019-10-22 10:26:03 +0800178The ITS flash interface depends on target-specific definitions from
179``platform/ext/target/<TARGET_NAME>/partition/flash_layout.h``.
180Please see the `Internal Trusted Storage Service Definitions` section for
181details.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100182
183*****************************
184ITS Service Integration Guide
185*****************************
186This section describes mandatory (i.e. **must** implement) or optional
187(i.e. **may** implement) interfaces which the system integrator has to take in
188to account in order to integrate the internal trusted storage service in a new
189platform.
190
191Maximum Asset Size
192==================
193An asset is stored in a contiguous space in a block/sector. The maximum size of
194an asset can be up-to the size of the data block/sector.
195
196Internal Trusted Storage Service Definitions
197============================================
198The 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 Hu74977d22019-10-22 10:26:03 +0800202- ``ITS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area for
Jamie Foxdd3de952019-11-25 17:45:40 +0000203 internal trusted storage in bytes.
204- ``ITS_SECTOR_SIZE`` - Defines the size of the flash sectors (the smallest
205 erasable unit) in bytes.
David Hu74977d22019-10-22 10:26:03 +0800206- ``ITS_SECTORS_PER_BLOCK`` - Defines the number of contiguous ITS_SECTOR_SIZE
Jamie Foxdd3de952019-11-25 17:45:40 +0000207 to form a logical block in the filesystem.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100208- ``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 Foxd70da212019-11-28 14:41:45 +0000211 bytes. Valid values are powers of two between 1 and ``ITS_SECTOR_SIZE``
212 inclusive.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100213- ``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 Hu74977d22019-10-22 10:26:03 +0800223The sectors reserved to be used as internal trusted storage **must** be
224contiguous sectors starting at ``ITS_FLASH_AREA_ADDR``.
225
TudorCretuc0e4bee2019-07-23 11:38:21 +0100226Target must provide a header file, called ``flash_layout.h``, which defines the
227information explained above. The defines must be named as they are specified
228above.
229
230More information about the ``flash_layout.h`` content, not ITS related, is
231available in :doc:`platform readme </platform/ext/readme>` along with other
232platform information.
233
Jamie Foxf7a82292019-11-18 17:39:50 +0000234The 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 Brand2603c292020-02-05 16:44:11 -0800244- ``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 Foxf7a82292019-11-18 17:39:50 +0000247
TudorCretuc0e4bee2019-07-23 11:38:21 +0100248Flash Interface
249===============
250For ITS service operations, a contiguous set of blocks must be earmarked for
251the internal trusted storage area. The design requires either 2 blocks, or any
252number of blocks greater than or equal to 4. Total number of blocks can not be
2530, 1 or 3. This is a design choice limitation to provide power failure safe
254update operations.
255
256For API specification, please check:
Ken Liu738a4b02020-06-04 14:52:38 +0800257``secure_fw/partitions/internal_trusted_storage/flash/its_flash.h``
TudorCretuc0e4bee2019-07-23 11:38:21 +0100258
259ITS Service Features Flags
260==========================
261ITS service defines a set of flags that can be used to compile in/out certain
262ITS service features. The ``CommonConfig.cmake`` file sets the default values
263of those flags. However, those flags values can be overwritten by setting them
264in ``platform/ext/<TARGET_NAME>.cmake`` based on the target capabilities or
265needs. 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 Foxf58bd222020-06-12 18:21:25 +0100280- ``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.
TudorCretuc0e4bee2019-07-23 11:38:21 +0100285
Soby Mathew728a20a2020-03-25 13:33:35 +0000286 .. Note::
Jamie Foxf58bd222020-06-12 18:21:25 +0100287 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 Mathew728a20a2020-03-25 13:33:35 +0000292
TudorCretuc0e4bee2019-07-23 11:38:21 +0100293--------------
294
Jamie Foxdd3de952019-11-25 17:45:40 +0000295*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
Chris Brand2603c292020-02-05 16:44:11 -0800296*Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.*