1 /*
2  * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
3  * Copyright (c) 2020-2022 Cypress Semiconductor Corporation (an Infineon
4  * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5  * reserved.
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 #ifndef __ITS_FLASH_H__
12 #define __ITS_FLASH_H__
13 
14 #include "config_tfm.h"
15 #include "its_utils.h"
16 #include "tfm_hal_its.h"
17 #ifdef TFM_PARTITION_PROTECTED_STORAGE
18 #include "tfm_hal_ps.h"
19 #endif
20 
21 /* Include the correct flash interface implementation for ITS */
22 #if ITS_RAM_FS
23 /* RAM FS: use a buffer to emulate storage in RAM */
24 #include "its_flash_ram.h"
25 extern uint8_t its_block_data[];
26 #define ITS_FLASH_DEV its_block_data
27 #define ITS_FLASH_ALIGNMENT TFM_HAL_ITS_PROGRAM_UNIT
28 #define ITS_FLASH_OPS its_flash_fs_ops_ram
29 
30 #elif (TFM_HAL_ITS_PROGRAM_UNIT > 16)
31 /* NAND flash: each filesystem block is buffered and then programmed in one
32  * shot, so no filesystem data alignment is required.
33  */
34 #include "its_flash_nand.h"
35 extern struct its_flash_nand_dev_t its_flash_nand_dev;
36 #define ITS_FLASH_DEV its_flash_nand_dev
37 #define ITS_FLASH_ALIGNMENT 1
38 #define ITS_FLASH_OPS its_flash_fs_ops_nand
39 
40 #else
41 /* NOR flash: no write buffering, require each file in the filesystem to be
42  * aligned to the program unit.
43  */
44 #include "its_flash_nor.h"
45 #define ITS_FLASH_DEV TFM_HAL_ITS_FLASH_DRIVER
46 #define ITS_FLASH_ALIGNMENT TFM_HAL_ITS_PROGRAM_UNIT
47 #define ITS_FLASH_OPS its_flash_fs_ops_nor
48 #endif
49 
50 /* Include the correct flash interface implementation for PS */
51 #ifdef TFM_PARTITION_PROTECTED_STORAGE
52 #if PS_RAM_FS
53 /* RAM FS: use a buffer to emulate storage in RAM */
54 #include "its_flash_ram.h"
55 extern uint8_t ps_block_data[];
56 #define PS_FLASH_DEV ps_block_data
57 #define PS_FLASH_ALIGNMENT TFM_HAL_PS_PROGRAM_UNIT
58 #define PS_FLASH_OPS its_flash_fs_ops_ram
59 
60 #elif (TFM_HAL_PS_PROGRAM_UNIT > 16)
61 /* NAND flash: each filesystem block is buffered and then programmed in one
62  * shot, so no filesystem data alignment is required.
63  */
64 #include "its_flash_nand.h"
65 extern struct its_flash_nand_dev_t ps_flash_nand_dev;
66 #define PS_FLASH_DEV ps_flash_nand_dev
67 #define PS_FLASH_ALIGNMENT 1
68 #define PS_FLASH_OPS its_flash_fs_ops_nand
69 
70 #else
71 /* NOR flash: no write buffering, require each file in the filesystem to be
72  * aligned to the program unit.
73  */
74 #include "its_flash_nor.h"
75 #define PS_FLASH_DEV TFM_HAL_PS_FLASH_DRIVER
76 #define PS_FLASH_ALIGNMENT TFM_HAL_PS_PROGRAM_UNIT
77 #define PS_FLASH_OPS its_flash_fs_ops_nor
78 #endif
79 #else /* TFM_PARTITION_PROTECTED_STORAGE */
80 #define PS_FLASH_ALIGNMENT 1
81 #endif /* TFM_PARTITION_PROTECTED_STORAGE */
82 
83 /**
84  * \brief Provides a compile-time constant for the maximum program unit required
85  *        by any flash device that can be accessed through this interface.
86  */
87 #define ITS_FLASH_MAX_ALIGNMENT ITS_UTILS_MAX(ITS_FLASH_ALIGNMENT, \
88                                               PS_FLASH_ALIGNMENT)
89 
90 #endif /* __ITS_FLASH_H__ */
91