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