1 /* 2 * Copyright (c) 2017-2024 Arm Limited. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __FLASH_LAYOUT_H__ 18 #define __FLASH_LAYOUT_H__ 19 20 /* This header file is included from linker scatter file as well, where only a 21 * limited C constructs are allowed. Therefore it is not possible to include 22 * here the platform_base_address.h to access flash related defines. To resolve 23 * this some of the values are redefined here with different names, these are 24 * marked with comment. 25 */ 26 27 #define MCUBOOT_MAX_IMG_SECTORS (32) 28 29 /********************************/ 30 /* Secure Enclave internal SRAM */ 31 /********************************/ 32 #define SRAM_BASE (0x30000000) 33 #define SRAM_SIZE (0x80000) /* 512 KB */ 34 35 #define BL2_DATA_GAP_SIZE (0x09800) /* 38 KB */ 36 37 38 /*****************/ 39 /***** Flash *****/ 40 /*****************/ 41 42 #define FLASH_BASE_ADDRESS (0x68000000) 43 #define FLASH_BL1_BASE_ADDRESS (FLASH_BASE_ADDRESS) 44 45 #if PLATFORM_IS_FVP 46 /* INTEL STRATA J3 NOR FLASH NVM */ 47 #define STRATA_NVM_FLASH_TOTAL_SIZE (0x04000000) /* 32 MB Nor Flash (PMOD SF3) */ 48 #define STRATA_NVM_FLASH_SECTOR_SIZE (0x00001000) /* 64 KB Sub sector size*/ 49 #define STRATA_NVM_FLASH_PAGE_SIZE (256U) /* 64 KB */ 50 #define STRATA_NVM_FLASH_PROGRAM_UNIT (1U) /* 4 B */ 51 52 #define FLASH_DEV_NAME Driver_FLASH0 53 #define FLASH_TOTAL_SIZE (STRATA_NVM_FLASH_TOTAL_SIZE) /* 32 MB */ 54 #define FLASH_AREA_IMAGE_SECTOR_SIZE (STRATA_NVM_FLASH_SECTOR_SIZE) /* 4 KiB */ 55 #define FLASH_SECTOR_SIZE (STRATA_NVM_FLASH_SECTOR_SIZE) /* 1 kB */ 56 #define TFM_HAL_FLASH_PROGRAM_UNIT (STRATA_NVM_FLASH_PROGRAM_UNIT) 57 58 #define STRATA_SE_FLASH_TOTAL_SIZE (0x00800000) /* 32 MB Nor Flash (PMOD SF3) */ 59 #define STRATA_SE_FLASH_SECTOR_SIZE (0x00001000) /* 64 KB Sub sector size*/ 60 #define STRATA_SE_FLASH_PAGE_SIZE (256U) /* 64 KB */ 61 #define STRATA_SE_FLASH_PROGRAM_UNIT (1U) /* 4 B */ 62 63 #define FLASH_DEV_NAME_SE_SECURE_FLASH Driver_FLASH1 64 #define SECURE_FLASH_SECTOR_SIZE STRATA_NVM_FLASH_SECTOR_SIZE 65 66 #else 67 68 /* PMOD SF3 NOR FLASH */ 69 #define PMOD_SF3_FLASH_TOTAL_SIZE (0x02000000) /* 32 MB Nor Flash (PMOD SF3) */ 70 #define PMOD_SF3_FLASH_SECTOR_SIZE (0x00001000) /* 4 KB Sub sector size*/ 71 #define PMOD_SF3_FLASH_PAGE_SIZE (256U) /* 256 B */ 72 #define PMOD_SF3_FLASH_PROGRAM_UNIT (1U) /* 1 B */ 73 74 /* SST26VF064B NOR FLASH */ 75 #define SST26VF064B_FLASH_TOTAL_SIZE (0x00800000) /* 8 MB Nor Flash (SST26VF064B) */ 76 #define SST26VF064B_FLASH_SECTOR_SIZE (0x00010000) /* 64 KB Sub sector size*/ 77 #define SST26VF064B_FLASH_PAGE_SIZE (256U) /* 256 B */ 78 #define SST26VF064B_FLASH_PROGRAM_UNIT (1U) /* 1 B */ 79 80 #define FLASH_DEV_NAME Driver_FLASH0 81 82 #define FLASH_TOTAL_SIZE (PMOD_SF3_FLASH_TOTAL_SIZE) /* 32 MB */ 83 #define FLASH_AREA_IMAGE_SECTOR_SIZE (PMOD_SF3_FLASH_SECTOR_SIZE) /* 4 KiB */ 84 #define FLASH_SECTOR_SIZE (PMOD_SF3_FLASH_SECTOR_SIZE) /* 1 kB */ 85 #define TFM_HAL_FLASH_PROGRAM_UNIT (PMOD_SF3_FLASH_PROGRAM_UNIT) 86 87 #define FLASH_DEV_NAME_SE_SECURE_FLASH Driver_FLASH1 88 #define SECURE_FLASH_SECTOR_SIZE SST26VF064B_FLASH_SECTOR_SIZE 89 90 #endif 91 92 #define FLASH_DEV_NAME_BL1 FLASH_DEV_NAME 93 94 /* Static Configurations of the Flash */ 95 #define SE_BL2_PARTITION_SIZE (0x18000) /* 96 KB */ 96 #define SE_BL2_BANK_0_OFFSET (0x9000) /* 72nd LBA */ 97 #define SE_BL2_BANK_1_OFFSET (0x1002000) /* 32784th LBA */ 98 99 /* Space in flash to store metadata and uefi variables */ 100 #define FWU_METADATA_FLASH_DEV (FLASH_DEV_NAME) 101 #define FWU_METADATA_FLASH_SECTOR_SIZE (FLASH_SECTOR_SIZE) 102 103 #define FWU_METADATA_REPLICA_1_OFFSET (0x5000) /* 40th LBA */ 104 #define FWU_METADATA_REPLICA_2_OFFSET (FWU_METADATA_REPLICA_1_OFFSET + \ 105 FWU_METADATA_FLASH_SECTOR_SIZE) 106 107 #define FWU_PRIVATE_METADATA_REPLICA_1_OFFSET (FWU_METADATA_REPLICA_2_OFFSET + \ 108 FWU_METADATA_FLASH_SECTOR_SIZE) 109 #define FWU_PRIVATE_METADATA_REPLICA_2_OFFSET (FWU_PRIVATE_METADATA_REPLICA_1_OFFSET + \ 110 FWU_METADATA_FLASH_SECTOR_SIZE) 111 112 #define BANK_0_PARTITION_OFFSET (SE_BL2_BANK_0_OFFSET + \ 113 SE_BL2_PARTITION_SIZE) 114 #define BANK_1_PARTITION_OFFSET (SE_BL2_BANK_1_OFFSET + \ 115 SE_BL2_PARTITION_SIZE) 116 117 /* BL1: mcuboot flashmap configurations */ 118 #define FLASH_AREA_8_ID (1) 119 #define FLASH_AREA_8_SIZE (SE_BL2_PARTITION_SIZE) 120 121 #define FLASH_INVALID_ID (0xFF) 122 #define FLASH_INVALID_OFFSET (0xFFFFFFFF) 123 #define FLASH_INVALID_SIZE (0xFFFFFFFF) 124 125 #define BL1_FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_8_ID : \ 126 255 ) 127 #define BL1_FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_INVALID_ID : \ 128 255 ) 129 130 #define BL1_FLASH_AREA_IMAGE_SCRATCH 255 131 132 /* FWU Configurations */ 133 #define NR_OF_FW_BANKS (2) 134 #define NR_OF_IMAGES_IN_FW_BANK (4) /* Secure Enclave: BL2 and TF-M \ 135 * Host: FIP and Kernel image 136 */ 137 138 /* Bank configurations */ 139 #define BANK_PARTITION_SIZE (0xFE0000) /* 15.875 MB */ 140 #define TFM_PARTITION_SIZE (0x5C000) /* 368 KB */ 141 142 /************************************************************/ 143 /* Bank : Images flash offsets are with respect to the bank */ 144 /************************************************************/ 145 146 /* Image 0: BL2 primary and secondary images */ 147 #define FLASH_AREA_0_ID (1) 148 #define FLASH_AREA_0_OFFSET (0) /* starting from 0th offset of the bank */ 149 #define FLASH_AREA_0_SIZE (SE_BL2_PARTITION_SIZE) 150 151 #define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) 152 #define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) 153 #define FLASH_AREA_1_SIZE (SE_BL2_PARTITION_SIZE) 154 155 /* Image 1: TF-M primary and secondary images */ 156 #define FLASH_AREA_2_ID (1) 157 #define FLASH_AREA_2_SIZE (TFM_PARTITION_SIZE) 158 #define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) 159 #define FLASH_AREA_3_SIZE (TFM_PARTITION_SIZE) 160 161 /* Image 2: Host FIP */ 162 #define FIP_SIGNATURE_AREA_SIZE (0x1000) /* 4 KB */ 163 164 /* Host BL2 (TF-A) primary and secondary image. */ 165 #define FLASH_AREA_4_ID (FLASH_AREA_3_ID + 1) 166 #define FLASH_AREA_5_ID (FLASH_AREA_4_ID + 1) 167 168 #define BL1_FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_0_ID : \ 169 255 ) 170 #define BL1_FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_1_ID : \ 171 255 ) 172 173 #define BL1_FLASH_AREA_IMAGE_SCRATCH 255 174 175 /* Macros needed to imgtool.py, used when creating TF-M signed image */ 176 #define S_IMAGE_LOAD_ADDRESS (SRAM_BASE) 177 #define SECURE_IMAGE_OFFSET (0x0) 178 #define SECURE_IMAGE_MAX_SIZE (TFM_PARTITION_SIZE) 179 #define NON_SECURE_IMAGE_OFFSET (TFM_PARTITION_SIZE) 180 #define NON_SECURE_IMAGE_MAX_SIZE (0x0) 181 182 #define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? FLASH_AREA_2_ID : \ 183 ((x) == 1) ? FLASH_AREA_4_ID : \ 184 255 ) 185 #define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? FLASH_AREA_3_ID : \ 186 ((x) == 1) ? FLASH_AREA_5_ID : \ 187 255 ) 188 189 #define FLASH_AREA_IMAGE_SCRATCH 255 190 191 /*******************************/ 192 /*** ITS, PS and NV Counters ***/ 193 /*******************************/ 194 195 #define FLASH_ITS_AREA_OFFSET (0x10000) /* 64 KB */ 196 #define FLASH_ITS_AREA_SIZE (4 * SECURE_FLASH_SECTOR_SIZE) 197 198 #define FLASH_PS_AREA_OFFSET (FLASH_ITS_AREA_OFFSET + \ 199 FLASH_ITS_AREA_SIZE) 200 #define FLASH_PS_AREA_SIZE (16 * SECURE_FLASH_SECTOR_SIZE) 201 202 /* OTP_definitions */ 203 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_PS_AREA_OFFSET + \ 204 FLASH_PS_AREA_SIZE) 205 #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (SECURE_FLASH_SECTOR_SIZE * 2) 206 #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE SECURE_FLASH_SECTOR_SIZE 207 208 /* Internal Trusted Storage (ITS) Service definitions 209 * Note: Further documentation of these definitions can be found in the 210 * TF-M ITS Integration Guide. 211 */ 212 #define TFM_HAL_ITS_FLASH_DRIVER FLASH_DEV_NAME_SE_SECURE_FLASH 213 214 /* Protected Storage (PS) Service definitions 215 * Note: Further documentation of these definitions can be found in the 216 * TF-M PS Integration Guide. 217 */ 218 #define TFM_HAL_PS_FLASH_DRIVER FLASH_DEV_NAME_SE_SECURE_FLASH 219 220 /* In this target the CMSIS driver requires only the offset from the base 221 * address instead of the full memory address. 222 */ 223 /* Base address of dedicated flash area for ITS */ 224 #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET 225 /* Size of dedicated flash area for ITS */ 226 #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE 227 /* Number of physical erase sectors per logical FS block */ 228 #define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) 229 /* Smallest flash programmable unit in bytes */ 230 #define TFM_HAL_ITS_PROGRAM_UNIT (1) 231 232 /* In this target the CMSIS driver requires only the offset from the base 233 * address instead of the full memory address. 234 */ 235 /* Base address of dedicated flash area for PS */ 236 #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET 237 /* Size of dedicated flash area for PS */ 238 #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE 239 /* Number of physical erase sectors per logical FS block */ 240 #define TFM_HAL_PS_SECTORS_PER_BLOCK (4) 241 /* Smallest flash programmable unit in bytes */ 242 #define TFM_HAL_PS_PROGRAM_UNIT (1) 243 244 #define OTP_NV_COUNTERS_FLASH_DEV FLASH_DEV_NAME_SE_SECURE_FLASH 245 246 /* OTP / NV counter definitions */ 247 #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) 248 #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET 249 #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE 250 #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ 251 TFM_OTP_NV_COUNTERS_AREA_SIZE) 252 #endif /* __FLASH_LAYOUT_H__ */ 253