blob: e5c2a14faf631c3f411f5de609058a89edad4388 [file] [log] [blame]
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
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__STACK_SIZE = 0x00060000;
19__HEAP_SIZE = 0x000f0000;
20
21/* System memory brief */
22MEMORY
23{
24 ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
25 DTCM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000
26 BRAM (rwx) : ORIGIN = 0x11000000, LENGTH = 0x00200000
27 SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00400000
28 DDR (rwx) : ORIGIN = 0x70000000, LENGTH = 0x02000000
Kshitij Sisodiaaa5e1f62021-09-24 14:42:08 +010029
30 /* Dynamic load regions declared for use by FVP only
31 * These regions are mentioned in the CMake subsystem profile.
32 * Do not change the addresses here in isolation. */
33 DDR_dynamic_model (rx) : ORIGIN = 0x90000000, LENGTH = 0x02000000
34 DDR_dynamic_ifm (rx) : ORIGIN = 0x92000000, LENGTH = 0x01000000
35 DDR_dynamic_ofm (rx) : ORIGIN = 0x93000000, LENGTH = 0x01000000
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010036}
37
38/* Linker script to place sections and symbol values. Should be used together
39 * with other linker script that defines memory regions ITCM and RAM.
40 * It references following symbols, which must be defined in code:
41 * Reset_Handler : Entry of reset handler
42 *
43 * It defines following symbols, which code can use without definition:
44 * __exidx_start
45 * __exidx_end
46 * __copy_table_start__
47 * __copy_table_end__
48 * __zero_table_start__
49 * __zero_table_end__
50 * __etext
51 * __data_start__
52 * __preinit_array_start
53 * __preinit_array_end
54 * __init_array_start
55 * __init_array_end
56 * __fini_array_start
57 * __fini_array_end
58 * __data_end__
59 * __bss_start__
60 * __bss_end__
61 * __end__
62 * end
63 * __HeapLimit
64 * __StackLimit
65 * __StackTop
66 * __stack
67 */
68ENTRY(Reset_Handler)
69
70SECTIONS
71{
72 .text.at_itcm :
73 {
74 KEEP(*(.vectors))
Richard Burton0d110592021-08-12 17:26:30 +010075
76 /**
77 * All code goes here, with one exception of
78 * all_ops_resolver object file. This code
79 * instead placed on BRAM. See comment in the
80 * BRAM section for details.
81 **/
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010082 *(EXCLUDE_FILE(*all_ops_resolver.o *hal.c.obj) .text*)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010083
84 KEEP(*(.init))
85 KEEP(*(.fini))
86
87 /* .ctors */
88 *crtbegin.o(.ctors)
89 *crtbegin?.o(.ctors)
90 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
91 *(SORT(.ctors.*))
92 *(.ctors)
93
94 /* .dtors */
95 *crtbegin.o(.dtors)
96 *crtbegin?.o(.dtors)
97 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
98 *(SORT(.dtors.*))
99 *(.dtors)
100
101 KEEP(*(.eh_frame*))
102 } > ITCM
103
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100104 __exidx_start = .;
105 .ARM.exidx.at_itcm :
106 {
107 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
108 } > ITCM
109 __exidx_end = .;
110
111 .zero.table.at_itcm :
112 {
113 . = ALIGN(4);
114 __zero_table_start__ = .;
115
116 LONG (__bss_start__)
117 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
118
119 __zero_table_end__ = .;
120 } > ITCM
121
122 .copy.table.at_itcm :
123 {
124 . = ALIGN(4);
125 __copy_table_start__ = .;
126
127 /* Section to be copied - part 1: any data to be placed in BRAM */
128 LONG (__etext)
129 LONG (__data_start__)
130 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
131
132 /* Section to be copied - part 2: RO data for for DTCM */
133 LONG (__etext2)
134 LONG (__ro_data_start__)
135 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
136
137 __copy_table_end__ = .;
138 } > ITCM
139
140 __itcm_total = ALIGN(4);
141
142 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
143
144 .sram :
145 {
146 . = ALIGN(16);
147 *(.bss.NoInit.activation_buf)
148 . = ALIGN(16);
149 } > SRAM AT > SRAM
150
151 .bss :
152 {
153 . = ALIGN(4);
154 __bss_start__ = .;
155 *(.bss)
156 *(.bss.*)
157 *(COMMON)
158 . = ALIGN(4);
159 __bss_end__ = .;
160 } > DTCM AT > DTCM
161
162 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
163 {
164 . = ALIGN(8);
165 __StackLimit = .;
166 . = . + __STACK_SIZE;
167 . = ALIGN(8);
168 __StackTop = .;
169 } > DTCM
170 PROVIDE(__stack = __StackTop);
171 ASSERT(
172 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
173 "DTCM overflow")
174
175 .ddr.at_ddr :
176 {
177 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
178 * Force the alignment here as a workaround */
179 . = ALIGN(16);
180 *(ifm)
181 . = ALIGN(16);
182 *(nn_model)
183 . = ALIGN (16);
184 *(labels)
185 . = ALIGN (16);
186 *(activation_buf)
187 . = ALIGN (16);
188 } > DDR AT > DDR
189
190 /**
191 * Location counter can end up 2byte aligned with narrow Thumb code but
192 * __etext is assumed by startup code to be the LMA of a section in DTCM
193 * which must be 4byte aligned
194 */
195 __etext = ALIGN (4);
196
197 .bram.at_ddr : AT (__etext)
198 {
199 __data_start__ = .;
200 *(vtable)
201 *(.data)
202 *(.data.*)
203 . = ALIGN(4);
204 PROVIDE_HIDDEN (__preinit_array_start = .);
205 KEEP(*(.preinit_array))
206 PROVIDE_HIDDEN (__preinit_array_end = .);
207 . = ALIGN(4);
208 PROVIDE_HIDDEN (__init_array_start = .);
209 KEEP(*(SORT(.init_array.*)))
210 KEEP(*(.init_array))
211 PROVIDE_HIDDEN (__init_array_end = .);
212 . = ALIGN(4);
213 PROVIDE_HIDDEN (__fini_array_start = .);
214 KEEP(*(SORT(.fini_array.*)))
215 KEEP(*(.fini_array))
216 PROVIDE_HIDDEN (__fini_array_end = .);
217 KEEP(*(.jcr*))
218 . = ALIGN(4);
219
Richard Burton0d110592021-08-12 17:26:30 +0100220 *(.ARM.extab* .gnu.linkonce.armextab.*)
221 . = ALIGN(4);
222
223 /**
224 * Place the all ops resolver code data here. This accounts
225 * for ~4k worth of saving on the ITCM load region. It is
226 * only designed to be included (by default) for the inference
227 * runner use case.
228 **/
229 *all_ops_resolver.o (*.text*)
230 . = ALIGN(4);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100231 *hal.c.obj (*.text*)
232 . = ALIGN(4);
Richard Burton0d110592021-08-12 17:26:30 +0100233
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100234 __data_end__ = .;
235 } > BRAM
236
237 __etext2 = __etext + (__data_end__ - __data_start__);
238
239 .data.at_ddr : AT (__etext2)
240 {
241 . = ALIGN(4);
242 __ro_data_start__ = .;
243
244 *(.rodata*)
245 . = ALIGN(4);
246 * (npu_driver_version)
247 . = ALIGN(4);
248 * (npu_driver_arch_version)
249 . = ALIGN(4);
250
251 __ro_data_end__ = .;
252 } > BRAM
253
254 .heap (COPY) :
255 {
256 . = ALIGN(8);
257 __end__ = .;
258 PROVIDE(end = .);
259 . = . + __HEAP_SIZE;
260 . = ALIGN(8);
261 __HeapLimit = .;
262 } > BRAM
263
264 ASSERT (
265 (__ro_data_end__ - __ro_data_start__)
266 + (__data_end__ - __data_start__)
267 + __HEAP_SIZE <= LENGTH(BRAM),
268 "BRAM overflow")
269}