blob: 8bb99cdeaf8094dec4084a55caa8591f8f1cb571 [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))
68 *(.text*)
69
70 KEEP(*(.init))
71 KEEP(*(.fini))
72
73 /* .ctors */
74 *crtbegin.o(.ctors)
75 *crtbegin?.o(.ctors)
76 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
77 *(SORT(.ctors.*))
78 *(.ctors)
79
80 /* .dtors */
81 *crtbegin.o(.dtors)
82 *crtbegin?.o(.dtors)
83 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
84 *(SORT(.dtors.*))
85 *(.dtors)
86
87 KEEP(*(.eh_frame*))
88 } > ITCM
89
90 .ARM.extab.at_itcm :
91 {
92 *(.ARM.extab* .gnu.linkonce.armextab.*)
93 } > ITCM
94
95 __exidx_start = .;
96 .ARM.exidx.at_itcm :
97 {
98 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
99 } > ITCM
100 __exidx_end = .;
101
102 .zero.table.at_itcm :
103 {
104 . = ALIGN(4);
105 __zero_table_start__ = .;
106
107 LONG (__bss_start__)
108 LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */
109
110 __zero_table_end__ = .;
111 } > ITCM
112
113 .copy.table.at_itcm :
114 {
115 . = ALIGN(4);
116 __copy_table_start__ = .;
117
118 /* Section to be copied - part 1: any data to be placed in BRAM */
119 LONG (__etext)
120 LONG (__data_start__)
121 LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */
122
123 /* Section to be copied - part 2: RO data for for DTCM */
124 LONG (__etext2)
125 LONG (__ro_data_start__)
126 LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */
127
128 __copy_table_end__ = .;
129 } > ITCM
130
131 __itcm_total = ALIGN(4);
132
133 ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow")
134
135 .sram :
136 {
137 . = ALIGN(16);
138 *(.bss.NoInit.activation_buf)
139 . = ALIGN(16);
140 } > SRAM AT > SRAM
141
142 .bss :
143 {
144 . = ALIGN(4);
145 __bss_start__ = .;
146 *(.bss)
147 *(.bss.*)
148 *(COMMON)
149 . = ALIGN(4);
150 __bss_end__ = .;
151 } > DTCM AT > DTCM
152
153 .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) :
154 {
155 . = ALIGN(8);
156 __StackLimit = .;
157 . = . + __STACK_SIZE;
158 . = ALIGN(8);
159 __StackTop = .;
160 } > DTCM
161 PROVIDE(__stack = __StackTop);
162 ASSERT(
163 (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM),
164 "DTCM overflow")
165
166 .ddr.at_ddr :
167 {
168 /* __attribute__((aligned(16))) is not handled by the CMSIS startup code.
169 * Force the alignment here as a workaround */
170 . = ALIGN(16);
171 *(ifm)
172 . = ALIGN(16);
173 *(nn_model)
174 . = ALIGN (16);
175 *(labels)
176 . = ALIGN (16);
177 *(activation_buf)
178 . = ALIGN (16);
179 } > DDR AT > DDR
180
181 /**
182 * Location counter can end up 2byte aligned with narrow Thumb code but
183 * __etext is assumed by startup code to be the LMA of a section in DTCM
184 * which must be 4byte aligned
185 */
186 __etext = ALIGN (4);
187
188 .bram.at_ddr : AT (__etext)
189 {
190 __data_start__ = .;
191 *(vtable)
192 *(.data)
193 *(.data.*)
194 . = ALIGN(4);
195 PROVIDE_HIDDEN (__preinit_array_start = .);
196 KEEP(*(.preinit_array))
197 PROVIDE_HIDDEN (__preinit_array_end = .);
198 . = ALIGN(4);
199 PROVIDE_HIDDEN (__init_array_start = .);
200 KEEP(*(SORT(.init_array.*)))
201 KEEP(*(.init_array))
202 PROVIDE_HIDDEN (__init_array_end = .);
203 . = ALIGN(4);
204 PROVIDE_HIDDEN (__fini_array_start = .);
205 KEEP(*(SORT(.fini_array.*)))
206 KEEP(*(.fini_array))
207 PROVIDE_HIDDEN (__fini_array_end = .);
208 KEEP(*(.jcr*))
209 . = ALIGN(4);
210
211 __data_end__ = .;
212 } > BRAM
213
214 __etext2 = __etext + (__data_end__ - __data_start__);
215
216 .data.at_ddr : AT (__etext2)
217 {
218 . = ALIGN(4);
219 __ro_data_start__ = .;
220
221 *(.rodata*)
222 . = ALIGN(4);
223 * (npu_driver_version)
224 . = ALIGN(4);
225 * (npu_driver_arch_version)
226 . = ALIGN(4);
227
228 __ro_data_end__ = .;
229 } > BRAM
230
231 .heap (COPY) :
232 {
233 . = ALIGN(8);
234 __end__ = .;
235 PROVIDE(end = .);
236 . = . + __HEAP_SIZE;
237 . = ALIGN(8);
238 __HeapLimit = .;
239 } > BRAM
240
241 ASSERT (
242 (__ro_data_end__ - __ro_data_start__)
243 + (__data_end__ - __data_start__)
244 + __HEAP_SIZE <= LENGTH(BRAM),
245 "BRAM overflow")
246}