1 /* 2 * Copyright (c) 2018-2022 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 /* Flash layout on Musca-B1 with BL2 (multiple image boot, boot from eFlash 0): 22 * 23 * 0x0A00_0000 BL2 - MCUBoot (128 KB) 24 * 0x0A02_0000 Secure image primary slot (384 KB) 25 * 0x0A08_0000 Non-secure image primary slot (512 KB) 26 * 0x0A10_0000 Secure image secondary slot (384 KB) 27 * 0x0A16_0000 Non-secure image secondary slot (512 KB) 28 * 0x0A1E_0000 Scratch area (64 KB) 29 * 0x0A1F_0000 Internal Trusted Storage Area (32 KB) 30 * 0x0A1F_8000 OTP / NV counter area (8 KB) 31 * 0x0A1F_A000 Unused (40 KB) 32 * 33 * Flash layout on Musca-B1 with BL2 (single image boot): 34 * 35 * 0x0A00_0000 BL2 - MCUBoot (128 KB) 36 * 0x0A02_0000 Primary image area (896 KB): 37 * 0x0A02_0000 Secure image primary (384 KB) 38 * 0x0A08_0000 Non-secure image primary (512 KB) 39 * 0x0A10_0000 Secondary image area (896 KB): 40 * 0x0A10_0000 Secure image secondary (384 KB) 41 * 0x0A16_0000 Non-secure image secondary (512 KB) 42 * 0x0A1E_0000 Scratch area (64 KB) 43 * 0x0A1F_0000 Internal Trusted Storage Area (32 KB) 44 * 0x0A1F_8000 OTP / NV counter area (8 KB) 45 * 0x0A1F_A000 Unused (40 KB) 46 * 47 * Note: As eFlash is written at runtime, the eFlash driver code is placed 48 * in code SRAM to avoid any interference. 49 * 50 * Flash layout on Musca-B1 without BL2: 51 * 0x0A00_0000 Secure image 52 * 0x0A08_0000 Non-secure image 53 * 54 * QSPI Flash layout 55 * 0x0000_0000 Protected Storage Area (20 KB) 56 */ 57 58 /* This header file is included from linker scatter file as well, where only a 59 * limited C constructs are allowed. Therefore it is not possible to include 60 * here the platform_base_address.h to access flash related defines. To resolve 61 * this some of the values are redefined here with different names, these are 62 * marked with comment. 63 */ 64 65 /* Size of a Secure and of a Non-secure image */ 66 #define FLASH_S_PARTITION_SIZE (0x60000) /* S partition: 384 KB */ 67 #define FLASH_NS_PARTITION_SIZE (0x80000) /* NS partition: 512 KB */ 68 69 #if (FLASH_S_PARTITION_SIZE > FLASH_NS_PARTITION_SIZE) 70 #define FLASH_MAX_PARTITION_SIZE FLASH_S_PARTITION_SIZE 71 #else 72 #define FLASH_MAX_PARTITION_SIZE FLASH_NS_PARTITION_SIZE 73 #endif 74 /* Sector size of the embedded flash hardware */ 75 #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x4000) /* 16 KB */ 76 #define FLASH_TOTAL_SIZE (0x200000) /* 2 MB */ 77 78 /* Sector size of the QSPI flash hardware */ 79 #define QSPI_FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4 KB */ 80 #define QSPI_FLASH_TOTAL_SIZE (0x800000) /* 8 MB */ 81 82 /* Flash layout info for BL2 bootloader */ 83 #define FLASH_BASE_ADDRESS (0x1A000000) 84 85 /* Offset and size definitions of the flash partitions that are handled by the 86 * bootloader. The image swapping is done between IMAGE_PRIMARY and 87 * IMAGE_SECONDARY, SCRATCH is used as a temporary storage during image 88 * swapping. 89 */ 90 #define FLASH_AREA_BL2_OFFSET (0x0) 91 #define FLASH_AREA_BL2_SIZE (0x20000) /* 128 KB */ 92 93 #if !defined(MCUBOOT_IMAGE_NUMBER) || (MCUBOOT_IMAGE_NUMBER == 1) 94 /* Secure + Non-secure image primary slot */ 95 #define FLASH_AREA_0_ID (1) 96 #define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) 97 #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE + \ 98 FLASH_NS_PARTITION_SIZE) 99 /* Secure + Non-secure secondary slot */ 100 #define FLASH_AREA_2_ID (FLASH_AREA_0_ID + 1) 101 #define FLASH_AREA_2_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) 102 #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE + \ 103 FLASH_NS_PARTITION_SIZE) 104 /* Scratch area */ 105 #define FLASH_AREA_SCRATCH_ID (FLASH_AREA_2_ID + 1) 106 #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) 107 #define FLASH_AREA_SCRATCH_SIZE (4 * FLASH_AREA_IMAGE_SECTOR_SIZE) 108 /* The maximum number of status entries supported by the bootloader. */ 109 #define MCUBOOT_STATUS_MAX_ENTRIES ((FLASH_S_PARTITION_SIZE + \ 110 FLASH_NS_PARTITION_SIZE) / \ 111 FLASH_AREA_SCRATCH_SIZE) 112 /* Maximum number of image sectors supported by the bootloader. */ 113 #define MCUBOOT_MAX_IMG_SECTORS ((FLASH_S_PARTITION_SIZE + \ 114 FLASH_NS_PARTITION_SIZE) / \ 115 FLASH_AREA_IMAGE_SECTOR_SIZE) 116 #elif (MCUBOOT_IMAGE_NUMBER == 2) 117 /* Secure image primary slot */ 118 #define FLASH_AREA_0_ID (1) 119 #define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) 120 #define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) 121 /* Non-secure image primary slot */ 122 #define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) 123 #define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) 124 #define FLASH_AREA_1_SIZE (FLASH_NS_PARTITION_SIZE) 125 /* Secure image secondary slot */ 126 #define FLASH_AREA_2_ID (FLASH_AREA_1_ID + 1) 127 #define FLASH_AREA_2_OFFSET (FLASH_AREA_1_OFFSET + FLASH_AREA_1_SIZE) 128 #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) 129 /* Non-secure image secondary slot */ 130 #define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) 131 #define FLASH_AREA_3_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) 132 #define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) 133 /* Scratch area */ 134 #define FLASH_AREA_SCRATCH_ID (FLASH_AREA_3_ID + 1) 135 #define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_3_OFFSET + FLASH_AREA_3_SIZE) 136 #define FLASH_AREA_SCRATCH_SIZE (4 * FLASH_AREA_IMAGE_SECTOR_SIZE) 137 /* The maximum number of status entries supported by the bootloader. */ 138 #define MCUBOOT_STATUS_MAX_ENTRIES (FLASH_MAX_PARTITION_SIZE / \ 139 FLASH_AREA_SCRATCH_SIZE) 140 /* Maximum number of image sectors supported by the bootloader. */ 141 #define MCUBOOT_MAX_IMG_SECTORS (FLASH_MAX_PARTITION_SIZE / \ 142 FLASH_AREA_IMAGE_SECTOR_SIZE) 143 #else /* MCUBOOT_IMAGE_NUMBER > 2 */ 144 #error "Only MCUBOOT_IMAGE_NUMBER 1 and 2 are supported!" 145 #endif /* MCUBOOT_IMAGE_NUMBER */ 146 147 /* Internal Trusted Storage (ITS) Service definitions (32 KB) */ 148 #define FLASH_ITS_AREA_OFFSET (FLASH_AREA_SCRATCH_OFFSET + \ 149 FLASH_AREA_SCRATCH_SIZE) 150 #define FLASH_ITS_AREA_SIZE (2 * FLASH_AREA_IMAGE_SECTOR_SIZE) 151 152 /* OTP_definitions */ 153 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_ITS_AREA_OFFSET + \ 154 FLASH_ITS_AREA_SIZE) 155 #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE * 2) 156 #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 157 158 /* Offset and size definition in flash area used by assemble.py */ 159 #define SECURE_IMAGE_OFFSET (0x0) 160 #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE 161 162 #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + \ 163 SECURE_IMAGE_MAX_SIZE) 164 #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE 165 166 /* Protected Storage (PS) Service definitions size is 20 KB. */ 167 /* Same as MUSCA_B1_QSPI_FLASH_S_BASE */ 168 #define QSPI_FLASH_BASE_ADDRESS (0x10000000) 169 #define FLASH_PS_AREA_OFFSET (0x0) 170 #define FLASH_PS_AREA_SIZE (5 * QSPI_FLASH_AREA_IMAGE_SECTOR_SIZE) 171 172 /* Flash device name used by BL2 173 * Name is defined in flash driver file: Driver_Flash.c 174 */ 175 #define FLASH_DEV_NAME Driver_EFLASH0 176 /* Smallest flash programmable unit in bytes */ 177 #define TFM_HAL_FLASH_PROGRAM_UNIT (0x4) 178 179 /* Protected Storage (PS) Service definitions 180 * Note: Further documentation of these definitions can be found in the 181 * TF-M PS Integration Guide. 182 */ 183 #define TFM_HAL_PS_FLASH_DRIVER Driver_QSPI_FLASH0 184 185 /* In this target the CMSIS driver requires only the offset from the base 186 * address instead of the full memory address. 187 */ 188 /* Base address of dedicated flash area for PS */ 189 #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET 190 /* Size of dedicated flash area for PS */ 191 #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE 192 #define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE 193 /* Number of physical erase sectors per logical FS block */ 194 #define TFM_HAL_PS_SECTORS_PER_BLOCK (1) 195 /* Smallest flash programmable unit in bytes */ 196 #define TFM_HAL_PS_PROGRAM_UNIT (0x1) 197 198 /* Internal Trusted Storage (ITS) Service definitions 199 * Note: Further documentation of these definitions can be found in the 200 * TF-M ITS Integration Guide. 201 */ 202 #define TFM_HAL_ITS_FLASH_DRIVER Driver_EFLASH0 203 204 /* In this target the CMSIS driver requires only the offset from the base 205 * address instead of the full memory address. 206 */ 207 /* Base address of dedicated flash area for ITS */ 208 #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET 209 /* Size of dedicated flash area for ITS */ 210 #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE 211 #define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE 212 /* Number of physical erase sectors per logical FS block */ 213 #define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) 214 /* Smallest flash programmable unit in bytes */ 215 #define TFM_HAL_ITS_PROGRAM_UNIT (0x4) 216 217 /* OTP / NV counter definitions */ 218 #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) 219 #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET 220 #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE 221 #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ 222 TFM_OTP_NV_COUNTERS_AREA_SIZE) 223 224 /* Use eFlash 0 memory to store Code data */ 225 #define S_ROM_ALIAS_BASE (0x1A000000) 226 #define NS_ROM_ALIAS_BASE (0x0A000000) 227 228 /* FIXME: Use SRAM2 memory to store RW data */ 229 #define S_RAM_ALIAS_BASE (0x30000000) 230 #define NS_RAM_ALIAS_BASE (0x20000000) 231 232 #define TOTAL_ROM_SIZE FLASH_TOTAL_SIZE 233 #define TOTAL_RAM_SIZE (0x80000) /* 512 KB */ 234 235 #endif /* __FLASH_LAYOUT_H__ */ 236