1 /* 2 * Copyright (c) 2017-2021 Arm Limited. All rights reserved. 3 * Copyright (c) 2019-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 with BL2: 22 * 23 * Not supported 24 * 25 * Flash layout if BL2 not defined: 26 * 27 * 0x1000_0000 Secure image primary (320 KB) 28 * 0x1005_0000 Non-secure image primary (1152 KB) 29 * 0x1017_0000 Secure image secondary (320 KB) 30 * 0x101c_0000 - 0x101f_ffff Reserved 31 * 0x101c_0000 Internal Trusted Storage Area (16 KB) 32 * 0x101c_4000 Protected Storage Area (24 KB) 33 * 0x101c_a000 Unused area (22 KB) 34 * 0x101c_f800 OTP / NV counters area (2 KB) 35 * 0x101d_0000 Reserved (192 KB) 36 * 0x101f_ffff End of Flash 37 * 38 */ 39 40 /* This header file is included from linker scatter file as well, where only a 41 * limited C constructs are allowed. Therefore it is not possible to include 42 * here the platform_base_address.h to access flash related defines. To resolve 43 * this some of the values are redefined here with different names, these are 44 * marked with comment. 45 */ 46 47 #ifdef BL2 48 #error "BL2 configuration is not supported" 49 #endif /* BL2 */ 50 51 /* The size of S partition */ 52 #define FLASH_S_PARTITION_SIZE 0x50000 /* 320 KB */ 53 /* The size of NS partition */ 54 #define FLASH_NS_PARTITION_SIZE 0x120000 /* 1152 KB */ 55 56 /* Sector size of the flash hardware; same as FLASH0_SECTOR_SIZE */ 57 #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x200) /* 512 B */ 58 /* Same as FLASH0_SIZE */ 59 #define FLASH_TOTAL_SIZE (0x00200000) /* 2 MB */ 60 61 /* Flash layout info for BL2 bootloader */ 62 #define FLASH_BASE_ADDRESS (0x10000000U) /* same as FLASH0_BASE */ 63 64 /* Reserved areas */ 65 #define FLASH_DATA_AREA_OFFSET (SECURE_IMAGE_OFFSET + \ 66 2*SECURE_IMAGE_MAX_SIZE + \ 67 NON_SECURE_IMAGE_MAX_SIZE) 68 69 /* FixMe: implement proper mcuboot partitioning for CYBL */ 70 71 /* Internal Trusted Storage Area */ 72 #define FLASH_ITS_AREA_OFFSET (FLASH_DATA_AREA_OFFSET) 73 #define FLASH_ITS_AREA_SIZE (0x4000) /* 16 KB */ 74 75 /* Protected Storage Area */ 76 #define FLASH_PS_AREA_OFFSET (FLASH_ITS_AREA_OFFSET + \ 77 FLASH_ITS_AREA_SIZE) 78 #define FLASH_PS_AREA_SIZE (0x6000) /* 24 KB */ 79 80 /* Unused Area */ 81 #define FLASH_UNUSED_AREA_OFFSET (FLASH_PS_AREA_OFFSET + \ 82 FLASH_PS_AREA_SIZE) 83 #define FLASH_UNUSED_AREA_SIZE (0x5800) /* 22 KB */ 84 85 /* OTP_definitions */ 86 #define FLASH_OTP_NV_COUNTERS_AREA_OFFSET (FLASH_UNUSED_AREA_OFFSET + \ 87 FLASH_UNUSED_AREA_SIZE) 88 #define FLASH_OTP_NV_COUNTERS_AREA_SIZE (FLASH_AREA_IMAGE_SECTOR_SIZE * 4) 89 #define FLASH_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_AREA_IMAGE_SECTOR_SIZE 90 91 #define FLASH_AREA_SYSTEM_RESERVED_SIZE (0x30000) /* 192 KB */ 92 93 94 /* Secure and non-secure images definition in flash area */ 95 96 #define SECURE_IMAGE_OFFSET 0x0 97 98 #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE 99 100 #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + \ 101 SECURE_IMAGE_MAX_SIZE) 102 103 #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE 104 105 /* Check if it fits into available Flash*/ 106 107 #define FLASH_DATA_AREA_SIZE (FLASH_ITS_AREA_SIZE + \ 108 FLASH_PS_AREA_SIZE + \ 109 FLASH_UNUSED_AREA_SIZE + \ 110 FLASH_OTP_NV_COUNTERS_AREA_SIZE + \ 111 FLASH_AREA_SYSTEM_RESERVED_SIZE) 112 113 #if (FLASH_DATA_AREA_OFFSET + FLASH_DATA_AREA_SIZE) > (FLASH_TOTAL_SIZE) 114 #error "Out of Flash memory" 115 #endif 116 117 #define TFM_HAL_FLASH_PROGRAM_UNIT 0x1 118 119 /* Protected Storage (PS) Service definitions 120 * Note: Further documentation of these definitions can be found in the 121 * TF-M PS Integration Guide. 122 */ 123 #define TFM_HAL_PS_FLASH_DRIVER Driver_FLASH0 124 125 /* In this target the CMSIS driver requires only the offset from the base 126 * address instead of the full memory address. 127 */ 128 /* Base address of dedicated flash area for PS */ 129 #define TFM_HAL_PS_FLASH_AREA_ADDR FLASH_PS_AREA_OFFSET 130 /* Size of dedicated flash area for PS */ 131 #define TFM_HAL_PS_FLASH_AREA_SIZE FLASH_PS_AREA_SIZE 132 #define PS_RAM_FS_SIZE TFM_HAL_PS_FLASH_AREA_SIZE 133 /* Number of physical erase sectors per logical FS block */ 134 #define TFM_HAL_PS_SECTORS_PER_BLOCK 8 135 /* Smallest flash programmable unit in bytes */ 136 #define TFM_HAL_PS_PROGRAM_UNIT 0x1 137 138 /* Internal Trusted Storage (ITS) Service definitions 139 * Note: Further documentation of these definitions can be found in the 140 * TF-M ITS Integration Guide. The ITS should be in the internal flash, but is 141 * allocated in the external flash just for development platforms that don't 142 * have internal flash available. 143 */ 144 #define TFM_HAL_ITS_FLASH_DRIVER Driver_FLASH0 145 146 /* In this target the CMSIS driver requires only the offset from the base 147 * address instead of the full memory address. 148 */ 149 /* Base address of dedicated flash area for ITS */ 150 #define TFM_HAL_ITS_FLASH_AREA_ADDR FLASH_ITS_AREA_OFFSET 151 /* Size of dedicated flash area for ITS */ 152 #define TFM_HAL_ITS_FLASH_AREA_SIZE FLASH_ITS_AREA_SIZE 153 #define ITS_RAM_FS_SIZE TFM_HAL_ITS_FLASH_AREA_SIZE 154 /* Number of physical erase sectors per logical FS block */ 155 #define TFM_HAL_ITS_SECTORS_PER_BLOCK 8 156 /* Smallest flash programmable unit in bytes */ 157 #define TFM_HAL_ITS_PROGRAM_UNIT 0x1 158 /* Decrease flash wear slightly, at the cost of increased ITS service memory */ 159 #define ITS_MAX_BLOCK_DATA_COPY 512 160 161 /* OTP / NV counter definitions */ 162 #define TFM_OTP_NV_COUNTERS_AREA_SIZE (FLASH_OTP_NV_COUNTERS_AREA_SIZE / 2) 163 #define TFM_OTP_NV_COUNTERS_AREA_ADDR FLASH_OTP_NV_COUNTERS_AREA_OFFSET 164 #define TFM_OTP_NV_COUNTERS_SECTOR_SIZE FLASH_OTP_NV_COUNTERS_SECTOR_SIZE 165 #define TFM_OTP_NV_COUNTERS_BACKUP_AREA_ADDR (TFM_OTP_NV_COUNTERS_AREA_ADDR + \ 166 TFM_OTP_NV_COUNTERS_AREA_SIZE) 167 168 169 /* Use Flash to store Code data */ 170 #define S_ROM_ALIAS_BASE (0x10000000) 171 #define NS_ROM_ALIAS_BASE (0x10000000) 172 173 /* Use SRAM to store RW data */ 174 #define S_RAM_ALIAS_BASE (0x08000000) 175 #define NS_RAM_ALIAS_BASE (0x08000000) 176 177 #endif /* __FLASH_LAYOUT_H__ */ 178