1 /* 2 * Copyright (c) 2023-2024, 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 #include "bl2_image_id.h" 21 #include "platform_base_address.h" 22 #include "size_defs.h" 23 24 /* Flash layout on RSE with BL2 (multiple image boot): 25 * 26 * Offset Image (Size) 27 * 0x0 BL2 - MCUBoot primary slot (128 KB) 28 * 0x2_0000 BL2 - MCUBoot secondary slot (128 KB) 29 * 0x4_0000 Secure image primary slot (384 KB) 30 * 0xA_0000 Non-secure image primary slot (384 KB) 31 * 0x10_0000 Secure image secondary slot (384 KB) 32 * 0x16_0000 Non-secure image secondary slot (384 KB) 33 * 0x1C_0000 SCP primary slot (512 KB) 34 * 0x24_0000 SCP secondary slot (512 KB) 35 * 0x2C_0000 MCP primary slot (512 KB) 36 * 0x34_0000 MCP secondary slot (512 KB) 37 * 0x3C_0000 LCP primary slot (64 KB) 38 * 0x3D_0000 LCP secondary slot (64 KB) 39 * 0x3E_0000 AP BL1 primary slot (512 KB) 40 * 0x46_0000 AP BL1 secondary slot (512 KB) 41 */ 42 43 /* 44 * This header file is included from linker scatter file as well, where only a 45 * limited C constructs are allowed. Therefore it is not possible to include 46 * here the platform_retarget.h to access flash related defines. To resolve this 47 * some of the values are redefined here with different names, these are marked 48 * with comment. 49 */ 50 51 /* Size of a Secure and of a Non-secure image */ 52 #define FLASH_BL2_PARTITION_SIZE (SIZE_DEF_BL2_IMAGE) /* BL2 partition */ 53 #define FLASH_S_PARTITION_SIZE (SIZE_DEF_S_IMAGE) /* S partition */ 54 #define FLASH_NS_PARTITION_SIZE (SIZE_DEF_NS_IMAGE) /* NS partition */ 55 #define FLASH_SCP_PARTITION_SIZE (SIZE_DEF_SCP_IMAGE) /* SCP partition */ 56 #define FLASH_MCP_PARTITION_SIZE (SIZE_DEF_MCP_IMAGE) /* MCP partition */ 57 #define FLASH_LCP_PARTITION_SIZE (SIZE_DEF_LCP_IMAGE) /* LCP partition */ 58 #define FLASH_AP_BL1_PARTITION_SIZE (SIZE_DEF_AP_BL1_IMAGE) /* AP BL1 partition */ 59 #define FLASH_MAX_PARTITION_SIZE ((FLASH_S_PARTITION_SIZE > \ 60 FLASH_NS_PARTITION_SIZE) ? \ 61 FLASH_S_PARTITION_SIZE : \ 62 FLASH_NS_PARTITION_SIZE) 63 64 /* Sector size of the flash hardware; same as FLASH0_SECTOR_SIZE */ 65 #define FLASH_AREA_IMAGE_SECTOR_SIZE (0x1000) /* 4 KB */ 66 /* Same as FLASH0_SIZE */ 67 #define FLASH_TOTAL_SIZE (BOOT_FLASH_SIZE) 68 69 /* Flash layout info for BL2 bootloader */ 70 /* Same as FLASH0_BASE_S */ 71 #define FLASH_BASE_ADDRESS (BOOT_FLASH_BASE_S) 72 #define FLASH_BL1_BASE_ADDRESS (FLASH_BASE_ADDRESS) 73 74 /* 75 * Offset and size definitions of the flash partitions that are handled by the 76 * bootloader. The image swapping is done between IMAGE_PRIMARY and 77 * IMAGE_SECONDARY, SCRATCH is used as a temporary storage during image 78 * swapping. 79 */ 80 81 /* BL2 primary slot */ 82 #define FLASH_AREA_0_ID (1) 83 #define FLASH_AREA_0_OFFSET (0) 84 #define FLASH_AREA_0_SIZE (FLASH_BL2_PARTITION_SIZE) 85 /* BL2 secondary slot */ 86 #define FLASH_AREA_1_ID (FLASH_AREA_0_ID + 1) 87 #define FLASH_AREA_1_OFFSET (FLASH_AREA_0_OFFSET + FLASH_AREA_0_SIZE) 88 #define FLASH_AREA_1_SIZE (FLASH_BL2_PARTITION_SIZE) 89 90 /* Secure image primary slot. */ 91 #define FLASH_AREA_2_ID (FLASH_AREA_1_ID + 1) 92 #define FLASH_AREA_2_OFFSET (FLASH_AREA_1_OFFSET + FLASH_AREA_1_SIZE) 93 #define FLASH_AREA_2_SIZE (FLASH_S_PARTITION_SIZE) 94 /* Non-secure image primary slot. */ 95 #define FLASH_AREA_3_ID (FLASH_AREA_2_ID + 1) 96 #define FLASH_AREA_3_OFFSET (FLASH_AREA_2_OFFSET + FLASH_AREA_2_SIZE) 97 #define FLASH_AREA_3_SIZE (FLASH_NS_PARTITION_SIZE) 98 /* Secure image secondary slot. */ 99 #define FLASH_AREA_4_ID (FLASH_AREA_3_ID + 1) 100 #define FLASH_AREA_4_OFFSET (FLASH_AREA_3_OFFSET + FLASH_AREA_3_SIZE) 101 #define FLASH_AREA_4_SIZE (FLASH_S_PARTITION_SIZE) 102 /* Non-secure image secondary slot. */ 103 #define FLASH_AREA_5_ID (FLASH_AREA_4_ID + 1) 104 #define FLASH_AREA_5_OFFSET (FLASH_AREA_4_OFFSET + FLASH_AREA_4_SIZE) 105 #define FLASH_AREA_5_SIZE (FLASH_NS_PARTITION_SIZE) 106 107 /* SCP image primary slot */ 108 #define FLASH_AREA_6_ID (FLASH_AREA_5_ID + 1) 109 #define FLASH_AREA_6_OFFSET (FLASH_AREA_5_OFFSET + FLASH_AREA_5_SIZE) 110 #define FLASH_AREA_6_SIZE (FLASH_SCP_PARTITION_SIZE) 111 /* SCP image primary slot */ 112 #define FLASH_AREA_7_ID (FLASH_AREA_6_ID + 1) 113 #define FLASH_AREA_7_OFFSET (FLASH_AREA_6_OFFSET + FLASH_AREA_6_SIZE) 114 #define FLASH_AREA_7_SIZE (FLASH_SCP_PARTITION_SIZE) 115 /* MCP image secondary slot */ 116 #define FLASH_AREA_8_ID (FLASH_AREA_7_ID + 1) 117 #define FLASH_AREA_8_OFFSET (FLASH_AREA_7_OFFSET + FLASH_AREA_7_SIZE) 118 #define FLASH_AREA_8_SIZE (FLASH_MCP_PARTITION_SIZE) 119 /* MCP image secondary slot */ 120 #define FLASH_AREA_9_ID (FLASH_AREA_8_ID + 1) 121 #define FLASH_AREA_9_OFFSET (FLASH_AREA_8_OFFSET + FLASH_AREA_8_SIZE) 122 #define FLASH_AREA_9_SIZE (FLASH_MCP_PARTITION_SIZE) 123 /* LCP image primary slot */ 124 #define FLASH_AREA_10_ID (FLASH_AREA_9_ID + 1) 125 #define FLASH_AREA_10_OFFSET (FLASH_AREA_9_OFFSET + FLASH_AREA_9_SIZE) 126 #define FLASH_AREA_10_SIZE (FLASH_LCP_PARTITION_SIZE) 127 /* LCP image secondary slot */ 128 #define FLASH_AREA_11_ID (FLASH_AREA_10_ID + 1) 129 #define FLASH_AREA_11_OFFSET (FLASH_AREA_10_OFFSET + FLASH_AREA_10_SIZE) 130 #define FLASH_AREA_11_SIZE (FLASH_LCP_PARTITION_SIZE) 131 /* AP BL1 image primary slot */ 132 #define FLASH_AREA_12_ID (FLASH_AREA_11_ID + 1) 133 #define FLASH_AREA_12_OFFSET (FLASH_AREA_11_OFFSET + FLASH_AREA_11_SIZE) 134 #define FLASH_AREA_12_SIZE (FLASH_AP_BL1_PARTITION_SIZE) 135 /* AP BL1 image secondary slot */ 136 #define FLASH_AREA_13_ID (FLASH_AREA_12_ID + 1) 137 #define FLASH_AREA_13_OFFSET (FLASH_AREA_12_OFFSET + FLASH_AREA_12_SIZE) 138 #define FLASH_AREA_13_SIZE (FLASH_AP_BL1_PARTITION_SIZE) 139 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 144 /* Check that all the images can fit in the Flash area. */ 145 #if (FLASH_AREA_13_OFFSET + FLASH_AREA_13_SIZE > FLASH_TOTAL_SIZE) 146 #error "Out of Flash memory!" 147 #endif 148 149 #define FLASH_AREA_IMAGE_PRIMARY(x) \ 150 (((x) == RSE_FIRMWARE_SECURE_ID) ? FLASH_AREA_2_ID : \ 151 ((x) == RSE_FIRMWARE_NON_SECURE_ID) ? FLASH_AREA_3_ID : \ 152 ((x) == RSE_FIRMWARE_SCP_ID) ? FLASH_AREA_6_ID : \ 153 ((x) == RSE_FIRMWARE_MCP_ID) ? FLASH_AREA_8_ID : \ 154 ((x) == RSE_FIRMWARE_LCP_ID) ? FLASH_AREA_10_ID : \ 155 ((x) == RSE_FIRMWARE_AP_BL1_ID) ? FLASH_AREA_12_ID : \ 156 255) 157 #define FLASH_AREA_IMAGE_SECONDARY(x) \ 158 (((x) == RSE_FIRMWARE_SECURE_ID) ? FLASH_AREA_4_ID : \ 159 ((x) == RSE_FIRMWARE_NON_SECURE_ID) ? FLASH_AREA_5_ID : \ 160 ((x) == RSE_FIRMWARE_SCP_ID) ? FLASH_AREA_7_ID : \ 161 ((x) == RSE_FIRMWARE_MCP_ID) ? FLASH_AREA_9_ID : \ 162 ((x) == RSE_FIRMWARE_LCP_ID) ? FLASH_AREA_11_ID : \ 163 ((x) == RSE_FIRMWARE_AP_BL1_ID) ? FLASH_AREA_13_ID : \ 164 255) 165 166 /* Scratch area is not used with RAM loading firmware upgrade */ 167 #define FLASH_AREA_IMAGE_SCRATCH 255 168 169 /* Offset and size definition in flash area used by assemble.py */ 170 #define SECURE_IMAGE_OFFSET (0x0) 171 #define SECURE_IMAGE_MAX_SIZE FLASH_S_PARTITION_SIZE 172 173 #define NON_SECURE_IMAGE_OFFSET (SECURE_IMAGE_OFFSET + \ 174 SECURE_IMAGE_MAX_SIZE) 175 #define NON_SECURE_IMAGE_MAX_SIZE FLASH_NS_PARTITION_SIZE 176 177 #define S_IMAGE_LOAD_ADDRESS (VM0_BASE_S) 178 #define NS_IMAGE_LOAD_ADDRESS (VM1_BASE_S + VM1_SIZE - \ 179 FLASH_NS_PARTITION_SIZE) 180 181 #define FLASH_SIC_TABLE_SIZE 0 182 183 /* 184 * Flash device name used by BL2 185 * Name is defined in flash driver file: Driver_Flash.c 186 */ 187 #define FLASH_DEV_NAME Driver_FLASH0 188 #define FLASH_DEV_NAME_BL1 FLASH_DEV_NAME 189 190 /* Smallest flash programmable unit in bytes */ 191 #define TFM_HAL_FLASH_PROGRAM_UNIT (0x1) 192 193 #endif /* __FLASH_LAYOUT_H__ */ 194