Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 1 | ########################## |
| 2 | Hardware Abstraction Layer |
| 3 | ########################## |
| 4 | |
| 5 | :Organization: Arm Limited |
| 6 | :Contact: tf-m@lists.trustedfirmware.org |
| 7 | |
| 8 | :API Version: 0.9 |
| 9 | |
| 10 | ************ |
| 11 | Introduction |
| 12 | ************ |
| 13 | :term:`TF-M` :term:`HAL` abstracts the hardware-oriented and platform specific |
| 14 | operations on the :term:`SPE` side and provides a set of APIs to the upper |
| 15 | layers such as :term:`SPM`, :term:`RoT Service`. |
| 16 | The :term:`HAL` aims to cover the platform different aspects whereas common |
| 17 | architecturally defined aspects are done generically within the common |
| 18 | :term:`SPE`. |
| 19 | In some cases, although the operations are defined architecturally, |
| 20 | it may not be possible to generalize implementations because lots of information |
| 21 | is only known to platforms. |
| 22 | It is more efficient to define a :term:`HAL` API for those architectural |
| 23 | operations as well. |
| 24 | |
| 25 | .. note:: |
| 26 | :term:`TBSA-M` provides the hardware requirements for security purposes. |
| 27 | :term:`TF-M` :term:`HAL` tries to reference :term:`TBSA-M` recommendations in |
| 28 | the interfaces from the software perspective only. Please reference |
| 29 | :term:`TBSA-M` for your security hardware design. |
| 30 | |
| 31 | Design Goals |
| 32 | ============ |
| 33 | :term:`TF-M` :term:`HAL` is designed to simplify the integration efforts on |
| 34 | different platforms. |
| 35 | |
| 36 | :term:`TF-M` :term:`HAL` is designed to make it easy to use the hardware and |
| 37 | develop the :term:`SPM` and :term:`RoT Service` which need to access the |
| 38 | devices. |
| 39 | |
| 40 | :term:`TF-M` :term:`HAL` is designed to make the structure clearer and let the |
| 41 | :term:`TF-M` mainly focus on :term:`PSA` implementation. |
| 42 | |
| 43 | ******** |
| 44 | Overview |
| 45 | ******** |
| 46 | This section provides an overview of the abstraction layer structure. |
| 47 | |
Anton Komlev | b3f6466 | 2023-01-28 11:53:05 +0000 | [diff] [blame] | 48 | .. figure:: /design_docs/media/hal_structure.png |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 49 | |
| 50 | Here lists a minimal set of necessary functionalities: |
| 51 | |
| 52 | - **Isolation API**: Provides the necessary isolation functionalities required |
| 53 | by the :term:`PSA-FF-M` and :term:`TBSA-M`, and provides APIs to :term:`SPM` |
| 54 | to check the permissions of memory access. |
| 55 | - **Platform API**: Provides the platform initialization, platform-specific |
| 56 | memory information, system reset, etc. |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 57 | - **Log dev API**: Provides the log system functions. |
| 58 | - **Interrupt API**: Provides the interrupt functions. |
| 59 | |
| 60 | .. note:: |
| 61 | - There is a non-secure :term:`HAL` that focuses on the mailbox operation API |
| 62 | for Dual-core topology. For more information about it, please refer to |
| 63 | :doc:`Mailbox Design in TF-M on Dual-core System |
Anton Komlev | ff7cbae | 2023-01-12 16:28:26 +0000 | [diff] [blame] | 64 | </design_docs/dual-cpu/mailbox_design_on_dual_core_system>`. |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 65 | - The minimal set of :term:`TF-M` :term:`HAL` is sufficient for Secure |
| 66 | Partitions by using customized peripheral interfaces. To provide easier |
| 67 | portability for the Secure Partitions, a Secure Partition :term:`HAL` is |
| 68 | provided in this design too. |
| 69 | - The debug mechanisms give the external entity the corresponding right to |
| 70 | access the system assets. :term:`TF-M` ensures that the external entity is |
| 71 | permitted access to those assets. Currently, :term:`TF-M` only needs the |
| 72 | debug authentication. The whole debug mechanism and related :term:`HAL` will |
| 73 | be enhanced in the future. Please refer to the :doc:`Debug authentication |
Anton Komlev | e69cf68 | 2023-01-31 11:59:25 +0000 | [diff] [blame] | 74 | settings section </integration_guide/source_structure/platform_folder>` |
| 75 | for more details. |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 76 | |
| 77 | ***************** |
| 78 | Design Principles |
| 79 | ***************** |
| 80 | As :term:`TF-M` runs on resource-constrained devices, the :term:`HAL` tries to |
| 81 | avoid multiple level abstractions which cost more resources. |
| 82 | |
| 83 | Part of the :term:`HAL` interfaces does not focus on exact hardware operations |
| 84 | such as power on/off or PIN manipulation. |
| 85 | Instead, the :term:`HAL` abstracts higher-level interfaces to reserve the |
| 86 | implementation flexibility for the platform vendors. |
| 87 | |
| 88 | The :term:`TF-M` :term:`HAL` should be easy to deprecate APIs and provide |
| 89 | compatibilities. |
| 90 | Any API incompatibility should be detected during building. |
| 91 | |
| 92 | :term:`TF-M` relies on the :term:`HAL` APIs to be implemented correctly and |
| 93 | trusts the :term:`HAL` APIs. |
| 94 | :term:`TFM` can provide assertions to detect common programming errors but |
| 95 | essentially no further extensive checks will be provided. |
| 96 | |
| 97 | ************ |
| 98 | Source Files |
| 99 | ************ |
| 100 | This section describes the source file of the :term:`TF-M` :term:`HAL`, |
| 101 | including the header and c files. |
| 102 | |
| 103 | tfm_hal_defs.h |
| 104 | ============== |
| 105 | This header file contains the definitions of common macros and types used by all |
| 106 | :term:`HAL` APIs. Please refer to `Status Codes`_ for detailed definitions. |
| 107 | |
| 108 | tfm_hal_[module].[h/c] |
| 109 | ====================== |
| 110 | All other headers and c files are classified by the modules, such as isolation, |
| 111 | platform, interrupt, devices, etc. |
| 112 | |
| 113 | .. note:: |
| 114 | There are common files in the platform folder include the implemented |
| 115 | :term:`HAL` APIs. The platform vendors can use them directly but need to |
| 116 | implement all the sub APIs. |
| 117 | |
| 118 | ************ |
| 119 | Status Codes |
| 120 | ************ |
| 121 | These are common status and error codes for all :term:`HAL` APIs. |
| 122 | |
| 123 | Types |
| 124 | ===== |
| 125 | tfm_hal_status_t |
| 126 | ---------------- |
| 127 | This is a status code to be used as the return type of :term:`HAL` APIs. |
| 128 | |
| 129 | .. code-block:: c |
| 130 | |
Summer Qin | 2ecfc9f | 2020-08-20 14:20:27 +0800 | [diff] [blame] | 131 | enum tfm_hal_status_t { |
Mingyang Sun | 45c6c20 | 2020-09-23 16:17:50 +0800 | [diff] [blame] | 132 | TFM_HAL_ERROR_MEM_FAULT = SCHAR_MIN, |
Summer Qin | 2ecfc9f | 2020-08-20 14:20:27 +0800 | [diff] [blame] | 133 | TFM_HAL_ERROR_MAX_VALUE, |
| 134 | TFM_HAL_ERROR_BAD_STATE, |
| 135 | TFM_HAL_ERROR_NOT_SUPPORTED, |
| 136 | TFM_HAL_ERROR_INVALID_INPUT, |
| 137 | TFM_HAL_ERROR_NOT_INIT, |
| 138 | TFM_HAL_ERROR_GENERIC, |
| 139 | TFM_HAL_SUCCESS = 0 |
| 140 | }; |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 141 | |
| 142 | Error Codes |
| 143 | =========== |
| 144 | Negative values indicate an error. Zero and positive values indicate success. |
| 145 | |
| 146 | Here is the general list. The detailed usages for each error code are described |
| 147 | in the API introduction sections. |
| 148 | |
| 149 | TFM_HAL_SUCCESS |
| 150 | --------------- |
| 151 | Status code to indicate general success. |
| 152 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 153 | TFM_HAL_ERROR_GENERIC |
| 154 | --------------------- |
| 155 | Status code to indicate an error that does not correspond to any defined failure |
| 156 | cause. |
| 157 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 158 | TFM_HAL_ERROR_NOT_INIT |
| 159 | ---------------------- |
| 160 | Status code to indicate that the module is not initialed. |
| 161 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 162 | TFM_HAL_ERROR_INVALID_INPUT |
| 163 | --------------------------- |
| 164 | Status code to indicate that the input is invalid. |
| 165 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 166 | TFM_HAL_ERROR_NOT_SUPPORTED |
| 167 | --------------------------- |
| 168 | Status code to indicate that the requested operation or a parameter is not |
| 169 | supported. |
| 170 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 171 | TFM_HAL_ERROR_BAD_STATE |
| 172 | ----------------------- |
| 173 | Status code to indicate that the requested action cannot be performed in the |
| 174 | current state. |
| 175 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 176 | TFM_HAL_ERROR_MAX_VALUE |
| 177 | ----------------------- |
| 178 | Status code to indicate that the current number has got the max value. |
| 179 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 180 | TFM_HAL_ERROR_MEM_FAULT |
| 181 | ----------------------- |
| 182 | Status code to indicate that the memory check failed. |
| 183 | |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 184 | *************************** |
| 185 | API Definition for TF-M SPM |
| 186 | *************************** |
| 187 | This section describes the APIs defined for :term:`TF-M` :term:`SPM`. |
| 188 | |
Edison Ai | f542e6b | 2020-07-01 17:55:42 +0800 | [diff] [blame] | 189 | Platform API |
| 190 | ============ |
| 191 | The platform API is a higher-level abstraction layer of the platform, other than |
| 192 | a dedicated API set for the special hardware devices. |
| 193 | |
| 194 | APIs |
| 195 | ---- |
| 196 | tfm_hal_platform_init() |
| 197 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 198 | **Prototype** |
| 199 | |
| 200 | .. code-block:: c |
| 201 | |
| 202 | enum tfm_hal_status_t tfm_hal_platform_init(void) |
| 203 | |
| 204 | **Description** |
| 205 | |
Kevin Peng | b8bc0d2 | 2021-09-08 14:37:50 +0800 | [diff] [blame] | 206 | This API performs the platform initializations **before** the :term:`SPM` |
| 207 | initialization. |
Edison Ai | f542e6b | 2020-07-01 17:55:42 +0800 | [diff] [blame] | 208 | |
Kevin Peng | b8bc0d2 | 2021-09-08 14:37:50 +0800 | [diff] [blame] | 209 | The initializations could include but not limited to: |
| 210 | - Fault handlers |
| 211 | - Reset configurations |
| 212 | - Debug init |
| 213 | - NVIC init |
Edison Ai | f542e6b | 2020-07-01 17:55:42 +0800 | [diff] [blame] | 214 | |
| 215 | **Parameter** |
| 216 | |
| 217 | - ``void`` - None. |
| 218 | |
| 219 | **Return Values** |
| 220 | |
| 221 | - ``TFM_HAL_SUCCESS`` - Init success. |
| 222 | - ``TFM_HAL_ERROR_GENERIC`` - Generic errors. |
| 223 | |
| 224 | tfm_hal_system_reset() |
| 225 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 226 | **Prototype** |
| 227 | |
| 228 | .. code-block:: c |
| 229 | |
| 230 | void tfm_hal_system_reset(void) |
| 231 | |
| 232 | **Description** |
| 233 | |
| 234 | This API performs a system reset. |
| 235 | |
| 236 | The platform can uninitialize some resources before reset. |
| 237 | |
Joakim Andersson | e0a1dc3 | 2022-09-27 10:39:18 +0200 | [diff] [blame] | 238 | When ``CONFIG_TFM_HALT_ON_CORE_PANIC`` is disabled this function is called to reset |
Sebastian Bøe | 055d83a | 2022-02-21 12:01:41 +0100 | [diff] [blame] | 239 | the system when a fatal error occurs. |
| 240 | |
| 241 | **Parameter** |
| 242 | |
| 243 | - ``void`` - None |
| 244 | |
| 245 | **Return Values** |
| 246 | |
| 247 | - ``void`` - None |
| 248 | |
| 249 | **Note** |
| 250 | |
| 251 | This API should not return. |
| 252 | |
| 253 | tfm_hal_system_halt() |
| 254 | ^^^^^^^^^^^^^^^^^^^^^ |
| 255 | **Prototype** |
| 256 | |
| 257 | .. code-block:: c |
| 258 | |
| 259 | void tfm_hal_system_halt(void) |
| 260 | |
| 261 | **Description** |
| 262 | |
| 263 | This API enters the CPU into an infinite loop. |
| 264 | |
| 265 | The platform can uninitialize some resources before looping forever. |
| 266 | |
Joakim Andersson | e0a1dc3 | 2022-09-27 10:39:18 +0200 | [diff] [blame] | 267 | When ``CONFIG_TFM_HALT_ON_CORE_PANIC`` is enabled this function is called to halt the |
Sebastian Bøe | 055d83a | 2022-02-21 12:01:41 +0100 | [diff] [blame] | 268 | system when a fatal error occurs. |
| 269 | |
Edison Ai | f542e6b | 2020-07-01 17:55:42 +0800 | [diff] [blame] | 270 | **Parameter** |
| 271 | |
| 272 | - ``void`` - None |
| 273 | |
| 274 | **Return Values** |
| 275 | |
| 276 | - ``void`` - None |
| 277 | |
| 278 | **Note** |
| 279 | |
| 280 | This API should not return. |
| 281 | |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 282 | Isolation API |
| 283 | ============= |
| 284 | The :term:`PSA-FF-M` defines three isolation levels and a memory access rule to |
Nicola Mazzucato | afd24bb | 2024-02-14 17:27:27 +0000 | [diff] [blame] | 285 | provide diverse levels of security. The isolation API provides the functions to |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 286 | implement these requirements. |
| 287 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 288 | The Isolation API operates on boundaries. A boundary represents a set of |
| 289 | protection settings that isolates components and domains. Below are the |
| 290 | boundary examples in the current implementation: |
| 291 | |
| 292 | - Boundaries between SPM and Secure Partitions. |
| 293 | - Boundaries between ARoT domain and PRoT domain. |
| 294 | |
| 295 | There are two types of boundaries: |
| 296 | |
| 297 | - Static boundaries: Set up when the system is initializing and |
| 298 | persistent after the initialization. This type of boundary needs the |
| 299 | set-up operations only. |
| 300 | - Partition boundaries: Keeps switching from one to another when the system |
| 301 | is running. This type of boundary needs both set-up and switching |
| 302 | operations. |
| 303 | |
| 304 | The boundary operations are abstracted as HAL interfaces because isolation |
| 305 | hardwares can be different for platforms: |
| 306 | |
| 307 | - The set-up HAL interface creates a partition boundary based on given |
| 308 | partition information. This created boundary is bound with the partition |
| 309 | for subsequent usage. The binding is done by storing the boundary into |
| 310 | partition runtime data. |
| 311 | - The activation HAL interface activates the partition boundary to secure |
| 312 | the execution for the partition to be switched. The target partition's |
| 313 | information and boundary are given to the activation HAL to accomplish |
| 314 | the operation. |
| 315 | |
| 316 | The data representing the partition boundary in runtime is defined with the |
| 317 | opaque type ``uintptr_t``: |
| 318 | |
| 319 | - It is required that one value represents one boundary. The different values |
| 320 | represent different boundaries. |
| 321 | - The value is created by HAL implementation with its own-defined encoding |
| 322 | scheme. |
| 323 | |
| 324 | The HAL implementation defined encoding scheme can be designed for |
| 325 | implementation convenience. For example: |
| 326 | |
| 327 | - The implementation scheme can encode attribute flags into integer bits. |
| 328 | This could help the activation HAL to extract the protection settings |
| 329 | quickly from this encoded value, or even write to hardware registers |
| 330 | directly in the most ideal case. The initial TF-M Isolation HAL reference |
| 331 | implementation applies this scheme. |
| 332 | - The implementation scheme can reference the addresses of isolation |
| 333 | hardware description data. This could help the activation HAL to reference |
| 334 | the protection settings directly by pointers. |
| 335 | |
| 336 | Multiple Secure Partitions can bind with the same boundary value. This |
| 337 | flexibility is useful for specific configurations. Take Isolation Level 2 as |
| 338 | an example, assigning PRoT and ARoT domain boundaries to respective partitions |
| 339 | can make execution more efficient, because switching two partitions in the |
| 340 | same domain does not need to change the activated boundary. |
| 341 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 342 | The boundary contains the partition's memory accessibility information, hence |
| 343 | memory access check shall be performed based on boundary. |
| 344 | |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 345 | Memory Access Attributes |
| 346 | ------------------------ |
| 347 | The memory access attributes are encoded as bit fields, you can logic OR them to |
Antonio de Angelis | 9d496a5 | 2025-01-07 21:18:00 +0000 | [diff] [blame] | 348 | have a combination of the attributes, for example |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 349 | ``TFM_HAL_ACCESS_UNPRIVILEGED | TFM_HAL_ACCESS_READABLE`` is unprivileged |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 350 | readable. The data type is `uint32_t`. |
| 351 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 352 | TFM_HAL_ACCESS_EXECUTABLE |
| 353 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 354 | The memory is executable. |
| 355 | |
| 356 | .. code-block:: c |
| 357 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 358 | #define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 359 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 360 | TFM_HAL_ACCESS_READABLE |
| 361 | ^^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 362 | The memory is readable. |
| 363 | |
| 364 | .. code-block:: c |
| 365 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 366 | #define TFM_HAL_ACCESS_READABLE (1UL << 1) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 367 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 368 | TFM_HAL_ACCESS_WRITABLE |
| 369 | ^^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 370 | The memory is writable. |
| 371 | |
| 372 | .. code-block:: c |
| 373 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 374 | #define TFM_HAL_ACCESS_WRITABLE (1UL << 2) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 375 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 376 | TFM_HAL_ACCESS_UNPRIVILEGED |
| 377 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 378 | The memory is unprivileged mode accessible. |
| 379 | |
| 380 | .. code-block:: c |
| 381 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 382 | #define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 383 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 384 | TFM_HAL_ACCESS_DEVICE |
| 385 | ^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 386 | The memory is a MMIO device. |
| 387 | |
| 388 | .. code-block:: c |
| 389 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 390 | #define TFM_HAL_ACCESS_DEVICE (1UL << 4) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 391 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 392 | TFM_HAL_ACCESS_NS |
| 393 | ^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 394 | The memory is accessible from :term:`NSPE` |
| 395 | |
| 396 | .. code-block:: c |
| 397 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 398 | #define TFM_HAL_ACCESS_NS (1UL << 5) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 399 | |
| 400 | APIs |
| 401 | ---- |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 402 | |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 403 | tfm_hal_verify_static_boundaries() |
| 404 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 405 | **Prototype** |
| 406 | |
| 407 | .. code-block:: c |
| 408 | |
| 409 | fih_int tfm_hal_verify_static_boundaries(void) |
| 410 | |
| 411 | **Description** |
| 412 | |
| 413 | This API verifies the static isolation boundaries. |
| 414 | |
| 415 | Refer to the :term:`PSA-FF-M` for the definitions of the isolation boundaries. |
| 416 | |
| 417 | **Parameter** |
| 418 | |
| 419 | - ``void`` - None |
| 420 | |
| 421 | **Return Values** |
| 422 | |
| 423 | - ``TFM_HAL_SUCCESS`` - Verification has been successful. |
| 424 | - ``TFM_HAL_ERROR_GENERIC`` - Verification failed. |
| 425 | |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 426 | tfm_hal_set_up_static_boundaries() |
| 427 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 428 | **Prototype** |
| 429 | |
| 430 | .. code-block:: c |
| 431 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 432 | enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 433 | |
| 434 | **Description** |
| 435 | |
| 436 | This API sets up the static isolation boundaries which are constant throughout |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 437 | the system runtime. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 438 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 439 | These boundaries include: |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 440 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 441 | - The boundary between the :term:`SPE` and the :term:`NSPE` |
| 442 | - The boundary to protect the SPM execution. For example, the PSA RoT |
| 443 | isolation boundary between the PSA Root of Trust and the Application Root of |
| 444 | Trust which is for isolation level 2 and 3 only. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 445 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 446 | Refer to the :term:`PSA-FF-M` for the definitions of the isolation boundaries. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 447 | |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 448 | **Parameter** |
| 449 | |
| 450 | - ``void`` - None |
| 451 | |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 452 | **Return Values** |
| 453 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 454 | - ``TFM_HAL_SUCCESS`` - Isolation boundaries have been set up. |
| 455 | - ``TFM_HAL_ERROR_GENERIC`` - Failed to set up the static boundaries. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 456 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 457 | tfm_hal_bind_boundary() |
| 458 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 459 | **Prototype** |
| 460 | |
| 461 | .. code-block:: c |
| 462 | |
| 463 | enum tfm_hal_status_t tfm_hal_bind_boundary( |
| 464 | const struct partition_load_info_t *p_ldinf, |
| 465 | uintptr_t *p_boundary); |
| 466 | |
| 467 | **Description** |
| 468 | |
| 469 | This API binds partition with a platform-generated boundary. The boundary is |
| 470 | bound by writing the generated value into ``p_boundary``. And this bound |
| 471 | boundary is used in subsequent calls to `tfm_hal_activate_boundary()`_ when |
| 472 | boundary's owner partition get scheduled for running. |
| 473 | |
| 474 | **Parameter** |
| 475 | |
| 476 | - ``p_ldinf`` - Load information of the partition that is under loading. |
| 477 | - ``p_boundary`` - Pointer for holding a partition's boundary. |
| 478 | |
| 479 | **Return Values** |
| 480 | |
| 481 | - ``TFM_HAL_SUCCESS`` - The boundary has been bound successfully. |
| 482 | - ``TFM_HAL_ERROR_GENERIC`` - Failed to bind the handle. |
| 483 | |
| 484 | tfm_hal_activate_boundary() |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 485 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 486 | **Prototype** |
| 487 | |
| 488 | .. code-block:: c |
| 489 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 490 | enum tfm_hal_status_t tfm_hal_activate_boundary( |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 491 | const struct partition_load_info_t *p_ldinf, |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 492 | uintptr_t boundary); |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 493 | |
| 494 | **Description** |
| 495 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 496 | This API requires the platform to activate the boundary to ensure the given |
| 497 | Secure Partition can run successfully. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 498 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 499 | The access permissions outside the boundary is platform-dependent. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 500 | |
| 501 | **Parameter** |
| 502 | |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 503 | - ``p_ldinf`` - The load information of the partition that is going to be run. |
| 504 | - ``boundary`` - The boundary for the owner partition of ``p_ldinf``. This |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 505 | value is bound in function ``tfm_hal_bind_boundary``. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 506 | |
| 507 | **Return Values** |
| 508 | |
| 509 | - ``TFM_HAL_SUCCESS`` - the isolation boundary has been set up. |
Nicola Mazzucato | afd24bb | 2024-02-14 17:27:27 +0000 | [diff] [blame] | 510 | - ``TFM_HAL_ERROR_GENERIC`` - failed to set up the isolation boundary. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 511 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 512 | tfm_hal_memory_check() |
| 513 | ^^^^^^^^^^^^^^^^^^^^^^ |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 514 | **Prototype** |
| 515 | |
| 516 | .. code-block:: c |
| 517 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 518 | tfm_hal_status_t tfm_hal_memory_check(uintptr_t boundary, |
| 519 | uintptr_t base, |
| 520 | size_t size, |
| 521 | uint32_t access_type) |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 522 | |
| 523 | **Description** |
| 524 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 525 | This API checks if a given range of memory can be accessed with specified |
| 526 | access types in boundary. The boundary belongs to a partition which |
| 527 | contains asset info. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 528 | |
| 529 | **Parameter** |
| 530 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 531 | - ``boundary`` - Boundary of a Secure Partition. |
| 532 | Check `tfm_hal_bind_boundary` for details. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 533 | - ``base`` - The base address of the region. |
| 534 | - ``size`` - The size of the region. |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 535 | - ``access_type`` - The memory access types to be checked between given memory |
| 536 | and boundaries. The `Memory Access Attributes`_. |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 537 | |
| 538 | **Return Values** |
| 539 | |
| 540 | - ``TFM_HAL_SUCCESS`` - The memory region has the access permissions. |
| 541 | - ``TFM_HAL_ERROR_MEM_FAULT`` - The memory region does not have the access |
| 542 | permissions. |
| 543 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs. |
| 544 | - ``TFM_HAL_ERROR_GENERIC`` - An error occurred. |
| 545 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 546 | **Note** |
| 547 | |
| 548 | If the implementation chooses to encode a pointer as the boundary, |
| 549 | a platform-specific pointer validation needs to be considered before |
| 550 | referencing the content in this pointer. |
| 551 | |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 552 | tfm_hal_boundary_need_switch() |
| 553 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 554 | **Prototype** |
| 555 | |
| 556 | .. code-block:: c |
| 557 | |
| 558 | bool tfm_hal_boundary_need_switch(uintptr_t boundary_from, |
| 559 | uintptr_t boundary_to) |
| 560 | |
| 561 | **Description** |
| 562 | |
| 563 | This API let the platform decide if a boundary switch is needed. |
| 564 | |
| 565 | **Parameter** |
| 566 | |
| 567 | - ``boundary_from`` - Boundary to switch from. |
| 568 | - ``boundary_to`` - Boundary to switch to. |
| 569 | |
| 570 | **Return Values** |
| 571 | |
| 572 | - ``true`` - A switching is needed |
| 573 | - ``false`` - No need for a boundary switch |
| 574 | |
Roman Mazurak | 96585b8 | 2024-04-03 14:35:00 +0300 | [diff] [blame] | 575 | tfm_hal_post_partition_init_hook() |
| 576 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 577 | **Prototype** |
| 578 | |
| 579 | .. code-block:: c |
| 580 | |
| 581 | enum tfm_hal_status_t tfm_hal_post_partition_init_hook(void) |
| 582 | |
| 583 | **Description** |
| 584 | |
| 585 | This API let the platform to finish static isolation after all partitions have been bound. |
| 586 | It's called by SPM right before starting scheduler. Use CONFIG_TFM_POST_PARTITION_INIT_HOOK |
| 587 | to enable it. |
| 588 | |
| 589 | **Parameter** |
| 590 | |
| 591 | - ``void`` - None |
| 592 | |
| 593 | **Return Values** |
| 594 | |
| 595 | - ``TFM_HAL_SUCCESS`` - Booting has been successful. |
| 596 | - ``TFM_HAL_ERROR_GENERIC`` - Error occurred. |
| 597 | |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 598 | Log API |
| 599 | ======= |
Anton Komlev | b3f6466 | 2023-01-28 11:53:05 +0000 | [diff] [blame] | 600 | The log API is used by the :term:`TF-M` :doc:`log system </design_docs/tfm_log_system_design_document>`. |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 601 | The log device could be uart, memory, usb, etc. |
| 602 | |
| 603 | APIs |
| 604 | ---- |
| 605 | tfm_hal_output_partition_log() |
| 606 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 607 | **Prototype** |
| 608 | |
| 609 | .. code-block:: c |
| 610 | |
| 611 | int32_t tfm_hal_output_partition_log(const unsigned char *str, uint32_t len) |
| 612 | |
| 613 | **Description** |
| 614 | |
| 615 | This API is called by Secure Partition to output logs. |
| 616 | |
| 617 | **Parameter** |
| 618 | |
| 619 | - ``str`` - The string to output. |
| 620 | - ``len`` - Length of the string in bytes. |
| 621 | |
| 622 | **Return Values** |
| 623 | |
| 624 | - Positive values - Number of bytes output. |
| 625 | - ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized. |
| 626 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` or |
| 627 | ``len`` is zero. |
| 628 | |
| 629 | **Note** |
| 630 | |
| 631 | None. |
| 632 | |
| 633 | tfm_hal_output_spm_log() |
| 634 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 635 | **Prototype** |
| 636 | |
| 637 | .. code-block:: c |
| 638 | |
| 639 | int32_t tfm_hal_output_spm_log(const unsigned char *str, uint32_t len) |
| 640 | |
| 641 | **Description** |
| 642 | |
| 643 | This API is called by :term:`SPM` to output logs. |
| 644 | |
| 645 | **Parameter** |
| 646 | |
| 647 | - ``str`` - The string to output. |
| 648 | - ``len`` - Length of the string in bytes. |
| 649 | |
| 650 | **Return Values** |
| 651 | |
| 652 | - Positive numbers - Number of bytes output. |
| 653 | - ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized. |
| 654 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` |
| 655 | or ``len`` is zero. |
| 656 | |
| 657 | **Note** |
| 658 | |
Anton Komlev | b3f6466 | 2023-01-28 11:53:05 +0000 | [diff] [blame] | 659 | Please check :doc:`TF-M log system </design_docs/tfm_log_system_design_document>` |
| 660 | for more information. |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 661 | |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 662 | Interrupt APIs |
| 663 | ============== |
| 664 | |
| 665 | The SPM HAL interrupt APIs are intended for operations on Interrupt Controllers |
| 666 | of platforms. |
| 667 | |
| 668 | APIs for control registers of interrupt sources are not in the scope of this set |
| 669 | of APIs. |
| 670 | Secure Partitions should define the APIs for managing interrupts with those MMIO |
| 671 | registers. |
| 672 | |
| 673 | APIs |
| 674 | ---- |
| 675 | |
| 676 | tfm_hal_irq_enable() |
| 677 | ^^^^^^^^^^^^^^^^^^^^ |
| 678 | |
| 679 | **Prototype** |
| 680 | |
| 681 | .. code-block:: c |
| 682 | |
| 683 | enum tfm_hal_status_t tfm_hal_irq_enable(uint32_t irq_num) |
| 684 | |
| 685 | **Description** |
| 686 | |
| 687 | This API enables an interrupt from the Interrupt Controller of the platform. |
| 688 | |
| 689 | **Parameter** |
| 690 | |
| 691 | - ``irq_num`` - the interrupt to be enabled with a number |
| 692 | |
| 693 | **Return Values** |
| 694 | |
| 695 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 696 | supported number of external interrupts. |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 697 | - ``TFM_HAL_ERROR_GENERIC`` - failed to enable the interrupt. |
| 698 | - ``TFM_HAL_SUCCESS`` - the interrupt is successfully enabled. |
| 699 | |
| 700 | tfm_hal_irq_disable() |
| 701 | ^^^^^^^^^^^^^^^^^^^^^ |
| 702 | |
| 703 | **Prototype** |
| 704 | |
| 705 | .. code-block:: c |
| 706 | |
| 707 | enum tfm_hal_status_t tfm_hal_irq_disable(uint32_t irq_num) |
| 708 | |
| 709 | **Description** |
| 710 | |
| 711 | This API disables an interrupt from the Interrupt Controller of the platform. |
| 712 | |
| 713 | **Parameter** |
| 714 | |
| 715 | - ``irq_num`` - the interrupt to be disabled with a number |
| 716 | |
| 717 | **Return Values** |
| 718 | |
| 719 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 720 | supported number of external interrupts. |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 721 | - ``TFM_HAL_ERROR_GENERIC`` - failed to disable the interrupt. |
| 722 | - ``TFM_HAL_SUCCESS`` - the interrupt is successfully disabled. |
| 723 | |
| 724 | tfm_hal_irq_clear_pending() |
| 725 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 726 | |
| 727 | **Prototype** |
| 728 | |
| 729 | .. code-block:: c |
| 730 | |
| 731 | enum tfm_hal_status_t tfm_hal_irq_clear_pending(uint32_t irq_num) |
| 732 | |
| 733 | **Description** |
| 734 | |
| 735 | This API clears an active and pending interrupt. |
| 736 | |
| 737 | **Parameter** |
| 738 | |
| 739 | - ``irq_num`` - the interrupt to be disabled with a number |
| 740 | |
| 741 | **Return Values** |
| 742 | |
| 743 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum |
Nicola Mazzucato | add545e | 2024-02-19 09:57:56 +0000 | [diff] [blame] | 744 | supported number of external interrupts. |
Kevin Peng | d399a1f | 2021-09-08 15:33:14 +0800 | [diff] [blame] | 745 | - ``TFM_HAL_ERROR_GENERIC`` - failed to clear the pending interrupt. |
| 746 | - ``TFM_HAL_SUCCESS`` - the pending interrupt has been cleared. |
| 747 | |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 748 | Initializations |
| 749 | ^^^^^^^^^^^^^^^ |
| 750 | |
| 751 | **Prototype** |
| 752 | |
| 753 | .. code-block:: c |
| 754 | |
| 755 | enum tfm_hal_status_t {source_symbol}_init(void *p_pt, |
Chris Brand | 11ff8a5 | 2022-10-18 17:46:50 -0700 | [diff] [blame] | 756 | const struct irq_load_info_t *p_ildi) |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 757 | |
| 758 | The ``{source_symbol}`` is: |
| 759 | |
| 760 | - ``irq_{source}``, if the ``source`` attribute of the IRQ in Partition manifest |
| 761 | is a number |
| 762 | - Lowercase of ``source`` attribute, if ``source`` is a symbolic name |
| 763 | |
| 764 | **Description** |
| 765 | |
| 766 | Each interrupt has an initialization function individually. |
| 767 | The :term:`SPM` calls the functions while loading the Partitions. |
| 768 | |
| 769 | The following initializations are required for each interrupt: |
| 770 | |
| 771 | - Setting the priority. The value must between 0 to 0x80 exclusively. |
| 772 | - Ensuring that the interrupt targets the Secure State. |
| 773 | - Saving the input parameters for future use. |
| 774 | |
| 775 | Platforms can have extra initializations as well. |
| 776 | |
| 777 | **Parameter** |
| 778 | |
| 779 | - ``p_pt`` - pointer to Partition runtime struct of the owner Partition |
| 780 | - ``p_ildi`` - pointer to ``irq_load_info_t`` struct of the interrupt |
| 781 | |
| 782 | **Note** |
| 783 | |
| 784 | Please refer to the |
Antonio de Angelis | 9d496a5 | 2025-01-07 21:18:00 +0000 | [diff] [blame] | 785 | :doc: `IRQ integration guide<tfm_secure_irq_integration_guide>` |
Kevin Peng | ec239bb | 2021-09-03 15:40:27 +0800 | [diff] [blame] | 786 | for more information. |
| 787 | |
Edison Ai | b28b971 | 2020-06-04 14:41:23 +0800 | [diff] [blame] | 788 | ************************************ |
| 789 | API Definition for Secure Partitions |
| 790 | ************************************ |
| 791 | The Secure Partition (SP) :term:`HAL` mainly focuses on two parts: |
| 792 | |
| 793 | - Peripheral devices. The peripherals accessed by the :term:`TF-M` default |
| 794 | Secure Partitions. |
| 795 | - Secure Partition abstraction support. The Secure Partition data that must be |
| 796 | provided by the platform. |
| 797 | |
| 798 | The Secure Partition abstraction support will be introduced in the peripheral |
| 799 | API definition. |
| 800 | |
| 801 | ITS and PS flash API |
| 802 | ==================== |
| 803 | There are two kinds of flash: |
| 804 | |
| 805 | - Internal flash. Accessed by the PSA Internal Trusted Storage (ITS) service. |
| 806 | - External flash. Accessed by the PSA Protected Storage (PS) service. |
| 807 | |
| 808 | The ITS HAL for the internal flash device is defined in the ``tfm_hal_its.h`` |
| 809 | header and the PS HAL in the ``tfm_hal_ps.h`` header. |
| 810 | |
| 811 | Macros |
| 812 | ------ |
| 813 | Internal Trusted Storage |
| 814 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 815 | TFM_HAL_ITS_FLASH_DRIVER |
| 816 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 817 | Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for |
| 818 | ITS. It must have been allocated by the platform and will be declared extern in |
| 819 | the HAL header. |
| 820 | |
| 821 | TFM_HAL_ITS_PROGRAM_UNIT |
| 822 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 823 | Defines the size of the ITS flash device's physical program unit (the smallest |
| 824 | unit of data that can be individually programmed to flash). It must be equal to |
| 825 | TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile |
| 826 | time so that filesystem structures can be statically sized. |
| 827 | |
| 828 | TFM_HAL_ITS_FLASH_AREA_ADDR |
| 829 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 830 | Defines the base address of the dedicated flash area for ITS. |
| 831 | |
| 832 | TFM_HAL_ITS_FLASH_AREA_SIZE |
| 833 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 834 | Defines the size of the dedicated flash area for ITS in bytes. |
| 835 | |
| 836 | TFM_HAL_ITS_SECTORS_PER_BLOCK |
| 837 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 838 | Defines the number of contiguous physical flash erase sectors that form a |
| 839 | logical filesystem erase block. |
| 840 | |
| 841 | Protected Storage |
| 842 | ^^^^^^^^^^^^^^^^^ |
| 843 | TFM_HAL_PS_FLASH_DRIVER |
| 844 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 845 | Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for |
| 846 | PS. It must have been allocated by the platform and will be declared extern in |
| 847 | the HAL header. |
| 848 | |
| 849 | TFM_HAL_PS_PROGRAM_UNIT |
| 850 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 851 | Defines the size of the PS flash device's physical program unit (the smallest |
| 852 | unit of data that can be individually programmed to flash). It must be equal to |
| 853 | TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile |
| 854 | time so that filesystem structures can be statically sized. |
| 855 | |
| 856 | TFM_HAL_PS_FLASH_AREA_ADDR |
| 857 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 858 | Defines the base address of the dedicated flash area for PS. |
| 859 | |
| 860 | TFM_HAL_PS_FLASH_AREA_SIZE |
| 861 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 862 | Defines the size of the dedicated flash area for PS in bytes. |
| 863 | |
| 864 | TFM_HAL_PS_SECTORS_PER_BLOCK |
| 865 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 866 | Defines the number of contiguous physical flash erase sectors that form a |
| 867 | logical filesystem erase block. |
| 868 | |
| 869 | Optional definitions |
| 870 | -------------------- |
| 871 | The ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` and |
| 872 | ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` definitions are optional. If not defined, the |
| 873 | platform must implement ``tfm_hal_its_fs_info()`` instead. |
| 874 | |
| 875 | Equivalently, ``tfm_hal_its_ps_info()`` must be implemented by the platform if |
| 876 | ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` or |
| 877 | ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` is not defined. |
| 878 | |
| 879 | Objects |
| 880 | ------- |
| 881 | ARM_DRIVER_FLASH |
| 882 | ^^^^^^^^^^^^^^^^ |
| 883 | The ITS and PS HAL headers each expose a CMSIS Flash Driver instance. |
| 884 | |
| 885 | .. code-block:: c |
| 886 | |
| 887 | extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER |
| 888 | |
| 889 | extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER |
| 890 | |
| 891 | The CMSIS Flash Driver provides the flash primitives ReadData(), ProgramData() |
| 892 | and EraseSector() as well as GetInfo() to access flash device properties such |
| 893 | as the sector size. |
| 894 | |
| 895 | Types |
| 896 | ----- |
| 897 | tfm_hal_its_fs_info_t |
| 898 | ^^^^^^^^^^^^^^^^^^^^^ |
| 899 | Struct containing information required from the platform at runtime to configure |
| 900 | the ITS filesystem. |
| 901 | |
| 902 | .. code-block:: c |
| 903 | |
| 904 | struct tfm_hal_its_fs_info_t { |
| 905 | uint32_t flash_area_addr; |
| 906 | size_t flash_area_size; |
| 907 | uint8_t sectors_per_block; |
| 908 | }; |
| 909 | |
| 910 | Each attribute is described below: |
| 911 | |
| 912 | - ``flash_area_addr`` - Location of the block of flash to use for ITS |
| 913 | - ``flash_area_size`` - Number of bytes of flash to use for ITS |
| 914 | - ``sectors_per_block`` - Number of erase sectors per logical FS block |
| 915 | |
| 916 | tfm_hal_ps_fs_info_t |
| 917 | ^^^^^^^^^^^^^^^^^^^^^ |
| 918 | Struct containing information required from the platform at runtime to configure |
| 919 | the PS filesystem. |
| 920 | |
| 921 | .. code-block:: c |
| 922 | |
| 923 | struct tfm_hal_ps_fs_info_t { |
| 924 | uint32_t flash_area_addr; |
| 925 | size_t flash_area_size; |
| 926 | uint8_t sectors_per_block; |
| 927 | }; |
| 928 | |
| 929 | Each attribute is described below: |
| 930 | |
| 931 | - ``flash_area_addr`` - Location of the block of flash to use for PS |
| 932 | - ``flash_area_size`` - Number of bytes of flash to use for PS |
| 933 | - ``sectors_per_block`` - Number of erase sectors per logical FS block |
| 934 | |
| 935 | Functions |
| 936 | --------- |
| 937 | tfm_hal_its_fs_info() |
| 938 | ^^^^^^^^^^^^^^^^^^^^^ |
| 939 | **Prototype** |
| 940 | |
| 941 | .. code-block:: c |
| 942 | |
| 943 | enum tfm_hal_status_t tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info); |
| 944 | |
| 945 | **Description** |
| 946 | |
| 947 | Retrieves the filesystem configuration parameters for ITS. |
| 948 | |
| 949 | **Parameter** |
| 950 | |
| 951 | - ``fs_info`` - Filesystem config information |
| 952 | |
| 953 | **Return values** |
| 954 | |
| 955 | - ``TFM_HAL_SUCCESS`` - The operation completed successfully |
| 956 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter |
| 957 | |
| 958 | **Note** |
| 959 | |
| 960 | This function should ensure that the values returned do not result in a security |
| 961 | compromise. The block of flash supplied must meet the security requirements of |
| 962 | Internal Trusted Storage. |
| 963 | |
| 964 | tfm_hal_ps_fs_info() |
| 965 | ^^^^^^^^^^^^^^^^^^^^ |
| 966 | **Prototype** |
| 967 | |
| 968 | .. code-block:: c |
| 969 | |
| 970 | enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info); |
| 971 | |
| 972 | **Description** |
| 973 | |
| 974 | Retrieves the filesystem configuration parameters for PS. |
| 975 | |
| 976 | **Parameter** |
| 977 | |
| 978 | - ``fs_info`` - Filesystem config information |
| 979 | |
| 980 | **Return values** |
| 981 | |
| 982 | - ``TFM_HAL_SUCCESS`` - The operation completed successfully |
| 983 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter |
| 984 | |
| 985 | **Note** |
| 986 | |
| 987 | This function should ensure that the values returned do not result in a security |
| 988 | compromise. |
| 989 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 990 | -------------- |
| 991 | |
Nicola Mazzucato | afd24bb | 2024-02-14 17:27:27 +0000 | [diff] [blame] | 992 | *Copyright (c) 2020-2024, Arm Limited. All rights reserved.* |
Chris Brand | 11ff8a5 | 2022-10-18 17:46:50 -0700 | [diff] [blame] | 993 | *Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) |
| 994 | or an affiliate of Cypress Semiconductor Corporation. All rights reserved.* |