1 /* 2 * Copyright (c) 2019-2022 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 __REGION_DEFS_H__ 18 #define __REGION_DEFS_H__ 19 20 #include "flash_layout.h" 21 22 #define BL2_HEAP_SIZE (0x0001000) 23 #define BL2_MSP_STACK_SIZE (0x0001800) 24 25 #ifdef ENABLE_HEAP 26 #define S_HEAP_SIZE (0x0000200) 27 #endif 28 29 #define S_MSP_STACK_SIZE (0x0000800) 30 #define S_PSP_STACK_SIZE (0x0000800) 31 32 #define NS_HEAP_SIZE (0x0001000) 33 #define NS_STACK_SIZE (0x00001E0) 34 35 /* This size of buffer is big enough to store an attestation 36 * token produced by initial attestation service 37 */ 38 #define PSA_INITIAL_ATTEST_TOKEN_MAX_SIZE (0x250) 39 40 /* This configuration uses QSPI for code memory and ISRAM0-3 as data 41 * memory. 42 */ 43 44 #ifdef BL2 45 #ifndef LINK_TO_SECONDARY_PARTITION 46 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET) 47 #define S_IMAGE_SECONDARY_PARTITION_OFFSET (FLASH_AREA_2_OFFSET) 48 #else 49 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_2_OFFSET) 50 #define S_IMAGE_SECONDARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET) 51 #endif /* !LINK_TO_SECONDARY_PARTITION */ 52 #else 53 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (0x0) 54 #endif /* BL2 */ 55 56 #ifndef LINK_TO_SECONDARY_PARTITION 57 #define NS_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET \ 58 + FLASH_S_PARTITION_SIZE) 59 #else 60 #define NS_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_2_OFFSET \ 61 + FLASH_S_PARTITION_SIZE) 62 #endif /* !LINK_TO_SECONDARY_PARTITION */ 63 64 #if (!defined(MCUBOOT_IMAGE_NUMBER) || (MCUBOOT_IMAGE_NUMBER == 1)) && \ 65 (NS_IMAGE_PRIMARY_PARTITION_OFFSET > S_IMAGE_PRIMARY_PARTITION_OFFSET) 66 /* If secure image and nonsecure image are concatenated, and nonsecure image 67 * locates at the higher memory range, then the secure image does not need 68 * the trailer area. 69 */ 70 #define IMAGE_S_CODE_SIZE \ 71 (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE) 72 #else 73 #define IMAGE_S_CODE_SIZE \ 74 (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE) 75 #endif 76 77 #define IMAGE_NS_CODE_SIZE \ 78 (FLASH_NS_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE) 79 80 /* Alias definitions for secure and non-secure areas*/ 81 #define S_ROM_ALIAS(x) (S_ROM_ALIAS_BASE + (x)) 82 #define NS_ROM_ALIAS(x) (NS_ROM_ALIAS_BASE + (x)) 83 84 #define S_RAM_ALIAS(x) (S_RAM_ALIAS_BASE + (x)) 85 #define NS_RAM_ALIAS(x) (NS_RAM_ALIAS_BASE + (x)) 86 87 /* Secure regions */ 88 #define S_IMAGE_PRIMARY_AREA_OFFSET \ 89 (S_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE) 90 #define S_CODE_START (S_ROM_ALIAS(S_IMAGE_PRIMARY_AREA_OFFSET)) 91 #define S_CODE_SIZE (IMAGE_S_CODE_SIZE) 92 #define S_CODE_LIMIT (S_CODE_START + S_CODE_SIZE - 1) 93 94 /* ISRAM0 and ISRAM1 are assigned to Secure data */ 95 #define S_DATA_START (S_RAM_ALIAS(0x0)) 96 #define S_DATA_SIZE (TOTAL_RAM_SIZE / 2 + (TOTAL_RAM_SIZE / 4)) 97 #define S_DATA_LIMIT (S_DATA_START + S_DATA_SIZE - 1) 98 99 /* Size of vector table: 143 interrupt handlers + 4 bytes MPS initial value */ 100 #define S_CODE_VECTOR_TABLE_SIZE (0x240) 101 102 /* Non-secure regions */ 103 #define NS_IMAGE_PRIMARY_AREA_OFFSET \ 104 (NS_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE) 105 #define NS_CODE_START (NS_ROM_ALIAS(NS_IMAGE_PRIMARY_AREA_OFFSET)) 106 #define NS_CODE_SIZE (IMAGE_NS_CODE_SIZE) 107 #define NS_CODE_LIMIT (NS_CODE_START + NS_CODE_SIZE - 1) 108 109 /* ISRAM2 and ISRAM3 are assigned to Secure data */ 110 #define NS_DATA_START (NS_RAM_ALIAS(S_DATA_SIZE)) 111 #define NS_DATA_SIZE (TOTAL_RAM_SIZE - S_DATA_SIZE) 112 #define NS_DATA_LIMIT (NS_DATA_START + NS_DATA_SIZE - 1) 113 114 /* NS partition information is used for MPC and SAU configuration */ 115 #define NS_PARTITION_START \ 116 (NS_ROM_ALIAS(NS_IMAGE_PRIMARY_PARTITION_OFFSET)) 117 #define NS_PARTITION_SIZE (FLASH_NS_PARTITION_SIZE) 118 119 #ifdef BL2 120 #define SECONDARY_PARTITION_START \ 121 (NS_ROM_ALIAS(S_IMAGE_SECONDARY_PARTITION_OFFSET)) 122 #define SECONDARY_PARTITION_SIZE (FLASH_S_PARTITION_SIZE + \ 123 FLASH_NS_PARTITION_SIZE) 124 #define SECONDARY_PARTITION_LIMIT (SECONDARY_PARTITION_START + \ 125 SECONDARY_PARTITION_SIZE - 1) 126 127 #define BL2_ROM_ALIAS_BASE (0x0) 128 #define BL2_ROM_ALIAS(x) (BL2_ROM_ALIAS_BASE + (x)) 129 130 /* Bootloader regions */ 131 #define BL2_CODE_START (BL2_ROM_ALIAS(FLASH_AREA_BL2_OFFSET)) 132 #define BL2_CODE_SIZE (FLASH_AREA_BL2_SIZE) 133 #define BL2_CODE_LIMIT (BL2_CODE_START + BL2_CODE_SIZE - 1) 134 135 #define BL2_DATA_START (S_RAM_ALIAS(0x0)) 136 #define BL2_DATA_SIZE (TOTAL_RAM_SIZE) 137 #define BL2_DATA_LIMIT (BL2_DATA_START + BL2_DATA_SIZE - 1) 138 #endif /* BL2 */ 139 140 /* Shared data area between bootloader and runtime firmware. 141 * Shared data area is allocated at the beginning of the RAM, it is overlapping 142 * with TF-M Secure code's MSP stack 143 */ 144 #define BOOT_TFM_SHARED_DATA_BASE S_RAM_ALIAS_BASE 145 #define BOOT_TFM_SHARED_DATA_SIZE (0x400) 146 #define BOOT_TFM_SHARED_DATA_LIMIT (BOOT_TFM_SHARED_DATA_BASE + \ 147 BOOT_TFM_SHARED_DATA_SIZE - 1) 148 149 #endif /* __REGION_DEFS_H__ */ 150