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