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_PS_H__
10 #define __TFM_HAL_PS_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 PS */
24 #ifndef TFM_HAL_PS_FLASH_DRIVER
25 #error "TFM_HAL_PS_FLASH_DRIVER must be defined by the target in flash_layout.h"
26 #endif
27 
28 /* The size of the PS flash device's physical program unit. Must be equal to
29  * TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but required at compile
30  * time.
31  */
32 #ifndef TFM_HAL_PS_PROGRAM_UNIT
33 #error "TFM_HAL_PS_PROGRAM_UNIT must be defined by the target in flash_layout.h"
34 #elif (TFM_HAL_PS_PROGRAM_UNIT < 1)
35 #error "TFM_HAL_PS_PROGRAM_UNIT must be greater than 1"
36 #elif (TFM_HAL_PS_PROGRAM_UNIT & (TFM_HAL_PS_PROGRAM_UNIT - 1) != 0)
37 #error "TFM_HAL_PS_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 PS filesystem.
43  */
44 struct tfm_hal_ps_fs_info_t {
45     uint32_t flash_area_addr;  /**< Location of the block of flash to use for PS
46                                 */
47     size_t flash_area_size;    /**< Number of bytes of flash to use for PS */
48     uint8_t sectors_per_block; /**< Number of erase sectors per logical FS block
49                                 */
50 };
51 
52 /**
53  * \brief The flash driver to use for PS.
54  */
55 extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER;
56 
57 /**
58  * \brief Retrieve the filesystem config for PS.
59  *
60  * Note that this function should ensure that the values returned do
61  * not result in a security compromise.
62  *
63  * \param [out] fs_info  Filesystem config information
64  *
65  * \return A status code as specified in \ref tfm_hal_status_t
66  * If an error is detected within this function, is should leave the
67  * content of the parameters unchanged.
68  *
69  * \retval TFM_HAL_SUCCESS              The operation completed successfully
70  * \retval TFM_HAL_ERROR_INVALID_INPUT  Invalid parameter
71  */
72 enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif /* __TFM_HAL_PS_H__ */
79