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