1 /* 2 * Copyright (c) 2018-2021 Arm Limited. All rights reserved. 3 * Copyright (c) 2020 Cypress Semiconductor Corporation. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef __FLASH_LAYOUT_H__ 19 #define __FLASH_LAYOUT_H__ 20 21 /* This header file is included from linker scatter file as well, where only a 22 * limited C constructs are allowed. Therefore it is not possible to include 23 * here the platform_retarget.h to access flash related defines. To resolve this 24 * some of the values are redefined here with different names, these are marked 25 * with comment. 26 * 27 * Flash layout on nucleo_l552ze_q with BL2 (multiple image boot): 28 * 29 * 0x0000_0000 BL2 - MCUBoot (38 KB) 30 * 0x0000_e000 OTP / NV counters area (8 KB) 31 * 0x0001_0000 Secure Storage Area (8 KB) 32 * 0x0001_2000 Internal Trusted Storage Area (8 KB) 33 * 0x0001_4000 Secure image primary slot (180 KB) 34 * 0x0004_1000 Non-secure image primary slot (36 KB) 35 * 0x0004_a000 Secure image secondary slot (180 KB) 36 * 0x0007_7000 Non-secure image secondary slot (36 KB) 37 * 38 * Flash layout on nucleo_l552ze_q with BL2 (multiple image boot, layout for test): 39 * No Firmware update , ITS, PS in RAM. 40 * 0x0000_0000 BL2 - MCUBoot (38 KB) 41 * 0x0000_e000 OTP / NV counters area area (8 KB) 42 * 0x0001_0000 Secure Storage Area (8 KB) 43 * 0x0001_2000 Internal Trusted Storage Area (8 KB) 44 * 0x0001_4000 Secure image primary slot (224 KB) 45 * 0x0004_c000 Non-secure image primary slot (172 KB) 46 * 0x0007_7000 Unused (40K) 47 * The size of a partition. This should be large enough to contain a S or NS 48 * sw binary. Each FLASH_AREA_IMAGE contains two partitions. See Flash layout 49 * above. 50 */ 51 52 /* Sector size of the flash hardware */ 53 #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4KB */ 54 55 #define FLASH_TOTAL_SIZE (0x80000) /* 512Kbytes*/ 56 57 /* Flash layout info for BL2 bootloader */ 58 #define FLASH_BASE_ADDRESS (0x0c000000) /* same as FLASH0_BASE_S */ 59 60 /* Offset and size definitions of the flash partitions that are handled by the 61 * bootloader. The image swapping is done between IMAGE_0 and IMAGE_1, SCRATCH 62 * is used as a temporary storage during image swapping. 63 */ 64 65 /* Area for downloading bl2 image */ 66 #define FLASH_AREA_BL2_BIN_OFFSET (0x0) 67 /* area for BL2 code protected by hdp */ 68 #define FLASH_AREA_BL2_OFFSET (0x0) 69 #define FLASH_AREA_BL2_SIZE (0xd800) 70 /* HDP area end at this address */ 71 #define FLASH_BL2_HDP_END (FLASH_AREA_BL2_OFFSET+FLASH_AREA_BL2_SIZE-1) 72 /* area for BL2 code not protected by hdp */ 73 #define FLASH_AREA_BL2_NOHDP_OFFSET (FLASH_AREA_BL2_OFFSET+FLASH_AREA_BL2_SIZE) 74 #define FLASH_AREA_BL2_NOHDP_SIZE (0x800) 75 76 /* scratch area */ 77 #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_BL2_NOHDP_OFFSET+FLASH_AREA_BL2_NOHDP_SIZE) 78 #define FLASH_AREA_SCRATCH_SIZE (0x0) 79 80 /* OTP_definitions */ 81 #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 82 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_AREA_SCRATCH_OFFSET + \ 83 FLASH_AREA_SCRATCH_SIZE) 84 #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_SECTOR_SIZE + \ 85 FLASH_OTP_NV_COUNTERS_SECTOR_SIZE) 86 87 /* according to test flash layout can change */ 88 #if defined(FLASH_LAYOUT_FOR_TEST) 89 /* fix me with test config PS and ITS in RAM */ 90 /* Secure Storage (PS) Service definitions */ 91 #define FLASH_PS_AREA_SIZE (0x2000) 92 #define FLASH_PS_AREA_OFFSET (FLASH_OTP_NV_COUNTERS_AREA_OFFSET + \ 93 FLASH_OTP_NV_COUNTERS_AREA_SIZE) 94 95 /* Internal Trusted Storage (ITS) Service definitions */ 96 #define FLASH_ITS_AREA_OFFSET (FLASH_PS_AREA_OFFSET+FLASH_PS_AREA_SIZE) 97 #define FLASH_ITS_AREA_SIZE (0x2000) /* 8 KB */ 98 99 #define FLASH_S_PARTITION_SIZE (0x38000) /* S partition */ 100 #define FLASH_NS_PARTITION_SIZE (0x2A000) /* NS partition */ 101 #define FLASH_PARTITION_SIZE (FLASH_S_PARTITION_SIZE+FLASH_NS_PARTITION_SIZE) 102 /* Secure image primary slot */ 103 #define FLASH_AREA_0_ID (1) 104 #define FLASH_AREA_0_OFFSET (FLASH_ITS_AREA_OFFSET+FLASH_ITS_AREA_SIZE) 105 #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) 106 #else 107 108 /* fix me with test config PS and ITS in RAM */ 109 /* Secure Storage (PS) Service definitions */ 110 #define FLASH_PS_AREA_SIZE (0x2000) 111 #define FLASH_PS_AREA_OFFSET (FLASH_OTP_NV_COUNTERS_AREA_OFFSET + \ 112 FLASH_OTP_NV_COUNTERS_AREA_SIZE) 113 114 /* Internal Trusted Storage (ITS) Service definitions */ 115 #define FLASH_ITS_AREA_OFFSET (FLASH_PS_AREA_OFFSET+FLASH_PS_AREA_SIZE) 116 #define FLASH_ITS_AREA_SIZE (0x2000) /* 8 KB */ 117 118 #define FLASH_S_PARTITION_SIZE (0x2D000) /* S partition */ 119 #define FLASH_NS_PARTITION_SIZE (0x9000) /* NS partition */ 120 #define FLASH_PARTITION_SIZE (FLASH_S_PARTITION_SIZE+FLASH_NS_PARTITION_SIZE) 121 /* Secure image primary slot */ 122 #define FLASH_AREA_0_ID (1) 123 #define FLASH_AREA_0_OFFSET (FLASH_ITS_AREA_OFFSET+FLASH_ITS_AREA_SIZE) 124 #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) 125 #endif 126 /* Non-secure image primary slot */ 127 #define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) 128 #define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) 129 #define FLASH_AREA_1_SIZE (FLASH_NS_PARTITION_SIZE) 130 /* Secure image secondary slot */ 131 #define FLASH_AREA_2_ID (FLASH_AREA_1_ID + 1) 132 #define FLASH_AREA_2_OFFSET (FLASH_AREA_1_OFFSET + FLASH_AREA_1_SIZE) 133 #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) 134 /* Non-secure image secondary slot */ 135 #define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) 136 #define FLASH_AREA_3_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) 137 #define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) 138 139 #define FLASH_AREA_SCRATCH_ID (FLASH_AREA_3_ID + 1) 140 141 /* 142 * The maximum number of status entries supported by the bootloader. 143 */ 144 #define MCUBOOT_STATUS_MAX_ENTRIES ((2 * FLASH_PARTITION_SIZE) / \ 145 FLASH_AREA_SCRATCH_SIZE) 146 /** Maximum number of image sectors supported by the bootloader. */ 147 #define MCUBOOT_MAX_IMG_SECTORS ((2 * FLASH_PARTITION_SIZE) / \ 148 FLASH_AREA_IMAGE_SECTOR_SIZE) 149 150 #define SECURE_IMAGE_OFFSET (0x0) 151 #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE 152 153 #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + SECURE_IMAGE_MAX_SIZE) 154 #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE 155 156 /* Flash device name used by BL2 and NV Counter 157 * Name is defined in flash driver file: Driver_Flash.c 158 */ 159 160 #define FLASH_DEV_NAME TFM_Driver_FLASH0 161 #define TFM_HAL_FLASH_PROGRAM_UNIT (0x8) 162 163 /* Protected Storage (PS) Service definitions 164 * Note: Further documentation of these definitions can be found in the 165 * TF-M PS Integration Guide. 166 */ 167 #define TFM_HAL_PS_FLASH_DRIVER TFM_Driver_FLASH0 168 169 /* In this target the CMSIS driver requires only the offset from the base 170 * address instead of the full memory address. 171 */ 172 /* Base address of dedicated flash area for PS */ 173 #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET 174 /* Size of dedicated flash area for PS */ 175 #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE 176 #define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE 177 /* Number of physical erase sectors per logical FS block */ 178 #define TFM_HAL_PS_SECTORS_PER_BLOCK (1) 179 /* Smallest flash programmable unit in bytes */ 180 #define TFM_HAL_PS_PROGRAM_UNIT (0x8) 181 182 /* Internal Trusted Storage (ITS) Service definitions 183 * Note: Further documentation of these definitions can be found in the 184 * TF-M ITS Integration Guide. 185 */ 186 #define TFM_HAL_ITS_FLASH_DRIVER TFM_Driver_FLASH0 187 188 /* In this target the CMSIS driver requires only the offset from the base 189 * address instead of the full memory address. 190 */ 191 /* Base address of dedicated flash area for ITS */ 192 #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET 193 /* Size of dedicated flash area for ITS */ 194 #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE 195 #define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE 196 /* Number of physical erase sectors per logical FS block */ 197 #define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) 198 /* Smallest flash programmable unit in bytes */ 199 #define TFM_HAL_ITS_PROGRAM_UNIT (0x8) 200 201 /* OTP / NV counter definitions */ 202 #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) 203 #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET 204 #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE 205 #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ 206 TFM_OTP_NV_COUNTERS_AREA_SIZE) 207 208 #define BL2_S_RAM_ALIAS_BASE (0x30000000) 209 #define BL2_NS_RAM_ALIAS_BASE (0x20000000) 210 211 /* This area in SRAM 2 is updated BL2 and can be lock to avoid any changes */ 212 #define BOOT_TFM_SHARED_DATA_SIZE (0x400) 213 #define BOOT_TFM_SHARED_DATA_BASE (0x3003fc00) 214 215 #endif /* __FLASH_LAYOUT_H__ */ 216