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 | |
| 48 | .. figure:: media/hal_structure.png |
| 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 |
| 64 | </docs/design_documents/dual-cpu/mailbox_design_on_dual_core_system>`. |
| 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 |
| 74 | settings section </platform/readme>` for more detail. |
| 75 | |
| 76 | ***************** |
| 77 | Design Principles |
| 78 | ***************** |
| 79 | As :term:`TF-M` runs on resource-constrained devices, the :term:`HAL` tries to |
| 80 | avoid multiple level abstractions which cost more resources. |
| 81 | |
| 82 | Part of the :term:`HAL` interfaces does not focus on exact hardware operations |
| 83 | such as power on/off or PIN manipulation. |
| 84 | Instead, the :term:`HAL` abstracts higher-level interfaces to reserve the |
| 85 | implementation flexibility for the platform vendors. |
| 86 | |
| 87 | The :term:`TF-M` :term:`HAL` should be easy to deprecate APIs and provide |
| 88 | compatibilities. |
| 89 | Any API incompatibility should be detected during building. |
| 90 | |
| 91 | :term:`TF-M` relies on the :term:`HAL` APIs to be implemented correctly and |
| 92 | trusts the :term:`HAL` APIs. |
| 93 | :term:`TFM` can provide assertions to detect common programming errors but |
| 94 | essentially no further extensive checks will be provided. |
| 95 | |
| 96 | ************ |
| 97 | Source Files |
| 98 | ************ |
| 99 | This section describes the source file of the :term:`TF-M` :term:`HAL`, |
| 100 | including the header and c files. |
| 101 | |
| 102 | tfm_hal_defs.h |
| 103 | ============== |
| 104 | This header file contains the definitions of common macros and types used by all |
| 105 | :term:`HAL` APIs. Please refer to `Status Codes`_ for detailed definitions. |
| 106 | |
| 107 | tfm_hal_[module].[h/c] |
| 108 | ====================== |
| 109 | All other headers and c files are classified by the modules, such as isolation, |
| 110 | platform, interrupt, devices, etc. |
| 111 | |
| 112 | .. note:: |
| 113 | There are common files in the platform folder include the implemented |
| 114 | :term:`HAL` APIs. The platform vendors can use them directly but need to |
| 115 | implement all the sub APIs. |
| 116 | |
| 117 | ************ |
| 118 | Status Codes |
| 119 | ************ |
| 120 | These are common status and error codes for all :term:`HAL` APIs. |
| 121 | |
| 122 | Types |
| 123 | ===== |
| 124 | tfm_hal_status_t |
| 125 | ---------------- |
| 126 | This is a status code to be used as the return type of :term:`HAL` APIs. |
| 127 | |
| 128 | .. code-block:: c |
| 129 | |
Summer Qin | 2ecfc9f | 2020-08-20 14:20:27 +0800 | [diff] [blame] | 130 | enum tfm_hal_status_t { |
Mingyang Sun | 45c6c20 | 2020-09-23 16:17:50 +0800 | [diff] [blame] | 131 | TFM_HAL_ERROR_MEM_FAULT = SCHAR_MIN, |
Summer Qin | 2ecfc9f | 2020-08-20 14:20:27 +0800 | [diff] [blame] | 132 | TFM_HAL_ERROR_MAX_VALUE, |
| 133 | TFM_HAL_ERROR_BAD_STATE, |
| 134 | TFM_HAL_ERROR_NOT_SUPPORTED, |
| 135 | TFM_HAL_ERROR_INVALID_INPUT, |
| 136 | TFM_HAL_ERROR_NOT_INIT, |
| 137 | TFM_HAL_ERROR_GENERIC, |
| 138 | TFM_HAL_SUCCESS = 0 |
| 139 | }; |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 140 | |
| 141 | Error Codes |
| 142 | =========== |
| 143 | Negative values indicate an error. Zero and positive values indicate success. |
| 144 | |
| 145 | Here is the general list. The detailed usages for each error code are described |
| 146 | in the API introduction sections. |
| 147 | |
| 148 | TFM_HAL_SUCCESS |
| 149 | --------------- |
| 150 | Status code to indicate general success. |
| 151 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 152 | TFM_HAL_ERROR_GENERIC |
| 153 | --------------------- |
| 154 | Status code to indicate an error that does not correspond to any defined failure |
| 155 | cause. |
| 156 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 157 | TFM_HAL_ERROR_NOT_INIT |
| 158 | ---------------------- |
| 159 | Status code to indicate that the module is not initialed. |
| 160 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 161 | TFM_HAL_ERROR_INVALID_INPUT |
| 162 | --------------------------- |
| 163 | Status code to indicate that the input is invalid. |
| 164 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 165 | TFM_HAL_ERROR_NOT_SUPPORTED |
| 166 | --------------------------- |
| 167 | Status code to indicate that the requested operation or a parameter is not |
| 168 | supported. |
| 169 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 170 | TFM_HAL_ERROR_BAD_STATE |
| 171 | ----------------------- |
| 172 | Status code to indicate that the requested action cannot be performed in the |
| 173 | current state. |
| 174 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 175 | TFM_HAL_ERROR_MAX_VALUE |
| 176 | ----------------------- |
| 177 | Status code to indicate that the current number has got the max value. |
| 178 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 179 | TFM_HAL_ERROR_MEM_FAULT |
| 180 | ----------------------- |
| 181 | Status code to indicate that the memory check failed. |
| 182 | |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 183 | *************************** |
| 184 | API Definition for TF-M SPM |
| 185 | *************************** |
| 186 | This section describes the APIs defined for :term:`TF-M` :term:`SPM`. |
| 187 | |
Edison Ai | f542e6b | 2020-07-01 17:55:42 +0800 | [diff] [blame] | 188 | Platform API |
| 189 | ============ |
| 190 | The platform API is a higher-level abstraction layer of the platform, other than |
| 191 | a dedicated API set for the special hardware devices. |
| 192 | |
| 193 | APIs |
| 194 | ---- |
| 195 | tfm_hal_platform_init() |
| 196 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 197 | **Prototype** |
| 198 | |
| 199 | .. code-block:: c |
| 200 | |
| 201 | enum tfm_hal_status_t tfm_hal_platform_init(void) |
| 202 | |
| 203 | **Description** |
| 204 | |
| 205 | This API performs the platform-specific initialization. |
| 206 | |
| 207 | This API is called after architecture and platform common initialization has |
| 208 | finished during system early startup. |
| 209 | |
| 210 | **Parameter** |
| 211 | |
| 212 | - ``void`` - None. |
| 213 | |
| 214 | **Return Values** |
| 215 | |
| 216 | - ``TFM_HAL_SUCCESS`` - Init success. |
| 217 | - ``TFM_HAL_ERROR_GENERIC`` - Generic errors. |
| 218 | |
| 219 | tfm_hal_system_reset() |
| 220 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 221 | **Prototype** |
| 222 | |
| 223 | .. code-block:: c |
| 224 | |
| 225 | void tfm_hal_system_reset(void) |
| 226 | |
| 227 | **Description** |
| 228 | |
| 229 | This API performs a system reset. |
| 230 | |
| 231 | The platform can uninitialize some resources before reset. |
| 232 | |
| 233 | **Parameter** |
| 234 | |
| 235 | - ``void`` - None |
| 236 | |
| 237 | **Return Values** |
| 238 | |
| 239 | - ``void`` - None |
| 240 | |
| 241 | **Note** |
| 242 | |
| 243 | This API should not return. |
| 244 | |
edison.ai | 37e0f60 | 2020-07-13 18:30:58 +0800 | [diff] [blame] | 245 | Isolation API |
| 246 | ============= |
| 247 | The :term:`PSA-FF-M` defines three isolation levels and a memory access rule to |
| 248 | provide diverse levels of securitiy. The isolation API provides the functions to |
| 249 | implement these requirements. |
| 250 | |
| 251 | Memory Access Attributes |
| 252 | ------------------------ |
| 253 | The memory access attributes are encoded as bit fields, you can logic OR them to |
| 254 | have a combination of the atrributes, for example |
| 255 | ``TFM_HAL_MEM_ATTR_UNPRIVILEGED | TFM_HAL_MEM_ATTR_READABLE`` is unprivileged |
| 256 | readable. The data type is `uint32_t`. |
| 257 | |
| 258 | TFM_HAL_MEM_ATTR_EXECUTABLE |
| 259 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 260 | The memory is executable. |
| 261 | |
| 262 | .. code-block:: c |
| 263 | |
| 264 | #define TFM_HAL_MEM_ATTR_EXECUTABLE (1UL << 0) |
| 265 | |
| 266 | TFM_HAL_MEM_ATTR_READABLE |
| 267 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 268 | The memory is readable. |
| 269 | |
| 270 | .. code-block:: c |
| 271 | |
| 272 | #define TFM_HAL_MEM_ATTR_READABLE (1UL << 1) |
| 273 | |
| 274 | TFM_HAL_MEM_ATTR_WRITABLE |
| 275 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 276 | The memory is writable. |
| 277 | |
| 278 | .. code-block:: c |
| 279 | |
| 280 | #define TFM_HAL_MEM_ATTR_WRITABLE (1UL << 2) |
| 281 | |
| 282 | TFM_HAL_MEM_ATTR_UNPRIVILEGED |
| 283 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 284 | The memory is unprivileged mode accessible. |
| 285 | |
| 286 | .. code-block:: c |
| 287 | |
| 288 | #define TFM_HAL_MEM_ATTR_UNPRIVILEGED (1UL << 3) |
| 289 | |
| 290 | TFM_HAL_MEM_ATTR_DEVICE |
| 291 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 292 | The memory is a MMIO device. |
| 293 | |
| 294 | .. code-block:: c |
| 295 | |
| 296 | #define TFM_HAL_MEM_ATTR_DEVICE (1UL << 4) |
| 297 | |
| 298 | TFM_HAL_MEM_ATTR_NS |
| 299 | ^^^^^^^^^^^^^^^^^^^ |
| 300 | The memory is accessible from :term:`NSPE` |
| 301 | |
| 302 | .. code-block:: c |
| 303 | |
| 304 | #define TFM_HAL_MEM_ATTR_NS (1UL << 5) |
| 305 | |
| 306 | APIs |
| 307 | ---- |
| 308 | tfm_hal_set_up_static_boundaries() |
| 309 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 310 | **Prototype** |
| 311 | |
| 312 | .. code-block:: c |
| 313 | |
| 314 | tfm_hal_status_t tfm_hal_set_up_static_boundaries(void) |
| 315 | |
| 316 | **Description** |
| 317 | |
| 318 | This API sets up the static isolation boundaries which are constant throughout |
| 319 | the runtime of the system. |
| 320 | |
| 321 | The boundaries include: |
| 322 | |
| 323 | - The SPE boundary between the :term:`SPE` and the :term:`NSPE` |
| 324 | - The PSA RoT isolation boundary between the PSA Root of Trust and the |
| 325 | Application Root of Trust which is for isolation level 2 and 3 only. |
| 326 | |
| 327 | Please refer to the :term:`PSA-FF-M` for the definitions of the isolation |
| 328 | boundaries. |
| 329 | |
| 330 | **Return Values** |
| 331 | |
| 332 | - ``TFM_HAL_SUCCESS`` - the isolation boundaries have been set up. |
| 333 | - ``TFM_HAL_ERROR_GENERIC`` - failed to set up the isolation boundaries. |
| 334 | |
| 335 | tfm_hal_mpu_update_partition_boundary |
| 336 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 337 | **Prototype** |
| 338 | |
| 339 | .. code-block:: c |
| 340 | |
| 341 | enum tfm_hal_status_t tfm_hal_mpu_update_partition_boundary(uintptr_t start, |
| 342 | uintptr_t end); |
| 343 | |
| 344 | **Description** |
| 345 | |
| 346 | This API updates the partition isolation boundary for isolation level 3. |
| 347 | Inside the partition isolation boundary is the private data of the running |
| 348 | Secure Partition. |
| 349 | This boundary is updated dynamically when :term:`SPM` switches Partitions in |
| 350 | isolation level 3. |
| 351 | |
| 352 | The access permissions of the boundary is all privileged mode read-write. |
| 353 | |
| 354 | Platforms decide which :term:`MPU` region the paritition boundary uses. |
| 355 | |
| 356 | **Parameter** |
| 357 | |
| 358 | - ``start`` - start address of the partition boundary. |
| 359 | - ``end`` - end address of the partition boundary. |
| 360 | |
| 361 | **Return Values** |
| 362 | |
| 363 | - ``TFM_HAL_SUCCESS`` - the isolation boundary has been set up. |
| 364 | - ``TFM_HAL_ERROR_GENERIC`` - failed to set upthe isolation boundary. |
| 365 | |
| 366 | **Note** |
| 367 | |
| 368 | This API is only for platforms using :term:`MPU` as isolation hardwares. |
| 369 | A generic API for all platforms will be introduced in future versions. |
| 370 | |
| 371 | tfm_hal_memory_has_access() |
| 372 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 373 | **Prototype** |
| 374 | |
| 375 | .. code-block:: c |
| 376 | |
| 377 | tfm_hal_status_t tfm_hal_memory_has_access(const uintptr_t base, |
| 378 | size_t size, |
| 379 | uint32_t attr) |
| 380 | |
| 381 | **Description** |
| 382 | |
| 383 | This API checks if the memory region defined by ``base`` and ``size`` has the |
| 384 | given access atrributes - ``attr``. |
| 385 | |
| 386 | The Attributes include :term:`NSPE` access, privileged mode, and read-write |
| 387 | permissions. |
| 388 | |
| 389 | **Parameter** |
| 390 | |
| 391 | - ``base`` - The base address of the region. |
| 392 | - ``size`` - The size of the region. |
| 393 | - ``attr`` - The `Memory Access Attributes`_. |
| 394 | |
| 395 | **Return Values** |
| 396 | |
| 397 | - ``TFM_HAL_SUCCESS`` - The memory region has the access permissions. |
| 398 | - ``TFM_HAL_ERROR_MEM_FAULT`` - The memory region does not have the access |
| 399 | permissions. |
| 400 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs. |
| 401 | - ``TFM_HAL_ERROR_GENERIC`` - An error occurred. |
| 402 | |
Edison Ai | f4b6113 | 2020-07-01 18:35:17 +0800 | [diff] [blame] | 403 | Log API |
| 404 | ======= |
| 405 | The log API is used by the :term:`TF-M` :doc:`log system <tfm_log_system_design_document>`. |
| 406 | The log device could be uart, memory, usb, etc. |
| 407 | |
| 408 | APIs |
| 409 | ---- |
| 410 | tfm_hal_output_partition_log() |
| 411 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 412 | **Prototype** |
| 413 | |
| 414 | .. code-block:: c |
| 415 | |
| 416 | int32_t tfm_hal_output_partition_log(const unsigned char *str, uint32_t len) |
| 417 | |
| 418 | **Description** |
| 419 | |
| 420 | This API is called by Secure Partition to output logs. |
| 421 | |
| 422 | **Parameter** |
| 423 | |
| 424 | - ``str`` - The string to output. |
| 425 | - ``len`` - Length of the string in bytes. |
| 426 | |
| 427 | **Return Values** |
| 428 | |
| 429 | - Positive values - Number of bytes output. |
| 430 | - ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized. |
| 431 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` or |
| 432 | ``len`` is zero. |
| 433 | |
| 434 | **Note** |
| 435 | |
| 436 | None. |
| 437 | |
| 438 | tfm_hal_output_spm_log() |
| 439 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 440 | **Prototype** |
| 441 | |
| 442 | .. code-block:: c |
| 443 | |
| 444 | int32_t tfm_hal_output_spm_log(const unsigned char *str, uint32_t len) |
| 445 | |
| 446 | **Description** |
| 447 | |
| 448 | This API is called by :term:`SPM` to output logs. |
| 449 | |
| 450 | **Parameter** |
| 451 | |
| 452 | - ``str`` - The string to output. |
| 453 | - ``len`` - Length of the string in bytes. |
| 454 | |
| 455 | **Return Values** |
| 456 | |
| 457 | - Positive numbers - Number of bytes output. |
| 458 | - ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized. |
| 459 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` |
| 460 | or ``len`` is zero. |
| 461 | |
| 462 | **Note** |
| 463 | |
| 464 | Please check :doc:`TF-M log system <tfm_log_system_design_document>` for more |
| 465 | information. |
| 466 | |
Edison Ai | b28b971 | 2020-06-04 14:41:23 +0800 | [diff] [blame] | 467 | ************************************ |
| 468 | API Definition for Secure Partitions |
| 469 | ************************************ |
| 470 | The Secure Partition (SP) :term:`HAL` mainly focuses on two parts: |
| 471 | |
| 472 | - Peripheral devices. The peripherals accessed by the :term:`TF-M` default |
| 473 | Secure Partitions. |
| 474 | - Secure Partition abstraction support. The Secure Partition data that must be |
| 475 | provided by the platform. |
| 476 | |
| 477 | The Secure Partition abstraction support will be introduced in the peripheral |
| 478 | API definition. |
| 479 | |
| 480 | ITS and PS flash API |
| 481 | ==================== |
| 482 | There are two kinds of flash: |
| 483 | |
| 484 | - Internal flash. Accessed by the PSA Internal Trusted Storage (ITS) service. |
| 485 | - External flash. Accessed by the PSA Protected Storage (PS) service. |
| 486 | |
| 487 | The ITS HAL for the internal flash device is defined in the ``tfm_hal_its.h`` |
| 488 | header and the PS HAL in the ``tfm_hal_ps.h`` header. |
| 489 | |
| 490 | Macros |
| 491 | ------ |
| 492 | Internal Trusted Storage |
| 493 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 494 | TFM_HAL_ITS_FLASH_DRIVER |
| 495 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 496 | Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for |
| 497 | ITS. It must have been allocated by the platform and will be declared extern in |
| 498 | the HAL header. |
| 499 | |
| 500 | TFM_HAL_ITS_PROGRAM_UNIT |
| 501 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 502 | Defines the size of the ITS flash device's physical program unit (the smallest |
| 503 | unit of data that can be individually programmed to flash). It must be equal to |
| 504 | TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile |
| 505 | time so that filesystem structures can be statically sized. |
| 506 | |
| 507 | TFM_HAL_ITS_FLASH_AREA_ADDR |
| 508 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 509 | Defines the base address of the dedicated flash area for ITS. |
| 510 | |
| 511 | TFM_HAL_ITS_FLASH_AREA_SIZE |
| 512 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 513 | Defines the size of the dedicated flash area for ITS in bytes. |
| 514 | |
| 515 | TFM_HAL_ITS_SECTORS_PER_BLOCK |
| 516 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 517 | Defines the number of contiguous physical flash erase sectors that form a |
| 518 | logical filesystem erase block. |
| 519 | |
| 520 | Protected Storage |
| 521 | ^^^^^^^^^^^^^^^^^ |
| 522 | TFM_HAL_PS_FLASH_DRIVER |
| 523 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 524 | Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for |
| 525 | PS. It must have been allocated by the platform and will be declared extern in |
| 526 | the HAL header. |
| 527 | |
| 528 | TFM_HAL_PS_PROGRAM_UNIT |
| 529 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 530 | Defines the size of the PS flash device's physical program unit (the smallest |
| 531 | unit of data that can be individually programmed to flash). It must be equal to |
| 532 | TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile |
| 533 | time so that filesystem structures can be statically sized. |
| 534 | |
| 535 | TFM_HAL_PS_FLASH_AREA_ADDR |
| 536 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 537 | Defines the base address of the dedicated flash area for PS. |
| 538 | |
| 539 | TFM_HAL_PS_FLASH_AREA_SIZE |
| 540 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 541 | Defines the size of the dedicated flash area for PS in bytes. |
| 542 | |
| 543 | TFM_HAL_PS_SECTORS_PER_BLOCK |
| 544 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 545 | Defines the number of contiguous physical flash erase sectors that form a |
| 546 | logical filesystem erase block. |
| 547 | |
| 548 | Optional definitions |
| 549 | -------------------- |
| 550 | The ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` and |
| 551 | ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` definitions are optional. If not defined, the |
| 552 | platform must implement ``tfm_hal_its_fs_info()`` instead. |
| 553 | |
| 554 | Equivalently, ``tfm_hal_its_ps_info()`` must be implemented by the platform if |
| 555 | ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` or |
| 556 | ``TFM_HAL_ITS_SECTORS_PER_BLOCK`` is not defined. |
| 557 | |
| 558 | Objects |
| 559 | ------- |
| 560 | ARM_DRIVER_FLASH |
| 561 | ^^^^^^^^^^^^^^^^ |
| 562 | The ITS and PS HAL headers each expose a CMSIS Flash Driver instance. |
| 563 | |
| 564 | .. code-block:: c |
| 565 | |
| 566 | extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER |
| 567 | |
| 568 | extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER |
| 569 | |
| 570 | The CMSIS Flash Driver provides the flash primitives ReadData(), ProgramData() |
| 571 | and EraseSector() as well as GetInfo() to access flash device properties such |
| 572 | as the sector size. |
| 573 | |
| 574 | Types |
| 575 | ----- |
| 576 | tfm_hal_its_fs_info_t |
| 577 | ^^^^^^^^^^^^^^^^^^^^^ |
| 578 | Struct containing information required from the platform at runtime to configure |
| 579 | the ITS filesystem. |
| 580 | |
| 581 | .. code-block:: c |
| 582 | |
| 583 | struct tfm_hal_its_fs_info_t { |
| 584 | uint32_t flash_area_addr; |
| 585 | size_t flash_area_size; |
| 586 | uint8_t sectors_per_block; |
| 587 | }; |
| 588 | |
| 589 | Each attribute is described below: |
| 590 | |
| 591 | - ``flash_area_addr`` - Location of the block of flash to use for ITS |
| 592 | - ``flash_area_size`` - Number of bytes of flash to use for ITS |
| 593 | - ``sectors_per_block`` - Number of erase sectors per logical FS block |
| 594 | |
| 595 | tfm_hal_ps_fs_info_t |
| 596 | ^^^^^^^^^^^^^^^^^^^^^ |
| 597 | Struct containing information required from the platform at runtime to configure |
| 598 | the PS filesystem. |
| 599 | |
| 600 | .. code-block:: c |
| 601 | |
| 602 | struct tfm_hal_ps_fs_info_t { |
| 603 | uint32_t flash_area_addr; |
| 604 | size_t flash_area_size; |
| 605 | uint8_t sectors_per_block; |
| 606 | }; |
| 607 | |
| 608 | Each attribute is described below: |
| 609 | |
| 610 | - ``flash_area_addr`` - Location of the block of flash to use for PS |
| 611 | - ``flash_area_size`` - Number of bytes of flash to use for PS |
| 612 | - ``sectors_per_block`` - Number of erase sectors per logical FS block |
| 613 | |
| 614 | Functions |
| 615 | --------- |
| 616 | tfm_hal_its_fs_info() |
| 617 | ^^^^^^^^^^^^^^^^^^^^^ |
| 618 | **Prototype** |
| 619 | |
| 620 | .. code-block:: c |
| 621 | |
| 622 | enum tfm_hal_status_t tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info); |
| 623 | |
| 624 | **Description** |
| 625 | |
| 626 | Retrieves the filesystem configuration parameters for ITS. |
| 627 | |
| 628 | **Parameter** |
| 629 | |
| 630 | - ``fs_info`` - Filesystem config information |
| 631 | |
| 632 | **Return values** |
| 633 | |
| 634 | - ``TFM_HAL_SUCCESS`` - The operation completed successfully |
| 635 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter |
| 636 | |
| 637 | **Note** |
| 638 | |
| 639 | This function should ensure that the values returned do not result in a security |
| 640 | compromise. The block of flash supplied must meet the security requirements of |
| 641 | Internal Trusted Storage. |
| 642 | |
| 643 | tfm_hal_ps_fs_info() |
| 644 | ^^^^^^^^^^^^^^^^^^^^ |
| 645 | **Prototype** |
| 646 | |
| 647 | .. code-block:: c |
| 648 | |
| 649 | enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info); |
| 650 | |
| 651 | **Description** |
| 652 | |
| 653 | Retrieves the filesystem configuration parameters for PS. |
| 654 | |
| 655 | **Parameter** |
| 656 | |
| 657 | - ``fs_info`` - Filesystem config information |
| 658 | |
| 659 | **Return values** |
| 660 | |
| 661 | - ``TFM_HAL_SUCCESS`` - The operation completed successfully |
| 662 | - ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter |
| 663 | |
| 664 | **Note** |
| 665 | |
| 666 | This function should ensure that the values returned do not result in a security |
| 667 | compromise. |
| 668 | |
Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame] | 669 | -------------- |
| 670 | |
Edison Ai | b28b971 | 2020-06-04 14:41:23 +0800 | [diff] [blame] | 671 | *Copyright (c) 2020-2021, Arm Limited. All rights reserved.* |