Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 1 | /* |
Kshitij Sisodia | 987efae | 2023-02-14 16:28:40 +0000 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 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 | |
Kshitij Sisodia | 7e56d8f | 2022-04-11 10:34:29 +0100 | [diff] [blame] | 18 | __STACK_SIZE = 0x00008000; |
Kshitij Sisodia | 661959c | 2021-11-24 10:39:52 +0000 | [diff] [blame] | 19 | __HEAP_SIZE = 0x000C0000; |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 20 | |
| 21 | /* System memory brief */ |
| 22 | MEMORY |
| 23 | { |
| 24 | ITCM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000 |
| 25 | DTCM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00080000 |
Kshitij Sisodia | 661959c | 2021-11-24 10:39:52 +0000 | [diff] [blame] | 26 | BRAM (rwx) : ORIGIN = 0x11000000, LENGTH = 0x00100000 |
| 27 | SRAM (rwx) : ORIGIN = 0x31000000, LENGTH = 0x00200000 |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 28 | DDR (rwx) : ORIGIN = 0x70000000, LENGTH = 0x02000000 |
Kshitij Sisodia | aa5e1f6 | 2021-09-24 14:42:08 +0100 | [diff] [blame] | 29 | |
| 30 | /* Dynamic load regions declared for use by FVP only |
| 31 | * These regions are mentioned in the CMake subsystem profile. |
| 32 | * Do not change the addresses here in isolation. */ |
| 33 | DDR_dynamic_model (rx) : ORIGIN = 0x90000000, LENGTH = 0x02000000 |
| 34 | DDR_dynamic_ifm (rx) : ORIGIN = 0x92000000, LENGTH = 0x01000000 |
| 35 | DDR_dynamic_ofm (rx) : ORIGIN = 0x93000000, LENGTH = 0x01000000 |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* Linker script to place sections and symbol values. Should be used together |
| 39 | * with other linker script that defines memory regions ITCM and RAM. |
| 40 | * It references following symbols, which must be defined in code: |
| 41 | * Reset_Handler : Entry of reset handler |
| 42 | * |
| 43 | * It defines following symbols, which code can use without definition: |
| 44 | * __exidx_start |
| 45 | * __exidx_end |
| 46 | * __copy_table_start__ |
| 47 | * __copy_table_end__ |
| 48 | * __zero_table_start__ |
| 49 | * __zero_table_end__ |
| 50 | * __etext |
| 51 | * __data_start__ |
| 52 | * __preinit_array_start |
| 53 | * __preinit_array_end |
| 54 | * __init_array_start |
| 55 | * __init_array_end |
| 56 | * __fini_array_start |
| 57 | * __fini_array_end |
| 58 | * __data_end__ |
| 59 | * __bss_start__ |
| 60 | * __bss_end__ |
| 61 | * __end__ |
| 62 | * end |
| 63 | * __HeapLimit |
| 64 | * __StackLimit |
| 65 | * __StackTop |
| 66 | * __stack |
| 67 | */ |
| 68 | ENTRY(Reset_Handler) |
| 69 | |
| 70 | SECTIONS |
| 71 | { |
| 72 | .text.at_itcm : |
| 73 | { |
| 74 | KEEP(*(.vectors)) |
Richard Burton | 0d11059 | 2021-08-12 17:26:30 +0100 | [diff] [blame] | 75 | |
| 76 | /** |
Kshitij Sisodia | 987efae | 2023-02-14 16:28:40 +0000 | [diff] [blame] | 77 | * Any code that is not time sensitive can be excluded from here. |
| 78 | * This code is instead placed on BRAM. See comment in the BRAM |
| 79 | * section for details. |
| 80 | */ |
| 81 | *(EXCLUDE_FILE(*all_ops_resolver.o |
| 82 | *hal.c.obj |
| 83 | *_allocator.o |
| 84 | *flatbuffer*.o |
| 85 | *lcd*.obj |
| 86 | *timing_adapter.c.obj) |
| 87 | .text*) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 88 | |
| 89 | KEEP(*(.init)) |
| 90 | KEEP(*(.fini)) |
| 91 | |
| 92 | /* .ctors */ |
| 93 | *crtbegin.o(.ctors) |
| 94 | *crtbegin?.o(.ctors) |
| 95 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) |
| 96 | *(SORT(.ctors.*)) |
| 97 | *(.ctors) |
| 98 | |
| 99 | /* .dtors */ |
| 100 | *crtbegin.o(.dtors) |
| 101 | *crtbegin?.o(.dtors) |
| 102 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) |
| 103 | *(SORT(.dtors.*)) |
| 104 | *(.dtors) |
| 105 | |
| 106 | KEEP(*(.eh_frame*)) |
| 107 | } > ITCM |
| 108 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 109 | __exidx_start = .; |
| 110 | .ARM.exidx.at_itcm : |
| 111 | { |
| 112 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) |
| 113 | } > ITCM |
| 114 | __exidx_end = .; |
| 115 | |
| 116 | .zero.table.at_itcm : |
| 117 | { |
| 118 | . = ALIGN(4); |
| 119 | __zero_table_start__ = .; |
| 120 | |
| 121 | LONG (__bss_start__) |
| 122 | LONG ((__bss_end__ - __bss_start__)/4) /* Size is in 32-bit words */ |
| 123 | |
| 124 | __zero_table_end__ = .; |
| 125 | } > ITCM |
| 126 | |
| 127 | .copy.table.at_itcm : |
| 128 | { |
| 129 | . = ALIGN(4); |
| 130 | __copy_table_start__ = .; |
| 131 | |
| 132 | /* Section to be copied - part 1: any data to be placed in BRAM */ |
| 133 | LONG (__etext) |
| 134 | LONG (__data_start__) |
| 135 | LONG ((__data_end__ - __data_start__)/4) /* Size is in 32-bit words */ |
| 136 | |
| 137 | /* Section to be copied - part 2: RO data for for DTCM */ |
| 138 | LONG (__etext2) |
| 139 | LONG (__ro_data_start__) |
| 140 | LONG ((__ro_data_end__ - __ro_data_start__)/4) /* Size is in 32-bit words */ |
| 141 | |
| 142 | __copy_table_end__ = .; |
| 143 | } > ITCM |
| 144 | |
| 145 | __itcm_total = ALIGN(4); |
| 146 | |
| 147 | ASSERT( __itcm_total < (ORIGIN(ITCM) + LENGTH(ITCM)), "ITCM overflow") |
| 148 | |
| 149 | .sram : |
| 150 | { |
| 151 | . = ALIGN(16); |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 152 | /* Cache area (if used) */ |
| 153 | *(.bss.NoInit.ethos_u_cache) |
| 154 | . = ALIGN (16); |
| 155 | /* activation buffers a.k.a tensor arena when memory mode sram only or shared sram */ |
| 156 | *(.bss.NoInit.activation_buf_sram) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 157 | . = ALIGN(16); |
| 158 | } > SRAM AT > SRAM |
| 159 | |
| 160 | .bss : |
| 161 | { |
| 162 | . = ALIGN(4); |
| 163 | __bss_start__ = .; |
| 164 | *(.bss) |
| 165 | *(.bss.*) |
| 166 | *(COMMON) |
| 167 | . = ALIGN(4); |
| 168 | __bss_end__ = .; |
| 169 | } > DTCM AT > DTCM |
| 170 | |
| 171 | .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) : |
| 172 | { |
| 173 | . = ALIGN(8); |
| 174 | __StackLimit = .; |
| 175 | . = . + __STACK_SIZE; |
| 176 | . = ALIGN(8); |
| 177 | __StackTop = .; |
| 178 | } > DTCM |
| 179 | PROVIDE(__stack = __StackTop); |
| 180 | ASSERT( |
| 181 | (__STACK_SIZE + __bss_end__ - __bss_start__) <= LENGTH(DTCM), |
| 182 | "DTCM overflow") |
| 183 | |
| 184 | .ddr.at_ddr : |
| 185 | { |
| 186 | /* __attribute__((aligned(16))) is not handled by the CMSIS startup code. |
| 187 | * Force the alignment here as a workaround */ |
| 188 | . = ALIGN(16); |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 189 | /* nn model's baked in input matrices */ |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 190 | *(ifm) |
| 191 | . = ALIGN(16); |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 192 | /* nn model's default space */ |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 193 | *(nn_model) |
| 194 | . = ALIGN (16); |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 195 | /* labels */ |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 196 | *(labels) |
| 197 | . = ALIGN (16); |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 198 | /* activation buffers a.k.a tensor arena when memory mode dedicated sram */ |
| 199 | *(activation_buf_dram) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 200 | . = ALIGN (16); |
| 201 | } > DDR AT > DDR |
| 202 | |
| 203 | /** |
| 204 | * Location counter can end up 2byte aligned with narrow Thumb code but |
| 205 | * __etext is assumed by startup code to be the LMA of a section in DTCM |
| 206 | * which must be 4byte aligned |
| 207 | */ |
| 208 | __etext = ALIGN (4); |
| 209 | |
| 210 | .bram.at_ddr : AT (__etext) |
| 211 | { |
| 212 | __data_start__ = .; |
| 213 | *(vtable) |
| 214 | *(.data) |
| 215 | *(.data.*) |
| 216 | . = ALIGN(4); |
| 217 | PROVIDE_HIDDEN (__preinit_array_start = .); |
| 218 | KEEP(*(.preinit_array)) |
| 219 | PROVIDE_HIDDEN (__preinit_array_end = .); |
| 220 | . = ALIGN(4); |
| 221 | PROVIDE_HIDDEN (__init_array_start = .); |
| 222 | KEEP(*(SORT(.init_array.*))) |
| 223 | KEEP(*(.init_array)) |
| 224 | PROVIDE_HIDDEN (__init_array_end = .); |
| 225 | . = ALIGN(4); |
| 226 | PROVIDE_HIDDEN (__fini_array_start = .); |
| 227 | KEEP(*(SORT(.fini_array.*))) |
| 228 | KEEP(*(.fini_array)) |
| 229 | PROVIDE_HIDDEN (__fini_array_end = .); |
| 230 | KEEP(*(.jcr*)) |
| 231 | . = ALIGN(4); |
| 232 | |
Richard Burton | 0d11059 | 2021-08-12 17:26:30 +0100 | [diff] [blame] | 233 | *(.ARM.extab* .gnu.linkonce.armextab.*) |
| 234 | . = ALIGN(4); |
| 235 | |
| 236 | /** |
| 237 | * Place the all ops resolver code data here. This accounts |
| 238 | * for ~4k worth of saving on the ITCM load region. It is |
| 239 | * only designed to be included (by default) for the inference |
| 240 | * runner use case. |
| 241 | **/ |
| 242 | *all_ops_resolver.o (*.text*) |
| 243 | . = ALIGN(4); |
Éanna Ó Catháin | 8f95887 | 2021-09-15 09:32:30 +0100 | [diff] [blame] | 244 | *hal.c.obj (*.text*) |
| 245 | . = ALIGN(4); |
Kshitij Sisodia | 987efae | 2023-02-14 16:28:40 +0000 | [diff] [blame] | 246 | *_allocator.o (*.text*) |
| 247 | . = ALIGN(4); |
| 248 | *flatbuffer*.o (*.text*) |
| 249 | . = ALIGN(4); |
| 250 | *lcd*.obj (*.text*) |
| 251 | . = ALIGN(4); |
| 252 | *timing_adapter.* (*.text*) |
| 253 | . = ALIGN(4); |
Richard Burton | 0d11059 | 2021-08-12 17:26:30 +0100 | [diff] [blame] | 254 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 255 | __data_end__ = .; |
| 256 | } > BRAM |
| 257 | |
| 258 | __etext2 = __etext + (__data_end__ - __data_start__); |
| 259 | |
| 260 | .data.at_ddr : AT (__etext2) |
| 261 | { |
| 262 | . = ALIGN(4); |
| 263 | __ro_data_start__ = .; |
| 264 | |
| 265 | *(.rodata*) |
| 266 | . = ALIGN(4); |
| 267 | * (npu_driver_version) |
| 268 | . = ALIGN(4); |
| 269 | * (npu_driver_arch_version) |
| 270 | . = ALIGN(4); |
| 271 | |
| 272 | __ro_data_end__ = .; |
| 273 | } > BRAM |
| 274 | |
| 275 | .heap (COPY) : |
| 276 | { |
| 277 | . = ALIGN(8); |
| 278 | __end__ = .; |
| 279 | PROVIDE(end = .); |
| 280 | . = . + __HEAP_SIZE; |
| 281 | . = ALIGN(8); |
| 282 | __HeapLimit = .; |
| 283 | } > BRAM |
| 284 | |
| 285 | ASSERT ( |
| 286 | (__ro_data_end__ - __ro_data_start__) |
| 287 | + (__data_end__ - __data_start__) |
| 288 | + __HEAP_SIZE <= LENGTH(BRAM), |
| 289 | "BRAM overflow") |
| 290 | } |