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