Rev Author Line No. Line
3328 povik 1 /*
2 * GCC linker script for STM32 microcontrollers (ARM Cortex-M).
3 *
4 * It exports the symbols needed for the CMSIS assembler startup script for GCC
5 * ARM toolchains (_sidata, _sdata, _edata, _sbss, _ebss) and sets the entry
6 * point to Reset_Handler.
7 *
8 * Adapt FLASH/RAM size for your particular device below.
9 *
10 * @author Bjørn Forsman
11 */
12  
13 MEMORY
14 {
15 flash (rx) : ORIGIN = 0x08000000, LENGTH = 256K
16 ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
17 }
18  
19 ENTRY(Reset_Handler)
20  
21 /*
22 * Reserve memory for heap and stack. The linker will issue an error if there
23 * is not enough memory.
24 *
25 * NOTE: The reserved heap and stack will be added to the bss column of the
26 * binutils size command.
27 */
28 _heap_size = 0; /* required amount of heap */
29 _stack_size = 0; /* required amount of stack */
30  
31 /*
32 * The stack starts at the end of RAM and grows downwards. Full-descending
33 * stack; decrement first, then store.
34 */
35 _estack = ORIGIN(ram) + LENGTH(ram);
36  
37 SECTIONS
38 {
39 /* Reset and ISR vectors */
40 .isr_vector :
41 {
42 __isr_vector_start__ = .;
43 KEEP(*(.isr_vector)) /* without 'KEEP' the garbage collector discards this section */
44 ASSERT(. != __isr_vector_start__, "The .isr_vector section is empty");
45 } >flash
46  
47  
48 /* Text section (code and read-only data) */
49 .text :
50 {
51 . = ALIGN(4);
52 _stext = .;
53 *(.text*) /* code */
54 *(.rodata*) /* read only data */
55  
56 /*
57 * NOTE: .glue_7 and .glue_7t sections are not needed because Cortex-M
58 * only supports Thumb instructions, no ARM/Thumb interworking.
59 */
60  
61 /* Static constructors and destructors */
62 KEEP(*(.init))
63 KEEP(*(.fini))
64  
65 . = ALIGN(4);
66 _etext = .;
67 } >flash
68  
69  
70 /*
71 * Stack unwinding and exception handling sections.
72 *
73 * ARM compilers emit object files with .ARM.extab and .ARM.exidx sections
74 * when using C++ exceptions. Also, at least GCC emits those sections when
75 * dividing large numbers (64-bit) in C. So we have to handle them.
76 *
77 * (ARM uses .ARM.extab and .ARM.exidx instead of the .eh_frame section
78 * used on x86.)
79 */
80 .ARM.extab : /* exception unwinding information */
81 {
82 *(.ARM.extab*)
83 } >flash
84 .ARM.exidx : /* index entries for section unwinding */
85 {
86 *(.ARM.exidx*)
87 } >flash
88  
89  
90 /*
91 * Newlib and Eglibc (at least) need these for C++ support.
92 *
93 * (Copied from Sourcery CodeBench Lite: arm-none-eabi-gcc -V)
94 */
95 .preinit_array :
96 {
97 PROVIDE_HIDDEN(__preinit_array_start = .);
98 KEEP(*(.preinit_array*))
99 PROVIDE_HIDDEN(__preinit_array_end = .);
100 } >flash
101 .init_array :
102 {
103 PROVIDE_HIDDEN(__init_array_start = .);
104 KEEP(*(SORT(.init_array.*)))
105 KEEP(*(.init_array*))
106 PROVIDE_HIDDEN(__init_array_end = .);
107 } >flash
108 .fini_array :
109 {
110 PROVIDE_HIDDEN(__fini_array_start = .);
111 KEEP(*(SORT(.fini_array.*)))
112 KEEP(*(.fini_array*))
113 PROVIDE_HIDDEN(__fini_array_end = .);
114 } >flash
115  
116  
117 /*
118 * Initialized data section. This section is programmed into FLASH (LMA
119 * address) and copied to RAM (VMA address) in startup code.
120 */
121 _sidata = .;
122 .data : AT(_sidata) /* LMA address is _sidata (in FLASH) */
123 {
124 . = ALIGN(4);
125 _sdata = .; /* data section VMA address */
126 *(.data*)
127 . = ALIGN(4);
128 _edata = .;
129 } >ram
130  
131  
132 /* Uninitialized data section (zeroed out by startup code) */
133 .bss :
134 {
135 . = ALIGN(4);
136 _sbss = .;
137 *(.bss*)
138 *(COMMON)
139 . = ALIGN(4);
140 _ebss = .;
141 } >ram
142  
143  
144 /*
145 * Reserve memory for heap and stack. The linker will issue an error if
146 * there is not enough memory.
147 */
148 ._heap :
149 {
150 end = .;
151 . = ALIGN(4);
152 . = . + _heap_size;
153 . = ALIGN(4);
154 } >ram
155 ._stack :
156 {
157 . = ALIGN(4);
158 . = . + _stack_size;
159 . = ALIGN(4);
160 } >ram
161 }
162  
163 /* Nice to have */
164 __isr_vector_size__ = SIZEOF(.isr_vector);
165 __text_size__ = SIZEOF(.text);
166 __data_size__ = SIZEOF(.data);
167 __bss_size__ = SIZEOF(.bss);