1;/*
2; * Copyright (c) 2018-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; * This file is derivative of CMSIS V5.00 gcc_arm.ld
18; */
19
20/* Linker script to configure memory regions. */
21/* This file will be run trough the pre-processor. */
22
23#include "region_defs.h"
24MEMORY
25{
26#if defined(BL2_NVMCNT_AREA_BASE)
27  FLASH_NVMCNT(rx) : ORIGIN = BL2_NVMCNT_AREA_BASE, LENGTH = BL2_NVMCNT_AREA_SIZE
28#endif
29  FLASH (rx)  : ORIGIN = BL2_CODE_START, LENGTH = BL2_CODE_SIZE
30  FLASH_NOHDP (rx)  : ORIGIN = BL2_NOHDP_CODE_START, LENGTH = BL2_NOHDP_CODE_SIZE
31#if defined(BL2_OTP_AREA_BASE)
32  FLASH_OTP(rx) : ORIGIN = BL2_OTP_AREA_BASE, LENGTH = BL2_OTP_AREA_SIZE
33#endif
34#if defined(BL2_NVM_AREA_BASE)
35  FLASH_NVM(rx) : ORIGIN = BL2_NVM_AREA_BASE, LENGTH = BL2_NVM_AREA_SIZE
36#endif
37  RAM   (rwx) : ORIGIN = BL2_DATA_START, LENGTH = BL2_DATA_SIZE
38}
39
40__heap_size__  = BL2_HEAP_SIZE;
41__msp_stack_size__ = BL2_MSP_STACK_SIZE;
42
43ENTRY(Reset_Handler)
44
45SECTIONS
46{
47
48#if defined(BL2_OTP_AREA_BASE)
49    .BL2_OTP :
50    {
51       KEEP(*(.BL2_OTP_Const))
52    } > FLASH_OTP
53#endif
54
55#if defined(BL2_NVM_AREA_BASE)
56    .BL2_NVM :
57    {
58        KEEP(*(.BL2_NVM_Const))
59    } > FLASH_NVM
60#endif
61
62#if defined(BL2_NVMCNT_AREA_BASE)
63    .BL2_NVMCNT :
64    {
65        KEEP(*(.BL2_NVMCNT_Const))
66    } > FLASH_NVMCNT
67#endif
68
69    .BL2_NoHdp_Code :
70    {
71        KEEP(*(.BL2_NoHdp_Data))
72        KEEP(*(.BL2_NoHdp_Code))
73        *mpu_armv8m_drv.o (.text* .rodata*)
74        KEEP(*(.BL2_Error_Code))
75        __hdp_end__ = .;
76    } > FLASH_NOHDP
77
78    .text (BL2_CODE_START) (READONLY) :
79    {
80
81        KEEP(*(.vectors))
82        __Vectors_End = .;
83        __Vectors_Size = __Vectors_End - __Vectors;
84        __end__ = .;
85
86        *(.text*)
87
88        . = ALIGN(4);
89        /* preinit data */
90        PROVIDE_HIDDEN (__preinit_array_start = .);
91        KEEP(*(.preinit_array))
92        PROVIDE_HIDDEN (__preinit_array_end = .);
93
94        . = ALIGN(4);
95        /* init data */
96        PROVIDE_HIDDEN (__init_array_start = .);
97        KEEP(*(SORT(.init_array.*)))
98        KEEP(*(.init_array))
99        PROVIDE_HIDDEN (__init_array_end = .);
100
101        . = ALIGN(4);
102        /* finit data */
103        PROVIDE_HIDDEN (__fini_array_start = .);
104        KEEP(*(SORT(.fini_array.*)))
105        KEEP(*(.fini_array))
106        PROVIDE_HIDDEN (__fini_array_end = .);
107
108        /* .copy.table */
109        . = ALIGN(4);
110        __copy_table_start__ = .;
111        LONG (__etext)
112        LONG (__data_start__)
113        LONG ((__data_end__ - __data_start__) / 4)
114        LONG (DEFINED(__etext2) ? __etext2 : 0)
115        LONG (DEFINED(__data2_start__) ? __data2_start__ : 0)
116        LONG (DEFINED(__data2_start__) ? ((__data2_end__ - __data2_start__) / 4) : 0)
117        __copy_table_end__ = .;
118
119        /* .zero.table */
120        . = ALIGN(4);
121        __zero_table_start__ = .;
122        LONG (__bss_start__)
123        LONG ((__bss_end__ - __bss_start__) / 4)
124        LONG (DEFINED(__bss2_start__) ? __bss2_start__ : 0)
125        LONG (DEFINED(__bss2_start__) ? ((__bss2_end__ - __bss2_start__) / 4) : 0)
126        __zero_table_end__ = .;
127
128        KEEP(*(.init))
129        KEEP(*(.fini))
130
131        /* .ctors */
132        *crtbegin.o(.ctors)
133        *crtbegin?.o(.ctors)
134        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
135        *(SORT(.ctors.*))
136        *(.ctors)
137
138        /* .dtors */
139         *crtbegin.o(.dtors)
140         *crtbegin?.o(.dtors)
141         *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
142         *(SORT(.dtors.*))
143         *(.dtors)
144
145        *(.rodata*)
146
147        KEEP(*(.eh_frame*))
148    } > FLASH
149
150    .ARM.extab :
151    {
152        *(.ARM.extab* .gnu.linkonce.armextab.*)
153    } > FLASH
154
155    __exidx_start = .;
156    .ARM.exidx :
157    {
158        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
159    } > FLASH
160    __exidx_end = .;
161
162    __etext = ALIGN(4);
163
164    .data : AT (__etext)
165    {
166        __data_start__ = .;
167        *(vtable)
168        *(.data*)
169
170        KEEP(*(.jcr*))
171        . = ALIGN(4);
172        /* All data end */
173        __data_end__ = .;
174
175    } > RAM
176    Image$$ER_CODE$$Base = __Vectors ;
177    Image$$ER_CODE$$Limit = __etext + + SIZEOF(.data);
178    .bss :
179    {
180        . = ALIGN(4);
181        __bss_start__ = .;
182        *(.bss*)
183        *(COMMON)
184        . = ALIGN(4);
185        __bss_end__ = .;
186    } > RAM
187
188    bss_size = __bss_end__ - __bss_start__;
189
190    .msp_stack :
191    {
192        . = ALIGN(8);
193        KEEP(*(.psp_stack*))
194        . += __msp_stack_size__;
195    } > RAM
196    Image$$ARM_LIB_STACK$$ZI$$Limit = ADDR(.msp_stack) + SIZEOF(.msp_stack);
197    Image$$ARM_LIB_STACK$$ZI$$Base = ADDR(.msp_stack) ;
198
199    .heap :
200    {
201        . = ALIGN(8);
202        __end__ = .;
203        PROVIDE(end = .);
204        __HeapBase = .;
205        . += __heap_size__;
206        __HeapLimit = .;
207        __heap_limit = .; /* Add for _sbrk */
208    } > RAM
209
210    PROVIDE(__stack = Image$$ARM_LIB_STACK$$ZI$$Limit);
211}
212