1 /*
2  * Copyright (c) 2017-2022 ARM Limited
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 #include "flash_layout.h"
20 
21 #define BL2_HEAP_SIZE           0x0001000
22 #define BL2_MSP_STACK_SIZE      0x0001800
23 
24 #ifdef ENABLE_HEAP
25     #define S_HEAP_SIZE             (0x0000200)
26 #endif
27 
28 #define S_MSP_STACK_SIZE        0x0000800
29 #define S_PSP_STACK_SIZE        0x0000800
30 
31 #define NS_HEAP_SIZE            0x0001000
32 #define NS_STACK_SIZE           0x0001000
33 
34 #define _SRAM2_TOP              (0x40000) /* 256Kbytes */
35 #define _SRAM1_SIZE_MAX         (0x30000)  /*!< SRAM1=192k*/
36 #define _SRAM2_SIZE_MAX         (0xfc00)  /*!< SRAM2=64k -0x400 */
37 /* Flash and internal SRAMs base addresses - Non secure aliased */
38 #define _FLASH_BASE_NS          (0x08000000) /*!< FLASH(up to 512 KB) base address */
39 #define _SRAM1_BASE_NS          (0x20000000) /*!< SRAM1(up to 192 KB) base address */
40 #define _SRAM2_BASE_NS          (0x20030000) /*!< SRAM2(64 KB) base address */
41 
42 /* Flash and internal SRAMs base addresses - Secure aliased */
43 #define _FLASH_BASE_S           (0x0C000000) /*!< FLASH(up to 512 KB) base address */
44 #define _SRAM1_BASE_S           (0x30000000) /*!< SRAM1(up to 192 KB) base address */
45 #define _SRAM2_BASE_S           (0x30030000) /*!< SRAM2(64 KB) base address */
46 
47 
48 #define TOTAL_ROM_SIZE          FLASH_TOTAL_SIZE
49 #define TOTAL_RAM_SIZE          (_SRAM1_SIZE_MAX+_SRAM2_SIZE_MAX )
50 /* 192 + 64 Kbytes - BOOT info */
51 /* boot info are placed and locked at top of SRAM2  */
52 #define S_TOTAL_RAM_SIZE        (0x1fc00 ) /*! size require for Secure part */
53 #define NS_TOTAL_RAM_SIZE       (TOTAL_RAM_SIZE - S_TOTAL_RAM_SIZE)
54 
55 #ifdef BL2
56 #ifndef LINK_TO_SECONDARY_PARTITION
57 #define  S_IMAGE_PRIMARY_PARTITION_OFFSET   (FLASH_AREA_0_OFFSET)
58 #define  S_IMAGE_SECONDARY_PARTITION_OFFSET (FLASH_AREA_2_OFFSET)
59 #else
60 #define  S_IMAGE_PRIMARY_PARTITION_OFFSET   (FLASH_AREA_2_OFFSET)
61 #define  S_IMAGE_SECONDARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET)
62 #endif /* !LINK_TO_SECONDARY_PARTITION */
63 #else
64 #define  S_IMAGE_PRIMARY_PARTITION_OFFSET   (0x0)
65 #endif /* BL2 */
66 
67 
68 
69 /*
70  * Boot partition structure if MCUBoot is used:
71  * 0x0_0000 Bootloader header
72  * 0x0_0400 Image area
73  * 0x7_0000 Trailer
74  */
75 /* IMAGE_CODE_SIZE is the space available for the software binary image.
76  * It is less than the FLASH_PARTITION_SIZE because we reserve space
77  * for the image header and trailer introduced by the bootloader.
78  */
79 
80 #ifdef BL2
81 #ifndef LINK_TO_SECONDARY_PARTITION
82 #define S_IMAGE_PRIMARY_PARTITION_OFFSET    (FLASH_AREA_0_OFFSET)
83 #define S_IMAGE_SECONDARY_PARTITION_OFFSET  (FLASH_AREA_2_OFFSET)
84 #else
85 #define S_IMAGE_PRIMARY_PARTITION_OFFSET    (FLASH_AREA_2_OFFSET)
86 #define S_IMAGE_SECONDARY_PARTITION_OFFSET  (FLASH_AREA_0_OFFSET)
87 #endif /* !LINK_TO_SECONDARY_PARTITION */
88 #else
89 #define S_IMAGE_PRIMARY_PARTITION_OFFSET (0x0)
90 #endif /* BL2 */
91 #ifndef LINK_TO_SECONDARY_PARTITION
92 #define NS_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_0_OFFSET + FLASH_S_PARTITION_SIZE)
93 #else
94 #define NS_IMAGE_PRIMARY_PARTITION_OFFSET (FLASH_AREA_2_OFFSET + FLASH_S_PARTITION_SIZE)
95 #endif /* !LINK_TO_SECONDARY_PARTITION */
96 
97 #define IMAGE_S_CODE_SIZE \
98             (FLASH_S_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)
99 #define IMAGE_NS_CODE_SIZE \
100             (FLASH_NS_PARTITION_SIZE - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)
101 
102 /* Use SRAM1 memory to store Code data */
103 #define S_ROM_ALIAS_BASE                    (_FLASH_BASE_S)
104 #define NS_ROM_ALIAS_BASE                   (_FLASH_BASE_NS)
105 
106 
107 #define S_RAM_ALIAS_BASE                    (_SRAM1_BASE_S)
108 #define NS_RAM_ALIAS_BASE                   (_SRAM1_BASE_NS)
109 
110 /* Alias definitions for secure and non-secure areas*/
111 #define S_ROM_ALIAS(x)                      (S_ROM_ALIAS_BASE + (x))
112 #define NS_ROM_ALIAS(x)                     (NS_ROM_ALIAS_BASE + (x))
113 
114 #define S_RAM_ALIAS(x)                      (S_RAM_ALIAS_BASE + (x))
115 #define NS_RAM_ALIAS(x)                     (NS_RAM_ALIAS_BASE + (x))
116 
117 
118 #define S_IMAGE_PRIMARY_AREA_OFFSET         (S_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE)
119 #define S_CODE_START                        (S_ROM_ALIAS(S_IMAGE_PRIMARY_AREA_OFFSET))
120 
121 #define S_CODE_SIZE                         (IMAGE_S_CODE_SIZE)
122 #define S_CODE_LIMIT                        ((S_CODE_START + S_CODE_SIZE) -1)
123 
124 #define S_DATA_START                        (S_RAM_ALIAS(NS_TOTAL_RAM_SIZE))
125 #define S_DATA_SIZE                         (S_TOTAL_RAM_SIZE)
126 #define S_DATA_LIMIT                        (S_DATA_START + S_DATA_SIZE - 1)
127 
128 /* Size of vector table: 124 interrupt handlers + 4 bytes MPS initial value */
129 #define S_CODE_VECTOR_TABLE_SIZE    (0x1F4)
130 
131 /* Non-secure regions */
132 
133 /* Secure regions , the end of secure regions must be aligned on page size for dual bank 0x800*/
134 /* Offset and size definition in flash area, used by assemble.py
135  * 0x11400+0x33c00= 13000+34000 = 45000*/
136 
137 #define NS_IMAGE_PRIMARY_AREA_OFFSET        (NS_IMAGE_PRIMARY_PARTITION_OFFSET + BL2_HEADER_SIZE)
138 #define NS_CODE_START                       (NS_ROM_ALIAS(NS_IMAGE_PRIMARY_AREA_OFFSET))
139 #define NS_CODE_SIZE                        (IMAGE_NS_CODE_SIZE)
140 #define NS_CODE_LIMIT                       (NS_CODE_START + NS_CODE_SIZE - 1)
141 #define NS_DATA_START                       (NS_RAM_ALIAS(0))
142 #define NS_NO_INIT_DATA_SIZE                (0x100)
143 #define NS_DATA_SIZE                        (NS_TOTAL_RAM_SIZE)
144 #define NS_DATA_LIMIT                       (NS_DATA_START + NS_DATA_SIZE - 1)
145 
146 /* NS partition information is used for GTZC and SAU configuration */
147 #define NS_PARTITION_START                  (NS_CODE_START)
148 #define NS_PARTITION_SIZE                   (NS_CODE_SIZE)
149 
150 /* Secondary partition for new images/ in case of firmware upgrade */
151 #define SECONDARY_PARTITION_START           (NS_ROM_ALIAS(S_IMAGE_SECONDARY_PARTITION_OFFSET))
152 #define SECONDARY_PARTITION_SIZE            (FLASH_AREA_2_SIZE)
153 
154 #ifdef BL2
155 /* Personalized region */
156 #define PERSO_START                         (S_ROM_ALIAS(FLASH_AREA_PERSO_OFFSET))
157 #define PERSO_SIZE                          (FLASH_AREA_PERSO_SIZE)
158 #define PERSO_LIMIT                         (PERSO_START + PERSO_SIZE - 1)
159 
160 /* Bootloader region protected by hdp */
161 #define BL2_CODE_START                      (S_ROM_ALIAS(FLASH_AREA_BL2_OFFSET))
162 #define BL2_CODE_SIZE                       (FLASH_AREA_BL2_SIZE)
163 #define BL2_CODE_LIMIT                      (BL2_CODE_START + BL2_CODE_SIZE - 1)
164 
165 /* Bootloader region not protected by hdp */
166 #define BL2_NOHDP_CODE_START                (S_ROM_ALIAS(FLASH_AREA_BL2_NOHDP_OFFSET))
167 #define BL2_NOHDP_CODE_SIZE                 (FLASH_AREA_BL2_NOHDP_SIZE)
168 #define BL2_NOHDP_CODE_LIMIT                (BL2_NOHDP_CODE_START + BL2_NOHDP_CODE_SIZE - 1)
169 
170 /*  keep 256 bytes unsed to place while(1) for non secure to enable */
171 /*  regression from local tool with non secure attachement
172  *  This avoid blocking board in case of hardening error */
173 #define BL2_DATA_START                      (S_RAM_ALIAS(_SRAM1_SIZE_MAX))
174 #define BL2_DATA_SIZE                       (BOOT_TFM_SHARED_DATA_BASE - BL2_DATA_START)
175 #define BL2_DATA_LIMIT                      (BL2_DATA_START + BL2_DATA_SIZE - 1)
176 #endif /* BL2 */
177 
178 #endif /* __REGION_DEFS_H__ */
179