|
| 1 | +/* Based on GCC ARM embedded samples. |
| 2 | + Defines the following symbols for use by code: |
| 3 | + __exidx_start |
| 4 | + __exidx_end |
| 5 | + __etext |
| 6 | + __data_start__ |
| 7 | + __preinit_array_start |
| 8 | + __preinit_array_end |
| 9 | + __init_array_start |
| 10 | + __init_array_end |
| 11 | + __fini_array_start |
| 12 | + __fini_array_end |
| 13 | + __data_end__ |
| 14 | + __bss_start__ |
| 15 | + __bss_end__ |
| 16 | + __end__ |
| 17 | + end |
| 18 | + __HeapLimit |
| 19 | + __StackLimit |
| 20 | + __StackTop |
| 21 | + __stack (== StackTop) |
| 22 | +*/ |
| 23 | + |
| 24 | +MEMORY |
| 25 | +{ |
| 26 | + FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 640k |
| 27 | + RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k |
| 28 | + SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k |
| 29 | + SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k |
| 30 | +} |
| 31 | + |
| 32 | +ENTRY(_entry_point) |
| 33 | + |
| 34 | +SECTIONS |
| 35 | +{ |
| 36 | + /* Second stage bootloader is prepended to the image. It must be 256 bytes big |
| 37 | + and checksummed. It is usually built by the boot_stage2 target |
| 38 | + in the Raspberry Pi Pico SDK |
| 39 | + */ |
| 40 | + |
| 41 | + .flash_begin : { |
| 42 | + __flash_binary_start = .; |
| 43 | + } > FLASH |
| 44 | + |
| 45 | + .boot2 : { |
| 46 | + __boot2_start__ = .; |
| 47 | + KEEP (*(.boot2)) |
| 48 | + __boot2_end__ = .; |
| 49 | + } > FLASH |
| 50 | + |
| 51 | + ASSERT(__boot2_end__ - __boot2_start__ == 256, |
| 52 | + "ERROR: Pico second stage bootloader must be 256 bytes in size") |
| 53 | + |
| 54 | + /* The second stage will always enter the image at the start of .text. |
| 55 | + The debugger will use the ELF entry point, which is the _entry_point |
| 56 | + symbol if present, otherwise defaults to start of .text. |
| 57 | + This can be used to transfer control back to the bootrom on debugger |
| 58 | + launches only, to perform proper flash setup. |
| 59 | + */ |
| 60 | + |
| 61 | + .text : { |
| 62 | + __logical_binary_start = .; |
| 63 | + KEEP (*(.vectors)) |
| 64 | + KEEP (*(.binary_info_header)) |
| 65 | + __binary_info_header_end = .; |
| 66 | + KEEP (*(.reset)) |
| 67 | + /* TODO revisit this now memset/memcpy/float in ROM */ |
| 68 | + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from |
| 69 | + * FLASH ... we will include any thing excluded here in .data below by default */ |
| 70 | + *(.init) |
| 71 | + /* Change for MicroPython... excluse gc.c, parse.c, vm.c from flash */ |
| 72 | + *(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib_a-mem*.o *libm.a: *gc.c.obj *vm.c.obj *parse.c.obj) .text*) |
| 73 | + *(.fini) |
| 74 | + /* Pull all c'tors into .text */ |
| 75 | + *crtbegin.o(.ctors) |
| 76 | + *crtbegin?.o(.ctors) |
| 77 | + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) |
| 78 | + *(SORT(.ctors.*)) |
| 79 | + *(.ctors) |
| 80 | + /* Followed by destructors */ |
| 81 | + *crtbegin.o(.dtors) |
| 82 | + *crtbegin?.o(.dtors) |
| 83 | + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) |
| 84 | + *(SORT(.dtors.*)) |
| 85 | + *(.dtors) |
| 86 | + |
| 87 | + *(.eh_frame*) |
| 88 | + . = ALIGN(4); |
| 89 | + } > FLASH |
| 90 | + |
| 91 | + .rodata : { |
| 92 | + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) |
| 93 | + . = ALIGN(4); |
| 94 | + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) |
| 95 | + . = ALIGN(4); |
| 96 | + } > FLASH |
| 97 | + |
| 98 | + .ARM.extab : |
| 99 | + { |
| 100 | + *(.ARM.extab* .gnu.linkonce.armextab.*) |
| 101 | + } > FLASH |
| 102 | + |
| 103 | + __exidx_start = .; |
| 104 | + .ARM.exidx : |
| 105 | + { |
| 106 | + *(.ARM.exidx* .gnu.linkonce.armexidx.*) |
| 107 | + } > FLASH |
| 108 | + __exidx_end = .; |
| 109 | + |
| 110 | + /* Machine inspectable binary information */ |
| 111 | + . = ALIGN(4); |
| 112 | + __binary_info_start = .; |
| 113 | + .binary_info : |
| 114 | + { |
| 115 | + KEEP(*(.binary_info.keep.*)) |
| 116 | + *(.binary_info.*) |
| 117 | + } > FLASH |
| 118 | + __binary_info_end = .; |
| 119 | + . = ALIGN(4); |
| 120 | + |
| 121 | + /* End of .text-like segments */ |
| 122 | + __etext = .; |
| 123 | + |
| 124 | + .ram_vector_table (COPY): { |
| 125 | + *(.ram_vector_table) |
| 126 | + } > RAM |
| 127 | + |
| 128 | + .data : { |
| 129 | + __data_start__ = .; |
| 130 | + *(vtable) |
| 131 | + |
| 132 | + *(.time_critical*) |
| 133 | + |
| 134 | + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ |
| 135 | + *(.text*) |
| 136 | + . = ALIGN(4); |
| 137 | + *(.rodata*) |
| 138 | + . = ALIGN(4); |
| 139 | + |
| 140 | + *(.data*) |
| 141 | + |
| 142 | + . = ALIGN(4); |
| 143 | + *(.after_data.*) |
| 144 | + . = ALIGN(4); |
| 145 | + /* preinit data */ |
| 146 | + PROVIDE_HIDDEN (__mutex_array_start = .); |
| 147 | + KEEP(*(SORT(.mutex_array.*))) |
| 148 | + KEEP(*(.mutex_array)) |
| 149 | + PROVIDE_HIDDEN (__mutex_array_end = .); |
| 150 | + |
| 151 | + . = ALIGN(4); |
| 152 | + /* preinit data */ |
| 153 | + PROVIDE_HIDDEN (__preinit_array_start = .); |
| 154 | + KEEP(*(SORT(.preinit_array.*))) |
| 155 | + KEEP(*(.preinit_array)) |
| 156 | + PROVIDE_HIDDEN (__preinit_array_end = .); |
| 157 | + |
| 158 | + . = ALIGN(4); |
| 159 | + /* init data */ |
| 160 | + PROVIDE_HIDDEN (__init_array_start = .); |
| 161 | + KEEP(*(SORT(.init_array.*))) |
| 162 | + KEEP(*(.init_array)) |
| 163 | + PROVIDE_HIDDEN (__init_array_end = .); |
| 164 | + |
| 165 | + . = ALIGN(4); |
| 166 | + /* finit data */ |
| 167 | + PROVIDE_HIDDEN (__fini_array_start = .); |
| 168 | + *(SORT(.fini_array.*)) |
| 169 | + *(.fini_array) |
| 170 | + PROVIDE_HIDDEN (__fini_array_end = .); |
| 171 | + |
| 172 | + *(.jcr) |
| 173 | + . = ALIGN(4); |
| 174 | + /* All data end */ |
| 175 | + __data_end__ = .; |
| 176 | + } > RAM AT> FLASH |
| 177 | + |
| 178 | + .uninitialized_data (COPY): { |
| 179 | + . = ALIGN(4); |
| 180 | + *(.uninitialized_data*) |
| 181 | + } > RAM |
| 182 | + |
| 183 | + /* Start and end symbols must be word-aligned */ |
| 184 | + .scratch_x : { |
| 185 | + __scratch_x_start__ = .; |
| 186 | + *(.scratch_x.*) |
| 187 | + . = ALIGN(4); |
| 188 | + __scratch_x_end__ = .; |
| 189 | + } > SCRATCH_X AT > FLASH |
| 190 | + __scratch_x_source__ = LOADADDR(.scratch_x); |
| 191 | + |
| 192 | + .scratch_y : { |
| 193 | + __scratch_y_start__ = .; |
| 194 | + *(.scratch_y.*) |
| 195 | + . = ALIGN(4); |
| 196 | + __scratch_y_end__ = .; |
| 197 | + } > SCRATCH_Y AT > FLASH |
| 198 | + __scratch_y_source__ = LOADADDR(.scratch_y); |
| 199 | + |
| 200 | + .bss : { |
| 201 | + . = ALIGN(4); |
| 202 | + __bss_start__ = .; |
| 203 | + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) |
| 204 | + *(COMMON) |
| 205 | + . = ALIGN(4); |
| 206 | + __bss_end__ = .; |
| 207 | + } > RAM |
| 208 | + |
| 209 | + .heap (COPY): |
| 210 | + { |
| 211 | + __end__ = .; |
| 212 | + end = __end__; |
| 213 | + *(.heap*) |
| 214 | + __HeapLimit = .; |
| 215 | + } > RAM |
| 216 | + |
| 217 | + /* .stack*_dummy section doesn't contains any symbols. It is only |
| 218 | + * used for linker to calculate size of stack sections, and assign |
| 219 | + * values to stack symbols later |
| 220 | + * |
| 221 | + * stack1 section may be empty/missing if platform_launch_core1 is not used */ |
| 222 | + |
| 223 | + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 |
| 224 | + * stack is not used then all of SCRATCH_X is free. |
| 225 | + */ |
| 226 | + .stack1_dummy (COPY): |
| 227 | + { |
| 228 | + *(.stack1*) |
| 229 | + } > SCRATCH_X |
| 230 | + .stack_dummy (COPY): |
| 231 | + { |
| 232 | + *(.stack*) |
| 233 | + } > SCRATCH_Y |
| 234 | + |
| 235 | + .flash_end : { |
| 236 | + __flash_binary_end = .; |
| 237 | + } > FLASH |
| 238 | + |
| 239 | + /* stack limit is poorly named, but historically is maximum heap ptr */ |
| 240 | + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); |
| 241 | + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); |
| 242 | + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); |
| 243 | + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); |
| 244 | + __StackBottom = __StackTop - SIZEOF(.stack_dummy); |
| 245 | + PROVIDE(__stack = __StackTop); |
| 246 | + |
| 247 | + /* Check if data + heap + stack exceeds RAM limit */ |
| 248 | + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") |
| 249 | + |
| 250 | + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") |
| 251 | + /* todo assert on extra code */ |
| 252 | +} |
| 253 | + |
0 commit comments