1 /* 2 * Copyright (c) 2017-2022 Arm Limited. All rights reserved. 3 * Copyright (c) 2020 Nuvoton Technology Corp. 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 __REGION_DEFS_H__ 19 #define __REGION_DEFS_H__ 20 21 #include "flash_layout.h" 22 23 #define BL2_HEAP_SIZE (0x0001000) 24 #define BL2_MSP_STACK_SIZE (0x0001800) 25 26 #ifdef ENABLE_HEAP 27 #define S_HEAP_SIZE (0x0000200) 28 #endif 29 30 #define S_MSP_STACK_SIZE (0x0000800) 31 #define S_PSP_STACK_SIZE (0x0000800) 32 33 #define NS_HEAP_SIZE (0x0001000) 34 #define NS_STACK_SIZE (0x0001000) 35 36 /* MPC granularity is 128 KB on AN519 MPS2 FPGA image. Alignment 37 * of partitions is defined in accordance with this constraint. 38 */ 39 40 #ifdef BL2 41 #ifndef LINK_TO_SECONDARY_PARTITION 42 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET) 43 #define S_IMAGE_SECONDARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET) 44 #else 45 #error "No secondary partition supported!" 46 #endif /* !LINK_TO_SECONDARY_PARTITION */ 47 #else 48 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (0x0) 49 #endif /* BL2 */ 50 51 #ifndef LINK_TO_SECONDARY_PARTITION 52 #define NS_IMAGE_PRIMARY_PARTITION_OFFSET (0x80000) 53 #else 54 #error "No secondary partition supported!" 55 #endif /* !LINK_TO_SECONDARY_PARTITION */ 56 57 /* Boot partition structure if MCUBoot is used: 58 * 0x0_0000 Bootloader header 59 * 0x0_0400 Image area 60 * 0x7_0000 Trailer 61 */ 62 /* IMAGE_CODE_SIZE is the space available for the software binary image. 63 * It is less than the FLASH_S_PARTITION_SIZE + FLASH_NS_PARTITION_SIZE 64 * because we reserve space for the image header and trailer introduced 65 * by the bootloader. 66 */ 67 68 #define IMAGE_S_CODE_SIZE (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE) 69 #define IMAGE_NS_CODE_SIZE (FLASH_NS_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE) 70 71 /* Alias definitions for secure and non-secure areas*/ 72 #define S_ROM_ALIAS(x) (S_ROM_ALIAS_BASE + (x)) 73 #define NS_ROM_ALIAS(x) (NS_ROM_ALIAS_BASE + (x)) 74 75 #define S_RAM_ALIAS(x) (S_RAM_ALIAS_BASE + (x)) 76 #define NS_RAM_ALIAS(x) (NS_RAM_ALIAS_BASE + (x)) 77 78 /* Secure regions */ 79 #define S_IMAGE_PRIMARY_AREA_OFFSET \ 80 (S_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE) /* 0x8400 */ 81 #define S_CODE_START (S_ROM_ALIAS(S_IMAGE_PRIMARY_AREA_OFFSET)) /* 0x8400 */ 82 #define S_CODE_SIZE (IMAGE_S_CODE_SIZE) 83 #define S_CODE_LIMIT (S_CODE_START + S_CODE_SIZE - 1) 84 85 #define S_DATA_START (S_RAM_ALIAS(0x0)) 86 #define S_DATA_SIZE (80 * 1024) 87 #define S_DATA_LIMIT (S_DATA_START + S_DATA_SIZE - 1) 88 89 /* Size of vector table: 117 interrupt handlers + 4 bytes MPS initial value */ 90 #define S_CODE_VECTOR_TABLE_SIZE (0x1D8) 91 92 /* Non-secure regions */ 93 #define NS_IMAGE_PRIMARY_AREA_OFFSET \ 94 (NS_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE) 95 #define NS_CODE_START (NS_ROM_ALIAS(NS_IMAGE_PRIMARY_AREA_OFFSET)) 96 #define NS_CODE_SIZE (IMAGE_NS_CODE_SIZE) 97 #define NS_CODE_LIMIT (NS_CODE_START + NS_CODE_SIZE - 1) 98 99 #define NS_DATA_START (NS_RAM_ALIAS(S_DATA_SIZE)) 100 #define NS_DATA_SIZE (TOTAL_RAM_SIZE - S_DATA_SIZE) 101 #define NS_DATA_LIMIT (NS_DATA_START + NS_DATA_SIZE - 1) 102 103 /* NS partition information is used for MPC and SAU configuration */ 104 #define NS_PARTITION_START \ 105 (NS_ROM_ALIAS(NS_IMAGE_PRIMARY_PARTITION_OFFSET)) 106 #define NS_PARTITION_SIZE (FLASH_NS_PARTITION_SIZE) 107 108 /* Secondary partition for new images in case of firmware upgrade */ 109 #define SECONDARY_PARTITION_START \ 110 (NS_ROM_ALIAS(S_IMAGE_SECONDARY_PARTITION_OFFSET)) 111 #define SECONDARY_PARTITION_SIZE (FLASH_S_PARTITION_SIZE + \ 112 FLASH_NS_PARTITION_SIZE) 113 114 #ifdef BL2 115 /* Bootloader regions */ 116 #define BL2_CODE_START (S_ROM_ALIAS(FLASH_AREA_BL2_OFFSET)) 117 #define BL2_CODE_SIZE (FLASH_AREA_BL2_SIZE) 118 #define BL2_CODE_LIMIT (BL2_CODE_START + BL2_CODE_SIZE - 1) 119 120 #define BL2_DATA_START (S_RAM_ALIAS(0x0)) 121 #define BL2_DATA_SIZE (TOTAL_RAM_SIZE) 122 #define BL2_DATA_LIMIT (BL2_DATA_START + BL2_DATA_SIZE - 1) 123 #endif /* BL2 */ 124 125 /* Shared data area between bootloader and runtime firmware. 126 * Shared data area is allocated at the beginning of the RAM, it is overlapping 127 * with TF-M Secure code's MSP stack 128 */ 129 #define BOOT_TFM_SHARED_DATA_BASE S_RAM_ALIAS_BASE 130 #define BOOT_TFM_SHARED_DATA_SIZE (0x400) 131 #define BOOT_TFM_SHARED_DATA_LIMIT (BOOT_TFM_SHARED_DATA_BASE + BOOT_TFM_SHARED_DATA_SIZE - 1) 132 133 #endif /* __REGION_DEFS_H__ */ 134