1 /* 2 * Copyright (c) 2018 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_retarget.h to access flash related defines. To resolve this 23 * some of the values are redefined here with different names, these are marked 24 * with comment. 25 */ 26 27 /* Flash layout (internal flash) on stm32h573i_dk with BL2 (multiple image boot) uses ovewrite method: 28 * 29 * 0x0000_0000 BL2 - MCUBoot (128 KB) 30 * 0x0002_0000 OTP / NV counters area (32 KB) 31 * 0x0002_8000 Secure Storage Area (16 KB) 32 * 0x0002_c000 Internal Trusted Storage Area (32 KB) 33 * 0x0003_4000 Secure image primary slot (256 KB) 34 * 0x0007_4000 Non-secure image primary slot (640 KB) 35 * 0x0011_4000 Secure image secondary slot (256 KB) 36 * 0x0015_4000 Non-secure image secondary slot (640 KB) 37 * 38 ** Flash layout (internal flash) on stm32h573i_dk with BL2 (multiple image boot): 39 * 40 * 0x0000_0000 BL2 - MCUBoot (128 KB) 41 * 0x0002_0000 SCRATCH (32 KB) 42 * 0x0002_8000 OTP / NV counters area (32 KB) 43 * 0x0003_2000 Secure Storage Area (16 KB) 44 * 0x0003_6000 Internal Trusted Storage (32 KB) 45 * 0x0003_e000 Secure image primary slot (256 KB) 46 * 0x0007_e000 Non-secure image primary slot (640 KB) 47 * 0x0014_c000 Secure image secondary slot (256 KB) 48 * 0x0017_a000 Non-secure image secondary slot (640 KB) 49 */ 50 /* TFM Partition configuration : begin */ 51 52 #define TFM_PARTITION_APP_ROT /* comment to remove APP_ROT partition */ 53 54 /*#define TFM_PARTITION_FIRMWARE_UPDATE*/ /* comment to remove TFM_PARTITION_FIRMWARE_UPDATE */ 55 56 /* TFM Partition configuration : end */ 57 58 /* Flash layout configuration : begin */ 59 #define MCUBOOT_OVERWRITE_ONLY /* Defined: the FW installation uses ovewrite method. 60 UnDefined: The FW installation uses swap mode. */ 61 62 /*#define MCUBOOT_PRIMARY_ONLY*/ /* Defined: No secondary (download) slot(s), 63 only primary slot(s) for each image. 64 Undefined: Primary and secondary slot(s) for each image. */ 65 66 /*#define MCUBOOT_EXT_LOADER*/ /* Defined: Add external local loader application. 67 To enter it, press user button at reset. 68 Undefined: No external local loader application. */ 69 #if defined (MCUBOOT_EXT_LOADER) 70 #define MCUBOOT_EXT_LOADER_CUSTOM /* Defined: Use UART loader in user flash. */ 71 #endif 72 73 #define MCUBOOT_APP_IMAGE_NUMBER 2 /* 1: S and NS application binaries are assembled in one single image. 74 2: Two separated images for S and NS application binaries. */ 75 76 #define MCUBOOT_S_DATA_IMAGE_NUMBER 0 /* 1: S data image for S application. 77 0: No S data image. */ 78 79 #define MCUBOOT_NS_DATA_IMAGE_NUMBER 0 /* 1: NS data image for NS application. 80 0: No NS data image. */ 81 82 /* Flash layout configuration : end */ 83 84 85 /* Total number of images */ 86 #ifndef MCUBOOT_IMAGE_NUMBER 87 #define MCUBOOT_IMAGE_NUMBER 2 /* (MCUBOOT_APP_IMAGE_NUMBER + MCUBOOT_S_DATA_IMAGE_NUMBER + MCUBOOT_NS_DATA_IMAGE_NUMBER)*/ 88 #endif 89 90 /* Use image hash reference to reduce boot time (signature check bypass) */ 91 #define MCUBOOT_USE_HASH_REF 92 93 /* control configuration */ 94 #if (defined(MCUBOOT_PRIMARY_ONLY) || defined(MCUBOOT_OVERWRITE_ONLY)) && defined(TFM_PARTITION_FIRMWARE_UPDATE) 95 #error "Config not supported: TFM_PARTITION_FIRMWARE_UPDATE is activated only in swap mode" 96 #endif 97 #if defined(MCUBOOT_PRIMARY_ONLY) && !defined(MCUBOOT_OVERWRITE_ONLY) 98 #error "Config not supported: When MCUBOOT_PRIMARY_ONLY is enabled, MCUBOOT_OVERWRITE_ONLY is required." 99 #endif /* defined(MCUBOOT_PRIMARY_ONLY) */ 100 101 /* The size of a partition. This should be large enough to contain a S or NS 102 * sw binary. Each FLASH_AREA_IMAGE contains two partitions. See Flash layout 103 * above. 104 */ 105 #define LOADER_FLASH_DEV_NAME TFM_Driver_FLASH0 106 107 /* Flash layout info for BL2 bootloader */ 108 #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x2000) /* 8 KB */ 109 #define FLASH_AREA_WRP_GROUP_SIZE (0x8000) /* 32 KB */ 110 #define FLASH_B_SIZE (0x100000) /* 1 MBytes*/ 111 #define FLASH_TOTAL_SIZE (FLASH_B_SIZE+FLASH_B_SIZE) /* 2 MBytes */ 112 #define FLASH_BASE_ADDRESS (0x0c000000) /* same as FLASH0_BASE_S */ 113 114 /* Flash area IDs */ 115 #define FLASH_AREA_0_ID (1) 116 #if (MCUBOOT_APP_IMAGE_NUMBER == 2) 117 #define FLASH_AREA_1_ID (2) 118 #endif /* MCUBOOT_APP_IMAGE_NUMBER == 2 */ 119 #if !defined(MCUBOOT_PRIMARY_ONLY) 120 #define FLASH_AREA_2_ID (3) 121 #if (MCUBOOT_APP_IMAGE_NUMBER == 2) 122 #define FLASH_AREA_3_ID (4) 123 #endif /* MCUBOOT_APP_IMAGE_NUMBER == 2 */ 124 #endif /* MCUBOOT_PRIMARY_ONLY */ 125 #if (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) 126 #define FLASH_AREA_4_ID (5) 127 #endif /* MCUBOOT_S_DATA_IMAGE_NUMBER == 1 */ 128 #if (MCUBOOT_NS_DATA_IMAGE_NUMBER == 1) 129 #define FLASH_AREA_5_ID (6) 130 #endif /* MCUBOOT_NS_DATA_IMAGE_NUMBER == 1 */ 131 #if !defined(MCUBOOT_PRIMARY_ONLY) 132 #if (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) 133 #define FLASH_AREA_6_ID (7) 134 #endif /* MCUBOOT_S_DATA_IMAGE_NUMBER == 1 */ 135 #if (MCUBOOT_NS_DATA_IMAGE_NUMBER == 1) 136 #define FLASH_AREA_7_ID (8) 137 #endif /* MCUBOOT_NS_DATA_IMAGE_NUMBER == 1 */ 138 #define FLASH_AREA_SCRATCH_ID (9) 139 #endif /* MCUBOOT_PRIMARY_ONLY */ 140 141 /* Offset and size definitions of the flash partitions that are handled by the 142 * bootloader. The image swapping is done between IMAGE_0 and IMAGE_1, SCRATCH 143 * is used as a temporary storage during image swapping. 144 */ 145 146 /* Area for downloading bl2 image */ 147 #define FLASH_AREA_BL2_BIN_OFFSET (0x0) 148 /* area for BL2 code protected by hdp */ 149 #define FLASH_AREA_BL2_OFFSET (0x0) 150 #if defined(EXTERNAL_FLASH) 151 #define FLASH_AREA_BL2_SIZE (0xF800) 152 #else 153 #define FLASH_AREA_BL2_SIZE (0x20000) 154 #endif /* EXTERNAL_FLASH */ 155 /* HDP area end at this address */ 156 #define FLASH_BL2_HDP_END (FLASH_AREA_BL2_OFFSET+FLASH_AREA_BL2_SIZE-1) 157 158 /* area for BL2 code not protected by hdp */ 159 #define FLASH_AREA_BL2_NOHDP_OFFSET (FLASH_AREA_BL2_OFFSET+FLASH_AREA_BL2_SIZE) 160 #if defined(EXTERNAL_FLASH) 161 #define FLASH_AREA_BL2_NOHDP_SIZE (0x1800) 162 #else 163 #define FLASH_AREA_BL2_NOHDP_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE) 164 #endif /* EXTERNAL_FLASH */ 165 166 167 /* scratch area */ 168 #if defined(FLASH_AREA_SCRATCH_ID) 169 #define FLASH_AREA_SCRATCH_DEVICE_ID (FLASH_DEVICE_ID - FLASH_DEVICE_ID) 170 #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_BL2_NOHDP_OFFSET + FLASH_AREA_BL2_NOHDP_SIZE) 171 #if defined(MCUBOOT_OVERWRITE_ONLY) 172 #define FLASH_AREA_SCRATCH_SIZE (0x0000) /* Not used in MCUBOOT_OVERWRITE_ONLY mode */ 173 #else 174 #define FLASH_AREA_SCRATCH_SIZE (0x8000) /* 32 KB */ 175 #endif 176 #endif 177 178 /* area for bl2 anti roll back counter */ 179 #define FLASH_BL2_NVCNT_AREA_OFFSET (FLASH_AREA_SCRATCH_OFFSET + FLASH_AREA_SCRATCH_SIZE) 180 #define FLASH_BL2_NVCNT_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE) 181 182 /* Non Volatile Counters definitions */ 183 #define FLASH_NV_COUNTERS_AREA_OFFSET (FLASH_BL2_NVCNT_AREA_OFFSET+FLASH_BL2_NVCNT_AREA_SIZE) 184 #define FLASH_NV_COUNTERS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE) 185 186 /* OTP / Non Volatile Counters definitions */ 187 #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE) 188 #if defined(EXTERNAL_FLASH) 189 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_NV_COUNTERS_AREA_OFFSET + \ 190 FLASH_NV_COUNTERS_AREA_SIZE) 191 #else 192 /* fix me with overwrite scratch is not required */ 193 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_NV_COUNTERS_AREA_OFFSET + \ 194 FLASH_NV_COUNTERS_AREA_SIZE) 195 #endif /* defined(EXTERNAL_FLASH) */ 196 197 #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_SECTOR_SIZE + \ 198 FLASH_OTP_NV_COUNTERS_SECTOR_SIZE) 199 /* Secure Storage (PS) Service definitions */ 200 #define FLASH_PS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE) 201 #define FLASH_PS_AREA_OFFSET (FLASH_OTP_NV_COUNTERS_AREA_OFFSET + \ 202 FLASH_OTP_NV_COUNTERS_AREA_SIZE) 203 204 /* Internal Trusted Storage (ITS) Service definitions */ 205 #define FLASH_ITS_AREA_OFFSET (FLASH_PS_AREA_OFFSET+FLASH_PS_AREA_SIZE) 206 #define FLASH_ITS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE) /* 8 KB */ 207 208 #define FLASH_S_PARTITION_SIZE (0x40000) /* 256 KB for S partition */ 209 #if !defined(MCUBOOT_PRIMARY_ONLY) 210 #define FLASH_NS_PARTITION_SIZE (0xA0000) /* 640 KB for NS partition */ 211 #else 212 #define FLASH_NS_PARTITION_SIZE (0x28000) /* 160 MB for NS partition */ 213 214 #endif /* MCUBOOT_PRIMARY_ONLY */ 215 #define FLASH_PARTITION_SIZE (FLASH_S_PARTITION_SIZE+FLASH_NS_PARTITION_SIZE) 216 217 #if (MCUBOOT_APP_IMAGE_NUMBER == 2) 218 #define FLASH_MAX_APP_PARTITION_SIZE ((FLASH_S_PARTITION_SIZE > \ 219 FLASH_NS_PARTITION_SIZE) ? \ 220 FLASH_S_PARTITION_SIZE : \ 221 FLASH_NS_PARTITION_SIZE) 222 #else 223 #define FLASH_MAX_APP_PARTITION_SIZE FLASH_PARTITION_SIZE 224 #endif /* (MCUBOOT_APP_IMAGE_NUMBER == 2) */ 225 #if (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) 226 #define FLASH_S_DATA_PARTITION_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE) 227 #else 228 #define FLASH_S_DATA_PARTITION_SIZE (0x0) 229 #endif /* (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) */ 230 #if (MCUBOOT_NS_DATA_IMAGE_NUMBER == 1) 231 #define FLASH_NS_DATA_PARTITION_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE+FLASH_AREA_IMAGE_SECTOR_SIZE) 232 #else 233 #define FLASH_NS_DATA_PARTITION_SIZE (0x0) 234 #endif /* (MCUBOOT_NS_DATA_IMAGE_NUMBER == 1) */ 235 236 #define FLASH_MAX_DATA_PARTITION_SIZE ((FLASH_S_DATA_PARTITION_SIZE > \ 237 FLASH_NS_DATA_PARTITION_SIZE) ? \ 238 FLASH_S_DATA_PARTITION_SIZE : \ 239 FLASH_NS_DATA_PARTITION_SIZE) 240 #define FLASH_MAX_PARTITION_SIZE ((FLASH_MAX_APP_PARTITION_SIZE > \ 241 FLASH_MAX_DATA_PARTITION_SIZE) ? \ 242 FLASH_MAX_APP_PARTITION_SIZE : \ 243 FLASH_MAX_DATA_PARTITION_SIZE) 244 245 /* BL2 flash areas */ 246 #define FLASH_AREA_BEGIN_OFFSET (FLASH_ITS_AREA_OFFSET + FLASH_ITS_AREA_SIZE) 247 248 #define FLASH_AREAS_DEVICE_ID (FLASH_DEVICE_ID - FLASH_DEVICE_ID) 249 250 /* Secure data image primary slot */ 251 #if defined (FLASH_AREA_4_ID) 252 #define FLASH_AREA_4_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 253 #define FLASH_AREA_4_OFFSET (FLASH_AREA_BEGIN_OFFSET) 254 #define FLASH_AREA_4_SIZE (FLASH_S_DATA_PARTITION_SIZE) 255 /* Control Secure data image primary slot */ 256 #if (FLASH_AREA_4_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 257 #error "FLASH_AREA_4_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 258 #endif /* (FLASH_AREA_4_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 259 #else /* FLASH_AREA_4_ID */ 260 #define FLASH_AREA_4_OFFSET (0x0) 261 #define FLASH_AREA_4_SIZE (0x0) 262 #endif /* FLASH_AREA_4_ID */ 263 264 /* Secure app image primary slot */ 265 #if defined(FLASH_AREA_0_ID) 266 #define FLASH_AREA_0_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 267 #define FLASH_AREA_0_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE) 268 #if (MCUBOOT_APP_IMAGE_NUMBER == 2) 269 #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) 270 #else 271 #define FLASH_AREA_0_SIZE (FLASH_PARTITION_SIZE) 272 #endif /* (MCUBOOT_APP_IMAGE_NUMBER == 2) */ 273 /* Control Secure app image primary slot */ 274 #if (FLASH_AREA_0_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 275 #error "FLASH_AREA_0_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 276 #endif /* (FLASH_AREA_0_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 277 #else /* FLASH_AREA_0_ID */ 278 #define FLASH_AREA_0_OFFSET (0x0) 279 #define FLASH_AREA_0_SIZE (0x0) 280 #endif /* FLASH_AREA_0_ID */ 281 282 /* Non-secure app image primary slot */ 283 #if defined(FLASH_AREA_1_ID) 284 #define FLASH_AREA_1_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 285 #define FLASH_AREA_1_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 286 FLASH_AREA_0_SIZE) 287 #define FLASH_AREA_1_SIZE (FLASH_NS_PARTITION_SIZE) 288 /* Control Non-secure app image primary slot */ 289 #if (FLASH_AREA_1_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 290 #error "FLASH_AREA_1_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 291 #endif /* (FLASH_AREA_1_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 292 #else /* FLASH_AREA_1_ID */ 293 #define FLASH_AREA_1_OFFSET (0x0) 294 #define FLASH_AREA_1_SIZE (0x0) 295 #endif /* FLASH_AREA_1_ID */ 296 297 /* Non-secure data image primary slot */ 298 #if defined(FLASH_AREA_5_ID) 299 #define FLASH_AREA_5_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 300 #define FLASH_AREA_5_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 301 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE) 302 #define FLASH_AREA_5_SIZE (FLASH_NS_DATA_PARTITION_SIZE) 303 /* Control Non-secure data image primary slot */ 304 #if (FLASH_AREA_5_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 305 #error "FLASH_AREA_5_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 306 #endif /* (FLASH_AREA_5_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 307 #else /* FLASH_AREA_5_ID */ 308 #define FLASH_AREA_5_OFFSET (0x0) 309 #define FLASH_AREA_5_SIZE (0x0) 310 #endif /* FLASH_AREA_5_ID */ 311 312 313 314 /* Secure app image secondary slot */ 315 #if defined(FLASH_AREA_2_ID) 316 #define FLASH_AREA_2_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 317 #define FLASH_AREA_2_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 318 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE + \ 319 FLASH_AREA_5_SIZE) 320 #if (MCUBOOT_APP_IMAGE_NUMBER == 2) 321 #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) 322 #else 323 #define FLASH_AREA_2_SIZE (FLASH_PARTITION_SIZE) 324 #endif /* (MCUBOOT_APP_IMAGE_NUMBER == 2) */ 325 /* Control Secure app image secondary slot */ 326 #if (FLASH_AREA_2_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 327 #error "FLASH_AREA_2_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 328 #endif /* (FLASH_AREA_2_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 329 #else /* FLASH_AREA_2_ID */ 330 #define FLASH_AREA_2_OFFSET (0x0) 331 #define FLASH_AREA_2_SIZE (0x0) 332 #endif /* FLASH_AREA_2_ID */ 333 334 /* Non-secure app image secondary slot */ 335 #if defined(FLASH_AREA_3_ID) 336 #define FLASH_AREA_3_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 337 #define FLASH_AREA_3_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 338 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE + \ 339 FLASH_AREA_5_SIZE + FLASH_AREA_2_SIZE) 340 #define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) 341 /* Control Non-Secure app image secondary slot */ 342 #if (FLASH_AREA_3_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 343 #error "FLASH_AREA_3_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 344 #endif /* (FLASH_AREA_3_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 345 #else /* FLASH_AREA_3_ID */ 346 #define FLASH_AREA_3_OFFSET (0x0) 347 #define FLASH_AREA_3_SIZE (0x0) 348 #endif /* FLASH_AREA_3_ID */ 349 350 351 /* Secure data image secondary slot */ 352 #if defined(FLASH_AREA_6_ID) 353 #define FLASH_AREA_6_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 354 #define FLASH_AREA_6_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 355 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE + \ 356 FLASH_AREA_5_SIZE + FLASH_AREA_2_SIZE + \ 357 FLASH_AREA_3_SIZE) 358 #define FLASH_AREA_6_SIZE (FLASH_S_DATA_PARTITION_SIZE) 359 /* Control Secure data image secondary slot */ 360 #if (FLASH_AREA_6_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 361 #error "FLASH_AREA_6_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 362 #endif /* (FLASH_AREA_6_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 363 #else /* FLASH_AREA_6_ID */ 364 #define FLASH_AREA_6_OFFSET (0x0) 365 #define FLASH_AREA_6_SIZE (0x0) 366 #endif /* FLASH_AREA_6_ID */ 367 368 /* Non-Secure data image secondary slot */ 369 #if defined(FLASH_AREA_7_ID) 370 #define FLASH_AREA_7_DEVICE_ID (FLASH_AREAS_DEVICE_ID) 371 #define FLASH_AREA_7_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 372 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE + \ 373 FLASH_AREA_5_SIZE + FLASH_AREA_2_SIZE + \ 374 FLASH_AREA_3_SIZE + FLASH_AREA_6_SIZE) 375 #define FLASH_AREA_7_SIZE (FLASH_NS_DATA_PARTITION_SIZE) 376 /* Control Non-Secure data image secondary slot */ 377 #if (FLASH_AREA_7_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 378 #error "FLASH_AREA_7_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 379 #endif /* (FLASH_AREA_7_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 380 #else /* FLASH_AREA_7_ID */ 381 #define FLASH_AREA_7_OFFSET (0x0) 382 #define FLASH_AREA_7_SIZE (0x0) 383 #endif /* FLASH_AREA_7_ID */ 384 385 /* flash areas end offset */ 386 /*#define FLASH_AREA_END_OFFSET (FLASH_AREA_BEGIN_OFFSET + FLASH_AREA_4_SIZE + \ 387 FLASH_AREA_0_SIZE + FLASH_AREA_1_SIZE + \ 388 FLASH_AREA_5_SIZE + FLASH_AREA_2_SIZE + \ 389 FLASH_AREA_3_SIZE + FLASH_AREA_6_SIZE + \ 390 FLASH_AREA_7_SIZE)*/ 391 /* Make all flash executable for user app following loader2 */ 392 #define FLASH_AREA_END_OFFSET 0x00200000 393 394 /* Control flash area end */ 395 #if (FLASH_AREA_END_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 396 #error "FLASH_AREA_END_OFFSET not aligned on FLASH_AREA_IMAGE_SECTOR_SIZE" 397 #endif /* (FLASH_AREA_END_OFFSET % FLASH_AREA_IMAGE_SECTOR_SIZE) != 0 */ 398 399 /* 400 * The maximum number of status entries supported by the bootloader. 401 */ 402 #define MCUBOOT_STATUS_MAX_ENTRIES ((FLASH_MAX_PARTITION_SIZE) / \ 403 FLASH_AREA_SCRATCH_SIZE) 404 /* Maximum number of image sectors supported by the bootloader. */ 405 #define MCUBOOT_MAX_IMG_SECTORS ((FLASH_MAX_PARTITION_SIZE) / \ 406 FLASH_AREA_IMAGE_SECTOR_SIZE) 407 #define SECURE_IMAGE_OFFSET (0x0) 408 #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE 409 410 #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + SECURE_IMAGE_MAX_SIZE) 411 #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE 412 413 414 /* Flash device name used by BL2 and NV Counter 415 * Name is defined in flash driver file: low_level_flash.c 416 */ 417 #if !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_APP_IMAGE_NUMBER == 2) 418 /* Flash Driver Used to Confirm Secure App Image */ 419 #define FLASH_PRIMARY_SECURE_DEV_NAME TFM_Driver_FLASH0 420 #endif /* !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_APP_IMAGE_NUMBER == 2) */ 421 /* Flash Driver Used to Confirm NonSecure App Image or MCUBOOT_APP_IMAGE_NUMBER = 1 */ 422 #define FLASH_PRIMARY_NONSECURE_DEV_NAME TFM_Driver_FLASH0 423 #if !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) 424 /* Flash Driver Used to Confirm Secure Data Image */ 425 #define FLASH_PRIMARY_DATA_SECURE_DEV_NAME TFM_Driver_FLASH0 426 #endif /* !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) */ 427 #if !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_NS_DATA_IMAGE_NUMBER == 1) 428 /* Flash Driver Used to Confirm NonSecure Data Image */ 429 #define FLASH_PRIMARY_DATA_NONSECURE_DEV_NAME TFM_Driver_FLASH0 430 #endif /* !defined(MCUBOOT_OVERWRITE_ONLY) && (MCUBOOT_S_DATA_IMAGE_NUMBER == 1) */ 431 432 #define TFM_NV_COUNTERS_FLASH_DEV TFM_Driver_FLASH0 433 #define FLASH_DEV_NAME TFM_Driver_FLASH0 434 #define TFM_HAL_FLASH_PROGRAM_UNIT (0x10) 435 /* Protected Storage (PS) Service definitions 436 * Note: Further documentation of these definitions can be found in the 437 * TF-M PS Integration Guide. 438 */ 439 #define TFM_HAL_PS_FLASH_DRIVER TFM_Driver_FLASH0 440 441 /* In this target the CMSIS driver requires only the offset from the base 442 * address instead of the full memory address. 443 */ 444 #define PS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 445 /* The sectors must be in consecutive memory location */ 446 #define PS_NBR_OF_SECTORS (FLASH_PS_AREA_SIZE / PS_SECTOR_SIZE) 447 /* The maximum asset size to be stored in the ITS area */ 448 #define ITS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 449 /* The sectors must be in consecutive memory location */ 450 #define ITS_NBR_OF_SECTORS (FLASH_ITS_AREA_SIZE / ITS_SECTOR_SIZE) 451 452 /* Base address of dedicated flash area for PS */ 453 #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET 454 /* Size of dedicated flash area for PS */ 455 #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE 456 #define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE 457 /* Number of physical erase sectors per logical FS block */ 458 #define TFM_HAL_PS_SECTORS_PER_BLOCK (1) 459 /* Smallest flash programmable unit in bytes */ 460 #define TFM_HAL_PS_PROGRAM_UNIT (0x10) 461 462 /* Internal Trusted Storage (ITS) Service definitions 463 * Note: Further documentation of these definitions can be found in the 464 * TF-M ITS Integration Guide. 465 */ 466 #define TFM_HAL_ITS_FLASH_DRIVER TFM_Driver_FLASH0 467 468 /* In this target the CMSIS driver requires only the offset from the base 469 * address instead of the full memory address. 470 */ 471 /* Base address of dedicated flash area for ITS */ 472 #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET 473 /* Size of dedicated flash area for ITS */ 474 #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE 475 #define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE 476 /* Number of physical erase sectors per logical FS block */ 477 #define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) 478 /* Smallest flash programmable unit in bytes */ 479 #define TFM_HAL_ITS_PROGRAM_UNIT (0x10) 480 481 482 /* NV Counters definitions */ 483 #define TFM_NV_COUNTERS_AREA_ADDR FLASH_NV_COUNTERS_AREA_OFFSET 484 #define TFM_NV_COUNTERS_AREA_SIZE (0x20)/* 32 Bytes */ 485 #define TFM_NV_COUNTERS_SECTOR_ADDR FLASH_NV_COUNTERS_AREA_OFFSET 486 #define TFM_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 487 488 /* OTP / NV counter definitions */ 489 #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) 490 #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET 491 #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE 492 #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ 493 TFM_OTP_NV_COUNTERS_AREA_SIZE) 494 495 /* BL2 NV Counters definitions */ 496 #define BL2_NV_COUNTERS_AREA_ADDR FLASH_BL2_NVCNT_AREA_OFFSET 497 #define BL2_NV_COUNTERS_AREA_SIZE FLASH_BL2_NVCNT_AREA_SIZE 498 499 /* FIXME: not valid today */ 500 #define BL2_S_RAM_ALIAS_BASE (0x30000000) 501 #define BL2_NS_RAM_ALIAS_BASE (0x20000000) 502 503 /* This area in SRAM 2 is updated BL2 and can be lock to avoid any changes */ 504 #define BOOT_TFM_SHARED_DATA_SIZE (0x400) 505 #define BOOT_TFM_SHARED_DATA_BASE (0x3004fc00) 506 507 /* OBK */ 508 #define OBK_HDPL0_OFFSET (0x00U) /* First OBkey Hdpl 0 */ 509 #define OBK_HDPL0_END (0xFFU) /* Last OBKey Hdpl 0 */ 510 #define OBK_HDPL1_OFFSET (0x100U) /* First OBkey Hdpl 1 */ 511 #define OBK_HDPL1_END (0x8FFU) /* Last OBKey Hdpl 1 */ 512 #define OBK_HDPL2_OFFSET (0x900U) /* First OBkey Hdpl 2 */ 513 #define OBK_HDPL2_END (0xBFFU) /* Last OBKey Hdpl 2 */ 514 #define OBK_HDPL3_OFFSET (0xC00U) /* First OBkey Hdpl 3 */ 515 #define OBK_HDPL3_END (0x1FFFU) /* Last OBKey Hdpl 3 */ 516 517 /* Engi bits */ 518 #define ENGI_BASE_NS (0x08FFF800U) 519 #define ENGI_SIZE (0x40U) 520 521 /* Systeme Flash description */ 522 #define RSS_LIB_BASE (0x0FF94000U) 523 #define RSS_LIB_SIZE (0x2000U) 524 #define BOOTLOADER_BASE_NS (0x0BF97000U) 525 #define BOOTLOADER_SIZE (0x9400U) 526 #define STM32_DESCRIPTOR_BASE_NS_3 (0x0BF9FB00U) 527 #define STM32_DESCRIPTOR_BASE_NS_2 (0x0BF9FD00U) 528 #define STM32_DESCRIPTOR_BASE_NS_1 (0x0BF9FE00U) 529 #define RSSLIB_PFUNC_3 (0x0BF9FB68UL) 530 #define RSSLIB_PFUNC_2 (0x0BF9FD68UL) 531 #define RSSLIB_PFUNC_1 (0x0BF9FE68UL) 532 #define STM32_DESCRIPTOR_SIZE (0x100U) 533 #define STM32_DESCRIPTOR_BASE_NS (STM32_DESCRIPTOR_BASE_NS_3) /* use for mpu region the lowest address*/ 534 #define STM32_DESCRIPTOR_END_NS (STM32_DESCRIPTOR_BASE_NS_1 + STM32_DESCRIPTOR_SIZE -1) /* to cover all descriptors */ 535 536 #endif /* __FLASH_LAYOUT_H__ */ 537