blob: dbedb8ed95fc0d313643d876eddcc069c3cc53d6 [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
31/* Linker script to place sections and symbol values. Should be used together
32 * with other linker script that defines memory regions ITCM and RAM.
33 * It references following symbols, which must be defined in code:
34 * Reset_Handler : Entry of reset handler
35 *
36 * It defines following symbols, which code can use without definition:
37 * __exidx_start
38 * __exidx_end
39 * __copy_table_start__
40 * __copy_table_end__
41 * __zero_table_start__
42 * __zero_table_end__
43 * __etext
44 * __data_start__
45 * __preinit_array_start
46 * __preinit_array_end
47 * __init_array_start
48 * __init_array_end
49 * __fini_array_start
50 * __fini_array_end
51 * __data_end__
52 * __bss_start__
53 * __bss_end__
54 * __end__
55 * end
56 * __HeapLimit
57 * __StackLimit
58 * __StackTop
59 * __stack
60 */
61ENTRY(Reset_Handler)
62
63SECTIONS
64{
65 .text.at_itcm :
66 {
67 KEEP(*(.vectors))
68
69 /**
70 * Any code that is not time sensitive can be excluded from here.
71 * This code is instead placed on BRAM. See comment in the BRAM
72 * section for details.
73 */
Richard Burton4865c4f2023-11-13 15:21:11 +000074 *(EXCLUDE_FILE(*MicroMutableAllOpsResolver*.obj
Kshitij Sisodia26bc9232023-03-10 16:33:23 +000075 *hal.c.obj
76 *_allocator.o
77 *flatbuffer*.o
78 *lcd*.obj
79 *Profiler*.obj
Richard Burton49482d52023-11-30 11:38:45 +000080 *timing_adapter.c.obj
81 *s4*.o)
Kshitij Sisodia26bc9232023-03-10 16:33:23 +000082 .text*)
83
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
104 __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 /* Cache area (if used) */
148 *(.bss.NoInit.ethos_u_cache)
149 . = ALIGN (16);
150 /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */
151 *(.bss.NoInit.activation_buf_sram)
152 . = ALIGN(16);
153 } > SRAM AT > SRAM
154
155 .bss :
156 {
157 . = ALIGN(4);
158 __bss_start__ = .;
159 *(.bss)
160 *(.bss.*)
161 *(COMMON)
162 . = ALIGN(4);
163 __bss_end__ = .;
164 } > DTCM AT > DTCM
165
166 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
167 {
168 . = ALIGN(8);
169 __StackLimit = .;
170 . = . + __STACK_SIZE;
171 . = ALIGN(8);
172 __StackTop = .;
173 } > DTCM
174 PROVIDE(__stack = __StackTop);
175 ASSERT(
176 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
177 "DTCM overflow")
178
179 .ddr.at_ddr :
180 {
181 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
182 * Force the alignment here as a workaround */
183 . = ALIGN(16);
184 /* nn model's baked in input matrices */
185 *(ifm)
186 . = ALIGN(16);
187 /* nn model's default space */
188 *(nn_model)
189 . = ALIGN (16);
190 /* labels */
191 *(labels)
192 . = ALIGN (16);
Richard Burton4865c4f2023-11-13 15:21:11 +0000193 *Labels*.obj (*.rodata*)
194 . = ALIGN (16);
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000195 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
196 *(activation_buf_dram)
197 . = ALIGN (16);
198 } > DDR AT > DDR
199
200 .text.at_ddr :
201 {
202 . = ALIGN(4);
203 *Profiler*.obj (*.text*)
204 . = ALIGN(4);
Richard Burton49482d52023-11-30 11:38:45 +0000205 *s4*.o (*.text*) /* Temporary solution to move s4 operations to DDR. */
206 . = ALIGN(4);
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000207 } > DDR AT > DDR
208
209 /**
210 * Location counter can end up 2byte aligned with narrow Thumb code but
211 * __etext is assumed by startup code to be the LMA of a section in DTCM
212 * which must be 4byte aligned
213 */
214 __etext = ALIGN (4);
215
216 .bram.at_ddr : AT (__etext)
217 {
218 __data_start__ = .;
219 *(vtable)
220 *(.data)
221 *(.data.*)
222 . = ALIGN(4);
223 PROVIDE_HIDDEN (__preinit_array_start = .);
224 KEEP(*(.preinit_array))
225 PROVIDE_HIDDEN (__preinit_array_end = .);
226 . = ALIGN(4);
227 PROVIDE_HIDDEN (__init_array_start = .);
228 KEEP(*(SORT(.init_array.*)))
229 KEEP(*(.init_array))
230 PROVIDE_HIDDEN (__init_array_end = .);
231 . = ALIGN(4);
232 PROVIDE_HIDDEN (__fini_array_start = .);
233 KEEP(*(SORT(.fini_array.*)))
234 KEEP(*(.fini_array))
235 PROVIDE_HIDDEN (__fini_array_end = .);
236 KEEP(*(.jcr*))
237 . = ALIGN(4);
238
239 *(.ARM.extab* .gnu.linkonce.armextab.*)
240 . = ALIGN(4);
241
242 /**
243 * Place the all ops resolver code data here. This accounts
Richard Burton4865c4f2023-11-13 15:21:11 +0000244 * for ~9k worth of saving on the ITCM load region. It is
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000245 * only designed to be included (by default) for the inference
246 * runner use case.
247 **/
Richard Burton4865c4f2023-11-13 15:21:11 +0000248 *MicroMutableAllOpsResolver*.obj (*.text*)
Kshitij Sisodia26bc9232023-03-10 16:33:23 +0000249 . = ALIGN(4);
250 *hal.c.obj (*.text*)
251 . = ALIGN(4);
252 *_allocator.o (*.text*)
253 . = ALIGN(4);
254 *flatbuffer*.o (*.text*)
255 . = ALIGN(4);
256 *lcd*.obj (*.text*)
257 . = ALIGN(4);
258 *timing_adapter.* (*.text*)
259 . = ALIGN(4);
260
261 __data_end__ = .;
262 } > BRAM
263
264 __etext2 = __etext + (__data_end__ - __data_start__);
265
266 .data.at_ddr : AT (__etext2)
267 {
268 . = ALIGN(4);
269 __ro_data_start__ = .;
270
271 *(.rodata*)
272 . = ALIGN(4);
273 * (npu_driver_version)
274 . = ALIGN(4);
275 * (npu_driver_arch_version)
276 . = ALIGN(4);
277
278 __ro_data_end__ = .;
279 } > BRAM
280
281 .heap (COPY) :
282 {
283 . = ALIGN(8);
284 __end__ = .;
285 PROVIDE(end = .);
286 . = . + __HEAP_SIZE;
287 . = ALIGN(8);
288 __HeapLimit = .;
289 } > BRAM
290
291 ASSERT (
292 (__ro_data_end__ - __ro_data_start__)
293 + (__data_end__ - __data_start__)
294 + __HEAP_SIZE <= LENGTH(BRAM),
295 "BRAM overflow")
296}