blob: 715cdeb3b414581508c18f5c1d036179ae1fed8c [file] [log] [blame]
Kshitij Sisodia26bc9232023-03-10 16:33:23 +00001/*
2 * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
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 = 0x00008000;
19__HEAP_SIZE = 0x000C0000;
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 = 0x00100000
27 SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00200000
28 DDR (rwx) : ORIGIN = 0x70000000, LENGTH = 0x02000000
29
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
36}
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))
75
76 /**
77 * Any code that is not time sensitive can be excluded from here.
78 * This code is instead placed on BRAM. See comment in the BRAM
79 * section for details.
80 */
81 *(EXCLUDE_FILE(*all_ops_resolver.o
82 *hal.c.obj
83 *_allocator.o
84 *flatbuffer*.o
85 *Profiler*.obj
86 *lcd*.obj
87 *timing_adapter.c.obj)
88 .text*)
89
90 KEEP(*(.init))
91 KEEP(*(.fini))
92
93 /* .ctors */
94 *crtbegin.o(.ctors)
95 *crtbegin?.o(.ctors)
96 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
97 *(SORT(.ctors.*))
98 *(.ctors)
99
100 /* .dtors */
101 *crtbegin.o(.dtors)
102 *crtbegin?.o(.dtors)
103 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
104 *(SORT(.dtors.*))
105 *(.dtors)
106
107 KEEP(*(.eh_frame*))
108 } > ITCM
109
110 __exidx_start = .;
111 .ARM.exidx.at_itcm :
112 {
113 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
114 } > ITCM
115 __exidx_end = .;
116
117 .zero.table.at_itcm :
118 {
119 . = ALIGN(4);
120 __zero_table_start__ = .;
121
122 LONG (__bss_start__)
123 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
124
125 __zero_table_end__ = .;
126 } > ITCM
127
128 .copy.table.at_itcm :
129 {
130 . = ALIGN(4);
131 __copy_table_start__ = .;
132
133 /* Section to be copied - part 1: any data to be placed in BRAM */
134 LONG (__etext)
135 LONG (__data_start__)
136 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
137
138 /* Section to be copied - part 2: RO data for for DTCM */
139 LONG (__etext2)
140 LONG (__ro_data_start__)
141 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
142
143 __copy_table_end__ = .;
144 } > ITCM
145
146 __itcm_total = ALIGN(4);
147
148 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
149
150 .sram :
151 {
152 . = ALIGN(16);
153 /* Cache area (if used) */
154 *(.bss.NoInit.ethos_u_cache)
155 . = ALIGN (16);
156 /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */
157 *(.bss.NoInit.activation_buf_sram)
158 . = ALIGN(16);
159 } > SRAM AT > SRAM
160
161 .bss :
162 {
163 . = ALIGN(4);
164 __bss_start__ = .;
165 *(.bss)
166 *(.bss.*)
167 *(COMMON)
168 . = ALIGN(4);
169 __bss_end__ = .;
170 } > DTCM AT > DTCM
171
172 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
173 {
174 . = ALIGN(8);
175 __StackLimit = .;
176 . = . + __STACK_SIZE;
177 . = ALIGN(8);
178 __StackTop = .;
179 } > DTCM
180 PROVIDE(__stack = __StackTop);
181 ASSERT(
182 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
183 "DTCM overflow")
184
185 .ddr.at_ddr :
186 {
187 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
188 * Force the alignment here as a workaround */
189 . = ALIGN(16);
190 /* nn model's baked in input matrices */
191 *(ifm)
192 . = ALIGN(16);
193 /* nn model's default space */
194 *(nn_model)
195 . = ALIGN (16);
196 /* labels */
197 *(labels)
198 . = ALIGN (16);
199 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
200 *(activation_buf_dram)
201 . = ALIGN (16);
202 } > DDR AT > DDR
203
204 .text.at_ddr :
205 {
206 . = ALIGN(4);
207 *Profiler*.obj (*.text*)
208 . = ALIGN(4);
209 } > DDR AT > DDR
210
211 /**
212 * Location counter can end up 2byte aligned with narrow Thumb code but
213 * __etext is assumed by startup code to be the LMA of a section in DTCM
214 * which must be 4byte aligned
215 */
216 __etext = ALIGN (4);
217
218 .bram.at_ddr : AT (__etext)
219 {
220 __data_start__ = .;
221 *(vtable)
222 *(.data)
223 *(.data.*)
224 . = ALIGN(4);
225 PROVIDE_HIDDEN (__preinit_array_start = .);
226 KEEP(*(.preinit_array))
227 PROVIDE_HIDDEN (__preinit_array_end = .);
228 . = ALIGN(4);
229 PROVIDE_HIDDEN (__init_array_start = .);
230 KEEP(*(SORT(.init_array.*)))
231 KEEP(*(.init_array))
232 PROVIDE_HIDDEN (__init_array_end = .);
233 . = ALIGN(4);
234 PROVIDE_HIDDEN (__fini_array_start = .);
235 KEEP(*(SORT(.fini_array.*)))
236 KEEP(*(.fini_array))
237 PROVIDE_HIDDEN (__fini_array_end = .);
238 KEEP(*(.jcr*))
239 . = ALIGN(4);
240
241 *(.ARM.extab* .gnu.linkonce.armextab.*)
242 . = ALIGN(4);
243
244 /**
245 * Place the all ops resolver code data here. This accounts
246 * for ~4k worth of saving on the ITCM load region. It is
247 * only designed to be included (by default) for the inference
248 * runner use case.
249 **/
250 *all_ops_resolver.o (*.text*)
251 . = ALIGN(4);
252 *hal.c.obj (*.text*)
253 . = ALIGN(4);
254 *_allocator.o (*.text*)
255 . = ALIGN(4);
256 *flatbuffer*.o (*.text*)
257 . = ALIGN(4);
258 *lcd*.obj (*.text*)
259 . = ALIGN(4);
260 *timing_adapter.* (*.text*)
261 . = ALIGN(4);
262
263 __data_end__ = .;
264 } > BRAM
265
266 __etext2 = __etext + (__data_end__ - __data_start__);
267
268 .data.at_ddr : AT (__etext2)
269 {
270 . = ALIGN(4);
271 __ro_data_start__ = .;
272
273 *(.rodata*)
274 . = ALIGN(4);
275 * (npu_driver_version)
276 . = ALIGN(4);
277 * (npu_driver_arch_version)
278 . = ALIGN(4);
279
280 __ro_data_end__ = .;
281 } > BRAM
282
283 .heap (COPY) :
284 {
285 . = ALIGN(8);
286 __end__ = .;
287 PROVIDE(end = .);
288 . = . + __HEAP_SIZE;
289 . = ALIGN(8);
290 __HeapLimit = .;
291 } > BRAM
292
293 ASSERT (
294 (__ro_data_end__ - __ro_data_start__)
295 + (__data_end__ - __data_start__)
296 + __HEAP_SIZE <= LENGTH(BRAM),
297 "BRAM overflow")
298}