Skip to content

Commit c90d996

Browse files
peterharperukdpgeorge
authored andcommitted
rp2: Update custom linker scripts for new pico-sdk.
Signed-off-by: Phil Howard <phil@gadgetoid.com> Signed-off-by: Damien George <damien@micropython.org>
1 parent 815d6a1 commit c90d996

3 files changed

Lines changed: 313 additions & 1 deletion

File tree

ports/rp2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ endif()
525525
# a linker script modification) until we explicitly add macro calls around the function
526526
# defs to move them into RAM.
527527
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
528-
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld)
528+
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_${PICO_PLATFORM}.ld)
529529
endif()
530530
531531
pico_add_extra_outputs(${MICROPY_TARGET})

ports/rp2/memmap_mp_rp2350.ld

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
/* Based on GCC ARM embedded samples.
2+
Defines the following symbols for use by code:
3+
__exidx_start
4+
__exidx_end
5+
__etext
6+
__data_start__
7+
__preinit_array_start
8+
__preinit_array_end
9+
__init_array_start
10+
__init_array_end
11+
__fini_array_start
12+
__fini_array_end
13+
__data_end__
14+
__bss_start__
15+
__bss_end__
16+
__end__
17+
end
18+
__HeapLimit
19+
__StackLimit
20+
__StackTop
21+
__stack (== StackTop)
22+
*/
23+
24+
MEMORY
25+
{
26+
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 4096k
27+
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k
28+
SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k
29+
SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k
30+
}
31+
32+
ENTRY(_entry_point)
33+
34+
SECTIONS
35+
{
36+
.flash_begin : {
37+
__flash_binary_start = .;
38+
} > FLASH
39+
40+
/* The bootrom will enter the image at the point indicated in your
41+
IMAGE_DEF, which is usually the reset handler of your vector table.
42+
43+
The debugger will use the ELF entry point, which is the _entry_point
44+
symbol, and in our case is *different from the bootrom's entry point.*
45+
This is used to go back through the bootrom on debugger launches only,
46+
to perform the same initial flash setup that would be performed on a
47+
cold boot.
48+
*/
49+
50+
.text : {
51+
__logical_binary_start = .;
52+
KEEP (*(.vectors))
53+
KEEP (*(.binary_info_header))
54+
__binary_info_header_end = .;
55+
KEEP (*(.embedded_block))
56+
__embedded_block_end = .;
57+
KEEP (*(.reset))
58+
/* TODO revisit this now memset/memcpy/float in ROM */
59+
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
60+
* FLASH ... we will include any thing excluded here in .data below by default */
61+
*(.init)
62+
*libgcc.a:cmse_nonsecure_call.o
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+
. = ALIGN(4);
80+
/* preinit data */
81+
PROVIDE_HIDDEN (__preinit_array_start = .);
82+
KEEP(*(SORT(.preinit_array.*)))
83+
KEEP(*(.preinit_array))
84+
PROVIDE_HIDDEN (__preinit_array_end = .);
85+
86+
. = ALIGN(4);
87+
/* init data */
88+
PROVIDE_HIDDEN (__init_array_start = .);
89+
KEEP(*(SORT(.init_array.*)))
90+
KEEP(*(.init_array))
91+
PROVIDE_HIDDEN (__init_array_end = .);
92+
93+
. = ALIGN(4);
94+
/* finit data */
95+
PROVIDE_HIDDEN (__fini_array_start = .);
96+
*(SORT(.fini_array.*))
97+
*(.fini_array)
98+
PROVIDE_HIDDEN (__fini_array_end = .);
99+
*(.eh_frame*)
100+
. = ALIGN(4);
101+
} > FLASH
102+
103+
/* Note the boot2 section is optional, and should be discarded if there is
104+
no reference to it *inside* the binary, as it is not called by the
105+
bootrom. (The bootrom performs a simple best-effort XIP setup and
106+
leaves it to the binary to do anything more sophisticated.) However
107+
there is still a size limit of 256 bytes, to ensure the boot2 can be
108+
stored in boot RAM.
109+
110+
Really this is a "XIP setup function" -- the name boot2 is historic and
111+
refers to its dual-purpose on RP2040, where it also handled vectoring
112+
from the bootrom into the user image.
113+
*/
114+
115+
.boot2 : {
116+
__boot2_start__ = .;
117+
*(.boot2)
118+
__boot2_end__ = .;
119+
} > FLASH
120+
121+
ASSERT(__boot2_end__ - __boot2_start__ <= 256,
122+
"ERROR: Pico second stage bootloader must be no more than 256 bytes in size")
123+
124+
.rodata : {
125+
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
126+
*(.srodata*)
127+
. = ALIGN(4);
128+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
129+
. = ALIGN(4);
130+
} > FLASH
131+
132+
.ARM.extab :
133+
{
134+
*(.ARM.extab* .gnu.linkonce.armextab.*)
135+
} > FLASH
136+
137+
__exidx_start = .;
138+
.ARM.exidx :
139+
{
140+
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
141+
} > FLASH
142+
__exidx_end = .;
143+
144+
/* Machine inspectable binary information */
145+
. = ALIGN(4);
146+
__binary_info_start = .;
147+
.binary_info :
148+
{
149+
KEEP(*(.binary_info.keep.*))
150+
*(.binary_info.*)
151+
} > FLASH
152+
__binary_info_end = .;
153+
. = ALIGN(4);
154+
155+
.ram_vector_table (NOLOAD): {
156+
*(.ram_vector_table)
157+
} > RAM
158+
159+
.uninitialized_data (NOLOAD): {
160+
. = ALIGN(4);
161+
*(.uninitialized_data*)
162+
} > RAM
163+
164+
.data : {
165+
__data_start__ = .;
166+
*(vtable)
167+
168+
*(.time_critical*)
169+
170+
/* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */
171+
*(.text*)
172+
. = ALIGN(4);
173+
*(.rodata*)
174+
. = ALIGN(4);
175+
176+
*(.data*)
177+
*(.sdata*)
178+
179+
. = ALIGN(4);
180+
*(.after_data.*)
181+
. = ALIGN(4);
182+
/* preinit data */
183+
PROVIDE_HIDDEN (__mutex_array_start = .);
184+
KEEP(*(SORT(.mutex_array.*)))
185+
KEEP(*(.mutex_array))
186+
PROVIDE_HIDDEN (__mutex_array_end = .);
187+
188+
*(.jcr)
189+
. = ALIGN(4);
190+
} > RAM AT> FLASH
191+
192+
.tdata : {
193+
. = ALIGN(4);
194+
*(.tdata .tdata.* .gnu.linkonce.td.*)
195+
/* All data end */
196+
__tdata_end = .;
197+
} > RAM AT> FLASH
198+
PROVIDE(__data_end__ = .);
199+
200+
/* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
201+
__etext = LOADADDR(.data);
202+
203+
.tbss (NOLOAD) : {
204+
. = ALIGN(4);
205+
__bss_start__ = .;
206+
__tls_base = .;
207+
*(.tbss .tbss.* .gnu.linkonce.tb.*)
208+
*(.tcommon)
209+
210+
__tls_end = .;
211+
} > RAM
212+
213+
.bss (NOLOAD) : {
214+
. = ALIGN(4);
215+
__tbss_end = .;
216+
217+
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*)))
218+
*(COMMON)
219+
PROVIDE(__global_pointer$ = . + 2K);
220+
*(.sbss*)
221+
. = ALIGN(4);
222+
__bss_end__ = .;
223+
} > RAM
224+
225+
.heap (NOLOAD):
226+
{
227+
__end__ = .;
228+
end = __end__;
229+
KEEP(*(.heap*))
230+
/* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however
231+
to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */
232+
/* Change for MicroPython: don't include this, it increases reported firmware size.
233+
/* . = ORIGIN(RAM) + LENGTH(RAM); */
234+
__HeapLimit = .;
235+
} > RAM
236+
237+
/* Start and end symbols must be word-aligned */
238+
.scratch_x : {
239+
__scratch_x_start__ = .;
240+
*(.scratch_x.*)
241+
. = ALIGN(4);
242+
__scratch_x_end__ = .;
243+
} > SCRATCH_X AT > FLASH
244+
__scratch_x_source__ = LOADADDR(.scratch_x);
245+
246+
.scratch_y : {
247+
__scratch_y_start__ = .;
248+
*(.scratch_y.*)
249+
. = ALIGN(4);
250+
__scratch_y_end__ = .;
251+
} > SCRATCH_Y AT > FLASH
252+
__scratch_y_source__ = LOADADDR(.scratch_y);
253+
254+
/* .stack*_dummy section doesn't contains any symbols. It is only
255+
* used for linker to calculate size of stack sections, and assign
256+
* values to stack symbols later
257+
*
258+
* stack1 section may be empty/missing if platform_launch_core1 is not used */
259+
260+
/* by default we put core 0 stack at the end of scratch Y, so that if core 1
261+
* stack is not used then all of SCRATCH_X is free.
262+
*/
263+
.stack1_dummy (NOLOAD):
264+
{
265+
*(.stack1*)
266+
} > SCRATCH_X
267+
.stack_dummy (NOLOAD):
268+
{
269+
KEEP(*(.stack*))
270+
} > SCRATCH_Y
271+
272+
.flash_end : {
273+
KEEP(*(.embedded_end_block*))
274+
PROVIDE(__flash_binary_end = .);
275+
} > FLASH =0xaa
276+
277+
/* stack limit is poorly named, but historically is maximum heap ptr */
278+
__StackLimit = __bss_end__ + __micropy_c_heap_size__;
279+
280+
/* Define start and end of GC heap */
281+
__GcHeapStart = __StackLimit; /* after the C heap (sbrk limit) */
282+
__GcHeapEnd = ORIGIN(RAM) + LENGTH(RAM) - __micropy_extra_stack__;
283+
284+
/* Define start and end of C stack */
285+
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
286+
__StackBottom = __GcHeapEnd;
287+
PROVIDE(__stack = __StackTop);
288+
289+
/* picolibc and LLVM */
290+
PROVIDE (__heap_start = __end__);
291+
PROVIDE (__heap_end = __HeapLimit);
292+
PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );
293+
PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1));
294+
PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );
295+
296+
/* llvm-libc */
297+
PROVIDE (_end = __end__);
298+
PROVIDE (__llvm_libc_heap_limit = __HeapLimit);
299+
300+
/* Check GC heap is at least 64 KB */
301+
/* This is half the minimum RAM suggested for full-featured MicroPython.
302+
* This value accounts for large static buffers included in user C or C++
303+
* modules, which might significantly reduce the available heap but also
304+
* lower demand for memory at runtime.
305+
*/
306+
ASSERT((__GcHeapEnd - __GcHeapStart) > 64*1024, "GcHeap is too small")
307+
308+
ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary")
309+
ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary")
310+
311+
/* todo assert on extra code */
312+
}

0 commit comments

Comments
 (0)