1 /*
2  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "its_flash.h"
9 
10 #include "config_tfm.h"
11 #include "flash_fs/its_flash_fs.h"
12 
13 #if ITS_RAM_FS
14 #ifndef ITS_RAM_FS_SIZE
15 #error "ITS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
16 #endif
17 uint8_t its_block_data[ITS_RAM_FS_SIZE];
18 
19 #elif (TFM_HAL_ITS_PROGRAM_UNIT > 16)
20 #ifndef ITS_FLASH_NAND_BUF_SIZE
21 #error "ITS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
22 #endif
23 static uint8_t its_write_buf_0[ITS_FLASH_NAND_BUF_SIZE];
24 static uint8_t its_write_buf_1[ITS_FLASH_NAND_BUF_SIZE];
25 struct its_flash_nand_dev_t its_flash_nand_dev = {
26     .driver = &TFM_HAL_ITS_FLASH_DRIVER,
27     .buf_block_id_0 = ITS_BLOCK_INVALID_ID,
28     .buf_block_id_1 = ITS_BLOCK_INVALID_ID,
29     .write_buf_0 = its_write_buf_0,
30     .write_buf_1 = its_write_buf_1,
31     .buf_size = sizeof(its_write_buf_0),
32 };
33 #endif
34 
35 #ifdef TFM_PARTITION_PROTECTED_STORAGE
36 #if PS_RAM_FS
37 #ifndef PS_RAM_FS_SIZE
38 #error "PS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
39 #endif
40 uint8_t ps_block_data[PS_RAM_FS_SIZE];
41 
42 #elif (TFM_HAL_PS_PROGRAM_UNIT > 16)
43 #ifndef PS_FLASH_NAND_BUF_SIZE
44 #error "PS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
45 #endif
46 static uint8_t ps_write_buf_0[PS_FLASH_NAND_BUF_SIZE];
47 static uint8_t ps_write_buf_1[PS_FLASH_NAND_BUF_SIZE];
48 struct its_flash_nand_dev_t ps_flash_nand_dev = {
49     .driver = &TFM_HAL_PS_FLASH_DRIVER,
50     .buf_block_id_0 = ITS_BLOCK_INVALID_ID,
51     .buf_block_id_1 = ITS_BLOCK_INVALID_ID,
52     .write_buf_0 = ps_write_buf_0,
53     .write_buf_1 = ps_write_buf_1,
54     .buf_size = sizeof(ps_write_buf_0),
55 };
56 #endif
57 #endif /* TFM_PARTITION_PROTECTED_STORAGE */
58