blob: d3364f0d0e52f08979d5b37e58a9983c532ba195 [file] [log] [blame]
Kshitij Sisodia26bc9232023-03-10 16:33:23 +00001/*
Kshitij Sisodia69f66162024-05-28 15:15:17 +01002 * SPDX-FileCopyrightText: Copyright 2021,2023-2024 Arm Limited and/or its
3 * affiliates <open-source-office@arm.com>
Kshitij Sisodia26bc9232023-03-10 16:33:23 +00004 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19__STACK_SIZE = 0x00008000;
20__HEAP_SIZE = 0x000C0000;
21
22/* System memory brief */
23MEMORY
24{
25 ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
26 DTCM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000
27 BRAM (rwx) : ORIGIN = 0x11000000, LENGTH = 0x00100000
28 SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00200000
29 DDR (rwx) : ORIGIN = 0x70000000, LENGTH = 0x02000000
30}
31
32/* Linker script to place sections and symbol values. Should be used together
33 * with other linker script that defines memory regions ITCM and RAM.
34 * It references following symbols, which must be defined in code:
35 * Reset_Handler : Entry of reset handler
36 *
37 * It defines following symbols, which code can use without definition:
38 * __exidx_start
39 * __exidx_end
40 * __copy_table_start__
41 * __copy_table_end__
42 * __zero_table_start__
43 * __zero_table_end__
44 * __etext
45 * __data_start__
46 * __preinit_array_start
47 * __preinit_array_end
48 * __init_array_start
49 * __init_array_end
50 * __fini_array_start
51 * __fini_array_end
52 * __data_end__
53 * __bss_start__
54 * __bss_end__
55 * __end__
56 * end
57 * __HeapLimit
58 * __StackLimit
59 * __StackTop
60 * __stack
61 */
62ENTRY(Reset_Handler)
63
64SECTIONS
65{
66 .text.at_itcm :
67 {
68 KEEP(*(.vectors))
69
70 /**
71 * Any code that is not time sensitive can be excluded from here.
72 * This code is instead placed on BRAM. See comment in the BRAM
73 * section for details.
74 */
Richard Burton4865c4f2023-11-13 15:21:11 +000075 *(EXCLUDE_FILE(*MicroMutableAllOpsResolver*.obj
Kshitij Sisodia26bc9232023-03-10 16:33:23 +000076 *hal.c.obj
77 *_allocator.o
78 *flatbuffer*.o
79 *lcd*.obj
80 *Profiler*.obj
Richard Burton49482d52023-11-30 11:38:45 +000081 *timing_adapter.c.obj
Kshitij Sisodia69f66162024-05-28 15:15:17 +010082 *s4*.o
83 *cp-demangle.o)
Kshitij Sisodia26bc9232023-03-10 16:33:23 +000084 .text*)
85
86 KEEP(*(.init))
87 KEEP(*(.fini))
88
89 /* .ctors */
90 *crtbegin.o(.ctors)
91 *crtbegin?.o(.ctors)
92 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
93 *(SORT(.ctors.*))
94 *(.ctors)
95
96 /* .dtors */
97 *crtbegin.o(.dtors)
98 *crtbegin?.o(.dtors)
99 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
100 *(SORT(.dtors.*))
101 *(.dtors)
102
103 KEEP(*(.eh_frame*))
104 } > ITCM
105
106 __exidx_start = .;
107 .ARM.exidx.at_itcm :
108 {
109 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
110 } > ITCM
111 __exidx_end = .;
112
113 .zero.table.at_itcm :
114 {
115 . = ALIGN(4);
116 __zero_table_start__ = .;
117
118 LONG (__bss_start__)
119 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
120
121 __zero_table_end__ = .;
122 } > ITCM
123
124 .copy.table.at_itcm :
125 {
126 . = ALIGN(4);
127 __copy_table_start__ = .;
128
129 /* Section to be copied - part 1: any data to be placed in BRAM */
130 LONG (__etext)
131 LONG (__data_start__)
132 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
133
134 /* Section to be copied - part 2: RO data for for DTCM */
135 LONG (__etext2)
136 LONG (__ro_data_start__)
137 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
138
139 __copy_table_end__ = .;
140 } > ITCM
141
142 __itcm_total = ALIGN(4);
143
144 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
145
146 .sram :
147 {
148 . = ALIGN(16);
149 /* Cache area (if used) */
150 *(.bss.NoInit.ethos_u_cache)
151 . = ALIGN (16);
152 /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */
153 *(.bss.NoInit.activation_buf_sram)
154 . = ALIGN(16);
155 } > SRAM AT > SRAM
156
157 .bss :
158 {
159 . = ALIGN(4);
160 __bss_start__ = .;
161 *(.bss)
162 *(.bss.*)
163 *(COMMON)
164 . = ALIGN(4);
165 __bss_end__ = .;
166 } > DTCM AT > DTCM
167
168 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
169 {
170 . = ALIGN(8);
171 __StackLimit = .;
172 . = . + __STACK_SIZE;
173 . = ALIGN(8);
174 __StackTop = .;
175 } > DTCM
176 PROVIDE(__stack = __StackTop);
177 ASSERT(
178 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
179 "DTCM overflow")
180
181 .ddr.at_ddr :
182 {
183 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
184 * Force the alignment here as a workaround */
185 . = ALIGN(16);
186 /* nn model's baked in input matrices */
187 *(ifm)
188 . = ALIGN(16);
189 /* nn model's default space */
190 *(nn_model)
191 . = ALIGN (16);
192 /* labels */
193 *(labels)
194 . = ALIGN (16);
Richard Burton4865c4f2023-11-13 15:21:11 +0000195 *Labels*.obj (*.rodata*)
196 . = ALIGN (16);
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000197 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
198 *(activation_buf_dram)
199 . = ALIGN (16);
200 } > DDR AT > DDR
201
202 .text.at_ddr :
203 {
204 . = ALIGN(4);
205 *Profiler*.obj (*.text*)
206 . = ALIGN(4);
Richard Burton49482d52023-11-30 11:38:45 +0000207 *s4*.o (*.text*) /* Temporary solution to move s4 operations to DDR. */
208 . = ALIGN(4);
Kshitij Sisodia69f66162024-05-28 15:15:17 +0100209 *cp-demangle.o (*.text*) /* from stdc++ lib */
210 . = ALIGN(4);
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000211 } > DDR AT > DDR
212
213 /**
214 * Location counter can end up 2byte aligned with narrow Thumb code but
215 * __etext is assumed by startup code to be the LMA of a section in DTCM
216 * which must be 4byte aligned
217 */
218 __etext = ALIGN (4);
219
220 .bram.at_ddr : AT (__etext)
221 {
222 __data_start__ = .;
223 *(vtable)
224 *(.data)
225 *(.data.*)
226 . = ALIGN(4);
227 PROVIDE_HIDDEN (__preinit_array_start = .);
228 KEEP(*(.preinit_array))
229 PROVIDE_HIDDEN (__preinit_array_end = .);
230 . = ALIGN(4);
231 PROVIDE_HIDDEN (__init_array_start = .);
232 KEEP(*(SORT(.init_array.*)))
233 KEEP(*(.init_array))
234 PROVIDE_HIDDEN (__init_array_end = .);
235 . = ALIGN(4);
236 PROVIDE_HIDDEN (__fini_array_start = .);
237 KEEP(*(SORT(.fini_array.*)))
238 KEEP(*(.fini_array))
239 PROVIDE_HIDDEN (__fini_array_end = .);
240 KEEP(*(.jcr*))
241 . = ALIGN(4);
242
243 *(.ARM.extab* .gnu.linkonce.armextab.*)
244 . = ALIGN(4);
245
246 /**
247 * Place the all ops resolver code data here. This accounts
Richard Burton4865c4f2023-11-13 15:21:11 +0000248 * for ~9k worth of saving on the ITCM load region. It is
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000249 * only designed to be included (by default) for the inference
250 * runner use case.
251 **/
Richard Burton4865c4f2023-11-13 15:21:11 +0000252 *MicroMutableAllOpsResolver*.obj (*.text*)
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000253 . = ALIGN(4);
254 *hal.c.obj (*.text*)
255 . = ALIGN(4);
256 *_allocator.o (*.text*)
257 . = ALIGN(4);
258 *flatbuffer*.o (*.text*)
259 . = ALIGN(4);
260 *lcd*.obj (*.text*)
261 . = ALIGN(4);
262 *timing_adapter.* (*.text*)
263 . = ALIGN(4);
264
265 __data_end__ = .;
266 } > BRAM
267
268 __etext2 = __etext + (__data_end__ - __data_start__);
269
270 .data.at_ddr : AT (__etext2)
271 {
272 . = ALIGN(4);
273 __ro_data_start__ = .;
274
275 *(.rodata*)
276 . = ALIGN(4);
277 * (npu_driver_version)
278 . = ALIGN(4);
279 * (npu_driver_arch_version)
280 . = ALIGN(4);
281
282 __ro_data_end__ = .;
283 } > BRAM
284
285 .heap (COPY) :
286 {
287 . = ALIGN(8);
288 __end__ = .;
289 PROVIDE(end = .);
290 . = . + __HEAP_SIZE;
291 . = ALIGN(8);
292 __HeapLimit = .;
293 } > BRAM
294
295 ASSERT (
296 (__ro_data_end__ - __ro_data_start__)
297 + (__data_end__ - __data_start__)
298 + __HEAP_SIZE <= LENGTH(BRAM),
299 "BRAM overflow")
300}