blob: 46b963654cde9c36f4abc5cd7418087cf5ddcfd8 [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 */
Richard Burton4865c4f2023-11-13 15:21:11 +000074 *(EXCLUDE_FILE(*hal.c.obj
Kshitij Sisodia987efae2023-02-14 16:28:40 +000075 *_allocator.o
76 *flatbuffer*.o
77 *lcd*.obj
78 *timing_adapter.c.obj)
79 .text*)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010080
81 KEEP(*(.init))
82 KEEP(*(.fini))
83
84 /* .ctors */
85 *crtbegin.o(.ctors)
86 *crtbegin?.o(.ctors)
87 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
88 *(SORT(.ctors.*))
89 *(.ctors)
90
91 /* .dtors */
92 *crtbegin.o(.dtors)
93 *crtbegin?.o(.dtors)
94 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
95 *(SORT(.dtors.*))
96 *(.dtors)
97
98 KEEP(*(.eh_frame*))
99 } > ITCM
100
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100101 __exidx_start = .;
102 .ARM.exidx.at_itcm :
103 {
104 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
105 } > ITCM
106 __exidx_end = .;
107
108 .zero.table.at_itcm :
109 {
110 . = ALIGN(4);
111 __zero_table_start__ = .;
112
113 LONG (__bss_start__)
114 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
115
116 __zero_table_end__ = .;
117 } > ITCM
118
119 .copy.table.at_itcm :
120 {
121 . = ALIGN(4);
122 __copy_table_start__ = .;
123
124 /* Section to be copied - part 1: any data to be placed in BRAM */
125 LONG (__etext)
126 LONG (__data_start__)
127 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
128
129 /* Section to be copied - part 2: RO data for for DTCM */
130 LONG (__etext2)
131 LONG (__ro_data_start__)
132 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
133
134 __copy_table_end__ = .;
135 } > ITCM
136
137 __itcm_total = ALIGN(4);
138
139 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
140
141 .sram :
142 {
143 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100144 /* Cache area (if used) */
145 *(.bss.NoInit.ethos_u_cache)
146 . = ALIGN (16);
147 /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */
148 *(.bss.NoInit.activation_buf_sram)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100149 . = ALIGN(16);
150 } > SRAM AT > SRAM
151
152 .bss :
153 {
154 . = ALIGN(4);
155 __bss_start__ = .;
156 *(.bss)
157 *(.bss.*)
158 *(COMMON)
159 . = ALIGN(4);
160 __bss_end__ = .;
161 } > DTCM AT > DTCM
162
163 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
164 {
165 . = ALIGN(8);
166 __StackLimit = .;
167 . = . + __STACK_SIZE;
168 . = ALIGN(8);
169 __StackTop = .;
170 } > DTCM
171 PROVIDE(__stack = __StackTop);
172 ASSERT(
173 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
174 "DTCM overflow")
175
176 .ddr.at_ddr :
177 {
178 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
179 * Force the alignment here as a workaround */
180 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100181 /* nn model's baked in input matrices */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100182 *(ifm)
183 . = ALIGN(16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100184 /* nn model's default space */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100185 *(nn_model)
186 . = ALIGN (16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100187 /* labels */
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100188 *(labels)
189 . = ALIGN (16);
Richard Burton4865c4f2023-11-13 15:21:11 +0000190 *Labels*.obj (*.rodata*)
191 . = ALIGN (16);
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100192 /* activation buffers a.k.a tensor arena when memory mode dedicated sram */
193 *(activation_buf_dram)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100194 . = ALIGN (16);
195 } > DDR AT > DDR
196
197 /**
198 * Location counter can end up 2byte aligned with narrow Thumb code but
199 * __etext is assumed by startup code to be the LMA of a section in DTCM
200 * which must be 4byte aligned
201 */
202 __etext = ALIGN (4);
203
204 .bram.at_ddr : AT (__etext)
205 {
206 __data_start__ = .;
207 *(vtable)
208 *(.data)
209 *(.data.*)
210 . = ALIGN(4);
211 PROVIDE_HIDDEN (__preinit_array_start = .);
212 KEEP(*(.preinit_array))
213 PROVIDE_HIDDEN (__preinit_array_end = .);
214 . = ALIGN(4);
215 PROVIDE_HIDDEN (__init_array_start = .);
216 KEEP(*(SORT(.init_array.*)))
217 KEEP(*(.init_array))
218 PROVIDE_HIDDEN (__init_array_end = .);
219 . = ALIGN(4);
220 PROVIDE_HIDDEN (__fini_array_start = .);
221 KEEP(*(SORT(.fini_array.*)))
222 KEEP(*(.fini_array))
223 PROVIDE_HIDDEN (__fini_array_end = .);
224 KEEP(*(.jcr*))
225 . = ALIGN(4);
226
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100227 *(.ARM.extab* .gnu.linkonce.armextab.*)
228 . = ALIGN(4);
229
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100230 *hal.c.obj (*.text*)
231 . = ALIGN(4);
Kshitij Sisodia987efae2023-02-14 16:28:40 +0000232 *_allocator.o (*.text*)
233 . = ALIGN(4);
234 *flatbuffer*.o (*.text*)
235 . = ALIGN(4);
236 *lcd*.obj (*.text*)
237 . = ALIGN(4);
238 *timing_adapter.* (*.text*)
239 . = ALIGN(4);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100240
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100241 __data_end__ = .;
242 } > BRAM
243
244 __etext2 = __etext + (__data_end__ - __data_start__);
245
246 .data.at_ddr : AT (__etext2)
247 {
248 . = ALIGN(4);
249 __ro_data_start__ = .;
250
251 *(.rodata*)
252 . = ALIGN(4);
253 * (npu_driver_version)
254 . = ALIGN(4);
255 * (npu_driver_arch_version)
256 . = ALIGN(4);
257
258 __ro_data_end__ = .;
259 } > BRAM
260
261 .heap (COPY) :
262 {
263 . = ALIGN(8);
264 __end__ = .;
265 PROVIDE(end = .);
266 . = . + __HEAP_SIZE;
267 . = ALIGN(8);
268 __HeapLimit = .;
269 } > BRAM
270
271 ASSERT (
272 (__ro_data_end__ - __ro_data_start__)
273 + (__data_end__ - __data_start__)
274 + __HEAP_SIZE <= LENGTH(BRAM),
275 "BRAM overflow")
276}