|
| 1 | +/* Linker script to configure memory regions. |
| 2 | + * Need modifying for a specific board. |
| 3 | + * FLASH.ORIGIN: starting address of flash |
| 4 | + * FLASH.LENGTH: length of flash |
| 5 | + * RAM.ORIGIN: starting address of RAM bank 0 |
| 6 | + * RAM.LENGTH: length of RAM bank 0 |
| 7 | + */ |
| 8 | +MEMORY |
| 9 | +{ |
| 10 | + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 |
| 11 | + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 |
| 12 | +} |
| 13 | + |
| 14 | +/* Linker script to place sections and symbol values. Should be used together |
| 15 | + * with other linker script that defines memory regions FLASH and RAM. |
| 16 | + * It references following symbols, which must be defined in code: |
| 17 | + * Reset_Handler : Entry of reset handler |
| 18 | + * |
| 19 | + * It defines following symbols, which code can use without definition: |
| 20 | + * __exidx_start |
| 21 | + * __exidx_end |
| 22 | + * __copy_table_start__ |
| 23 | + * __copy_table_end__ |
| 24 | + * __zero_table_start__ |
| 25 | + * __zero_table_end__ |
| 26 | + * __etext |
| 27 | + * __data_start__ |
| 28 | + * __preinit_array_start |
| 29 | + * __preinit_array_end |
| 30 | + * __init_array_start |
| 31 | + * __init_array_end |
| 32 | + * __fini_array_start |
| 33 | + * __fini_array_end |
| 34 | + * __data_end__ |
| 35 | + * __bss_start__ |
| 36 | + * __bss_end__ |
| 37 | + * __end__ |
| 38 | + * end |
| 39 | + * __HeapLimit |
| 40 | + * __StackLimit |
| 41 | + * __StackTop |
| 42 | + * __stack |
| 43 | + */ |
| 44 | +ENTRY(Reset_Handler) |
| 45 | + |
| 46 | +SECTIONS |
| 47 | +{ |
| 48 | + .text : |
| 49 | + { |
| 50 | + KEEP(*(.isr_vector)) |
| 51 | + *(.text*) |
| 52 | + |
| 53 | + KEEP(*(.init)) |
| 54 | + KEEP(*(.fini)) |
| 55 | + |
| 56 | + /* .ctors */ |
| 57 | + *crtbegin.o(.ctors) |
| 58 | + *crtbegin?.o(.ctors) |
| 59 | + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) |
| 60 | + *(SORT(.ctors.*)) |
| 61 | + *(.ctors) |
| 62 | + |
| 63 | + /* .dtors */ |
| 64 | + *crtbegin.o(.dtors) |
| 65 | + *crtbegin?.o(.dtors) |
| 66 | + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) |
| 67 | + *(SORT(.dtors.*)) |
| 68 | + *(.dtors) |
| 69 | + |
| 70 | + KEEP(*(.eh_frame*)) |
| 71 | + } > FLASH |
| 72 | + |
| 73 | + .rodata : |
| 74 | + { |
| 75 | + *(.rodata .rodata.*) |
| 76 | + } > FLASH |
| 77 | + |
| 78 | + .ARM.extab : |
| 79 | + { |
| 80 | + *(.ARM.extab* .gnu.linkonce.armextab.*) |
| 81 | + } > FLASH |
| 82 | + |
| 83 | + __exidx_start = .; |
| 84 | + .ARM.exidx : |
| 85 | + { |
| 86 | + *(.ARM.exidx .ARM.exidx* .gnu.linkonce.armexidx.*) |
| 87 | + } > FLASH |
| 88 | + __exidx_end = .; |
| 89 | + |
| 90 | + /* To copy multiple ROM to RAM sections, |
| 91 | + * uncomment .copy.table section and, |
| 92 | + * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */ |
| 93 | + /* |
| 94 | + .copy.table : |
| 95 | + { |
| 96 | + . = ALIGN(4); |
| 97 | + __copy_table_start__ = .; |
| 98 | + LONG (__etext) |
| 99 | + LONG (__data_start__) |
| 100 | + LONG (__data_end__ - __data_start__) |
| 101 | + LONG (__etext2) |
| 102 | + LONG (__data2_start__) |
| 103 | + LONG (__data2_end__ - __data2_start__) |
| 104 | + __copy_table_end__ = .; |
| 105 | + } > FLASH |
| 106 | + */ |
| 107 | + |
| 108 | + /* To clear multiple BSS sections, |
| 109 | + * uncomment .zero.table section and, |
| 110 | + * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */ |
| 111 | + /* |
| 112 | + .zero.table : |
| 113 | + { |
| 114 | + . = ALIGN(4); |
| 115 | + __zero_table_start__ = .; |
| 116 | + LONG (__bss_start__) |
| 117 | + LONG (__bss_end__ - __bss_start__) |
| 118 | + LONG (__bss2_start__) |
| 119 | + LONG (__bss2_end__ - __bss2_start__) |
| 120 | + __zero_table_end__ = .; |
| 121 | + } > FLASH |
| 122 | + */ |
| 123 | + |
| 124 | + /* Location counter can end up 2byte aligned with narrow Thumb code but |
| 125 | + __etext is assumed by startup code to be the LMA of a section in RAM |
| 126 | + which must be 4byte aligned */ |
| 127 | + __etext = ALIGN (4); |
| 128 | + |
| 129 | + .data : AT (__etext) |
| 130 | + { |
| 131 | + __data_start__ = .; |
| 132 | + *(vtable) |
| 133 | + *(.data*) |
| 134 | + |
| 135 | + . = ALIGN(4); |
| 136 | + /* preinit data */ |
| 137 | + PROVIDE_HIDDEN (__preinit_array_start = .); |
| 138 | + KEEP(*(.preinit_array)) |
| 139 | + PROVIDE_HIDDEN (__preinit_array_end = .); |
| 140 | + |
| 141 | + . = ALIGN(4); |
| 142 | + /* init data */ |
| 143 | + PROVIDE_HIDDEN (__init_array_start = .); |
| 144 | + KEEP(*(SORT(.init_array.*))) |
| 145 | + KEEP(*(.init_array)) |
| 146 | + PROVIDE_HIDDEN (__init_array_end = .); |
| 147 | + |
| 148 | + |
| 149 | + . = ALIGN(4); |
| 150 | + /* finit data */ |
| 151 | + PROVIDE_HIDDEN (__fini_array_start = .); |
| 152 | + KEEP(*(SORT(.fini_array.*))) |
| 153 | + KEEP(*(.fini_array)) |
| 154 | + PROVIDE_HIDDEN (__fini_array_end = .); |
| 155 | + |
| 156 | + KEEP(*(.jcr*)) |
| 157 | + . = ALIGN(4); |
| 158 | + /* All data end */ |
| 159 | + __data_end__ = .; |
| 160 | + |
| 161 | + } > RAM |
| 162 | + |
| 163 | + .bss : |
| 164 | + { |
| 165 | + . = ALIGN(4); |
| 166 | + __bss_start__ = .; |
| 167 | + *(.bss*) |
| 168 | + *(COMMON) |
| 169 | + . = ALIGN(4); |
| 170 | + __bss_end__ = .; |
| 171 | + } > RAM |
| 172 | + |
| 173 | + .heap (COPY): |
| 174 | + { |
| 175 | + __end__ = .; |
| 176 | + PROVIDE(end = .); |
| 177 | + *(.heap*) |
| 178 | + __HeapLimit = .; |
| 179 | + } > RAM |
| 180 | + |
| 181 | + /* .stack_dummy section doesn't contains any symbols. It is only |
| 182 | + * used for linker to calculate size of stack sections, and assign |
| 183 | + * values to stack symbols later */ |
| 184 | + .stack_dummy (COPY): |
| 185 | + { |
| 186 | + *(.stack*) |
| 187 | + } > RAM |
| 188 | + |
| 189 | + /* Set stack top to end of RAM, and stack limit move down by |
| 190 | + * size of stack_dummy section */ |
| 191 | + __StackTop = ORIGIN(RAM) + LENGTH(RAM); |
| 192 | + __StackLimit = __StackTop - SIZEOF(.stack_dummy); |
| 193 | + PROVIDE(__stack = __StackTop); |
| 194 | + |
| 195 | + /* Check if data + heap + stack exceeds RAM limit */ |
| 196 | + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") |
| 197 | +} |
0 commit comments