Merge pull request #10445 from mikeller/revert-10388_in_maintenance_branch
[betaflight.git] / src / link / stm32_flash.ld
blobc88e3fc53a4c412bcfb08faf8dcec796353f2997
1 /*
2 *****************************************************************************
3 **
4 **  File        : stm32_flash.ld
5 **
6 **  Abstract    : Common linker script for STM32 devices.
7 **
8 *****************************************************************************
9 */
11 /* Entry Point */
12 ENTRY(Reset_Handler)
14 /* Highest address of the user mode stack */
15 _estack = ORIGIN(STACKRAM) + LENGTH(STACKRAM);    /* end of RAM */
17 /* Base address where the config is stored. */
18 __config_start = ORIGIN(FLASH_CONFIG);
19 __config_end = ORIGIN(FLASH_CONFIG) + LENGTH(FLASH_CONFIG);
21 /* Generate a link error if heap and stack don't fit into RAM */
22 _Min_Heap_Size = 0;      /* required amount of heap  */
23 _Min_Stack_Size = 0x800; /* required amount of stack */
25 /* Define output sections */
26 SECTIONS
28   /* The startup code goes first into FLASH */
29   .isr_vector :
30   {
31     . = ALIGN(4);
32     PROVIDE (isr_vector_table_base = .);
33     KEEP(*(.isr_vector)) /* Startup code */
34     . = ALIGN(4);
35   } >FLASH
37   /* The program code and other data goes into FLASH */
38   .text :
39   {
40     . = ALIGN(4);
41     *(.text)           /* .text sections (code) */
42     *(.text*)          /* .text* sections (code) */
43     *(.rodata)         /* .rodata sections (constants, strings, etc.) */
44     *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
45     *(.glue_7)         /* glue arm to thumb code */
46     *(.glue_7t)        /* glue thumb to arm code */
47     *(.eh_frame)
49     KEEP (*(.init))
50     KEEP (*(.fini))
52     . = ALIGN(4);
53     _etext = .;        /* define a global symbols at end of code */
54   } >FLASH
56   /* Critical program code goes into CCM RAM */
57   /* Copy specific fast-executing code to CCM RAM */ 
58   ccm_code = LOADADDR(.ccm_code); 
59   .ccm_code :
60   {
61     . = ALIGN(4);
62     ccm_code_start = .; 
63     *(.ccm_code)
64     *(.ccm_code*)
65     . = ALIGN(4);
66     ccm_code_end = .; 
67   } >CCM AT >FLASH
70    .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
71     .ARM : {
72     __exidx_start = .;
73       *(.ARM.exidx*)
74       __exidx_end = .;
75     } >FLASH
77   .preinit_array     :
78   {
79     PROVIDE_HIDDEN (__preinit_array_start = .);
80     KEEP (*(.preinit_array*))
81     PROVIDE_HIDDEN (__preinit_array_end = .);
82   } >FLASH
83   .init_array :
84   {
85     PROVIDE_HIDDEN (__init_array_start = .);
86     KEEP (*(SORT(.init_array.*)))
87     KEEP (*(.init_array*))
88     PROVIDE_HIDDEN (__init_array_end = .);
89   } >FLASH
90   .fini_array :
91   {
92     PROVIDE_HIDDEN (__fini_array_start = .);
93     KEEP (*(.fini_array*))
94     KEEP (*(SORT(.fini_array.*)))
95     PROVIDE_HIDDEN (__fini_array_end = .);
96   } >FLASH
97   .pg_registry :
98   {
99     PROVIDE_HIDDEN (__pg_registry_start = .);
100     KEEP (*(.pg_registry))
101     KEEP (*(SORT(.pg_registry.*)))
102     PROVIDE_HIDDEN (__pg_registry_end = .);
103   } >FLASH
104   .pg_resetdata :
105   {
106     PROVIDE_HIDDEN (__pg_resetdata_start = .);
107     KEEP (*(.pg_resetdata))
108     PROVIDE_HIDDEN (__pg_resetdata_end = .);
109   } >FLASH
111   /* used by the startup to initialize data */
112   _sidata = .;
114   /* Initialized data sections goes into RAM, load LMA copy after code */
115   .data :
116   {
117     . = ALIGN(4);
118     _sdata = .;        /* create a global symbol at data start */
119     *(.data)           /* .data sections */
120     *(.data*)          /* .data* sections */
122     . = ALIGN(4);
123     _edata = .;        /* define a global symbol at data end */
124   } >RAM AT> FLASH
126   /* Uninitialized data section */
127   . = ALIGN(4);
128   .bss :
129   {
130     /* This is used by the startup in order to initialize the .bss secion */
131     _sbss = .;         /* define a global symbol at bss start */
132     __bss_start__ = _sbss;
133     *(.bss)
134     *(SORT_BY_ALIGNMENT(.bss*))
135     *(COMMON)
137     . = ALIGN(4);
138     _ebss = .;         /* define a global symbol at bss end */
139     __bss_end__ = _ebss;
140   } >RAM
141   
142   .fastram_bss (NOLOAD) :
143   {
144     __fastram_bss_start__ = .;
145     *(.fastram_bss)
146     *(SORT_BY_ALIGNMENT(.fastram_bss*))
147     . = ALIGN(4);
148     __fastram_bss_end__ = .;
149   } >FASTRAM
151   /* User_heap_stack section, used to check that there is enough RAM left */
152   _heap_stack_end = ORIGIN(STACKRAM)+LENGTH(STACKRAM) - 8; /* 8 bytes to allow for alignment */
153   _heap_stack_begin = _heap_stack_end - _Min_Stack_Size  - _Min_Heap_Size;
154   . = _heap_stack_begin;
155   ._user_heap_stack :
156   {
157     . = ALIGN(4);
158     PROVIDE ( end = . );
159     PROVIDE ( _end = . );
160     . = . + _Min_Heap_Size;
161     . = . + _Min_Stack_Size;
162     . = ALIGN(4);
163   } >STACKRAM = 0xa5
165   /* MEMORY_bank1 section, code must be located here explicitly            */
166   /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
167   .memory_b1_text :
168   {
169     *(.mb1text)        /* .mb1text sections (code) */
170     *(.mb1text*)       /* .mb1text* sections (code)  */
171     *(.mb1rodata)      /* read-only data (constants) */
172     *(.mb1rodata*)
173   } >MEMORY_B1
175   /* Remove information from the standard libraries */
176   /DISCARD/ :
177   {
178     libc.a ( * )
179     libm.a ( * )
180     libgcc.a ( * )
181   }
183   .ARM.attributes 0 : { *(.ARM.attributes) }