2323
2424MEMORY
2525{
26- FLASH (rx) : ORIGIN = 0x10000100 , LENGTH = 16384k
27- RAM (rwx) : ORIGIN = 0x20000000 , LENGTH = 212k
28- /* We split RAM into main (where the flash->ram code will be copied) and GLOBALS which has all large arrays */
29- /* By placing those arrays at the end of RAM we can avoid overwriting uninitialize_ram from the main app as */
30- /* long as those vars are stored after 12K by using an alignment value in the main app linker file. */
26+ INCLUDE " pico_flash_region.ld"
27+ RAM (rwx) : ORIGIN = 0x20000000 , LENGTH = 212k
3128 GLOBALS (rwx) : ORIGIN = 0x20035000 , LENGTH = 44k
32- SCRATCH_X (rwx) : ORIGIN = 0x20040000 , LENGTH = 4k
33- SCRATCH_Y (rwx) : ORIGIN = 0x20041000 , LENGTH = 4k
29+ SCRATCH_X (rwx) : ORIGIN = 0x20080000 , LENGTH = 4k
30+ SCRATCH_Y (rwx) : ORIGIN = 0x20081000 , LENGTH = 4k
3431}
3532
3633ENTRY (_entry_point)
3734
38- SECTIONS {
35+ SECTIONS
36+ {
3937 /* Second stage bootloader is prepended to the image. It must be 256 bytes big
4038 and checksummed. It is usually built by the boot_stage2 target
4139 in the Raspberry Pi Pico SDK
@@ -45,57 +43,71 @@ SECTIONS {
4543 .globals (NOLOAD) : {
4644 } > GLOBALS
4745
46+
4847 .flash_begin : {
4948 __flash_binary_start = .;
5049 } > FLASH
51- /*
52- .boot2 : {
53- __boot2_start__ = .;
54- KEEP (*(.boot2))
55- __boot2_end__ = .;
56- } > FLASH
5750
58- ASSERT(__boot2_end__ - __boot2_start__ == 256,
59- "ERROR: Pico second stage bootloader must be 256 bytes in size")
60- */
61- /* The second stage will always enter the image at the start of .text.
51+ /* The bootrom will enter the image at the point indicated in your
52+ IMAGE_DEF, which is usually the reset handler of your vector table.
53+
6254 The debugger will use the ELF entry point, which is the _entry_point
63- symbol if present, otherwise defaults to start of .text.
64- This can be used to transfer control back to the bootrom on debugger
65- launches only, to perform proper flash setup.
55+ symbol, and in our case is *different from the bootrom's entry point.*
56+ This is used to go back through the bootrom on debugger launches only,
57+ to perform the same initial flash setup that would be performed on a
58+ cold boot.
6659 */
6760
6861 .flashtext : {
6962 __logical_binary_start = .;
7063 KEEP (*(.vectors ))
7164 KEEP (*(.binary_info_header ))
7265 __binary_info_header_end = .;
66+ KEEP (*(.embedded_block ))
67+ __embedded_block_end = .;
7368 KEEP (*(.reset ))
74- }
69+ . = ALIGN (4 );
70+ } > FLASH
7571
7672 .rodata : {
7773 /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */
7874 *(SORT_BY_ALIGNMENT (SORT_BY_NAME (.flashdata *)))
7975 . = ALIGN (4 );
8076 } > FLASH
8177
82- .ARM.extab : {
78+ .ARM.extab :
79+ {
8380 *(.ARM .extab * .gnu .linkonce .armextab .*)
8481 } > FLASH
8582
8683 __exidx_start = .;
87- .ARM.exidx : {
84+ .ARM.exidx :
85+ {
8886 *(.ARM .exidx * .gnu .linkonce .armexidx .*)
8987 } > FLASH
9088 __exidx_end = .;
9189
90+ /* Machine inspectable binary information */
91+ . = ALIGN (4 );
92+ __binary_info_start = .;
93+ .binary_info :
94+ {
95+ KEEP (*(.binary_info .keep .*))
96+ *(.binary_info .*)
97+ } > FLASH
98+ __binary_info_end = .;
9299 . = ALIGN (4 );
93100
94101 /* Vector table goes first in RAM, to avoid large alignment hole */
95- .ram_vector_table (COPY ) : {
102+ .ram_vector_table (NOLOAD ) : {
96103 *(.ram_vector_table )
97104 } > RAM
98105
106+ .uninitialized_data (NOLOAD) : {
107+ . = ALIGN (4 );
108+ *(.uninitialized_data *)
109+ } > RAM
110+
99111 .text : {
100112 __ram_text_start__ = .;
101113 *(.init )
@@ -119,7 +131,7 @@ SECTIONS {
119131 __ram_text_end__ = .;
120132 } > RAM AT> FLASH
121133 __ram_text_source__ = LOADADDR (.text );
122-
134+ . = ALIGN ( 4 );
123135
124136 .data : {
125137 __data_start__ = .;
@@ -176,6 +188,50 @@ SECTIONS {
176188 *(.uninitialized_data *)
177189 } > RAM
178190
191+ .tdata : {
192+ . = ALIGN (4 );
193+ *(.tdata .tdata .* .gnu .linkonce .td .*)
194+ /* All data end */
195+ __tdata_end = .;
196+ } > RAM AT> FLASH
197+ PROVIDE (__data_end__ = .);
198+
199+ /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */
200+ __etext = LOADADDR (.data );
201+
202+ .tbss (NOLOAD) : {
203+ . = ALIGN (4 );
204+ __bss_start__ = .;
205+ __tls_base = .;
206+ *(.tbss .tbss .* .gnu .linkonce .tb .*)
207+ *(.tcommon )
208+
209+ __tls_end = .;
210+ } > RAM
211+
212+ .bss : {
213+ . = ALIGN (4 );
214+ __tbss_end = .;
215+
216+ *(SORT_BY_ALIGNMENT (SORT_BY_NAME (.bss *)))
217+ *(COMMON)
218+ PROVIDE (__global_pointer$ = . + 2K);
219+ *(.sbss *)
220+ . = ALIGN (4 );
221+ __bss_end__ = .;
222+ } > RAM
223+
224+ .heap (NOLOAD) :
225+ {
226+ __end__ = .;
227+ end = __end__;
228+ KEEP (*(.heap *))
229+ /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however
230+ to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */
231+ . = ORIGIN (RAM) + LENGTH (RAM);
232+ __HeapLimit = .;
233+ } > RAM
234+
179235 /* Start and end symbols must be word-aligned */
180236 .scratch_x : {
181237 __scratch_x_start__ = .;
@@ -193,22 +249,6 @@ SECTIONS {
193249 } > SCRATCH_Y AT > FLASH
194250 __scratch_y_source__ = LOADADDR (.scratch_y );
195251
196- .bss : {
197- . = ALIGN (4 );
198- __bss_start__ = .;
199- *(SORT_BY_ALIGNMENT (SORT_BY_NAME (.bss *)))
200- *(COMMON)
201- . = ALIGN (4 );
202- __bss_end__ = .;
203- } > RAM
204-
205- .heap (COPY) : {
206- __end__ = .;
207- end = __end__;
208- *(.heap *)
209- __HeapLimit = .;
210- } > RAM
211-
212252 /* .stack*_dummy section doesn't contains any symbols. It is only
213253 * used for linker to calculate size of stack sections, and assign
214254 * values to stack symbols later
@@ -218,16 +258,19 @@ SECTIONS {
218258 /* by default we put core 0 stack at the end of scratch Y, so that if core 1
219259 * stack is not used then all of SCRATCH_X is free.
220260 */
221- .stack1_dummy (COPY) : {
261+ .stack1_dummy (NOLOAD) :
262+ {
222263 *(.stack1 *)
223264 } > SCRATCH_X
224- .stack_dummy (COPY) : {
225- *(.stack *)
265+ .stack_dummy (NOLOAD) :
266+ {
267+ KEEP (*(.stack *))
226268 } > SCRATCH_Y
227269
228270 .flash_end : {
229- __flash_binary_end = .;
230- } > FLASH
271+ KEEP (*(.embedded_end_block *))
272+ PROVIDE (__flash_binary_end = .);
273+ } > FLASH =0xaa
231274
232275 /* stack limit is poorly named, but historically is maximum heap ptr */
233276 __StackLimit = ORIGIN (RAM) + LENGTH (RAM);
@@ -237,10 +280,23 @@ SECTIONS {
237280 __StackBottom = __StackTop - SIZEOF (.stack_dummy );
238281 PROVIDE (__stack = __StackTop);
239282
283+ /* picolibc and LLVM */
284+ PROVIDE (__heap_start = __end__);
285+ PROVIDE (__heap_end = __HeapLimit);
286+ PROVIDE ( __tls_align = MAX (ALIGNOF (.tdata ), ALIGNOF (.tbss )) );
287+ PROVIDE ( __tls_size_align = (__tls_size + __tls_align - 1 ) & ~(__tls_align - 1 ));
288+ PROVIDE ( __arm32_tls_tcb_offset = MAX (8 , __tls_align) );
289+
290+ /* llvm-libc */
291+ PROVIDE (_end = __end__);
292+ PROVIDE (__llvm_libc_heap_limit = __HeapLimit);
293+
240294 /* Check if data + heap + stack exceeds RAM limit */
241295 ASSERT (__StackLimit >= __HeapLimit, " region RAM overflowed" )
242296
243- /* ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")*/
297+ ASSERT ( __binary_info_header_end - __logical_binary_start <= 1024 , " Binary info must be in first 1024 bytes of the binary" )
298+ ASSERT ( __embedded_block_end - __logical_binary_start <= 4096 , " Embedded block must be in first 4096 bytes of the binary" )
299+
244300 /* todo assert on extra code */
245301}
246302
0 commit comments