Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 1 | /* |
Per Åstrand | 81e01af | 2021-02-19 13:45:26 +0100 | [diff] [blame] | 2 | * Copyright (c) 2009-2021 Arm Limited. All rights reserved. |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | * not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 19 | __STACK_SIZE = 0x00008000; |
| 20 | __HEAP_SIZE = 0x00008000; |
| 21 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 22 | MEMORY |
| 23 | { |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 24 | ITCM (rx) : ORIGIN = 0x10000000, LENGTH = 0x00080000 |
| 25 | SRAM (rw) : ORIGIN = 0x11000000, LENGTH = 0x01000000 |
| 26 | DTCM (rw) : ORIGIN = 0x30000000, LENGTH = 0x00080000 |
| 27 | DDR (rwx) : ORIGIN = 0x70000000, LENGTH = 0x60000000 |
| 28 | } |
| 29 | |
| 30 | PHDRS |
| 31 | { |
| 32 | rom_exec PT_LOAD; |
| 33 | rom_dram PT_LOAD; |
| 34 | null PT_NULL; |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* Linker script to place sections and symbol values. Should be used together |
| 38 | * with other linker script that defines memory regions ITCM and RAM. |
| 39 | * It references following symbols, which must be defined in code: |
| 40 | * Reset_Handler : Entry of reset handler |
| 41 | * |
| 42 | * It defines following symbols, which code can use without definition: |
| 43 | * __exidx_start |
| 44 | * __exidx_end |
| 45 | * __copy_table_start__ |
| 46 | * __copy_table_end__ |
| 47 | * __zero_table_start__ |
| 48 | * __zero_table_end__ |
| 49 | * __etext |
| 50 | * __data_start__ |
| 51 | * __preinit_array_start |
| 52 | * __preinit_array_end |
| 53 | * __init_array_start |
| 54 | * __init_array_end |
| 55 | * __fini_array_start |
| 56 | * __fini_array_end |
| 57 | * __data_end__ |
| 58 | * __bss_start__ |
| 59 | * __bss_end__ |
| 60 | * __end__ |
| 61 | * end |
| 62 | * __HeapLimit |
| 63 | * __StackLimit |
| 64 | * __StackTop |
| 65 | * __stack |
| 66 | */ |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 67 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 68 | ENTRY(Reset_Handler) |
| 69 | |
| 70 | SECTIONS |
| 71 | { |
| 72 | .text : |
| 73 | { |
| 74 | KEEP(*(.vectors)) |
| 75 | *(.text*) |
| 76 | |
| 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 | *(.rodata*) |
| 95 | |
| 96 | KEEP(*(.eh_frame*)) |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 97 | } > ITCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * SG veneers: |
| 101 | * All SG veneers are placed in the special output section .gnu.sgstubs. Its start address |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 102 | * must be set, either with the command line option '--section-start' or in a linker script, |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 103 | * to indicate where to place these veneers in memory. |
| 104 | */ |
| 105 | /* |
| 106 | .gnu.sgstubs : |
| 107 | { |
| 108 | . = ALIGN(32); |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 109 | } > ITCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 110 | */ |
| 111 | .ARM.extab : |
| 112 | { |
| 113 | *(.ARM.extab* .gnu.linkonce.armextab.*) |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 114 | } > ITCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 115 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 116 | .ARM.exidx : |
| 117 | { |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 118 | __exidx_start = .; |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 119 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 120 | __exidx_end = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 121 | } > ITCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 122 | |
| 123 | .copy.table : |
| 124 | { |
| 125 | . = ALIGN(4); |
| 126 | __copy_table_start__ = .; |
| 127 | LONG (__etext) |
| 128 | LONG (__data_start__) |
| 129 | LONG (__data_end__ - __data_start__) |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 130 | |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 131 | LONG (__eddr_data) |
| 132 | LONG (__sram_data_start__) |
| 133 | LONG (__sram_data_end__ - __sram_data_start__ ) |
| 134 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 135 | __copy_table_end__ = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 136 | } > ITCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 137 | |
| 138 | .zero.table : |
| 139 | { |
| 140 | . = ALIGN(4); |
| 141 | __zero_table_start__ = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 142 | LONG (__bss_start__) |
| 143 | LONG (__bss_end__ - __bss_start__) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 144 | __zero_table_end__ = .; |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Location counter can end up 2byte aligned with narrow Thumb code but |
| 148 | * __etext is assumed by startup code to be the LMA of a section in DTCM |
| 149 | * which must be 4byte aligned |
| 150 | */ |
| 151 | __etext = ALIGN (4); |
| 152 | |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 153 | } > ITCM :rom_exec |
| 154 | |
| 155 | .data : AT(__etext) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 156 | { |
| 157 | __data_start__ = .; |
| 158 | *(vtable) |
| 159 | *(.data) |
| 160 | *(.data.*) |
| 161 | |
| 162 | . = ALIGN(4); |
| 163 | /* preinit data */ |
| 164 | PROVIDE_HIDDEN (__preinit_array_start = .); |
| 165 | KEEP(*(.preinit_array)) |
| 166 | PROVIDE_HIDDEN (__preinit_array_end = .); |
| 167 | |
| 168 | . = ALIGN(4); |
| 169 | /* init data */ |
| 170 | PROVIDE_HIDDEN (__init_array_start = .); |
| 171 | KEEP(*(SORT(.init_array.*))) |
| 172 | KEEP(*(.init_array)) |
| 173 | PROVIDE_HIDDEN (__init_array_end = .); |
| 174 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 175 | . = ALIGN(4); |
| 176 | /* finit data */ |
| 177 | PROVIDE_HIDDEN (__fini_array_start = .); |
| 178 | KEEP(*(SORT(.fini_array.*))) |
| 179 | KEEP(*(.fini_array)) |
| 180 | PROVIDE_HIDDEN (__fini_array_end = .); |
| 181 | |
| 182 | KEEP(*(.jcr*)) |
| 183 | . = ALIGN(4); |
| 184 | /* All data end */ |
| 185 | __data_end__ = .; |
| 186 | |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 187 | } > DTCM :rom_exec |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 188 | |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 189 | .sram.bss : |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 190 | { |
| 191 | . = ALIGN(16); |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 192 | #ifdef ETHOSU_FAST_MEMORY_SIZE |
Per Åstrand | 81e01af | 2021-02-19 13:45:26 +0100 | [diff] [blame] | 193 | *(.bss.ethosu_scratch); |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 194 | #else |
| 195 | *(.bss.tensor_arena) |
| 196 | #endif |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 197 | *.(output_data_sec) |
| 198 | } > SRAM :null |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 199 | |
| 200 | .ddr : |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 201 | { |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 202 | #ifdef ETHOSU_FAST_MEMORY_SIZE |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 203 | . = ALIGN(16); |
Jonny Svärd | f521be9 | 2021-03-01 14:35:49 +0100 | [diff] [blame] | 204 | *(.bss.tensor_arena) |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 205 | #endif |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 206 | . = ALIGN(4); |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 207 | *(input_data_sec) |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 208 | . = ALIGN(16); |
| 209 | *(network_model_sec) |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 210 | *(expected_output_data_sec) |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 211 | } > DDR :rom_dram |
| 212 | |
| 213 | __eddr_data = ALIGN (16) ; |
| 214 | .sram.data : { |
| 215 | __sram_data_start__ = .; |
| 216 | *(.sram.data) |
| 217 | __sram_data_end__ = .; |
| 218 | } > SRAM AT >DDR :rom_dram |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 219 | |
| 220 | .bss : |
| 221 | { |
| 222 | . = ALIGN(4); |
| 223 | __bss_start__ = .; |
| 224 | *(.bss) |
| 225 | *(.bss.*) |
| 226 | *(COMMON) |
| 227 | . = ALIGN(4); |
| 228 | __bss_end__ = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 229 | } > DTCM :null |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 230 | |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 231 | .heap (COPY) : |
| 232 | { |
| 233 | . = ALIGN(8); |
| 234 | __end__ = .; |
| 235 | PROVIDE(end = .); |
| 236 | . = . + __HEAP_SIZE; |
| 237 | . = ALIGN(8); |
| 238 | __HeapLimit = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 239 | } > DTCM :null |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 240 | |
| 241 | .stack (ORIGIN(DTCM) + LENGTH(DTCM) - __STACK_SIZE) (COPY) : |
| 242 | { |
| 243 | . = ALIGN(8); |
| 244 | __StackLimit = .; |
| 245 | . = . + __STACK_SIZE; |
| 246 | . = ALIGN(8); |
| 247 | __StackTop = .; |
Per Åstrand | 0b7bbb4 | 2021-03-25 12:34:24 +0100 | [diff] [blame] | 248 | } > DTCM :null |
Kristofer Jonsson | 43ce491 | 2020-11-20 09:42:53 +0100 | [diff] [blame] | 249 | PROVIDE(__stack = __StackTop); |
| 250 | |
| 251 | /* Check if data + heap + stack exceeds DTCM limit */ |
| 252 | ASSERT(__StackLimit >= __HeapLimit, "region DTCM overflowed with stack") |
| 253 | } |