blob: 9a4f88a5416034909f517e5f2300fbb8af417c46 [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 */
74 *(EXCLUDE_FILE(*all_ops_resolver.o
75 *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);
192 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
193 *(activation_buf_dram)
194 . = ALIGN (16);
195 } > DDR AT > DDR
196
197 .text.at_ddr :
198 {
199 . = ALIGN(4);
200 *Profiler*.obj (*.text*)
201 . = ALIGN(4);
202 } > DDR AT > DDR
203
204 /**
205 * Location counter can end up 2byte aligned with narrow Thumb code but
206 * __etext is assumed by startup code to be the LMA of a section in DTCM
207 * which must be 4byte aligned
208 */
209 __etext = ALIGN (4);
210
211 .bram.at_ddr : AT (__etext)
212 {
213 __data_start__ = .;
214 *(vtable)
215 *(.data)
216 *(.data.*)
217 . = ALIGN(4);
218 PROVIDE_HIDDEN (__preinit_array_start = .);
219 KEEP(*(.preinit_array))
220 PROVIDE_HIDDEN (__preinit_array_end = .);
221 . = ALIGN(4);
222 PROVIDE_HIDDEN (__init_array_start = .);
223 KEEP(*(SORT(.init_array.*)))
224 KEEP(*(.init_array))
225 PROVIDE_HIDDEN (__init_array_end = .);
226 . = ALIGN(4);
227 PROVIDE_HIDDEN (__fini_array_start = .);
228 KEEP(*(SORT(.fini_array.*)))
229 KEEP(*(.fini_array))
230 PROVIDE_HIDDEN (__fini_array_end = .);
231 KEEP(*(.jcr*))
232 . = ALIGN(4);
233
234 *(.ARM.extab* .gnu.linkonce.armextab.*)
235 . = ALIGN(4);
236
237 /**
238 * Place the all ops resolver code data here. This accounts
239 * for ~4k worth of saving on the ITCM load region. It is
240 * only designed to be included (by default) for the inference
241 * runner use case.
242 **/
243 *all_ops_resolver.o (*.text*)
244 . = ALIGN(4);
245 *hal.c.obj (*.text*)
246 . = ALIGN(4);
247 *_allocator.o (*.text*)
248 . = ALIGN(4);
249 *flatbuffer*.o (*.text*)
250 . = ALIGN(4);
251 *lcd*.obj (*.text*)
252 . = ALIGN(4);
253 *timing_adapter.* (*.text*)
254 . = ALIGN(4);
255
256 __data_end__ = .;
257 } > BRAM
258
259 __etext2 = __etext + (__data_end__ - __data_start__);
260
261 .data.at_ddr : AT (__etext2)
262 {
263 . = ALIGN(4);
264 __ro_data_start__ = .;
265
266 *(.rodata*)
267 . = ALIGN(4);
268 * (npu_driver_version)
269 . = ALIGN(4);
270 * (npu_driver_arch_version)
271 . = ALIGN(4);
272
273 __ro_data_end__ = .;
274 } > BRAM
275
276 .heap (COPY) :
277 {
278 . = ALIGN(8);
279 __end__ = .;
280 PROVIDE(end = .);
281 . = . + __HEAP_SIZE;
282 . = ALIGN(8);
283 __HeapLimit = .;
284 } > BRAM
285
286 ASSERT (
287 (__ro_data_end__ - __ro_data_start__)
288 + (__data_end__ - __data_start__)
289 + __HEAP_SIZE <= LENGTH(BRAM),
290 "BRAM overflow")
291}