|
| 1 | +/* |
| 2 | + * Copyright (c) 2018-2022 Arm Limited. All rights reserved. |
| 3 | + * Copyright (c) 2020 Nordic Semiconductor ASA. 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 nRF91 with BL2: |
| 22 | + * |
| 23 | + * 0x0000_0000 BL2 - MCUBoot (64 KB) |
| 24 | + * 0x0001_0000 Primary image area (448 KB): |
| 25 | + * 0x0001_0000 Secure image primary (256 KB) |
| 26 | + * 0x0005_0000 Non-secure image primary (192 KB) |
| 27 | + * 0x0008_0000 Secondary image area (448 KB): |
| 28 | + * 0x0008_0000 Secure image secondary (256 KB) |
| 29 | + * 0x000c_0000 Non-secure image secondary (192 KB) |
| 30 | + * 0x000f_0000 Protected Storage Area (16 KB) |
| 31 | + * 0x000f_4000 Internal Trusted Storage Area (8 KB) |
| 32 | + * 0x000f_6000 OTP / NV counters area (8 KB) |
| 33 | + * 0x000f_8000 Non-secure storage, used when built with NRF_NS_STORAGE=ON, |
| 34 | + * otherwise unused (32 KB) |
| 35 | + * |
| 36 | + * Flash layout on nRF91 without BL2: |
| 37 | + * |
| 38 | + * 0x0000_0000 Primary image area (960 KB): |
| 39 | + * 0x0000_0000 Secure image primary (480 KB) |
| 40 | + * 0x0007_8000 Non-secure image primary (480 KB) |
| 41 | + * 0x000f_0000 Protected Storage Area (16 KB) |
| 42 | + * 0x000f_4000 Internal Trusted Storage Area (8 KB) |
| 43 | + * 0x000f_6000 OTP / NV counters area (8 KB) |
| 44 | + * 0x000f_8000 Non-secure storage, used when built with NRF_NS_STORAGE=ON, |
| 45 | + * otherwise unused (32 KB) |
| 46 | + */ |
| 47 | + |
| 48 | +/* This header file is included from linker scatter file as well, where only a |
| 49 | + * limited C constructs are allowed. Therefore it is not possible to include |
| 50 | + * here the platform_base_address.h to access flash related defines. To resolve |
| 51 | + * this some of the values are redefined here with different names, these are |
| 52 | + * marked with comment. |
| 53 | + */ |
| 54 | + |
| 55 | +/* Size of a Secure and of a Non-secure image */ |
| 56 | +#ifdef PSA_API_TEST_IPC |
| 57 | +/* Firmware Framework test suites */ |
| 58 | +#define FLASH_S_PARTITION_SIZE (0x48000) /* S partition: 288 kB*/ |
| 59 | +#define FLASH_NS_PARTITION_SIZE (0x28000) /* NS partition: 160 kB*/ |
| 60 | +#else |
| 61 | +#define FLASH_S_PARTITION_SIZE (0x40000) /* S partition: 256 kB*/ |
| 62 | +#define FLASH_NS_PARTITION_SIZE (0x30000) /* NS partition: 192 kB*/ |
| 63 | +#endif |
| 64 | + |
| 65 | +#if (FLASH_S_PARTITION_SIZE > FLASH_NS_PARTITION_SIZE) |
| 66 | +#define FLASH_MAX_PARTITION_SIZE FLASH_S_PARTITION_SIZE |
| 67 | +#else |
| 68 | +#define FLASH_MAX_PARTITION_SIZE FLASH_NS_PARTITION_SIZE |
| 69 | +#endif |
| 70 | +/* Sector size of the embedded flash hardware (erase/program) */ |
| 71 | +#define FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4 KB. Flash memory program/erase operations have a page granularity. */ |
| 72 | + |
| 73 | +/* FLASH size */ |
| 74 | +#define FLASH_TOTAL_SIZE (0x100000) /* 1024 kB. */ |
| 75 | + |
| 76 | +/* Flash layout info for BL2 bootloader */ |
| 77 | +#define FLASH_BASE_ADDRESS (0x00000000) |
| 78 | + |
| 79 | + |
| 80 | +/* Offset and size definitions of the flash partitions that are handled by the |
| 81 | + * bootloader. The image swapping is done between IMAGE_PRIMARY and |
| 82 | + * IMAGE_SECONDARY, SCRATCH is used as a temporary storage during image |
| 83 | + * swapping. |
| 84 | + */ |
| 85 | +#define FLASH_AREA_BL2_OFFSET (0x0) |
| 86 | +#define FLASH_AREA_BL2_SIZE (0x10000) /* 64 KB */ |
| 87 | + |
| 88 | +#if !defined(MCUBOOT_IMAGE_NUMBER) || (MCUBOOT_IMAGE_NUMBER == 1) |
| 89 | +/* Secure + Non-secure image primary slot */ |
| 90 | +#define FLASH_AREA_0_ID (1) |
| 91 | +#define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) |
| 92 | +#define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE + \ |
| 93 | + FLASH_NS_PARTITION_SIZE) |
| 94 | +/* Secure + Non-secure secondary slot */ |
| 95 | +#define FLASH_AREA_2_ID (FLASH_AREA_0_ID + 1) |
| 96 | +#define FLASH_AREA_2_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) |
| 97 | +#define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE + \ |
| 98 | + FLASH_NS_PARTITION_SIZE) |
| 99 | +/* Not used, only the Non-swapping firmware upgrade operation |
| 100 | + * is supported on nRF91. |
| 101 | + */ |
| 102 | +#define FLASH_AREA_SCRATCH_ID (FLASH_AREA_2_ID + 1) |
| 103 | +#define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) |
| 104 | +#define FLASH_AREA_SCRATCH_SIZE (0) |
| 105 | +/* Maximum number of image sectors supported by the bootloader. */ |
| 106 | +#define MCUBOOT_MAX_IMG_SECTORS ((FLASH_S_PARTITION_SIZE + \ |
| 107 | + FLASH_NS_PARTITION_SIZE) / \ |
| 108 | + FLASH_AREA_IMAGE_SECTOR_SIZE) |
| 109 | +#elif (MCUBOOT_IMAGE_NUMBER == 2) |
| 110 | +/* Secure image primary slot */ |
| 111 | +#define FLASH_AREA_0_ID (1) |
| 112 | +#define FLASH_AREA_0_OFFSET (FLASH_AREA_BL2_OFFSET + FLASH_AREA_BL2_SIZE) |
| 113 | +#define FLASH_AREA_0_SIZE (FLASH_S_PARTITION_SIZE) |
| 114 | +/* Non-secure image primary slot */ |
| 115 | +#define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) |
| 116 | +#define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) |
| 117 | +#define FLASH_AREA_1_SIZE (FLASH_NS_PARTITION_SIZE) |
| 118 | +/* Secure image secondary slot */ |
| 119 | +#define FLASH_AREA_2_ID (FLASH_AREA_1_ID + 1) |
| 120 | +#define FLASH_AREA_2_OFFSET (FLASH_AREA_1_OFFSET + FLASH_AREA_1_SIZE) |
| 121 | +#define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) |
| 122 | +/* Non-secure image secondary slot */ |
| 123 | +#define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) |
| 124 | +#define FLASH_AREA_3_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) |
| 125 | +#define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) |
| 126 | +/* Not used, only the Non-swapping firmware upgrade operation |
| 127 | + * is supported on nRF91. |
| 128 | + */ |
| 129 | +#define FLASH_AREA_SCRATCH_ID (FLASH_AREA_3_ID + 1) |
| 130 | +#define FLASH_AREA_SCRATCH_OFFSET (FLASH_AREA_3_OFFSET + FLASH_AREA_3_SIZE) |
| 131 | +#define FLASH_AREA_SCRATCH_SIZE (0) |
| 132 | +/* Maximum number of image sectors supported by the bootloader. */ |
| 133 | +#define MCUBOOT_MAX_IMG_SECTORS (FLASH_MAX_PARTITION_SIZE / \ |
| 134 | + FLASH_AREA_IMAGE_SECTOR_SIZE) |
| 135 | +#else /* MCUBOOT_IMAGE_NUMBER > 2 */ |
| 136 | +#error "Only MCUBOOT_IMAGE_NUMBER 1 and 2 are supported!" |
| 137 | +#endif /* MCUBOOT_IMAGE_NUMBER */ |
| 138 | + |
| 139 | +/* Not used, only the Non-swapping firmware upgrade operation |
| 140 | + * is supported on nRF91. The maximum number of status entries |
| 141 | + * supported by the bootloader. |
| 142 | + */ |
| 143 | +#define MCUBOOT_STATUS_MAX_ENTRIES (0) |
| 144 | + |
| 145 | + |
| 146 | +/* Protected Storage (PS) Service definitions */ |
| 147 | +#define FLASH_PS_AREA_OFFSET (FLASH_AREA_SCRATCH_OFFSET + \ |
| 148 | + FLASH_AREA_SCRATCH_SIZE) |
| 149 | +#define FLASH_PS_AREA_SIZE (0x4000) /* 16 KB */ |
| 150 | + |
| 151 | +/* Internal Trusted Storage (ITS) Service definitions */ |
| 152 | +#define FLASH_ITS_AREA_OFFSET (FLASH_PS_AREA_OFFSET + \ |
| 153 | + FLASH_PS_AREA_SIZE) |
| 154 | +#define FLASH_ITS_AREA_SIZE (0x2000) /* 8 KB */ |
| 155 | + |
| 156 | +/* OTP_definitions */ |
| 157 | +#define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_ITS_AREA_OFFSET + \ |
| 158 | + FLASH_ITS_AREA_SIZE) |
| 159 | +#define FLASH_OTP_NV_COUNTERS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE * 2) |
| 160 | +#define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE |
| 161 | + |
| 162 | +/* Non-secure storage region */ |
| 163 | +#define NRF_FLASH_NS_STORAGE_AREA_OFFSET (FLASH_TOTAL_SIZE - \ |
| 164 | + NRF_FLASH_NS_STORAGE_AREA_SIZE) |
| 165 | +#define NRF_FLASH_NS_STORAGE_AREA_SIZE (0x8000) /* 32 KB */ |
| 166 | + |
| 167 | +/* Offset and size definition in flash area used by assemble.py */ |
| 168 | +#define SECURE_IMAGE_OFFSET (0x0) |
| 169 | +#define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE |
| 170 | + |
| 171 | +#define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + \ |
| 172 | + SECURE_IMAGE_MAX_SIZE) |
| 173 | +#define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE |
| 174 | + |
| 175 | +/* Flash device name used by BL2 |
| 176 | + * Name is defined in flash driver file: Driver_Flash.c |
| 177 | + */ |
| 178 | +#define FLASH_DEV_NAME Driver_FLASH0 |
| 179 | +/* Smallest flash programmable unit in bytes */ |
| 180 | +#define TFM_HAL_FLASH_PROGRAM_UNIT (0x4) |
| 181 | + |
| 182 | +/* Protected Storage (PS) Service definitions |
| 183 | + * Note: Further documentation of these definitions can be found in the |
| 184 | + * TF-M PS Integration Guide. |
| 185 | + */ |
| 186 | +#define TFM_HAL_PS_FLASH_DRIVER 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 PS */ |
| 192 | +#define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET |
| 193 | +/* Size of dedicated flash area for PS */ |
| 194 | +#define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE |
| 195 | +#define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE |
| 196 | +/* Number of physical erase sectors per logical FS block */ |
| 197 | +#define TFM_HAL_PS_SECTORS_PER_BLOCK (1) |
| 198 | +/* Smallest flash programmable unit in bytes */ |
| 199 | +#define TFM_HAL_PS_PROGRAM_UNIT (0x4) |
| 200 | + |
| 201 | +/* Internal Trusted Storage (ITS) Service definitions |
| 202 | + * Note: Further documentation of these definitions can be found in the |
| 203 | + * TF-M ITS Integration Guide. The ITS should be in the internal flash, but is |
| 204 | + * allocated in the external flash just for development platforms that don't |
| 205 | + * have internal flash available. |
| 206 | + */ |
| 207 | +#define TFM_HAL_ITS_FLASH_DRIVER Driver_FLASH0 |
| 208 | + |
| 209 | +/* In this target the CMSIS driver requires only the offset from the base |
| 210 | + * address instead of the full memory address. |
| 211 | + */ |
| 212 | +/* Base address of dedicated flash area for ITS */ |
| 213 | +#define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET |
| 214 | +/* Size of dedicated flash area for ITS */ |
| 215 | +#define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE |
| 216 | +#define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE |
| 217 | +/* Number of physical erase sectors per logical FS block */ |
| 218 | +#define TFM_HAL_ITS_SECTORS_PER_BLOCK (1) |
| 219 | +/* Smallest flash programmable unit in bytes */ |
| 220 | +#define TFM_HAL_ITS_PROGRAM_UNIT (0x4) |
| 221 | + |
| 222 | +/* OTP / NV counter definitions */ |
| 223 | +#define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) |
| 224 | +#define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET |
| 225 | +#define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE |
| 226 | +#define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ |
| 227 | + TFM_OTP_NV_COUNTERS_AREA_SIZE) |
| 228 | + |
| 229 | +/* Use Flash memory to store Code data */ |
| 230 | +#define FLASH_BASE_ADDRESS (0x00000000) |
| 231 | +#define S_ROM_ALIAS_BASE FLASH_BASE_ADDRESS |
| 232 | +#define NS_ROM_ALIAS_BASE FLASH_BASE_ADDRESS |
| 233 | + |
| 234 | +/* Use SRAM memory to store RW data */ |
| 235 | +#define SRAM_BASE_ADDRESS (0x20000000) |
| 236 | +#define S_RAM_ALIAS_BASE SRAM_BASE_ADDRESS |
| 237 | +#define NS_RAM_ALIAS_BASE SRAM_BASE_ADDRESS |
| 238 | + |
| 239 | +#define TOTAL_ROM_SIZE FLASH_TOTAL_SIZE |
| 240 | +#define TOTAL_RAM_SIZE (0x00040000) /* 256 kB */ |
| 241 | + |
| 242 | +#endif /* __FLASH_LAYOUT_H__ */ |
0 commit comments