2 *****************************************************************************
4 ** File : stm32_flash_split.ld
6 ** Abstract : Common linker script for STM32 devices.
8 *****************************************************************************
14 /* Highest address of the user mode stack */
15 _Hot_Reboot_Flags_Size = 16;
16 _estack = ORIGIN(STACKRAM) + LENGTH(STACKRAM) - _Hot_Reboot_Flags_Size; /* end of RAM */
18 /* Base address where the config is stored. */
19 __config_start = ORIGIN(FLASH_CONFIG);
20 __config_end = ORIGIN(FLASH_CONFIG) + LENGTH(FLASH_CONFIG);
22 /* Generate a link error if heap and stack don't fit into RAM */
23 _Min_Heap_Size = 0; /* required amount of heap */
24 _Min_Stack_Size = 0x800; /* required amount of stack */
26 /* Define output sections */
30 * The ISR vector table is loaded at the beginning of the FLASH,
31 * But it is linked (space reserved) at the beginning of the VECTAB region,
32 * which is aliased either to FLASH or RAM.
33 * When linked to RAM, the table can optionally be copied from FLASH to RAM
34 * for table relocation.
37 _isr_vector_table_flash_base = LOADADDR(.isr_vector);
38 PROVIDE (isr_vector_table_flash_base = _isr_vector_table_flash_base);
43 PROVIDE (isr_vector_table_base = .);
44 KEEP(*(.isr_vector)) /* Startup code */
46 PROVIDE (isr_vector_table_end = .);
49 /* System memory (read-only bootloader) interrupt vector */
50 .system_isr_vector (NOLOAD) :
53 PROVIDE (system_isr_vector_table_base = .);
54 KEEP(*(.system_isr_vector)) /* Bootloader code */
58 /* The program code and other data goes into FLASH */
62 *(.text) /* .text sections (code) */
63 *(.text*) /* .text* sections (code) */
64 *(.rodata) /* .rodata sections (constants, strings, etc.) */
65 *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
66 *(.glue_7) /* glue arm to thumb code */
67 *(.glue_7t) /* glue thumb to arm code */
74 _etext = .; /* define a global symbols at end of code */
78 .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
87 PROVIDE_HIDDEN (__preinit_array_start = .);
88 KEEP (*(.preinit_array*))
89 PROVIDE_HIDDEN (__preinit_array_end = .);
93 PROVIDE_HIDDEN (__init_array_start = .);
94 KEEP (*(SORT(.init_array.*)))
95 KEEP (*(.init_array*))
96 PROVIDE_HIDDEN (__init_array_end = .);
100 PROVIDE_HIDDEN (__fini_array_start = .);
101 KEEP (*(.fini_array*))
102 KEEP (*(SORT(.fini_array.*)))
103 PROVIDE_HIDDEN (__fini_array_end = .);
107 PROVIDE_HIDDEN (__pg_registry_start = .);
108 KEEP (*(.pg_registry))
109 KEEP (*(SORT(.pg_registry.*)))
110 PROVIDE_HIDDEN (__pg_registry_end = .);
114 PROVIDE_HIDDEN (__pg_resetdata_start = .);
115 KEEP (*(.pg_resetdata))
116 PROVIDE_HIDDEN (__pg_resetdata_end = .);
119 /* Storage for the address for the configuration section so we can grab it out of the hex file */
123 KEEP (*(.custom_defaults_start_address))
125 KEEP (*(.custom_defaults_end_address))
127 __custom_defaults_internal_start = .;
129 } >FLASH_CUSTOM_DEFAULTS
131 PROVIDE_HIDDEN (__custom_defaults_start = DEFINED(USE_CUSTOM_DEFAULTS_EXTENDED) ? ORIGIN(FLASH_CUSTOM_DEFAULTS_EXTENDED) : __custom_defaults_internal_start);
132 PROVIDE_HIDDEN (__custom_defaults_end = DEFINED(USE_CUSTOM_DEFAULTS_EXTENDED) ? ORIGIN(FLASH_CUSTOM_DEFAULTS_EXTENDED) + LENGTH(FLASH_CUSTOM_DEFAULTS_EXTENDED) : ORIGIN(FLASH_CUSTOM_DEFAULTS) + LENGTH(FLASH_CUSTOM_DEFAULTS));
134 /* used by the startup to initialize data */
135 _sidata = LOADADDR(.data);
137 /* Initialized data sections goes into RAM, load LMA copy after code */
141 _sdata = .; /* create a global symbol at data start */
142 *(.data) /* .data sections */
143 *(.data*) /* .data* sections */
146 _edata = .; /* define a global symbol at data end */
149 /* Uninitialized data section */
153 /* This is used by the startup in order to initialize the .bss secion */
154 _sbss = .; /* define a global symbol at bss start */
155 __bss_start__ = _sbss;
157 *(SORT_BY_ALIGNMENT(.bss*))
161 _ebss = .; /* define a global symbol at bss end */
165 /* used during startup to initialized fastram_data */
166 _sfastram_idata = LOADADDR(.fastram_data);
168 /* Initialized FAST_RAM section for unsuspecting developers */
172 _sfastram_data = .; /* create a global symbol at data start */
173 *(.fastram_data) /* .data sections */
174 *(.fastram_data*) /* .data* sections */
177 _efastram_data = .; /* define a global symbol at data end */
178 } >FASTRAM AT> FLASH1
181 .fastram_bss (NOLOAD) :
183 __fastram_bss_start__ = .;
185 *(SORT_BY_ALIGNMENT(.fastram_bss*))
187 __fastram_bss_end__ = .;
190 .persistent_data (NOLOAD) :
192 __persistent_data_start__ = .;
195 __persistent_data_end__ = .;
198 /* User_heap_stack section, used to check that there is enough RAM left */
199 _heap_stack_end = ORIGIN(STACKRAM) + LENGTH(STACKRAM) - _Hot_Reboot_Flags_Size;
200 _heap_stack_begin = _heap_stack_end - _Min_Stack_Size - _Min_Heap_Size;
201 . = _heap_stack_begin;
206 PROVIDE ( _end = . );
207 . = . + _Min_Heap_Size;
208 . = . + _Min_Stack_Size;
212 /* MEMORY_bank1 section, code must be located here explicitly */
213 /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
216 *(.mb1text) /* .mb1text sections (code) */
217 *(.mb1text*) /* .mb1text* sections (code) */
218 *(.mb1rodata) /* read-only data (constants) */
222 /* Remove information from the standard libraries */
230 .ARM.attributes 0 : { *(.ARM.attributes) }