1 /*
2  * Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
3  * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #ifndef __TFM_HAL_ITS_H__
10 #define __TFM_HAL_ITS_H__
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include "Driver_Flash.h"
16 #include "flash_layout.h"
17 #include "tfm_hal_defs.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* The name of the ARM_DRIVER_FLASH to use for ITS */
24 #ifndef TFM_HAL_ITS_FLASH_DRIVER
25 #error "TFM_HAL_ITS_FLASH_DRIVER must be defined by the target in flash_layout.h"
26 #endif
27 
28 /* The size of the ITS flash device's physical program unit. Must be equal to
29  * TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but required at compile
30  * time.
31  */
32 #ifndef TFM_HAL_ITS_PROGRAM_UNIT
33 #error "TFM_HAL_ITS_PROGRAM_UNIT must be defined by the target in flash_layout.h"
34 #elif (TFM_HAL_ITS_PROGRAM_UNIT < 1)
35 #error "TFM_HAL_ITS_PROGRAM_UNIT must be greater than 1"
36 #elif (TFM_HAL_ITS_PROGRAM_UNIT & (TFM_HAL_ITS_PROGRAM_UNIT - 1) != 0)
37 #error "TFM_HAL_ITS_PROGRAM_UNIT must be a power of two"
38 #endif
39 
40 /**
41  * \brief Struct containing information required from the platform at runtime
42  *        to configure the ITS filesystem.
43  */
44 struct tfm_hal_its_fs_info_t {
45     uint32_t flash_area_addr;  /**< Location of the block of flash to use for
46                                 *   ITS
47                                 */
48     size_t flash_area_size;    /**< Number of bytes of flash to use for ITS */
49     uint8_t sectors_per_block; /**< Number of erase sectors per logical FS block
50                                 */
51 };
52 
53 /**
54  * \brief The flash driver to use for ITS.
55  */
56 extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER;
57 
58 /**
59  * \brief Retrieve the filesystem config for ITS.
60  *
61  * Note that this function should ensure that the values returned do
62  * not result in a security compromise.
63  *
64  * \param [out] fs_info  Filesystem config information
65  *
66  * \return A status code as specified in \ref tfm_hal_status_t
67  * If an error is detected within this function, is should leave the
68  * content of the parameters unchanged.
69  *
70  * \retval TFM_HAL_SUCCESS              The operation completed successfully
71  * \retval TFM_HAL_ERROR_INVALID_INPUT  Invalid parameter
72  */
73 enum tfm_hal_status_t
74 tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* __TFM_HAL_ITS_H__ */
81