blob: ceaff7d673a98f2e80bfc286be4bfd29554835fb [file] [log] [blame]
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +01001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
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 = 0x00060000;
19__HEAP_SIZE = 0x000f0000;
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 = 0x00200000
27 SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00400000
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))
Richard Burton0d110592021-08-12 17:26:30 +010068
69 /**
70 * All code goes here, with one exception of
71 * all_ops_resolver object file. This code
72 * instead placed on BRAM. See comment in the
73 * BRAM section for details.
74 **/
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010075 *(EXCLUDE_FILE(*all_ops_resolver.o *hal.c.obj) .text*)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010076
77 KEEP(*(.init))
78 KEEP(*(.fini))
79
80 /* .ctors */
81 *crtbegin.o(.ctors)
82 *crtbegin?.o(.ctors)
83 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
84 *(SORT(.ctors.*))
85 *(.ctors)
86
87 /* .dtors */
88 *crtbegin.o(.dtors)
89 *crtbegin?.o(.dtors)
90 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
91 *(SORT(.dtors.*))
92 *(.dtors)
93
94 KEEP(*(.eh_frame*))
95 } > ITCM
96
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010097 __exidx_start = .;
98 .ARM.exidx.at_itcm :
99 {
100 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
101 } > ITCM
102 __exidx_end = .;
103
104 .zero.table.at_itcm :
105 {
106 . = ALIGN(4);
107 __zero_table_start__ = .;
108
109 LONG (__bss_start__)
110 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
111
112 __zero_table_end__ = .;
113 } > ITCM
114
115 .copy.table.at_itcm :
116 {
117 . = ALIGN(4);
118 __copy_table_start__ = .;
119
120 /* Section to be copied - part 1: any data to be placed in BRAM */
121 LONG (__etext)
122 LONG (__data_start__)
123 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
124
125 /* Section to be copied - part 2: RO data for for DTCM */
126 LONG (__etext2)
127 LONG (__ro_data_start__)
128 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
129
130 __copy_table_end__ = .;
131 } > ITCM
132
133 __itcm_total = ALIGN(4);
134
135 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
136
137 .sram :
138 {
139 . = ALIGN(16);
140 *(.bss.NoInit.activation_buf)
141 . = ALIGN(16);
142 } > SRAM AT > SRAM
143
144 .bss :
145 {
146 . = ALIGN(4);
147 __bss_start__ = .;
148 *(.bss)
149 *(.bss.*)
150 *(COMMON)
151 . = ALIGN(4);
152 __bss_end__ = .;
153 } > DTCM AT > DTCM
154
155 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
156 {
157 . = ALIGN(8);
158 __StackLimit = .;
159 . = . + __STACK_SIZE;
160 . = ALIGN(8);
161 __StackTop = .;
162 } > DTCM
163 PROVIDE(__stack = __StackTop);
164 ASSERT(
165 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
166 "DTCM overflow")
167
168 .ddr.at_ddr :
169 {
170 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
171 * Force the alignment here as a workaround */
172 . = ALIGN(16);
173 *(ifm)
174 . = ALIGN(16);
175 *(nn_model)
176 . = ALIGN (16);
177 *(labels)
178 . = ALIGN (16);
179 *(activation_buf)
180 . = ALIGN (16);
181 } > DDR AT > DDR
182
183 /**
184 * Location counter can end up 2byte aligned with narrow Thumb code but
185 * __etext is assumed by startup code to be the LMA of a section in DTCM
186 * which must be 4byte aligned
187 */
188 __etext = ALIGN (4);
189
190 .bram.at_ddr : AT (__etext)
191 {
192 __data_start__ = .;
193 *(vtable)
194 *(.data)
195 *(.data.*)
196 . = ALIGN(4);
197 PROVIDE_HIDDEN (__preinit_array_start = .);
198 KEEP(*(.preinit_array))
199 PROVIDE_HIDDEN (__preinit_array_end = .);
200 . = ALIGN(4);
201 PROVIDE_HIDDEN (__init_array_start = .);
202 KEEP(*(SORT(.init_array.*)))
203 KEEP(*(.init_array))
204 PROVIDE_HIDDEN (__init_array_end = .);
205 . = ALIGN(4);
206 PROVIDE_HIDDEN (__fini_array_start = .);
207 KEEP(*(SORT(.fini_array.*)))
208 KEEP(*(.fini_array))
209 PROVIDE_HIDDEN (__fini_array_end = .);
210 KEEP(*(.jcr*))
211 . = ALIGN(4);
212
Richard Burton0d110592021-08-12 17:26:30 +0100213 *(.ARM.extab* .gnu.linkonce.armextab.*)
214 . = ALIGN(4);
215
216 /**
217 * Place the all ops resolver code data here. This accounts
218 * for ~4k worth of saving on the ITCM load region. It is
219 * only designed to be included (by default) for the inference
220 * runner use case.
221 **/
222 *all_ops_resolver.o (*.text*)
223 . = ALIGN(4);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100224 *hal.c.obj (*.text*)
225 . = ALIGN(4);
Richard Burton0d110592021-08-12 17:26:30 +0100226
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100227 __data_end__ = .;
228 } > BRAM
229
230 __etext2 = __etext + (__data_end__ - __data_start__);
231
232 .data.at_ddr : AT (__etext2)
233 {
234 . = ALIGN(4);
235 __ro_data_start__ = .;
236
237 *(.rodata*)
238 . = ALIGN(4);
239 * (npu_driver_version)
240 . = ALIGN(4);
241 * (npu_driver_arch_version)
242 . = ALIGN(4);
243
244 __ro_data_end__ = .;
245 } > BRAM
246
247 .heap (COPY) :
248 {
249 . = ALIGN(8);
250 __end__ = .;
251 PROVIDE(end = .);
252 . = . + __HEAP_SIZE;
253 . = ALIGN(8);
254 __HeapLimit = .;
255 } > BRAM
256
257 ASSERT (
258 (__ro_data_end__ - __ro_data_start__)
259 + (__data_end__ - __data_start__)
260 + __HEAP_SIZE <= LENGTH(BRAM),
261 "BRAM overflow")
262}