blob: 492f6da20bf94d66fa4d44ad776c902799cdaf6f [file] [log] [blame]
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01001/*
Kshitij Sisodia987efae2023-02-14 16:28:40 +00002 * SPDX-FileCopyrightText: Copyright 2021,2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01003 * 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
Kshitij Sisodia7e56d8f2022-04-11 10:34:29 +010018__STACK_SIZE = 0x00008000;
Kshitij Sisodia661959c2021-11-24 10:39:52 +000019__HEAP_SIZE = 0x000C0000;
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010020
21/* System memory brief */
22MEMORY
23{
24 ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000
25 DTCM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000
Kshitij Sisodia661959c2021-11-24 10:39:52 +000026 BRAM (rwx) : ORIGIN = 0x11000000, LENGTH = 0x00100000
27 SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00200000
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010028 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))
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010068
69 /**
Kshitij Sisodia987efae2023-02-14 16:28:40 +000070 * 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 *timing_adapter.c.obj)
80 .text*)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010081
82 KEEP(*(.init))
83 KEEP(*(.fini))
84
85 /* .ctors */
86 *crtbegin.o(.ctors)
87 *crtbegin?.o(.ctors)
88 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
89 *(SORT(.ctors.*))
90 *(.ctors)
91
92 /* .dtors */
93 *crtbegin.o(.dtors)
94 *crtbegin?.o(.dtors)
95 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
96 *(SORT(.dtors.*))
97 *(.dtors)
98
99 KEEP(*(.eh_frame*))
100 } > ITCM
101
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100102 __exidx_start = .;
103 .ARM.exidx.at_itcm :
104 {
105 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
106 } > ITCM
107 __exidx_end = .;
108
109 .zero.table.at_itcm :
110 {
111 . = ALIGN(4);
112 __zero_table_start__ = .;
113
114 LONG (__bss_start__)
115 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
116
117 __zero_table_end__ = .;
118 } > ITCM
119
120 .copy.table.at_itcm :
121 {
122 . = ALIGN(4);
123 __copy_table_start__ = .;
124
125 /* Section to be copied - part 1: any data to be placed in BRAM */
126 LONG (__etext)
127 LONG (__data_start__)
128 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
129
130 /* Section to be copied - part 2: RO data for for DTCM */
131 LONG (__etext2)
132 LONG (__ro_data_start__)
133 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
134
135 __copy_table_end__ = .;
136 } > ITCM
137
138 __itcm_total = ALIGN(4);
139
140 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
141
142 .sram :
143 {
144 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100145 /* Cache area (if used) */
146 *(.bss.NoInit.ethos_u_cache)
147 . = ALIGN (16);
148 /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */
149 *(.bss.NoInit.activation_buf_sram)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100150 . = ALIGN(16);
151 } > SRAM AT > SRAM
152
153 .bss :
154 {
155 . = ALIGN(4);
156 __bss_start__ = .;
157 *(.bss)
158 *(.bss.*)
159 *(COMMON)
160 . = ALIGN(4);
161 __bss_end__ = .;
162 } > DTCM AT > DTCM
163
164 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
165 {
166 . = ALIGN(8);
167 __StackLimit = .;
168 . = . + __STACK_SIZE;
169 . = ALIGN(8);
170 __StackTop = .;
171 } > DTCM
172 PROVIDE(__stack = __StackTop);
173 ASSERT(
174 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
175 "DTCM overflow")
176
177 .ddr.at_ddr :
178 {
179 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
180 * Force the alignment here as a workaround */
181 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100182 /* nn model's baked in input matrices */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100183 *(ifm)
184 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100185 /* nn model's default space */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100186 *(nn_model)
187 . = ALIGN (16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100188 /* labels */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100189 *(labels)
190 . = ALIGN (16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100191 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
192 *(activation_buf_dram)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100193 . = ALIGN (16);
194 } > DDR AT > DDR
195
196 /**
197 * Location counter can end up 2byte aligned with narrow Thumb code but
198 * __etext is assumed by startup code to be the LMA of a section in DTCM
199 * which must be 4byte aligned
200 */
201 __etext = ALIGN (4);
202
203 .bram.at_ddr : AT (__etext)
204 {
205 __data_start__ = .;
206 *(vtable)
207 *(.data)
208 *(.data.*)
209 . = ALIGN(4);
210 PROVIDE_HIDDEN (__preinit_array_start = .);
211 KEEP(*(.preinit_array))
212 PROVIDE_HIDDEN (__preinit_array_end = .);
213 . = ALIGN(4);
214 PROVIDE_HIDDEN (__init_array_start = .);
215 KEEP(*(SORT(.init_array.*)))
216 KEEP(*(.init_array))
217 PROVIDE_HIDDEN (__init_array_end = .);
218 . = ALIGN(4);
219 PROVIDE_HIDDEN (__fini_array_start = .);
220 KEEP(*(SORT(.fini_array.*)))
221 KEEP(*(.fini_array))
222 PROVIDE_HIDDEN (__fini_array_end = .);
223 KEEP(*(.jcr*))
224 . = ALIGN(4);
225
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100226 *(.ARM.extab* .gnu.linkonce.armextab.*)
227 . = ALIGN(4);
228
229 /**
230 * Place the all ops resolver code data here. This accounts
231 * for ~4k worth of saving on the ITCM load region. It is
232 * only designed to be included (by default) for the inference
233 * runner use case.
234 **/
235 *all_ops_resolver.o (*.text*)
236 . = ALIGN(4);
237 *hal.c.obj (*.text*)
238 . = ALIGN(4);
Kshitij Sisodia987efae2023-02-14 16:28:40 +0000239 *_allocator.o (*.text*)
240 . = ALIGN(4);
241 *flatbuffer*.o (*.text*)
242 . = ALIGN(4);
243 *lcd*.obj (*.text*)
244 . = ALIGN(4);
245 *timing_adapter.* (*.text*)
246 . = ALIGN(4);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100247
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100248 __data_end__ = .;
249 } > BRAM
250
251 __etext2 = __etext + (__data_end__ - __data_start__);
252
253 .data.at_ddr : AT (__etext2)
254 {
255 . = ALIGN(4);
256 __ro_data_start__ = .;
257
258 *(.rodata*)
259 . = ALIGN(4);
260 * (npu_driver_version)
261 . = ALIGN(4);
262 * (npu_driver_arch_version)
263 . = ALIGN(4);
264
265 __ro_data_end__ = .;
266 } > BRAM
267
268 .heap (COPY) :
269 {
270 . = ALIGN(8);
271 __end__ = .;
272 PROVIDE(end = .);
273 . = . + __HEAP_SIZE;
274 . = ALIGN(8);
275 __HeapLimit = .;
276 } > BRAM
277
278 ASSERT (
279 (__ro_data_end__ - __ro_data_start__)
280 + (__data_end__ - __data_start__)
281 + __HEAP_SIZE <= LENGTH(BRAM),
282 "BRAM overflow")
283}