Skip to content

Commit 3009ce7

Browse files
committed
add mp linker script
1 parent 704474d commit 3009ce7

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
/* MicroPython
2+
Based on GCC ARM embedded samples.
3+
Defines the following symbols for use by code:
4+
__exidx_start
5+
__exidx_end
6+
__etext
7+
__data_start__
8+
__preinit_array_start
9+
__preinit_array_end
10+
__init_array_start
11+
__init_array_end
12+
__fini_array_start
13+
__fini_array_end
14+
__data_end__
15+
__bss_start__
16+
__bss_end__
17+
__end__
18+
end
19+
__HeapLimit
20+
__StackLimit
21+
__StackTop
22+
__stack (== StackTop)
23+
*/
24+
25+
MEMORY
26+
{
27+
FLASH(rx) : ORIGIN = 0x10000000 + 940k, LENGTH = 2048k - 940k
28+
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
29+
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
30+
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
31+
}
32+
33+
ENTRY(_entry_point)
34+
35+
SECTIONS
36+
{
37+
/* Second stage bootloader is prepended to the image. It must be 256 bytes big
38+
and checksummed. It is usually built by the boot_stage2 target
39+
in the Raspberry Pi Pico SDK
40+
*/
41+
42+
.flash_begin : {
43+
__flash_binary_start = .;
44+
} > FLASH
45+
46+
/* The second stage will always enter the image at the start of .text.
47+
The debugger will use the ELF entry point, which is the _entry_point
48+
symbol if present, otherwise defaults to start of .text.
49+
This can be used to transfer control back to the bootrom on debugger
50+
launches only, to perform proper flash setup.
51+
*/
52+
53+
.text : {
54+
__logical_binary_start = .;
55+
KEEP (*(.vectors))
56+
KEEP (*(.binary_info_header))
57+
__binary_info_header_end = .;
58+
KEEP (*(.reset))
59+
/* TODO revisit this now memset/memcpy/float in ROM */
60+
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
61+
* FLASH ... we will include any thing excluded here in .data below by default */
62+
*(.init)
63+
/* Change for MicroPython... exclude gc.c, parse.c, vm.c from flash */
64+
*(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib_a-mem*.o *libm.a: *gc.c.obj *vm.c.obj *parse.c.obj) .text*)
65+
*(.fini)
66+
/* Pull all c'tors into .text */
67+
*crtbegin.o(.ctors)
68+
*crtbegin?.o(.ctors)
69+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
70+
*(SORT(.ctors.*))
71+
*(.ctors)
72+
/* Followed by destructors */
73+
*crtbegin.o(.dtors)
74+
*crtbegin?.o(.dtors)
75+
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
76+
*(SORT(.dtors.*))
77+
*(.dtors)
78+
79+
*(.eh_frame*)
80+
. = ALIGN(4);
81+
} > FLASH
82+
83+
.rodata : {
84+
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
85+
. = ALIGN(4);
86+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
87+
. = ALIGN(4);
88+
} > FLASH
89+
90+
.ARM.extab :
91+
{
92+
*(.ARM.extab* .gnu.linkonce.armextab.*)
93+
} > FLASH
94+
95+
__exidx_start = .;
96+
.ARM.exidx :
97+
{
98+
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
99+
} > FLASH
100+
__exidx_end = .;
101+
102+
/* Machine inspectable binary information */
103+
. = ALIGN(4);
104+
__binary_info_start = .;
105+
.binary_info :
106+
{
107+
KEEP(*(.binary_info.keep.*))
108+
*(.binary_info.*)
109+
} > FLASH
110+
__binary_info_end = .;
111+
. = ALIGN(4);
112+
113+
/* End of .text-like segments */
114+
__etext = .;
115+
116+
.ram_vector_table (COPY): {
117+
*(.ram_vector_table)
118+
} > RAM
119+
120+
.data : {
121+
__data_start__ = .;
122+
*(vtable)
123+
124+
*(.time_critical*)
125+
126+
/* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
127+
*(.text*)
128+
. = ALIGN(4);
129+
*(.rodata*)
130+
. = ALIGN(4);
131+
132+
*(.data*)
133+
134+
. = ALIGN(4);
135+
*(.after_data.*)
136+
. = ALIGN(4);
137+
/* preinit data */
138+
PROVIDE_HIDDEN (__mutex_array_start = .);
139+
KEEP(*(SORT(.mutex_array.*)))
140+
KEEP(*(.mutex_array))
141+
PROVIDE_HIDDEN (__mutex_array_end = .);
142+
143+
. = ALIGN(4);
144+
/* preinit data */
145+
PROVIDE_HIDDEN (__preinit_array_start = .);
146+
KEEP(*(SORT(.preinit_array.*)))
147+
KEEP(*(.preinit_array))
148+
PROVIDE_HIDDEN (__preinit_array_end = .);
149+
150+
. = ALIGN(4);
151+
/* init data */
152+
PROVIDE_HIDDEN (__init_array_start = .);
153+
KEEP(*(SORT(.init_array.*)))
154+
KEEP(*(.init_array))
155+
PROVIDE_HIDDEN (__init_array_end = .);
156+
157+
. = ALIGN(4);
158+
/* finit data */
159+
PROVIDE_HIDDEN (__fini_array_start = .);
160+
*(SORT(.fini_array.*))
161+
*(.fini_array)
162+
PROVIDE_HIDDEN (__fini_array_end = .);
163+
164+
*(.jcr)
165+
. = ALIGN(4);
166+
/* All data end */
167+
__data_end__ = .;
168+
} > RAM AT> FLASH
169+
170+
.uninitialized_data (COPY): {
171+
. = ALIGN(4);
172+
*(.uninitialized_data*)
173+
} > RAM
174+
175+
/* bss without zero init on startup */
176+
.uninitialized_bss (NOLOAD): {
177+
. = ALIGN(4);
178+
*(.uninitialized_bss*)
179+
} > RAM
180+
181+
/* Start and end symbols must be word-aligned */
182+
.scratch_x : {
183+
__scratch_x_start__ = .;
184+
*(.scratch_x.*)
185+
. = ALIGN(4);
186+
__scratch_x_end__ = .;
187+
} > SCRATCH_X AT > FLASH
188+
__scratch_x_source__ = LOADADDR(.scratch_x);
189+
190+
.scratch_y : {
191+
__scratch_y_start__ = .;
192+
*(.scratch_y.*)
193+
. = ALIGN(4);
194+
__scratch_y_end__ = .;
195+
} > SCRATCH_Y AT > FLASH
196+
__scratch_y_source__ = LOADADDR(.scratch_y);
197+
198+
.bss : {
199+
. = ALIGN(4);
200+
__bss_start__ = .;
201+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
202+
*(COMMON)
203+
. = ALIGN(4);
204+
__bss_end__ = .;
205+
} > RAM
206+
207+
.heap (COPY):
208+
{
209+
__end__ = .;
210+
end = __end__;
211+
*(.heap*)
212+
__HeapLimit = .;
213+
} > RAM
214+
215+
/* .stack*_dummy section doesn't contains any symbols. It is only
216+
* used for linker to calculate size of stack sections, and assign
217+
* values to stack symbols later
218+
*
219+
* stack1 section may be empty/missing if platform_launch_core1 is not used */
220+
221+
/* by default we put core 0 stack at the end of scratch Y, so that if core 1
222+
* stack is not used then all of SCRATCH_X is free.
223+
*/
224+
.stack1_dummy (COPY):
225+
{
226+
*(.stack1*)
227+
} > SCRATCH_X
228+
.stack_dummy (COPY):
229+
{
230+
*(.stack*)
231+
} > SCRATCH_Y
232+
233+
.flash_end : {
234+
__flash_binary_end = .;
235+
} > FLASH
236+
237+
/* stack limit is poorly named, but historically is maximum heap ptr */
238+
__StackLimit = __bss_end__ + __micropy_c_heap_size__;
239+
240+
/* Define start and end of GC heap */
241+
__GcHeapStart = __StackLimit; /* after the C heap (sbrk limit) */
242+
__GcHeapEnd = ORIGIN(RAM) + LENGTH(RAM);
243+
244+
/* Define memory for the C stack */
245+
__StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
246+
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
247+
__StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
248+
__StackBottom = __StackTop - SIZEOF(.stack_dummy);
249+
PROVIDE(__stack = __StackTop);
250+
251+
/* Check GC heap is at least 32 KB */
252+
/* This is quarter the minimum RAM suggested for full-featured MicroPython.
253+
* This value accounts for large static buffers included in user C or C++
254+
* modules, which might significantly reduce the available heap but also
255+
* lower demand for memory at runtime.
256+
*/
257+
ASSERT((__GcHeapEnd - __GcHeapStart) > 32*1024, "GcHeap is too small")
258+
259+
ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
260+
/* todo assert on extra code */
261+
}

0 commit comments

Comments
 (0)