From b8f699f6ff4aaf16c7cb9641f4041aace9f3bc61 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 1 Dec 2025 19:32:27 +0000 Subject: [PATCH 01/15] Separate linker scripts out into include files Allows for much simpler custom linker scripts --- .../pico_crt0/rp2040/memmap_blocked_ram.ld | 287 +--------------- .../pico_crt0/rp2040/memmap_copy_to_ram.ld | 288 +--------------- .../pico_crt0/rp2040/memmap_default.ld | 287 +--------------- .../pico_crt0/rp2040/memmap_no_flash.ld | 249 +------------- .../pico_crt0/rp2040/memory_blocked_ram.ld | 4 + .../pico_crt0/rp2040/memory_flash.ld | 4 + src/rp2_common/pico_crt0/rp2040/memory_ram.ld | 4 + .../pico_crt0/rp2040/memory_scratch.ld | 5 + .../pico_crt0/rp2040/sections_copy_to_ram.ld | 276 ++++++++++++++++ .../pico_crt0/rp2040/sections_default.ld | 275 ++++++++++++++++ .../pico_crt0/rp2040/sections_no_flash.ld | 239 ++++++++++++++ .../pico_crt0/rp2350/memmap_copy_to_ram.ld | 310 +----------------- .../pico_crt0/rp2350/memmap_default.ld | 303 +---------------- .../pico_crt0/rp2350/memmap_no_flash.ld | 256 +-------------- .../pico_crt0/rp2350/memory_copy_to_ram.ld | 0 .../pico_crt0/rp2350/memory_flash.ld | 4 + src/rp2_common/pico_crt0/rp2350/memory_ram.ld | 4 + .../pico_crt0/rp2350/memory_scratch.ld | 5 + .../pico_crt0/rp2350/memory_xip_ram.ld | 4 + .../pico_crt0/rp2350/sections_copy_to_ram.ld | 298 +++++++++++++++++ .../pico_crt0/rp2350/sections_default.ld | 291 ++++++++++++++++ .../pico_crt0/rp2350/sections_no_flash.ld | 246 ++++++++++++++ .../pico_standard_link/CMakeLists.txt | 5 +- 23 files changed, 1689 insertions(+), 1955 deletions(-) create mode 100644 src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/memory_flash.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/memory_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/memory_scratch.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/sections_default.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/memory_flash.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/memory_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/memory_scratch.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/sections_default.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index 6f500056..150176eb 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -1,286 +1,7 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - INCLUDE "pico_flash_region.ld" - RAM(rwx) : ORIGIN = 0x21000000, LENGTH = 256k - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} +INCLUDE "memory_flash.ld" +INCLUDE "memory_blocked_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} - +INCLUDE "sections_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld index 842ebfd3..7b99a774 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld @@ -1,287 +1,7 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - INCLUDE "pico_flash_region.ld" - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .flashtext : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - } - - .rodata : { - /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - /* Vector table goes first in RAM, to avoid large alignment hole */ - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .text : { - __ram_text_start__ = .; - *(.init) - *(.text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - __ram_text_end__ = .; - } > RAM AT> FLASH - __ram_text_source__ = LOADADDR(.text); - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} - +INCLUDE "sections_copy_to_ram.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld index 51254012..75fd340d 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld @@ -1,286 +1,7 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - INCLUDE "pico_flash_region.ld" - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} - +INCLUDE "sections_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld index dbf006a8..cde63059 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld @@ -1,249 +1,6 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger - entry (ELF entry point), are *first* in the image, and the vector table - follows immediately afterward. This is because the bootrom enters RAM - binaries directly at their lowest address (preferring main RAM over XIP - cache-as-SRAM if both are used). - */ - - .text : { - __logical_binary_start = .; - __reset_start = .; - KEEP (*(.reset)) - __reset_end = .; - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - . = ALIGN(256); - KEEP (*(.vectors)) - *(.time_critical*) - *(.text*) - . = ALIGN(4); - *(.init) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - } > RAM - - .rodata : { - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > RAM - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > RAM - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > RAM - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > RAM - __binary_info_end = .; - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM - PROVIDE(__data_end__ = .); - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} - +INCLUDE "sections_no_flash.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld new file mode 100644 index 00000000..57cbad6b --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + RAM(rwx) : ORIGIN = 0x21000000, LENGTH = 256k +} diff --git a/src/rp2_common/pico_crt0/rp2040/memory_flash.ld b/src/rp2_common/pico_crt0/rp2040/memory_flash.ld new file mode 100644 index 00000000..669fe00e --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/memory_flash.ld @@ -0,0 +1,4 @@ +MEMORY +{ + INCLUDE "pico_flash_region.ld" +} diff --git a/src/rp2_common/pico_crt0/rp2040/memory_ram.ld b/src/rp2_common/pico_crt0/rp2040/memory_ram.ld new file mode 100644 index 00000000..1e1515dd --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/memory_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k +} diff --git a/src/rp2_common/pico_crt0/rp2040/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2040/memory_scratch.ld new file mode 100644 index 00000000..a4b982b9 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/memory_scratch.ld @@ -0,0 +1,5 @@ +MEMORY +{ + SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k + SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k +} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld new file mode 100644 index 00000000..5557ee1c --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld @@ -0,0 +1,276 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Raspberry Pi Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .flashtext : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + } + + .rodata : { + /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + /* Vector table goes first in RAM, to avoid large alignment hole */ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .text : { + __ram_text_start__ = .; + *(.init) + *(.text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + __ram_text_end__ = .; + } > RAM AT> FLASH + __ram_text_source__ = LOADADDR(.text); + . = ALIGN(4); + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + .flash_end : { + KEEP(*(.embedded_end_block*)) + PROVIDE(__flash_binary_end = .); + } > FLASH + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_default.ld b/src/rp2_common/pico_crt0/rp2040/sections_default.ld new file mode 100644 index 00000000..57984e46 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/sections_default.ld @@ -0,0 +1,275 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Raspberry Pi Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + .flash_end : { + KEEP(*(.embedded_end_block*)) + PROVIDE(__flash_binary_end = .); + } > FLASH + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld new file mode 100644 index 00000000..9e082d53 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld @@ -0,0 +1,239 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger + entry (ELF entry point), are *first* in the image, and the vector table + follows immediately afterward. This is because the bootrom enters RAM + binaries directly at their lowest address (preferring main RAM over XIP + cache-as-SRAM if both are used). + */ + + .text : { + __logical_binary_start = .; + __reset_start = .; + KEEP (*(.reset)) + __reset_end = .; + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + . = ALIGN(256); + KEEP (*(.vectors)) + *(.time_critical*) + *(.text*) + . = ALIGN(4); + *(.init) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + } > RAM + + .rodata : { + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > RAM + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > RAM + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > RAM + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > RAM + __binary_info_end = .; + . = ALIGN(4); + + .data : { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM + PROVIDE(__data_end__ = .); + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld index 44c69f3b..7b99a774 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld @@ -1,309 +1,7 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - INCLUDE "pico_flash_region.ld" - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k - SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k -} +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* On Arm, the bootrom expects a VT at the start of the - image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGE_DEF item is required to specify the - nondefault entry point. */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - /* The bootrom will enter the image at the point indicated in your - IMAGE_DEF, which is usually the reset handler of your vector table. - - The debugger will use the ELF entry point, which is the _entry_point - symbol, and in our case is *different from the bootrom's entry point.* - This is used to go back through the bootrom on debugger launches only, - to perform the same initial flash setup that would be performed on a - cold boot. - */ - - .flashtext : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - . = ALIGN(4); - } > FLASH - - /* Note the boot2 section is optional, and should be discarded if there is - no reference to it *inside* the binary, as it is not called by the - bootrom. (The bootrom performs a simple best-effort XIP setup and - leaves it to the binary to do anything more sophisticated.) However - there is still a size limit of 256 bytes, to ensure the boot2 can be - stored in boot RAM. - - Really this is a "XIP setup function" -- the name boot2 is historic and - refers to its dual-purpose on RP2040, where it also handled vectoring - from the bootrom into the user image. - */ - - .boot2 : { - __boot2_start__ = .; - *(.boot2) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ <= 256, - "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") - - .rodata : { - /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - /* Vector table goes first in RAM, to avoid large alignment hole */ - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .text : { - __ram_text_start__ = .; - *(.init) - *(.text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - __ram_text_end__ = .; - } > RAM AT> FLASH - __ram_text_source__ = LOADADDR(.text); - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - . = ALIGN(4); - *(.rodata*) - *(.srodata*) - . = ALIGN(4); - - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH =0xaa - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} - +INCLUDE "sections_copy_to_ram.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld index bce316d1..75fd340d 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld @@ -1,302 +1,7 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - INCLUDE "pico_flash_region.ld" - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k - SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k -} +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - /* The bootrom will enter the image at the point indicated in your - IMAGE_DEF, which is usually the reset handler of your vector table. - - The debugger will use the ELF entry point, which is the _entry_point - symbol, and in our case is *different from the bootrom's entry point.* - This is used to go back through the bootrom on debugger launches only, - to perform the same initial flash setup that would be performed on a - cold boot. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - *libgcc.a:cmse_nonsecure_call.o - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH - - /* Note the boot2 section is optional, and should be discarded if there is - no reference to it *inside* the binary, as it is not called by the - bootrom. (The bootrom performs a simple best-effort XIP setup and - leaves it to the binary to do anything more sophisticated.) However - there is still a size limit of 256 bytes, to ensure the boot2 can be - stored in boot RAM. - - Really this is a "XIP setup function" -- the name boot2 is historic and - refers to its dual-purpose on RP2040, where it also handled vectoring - from the bootrom into the user image. - */ - - .boot2 : { - __boot2_start__ = .; - *(.boot2) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ <= 256, - "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - *(.srodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH =0xaa - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} - +INCLUDE "sections_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld index 5bedf6d2..cde63059 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld @@ -1,256 +1,6 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k - SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k -} +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" ENTRY(_entry_point) -SECTIONS -{ - /* Note unlike RP2040, we start the image with a vector table even for - NO_FLASH builds. On Arm, the bootrom expects a VT at the start of the - image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGE_DEF item is required to specify the - nondefault entry point. */ - - .text : { - __logical_binary_start = .; - /* Vectors require 512-byte alignment on v8-M when >48 IRQs are used, - so we would waste RAM if the vector table were not at the - start. */ - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - __reset_start = .; - KEEP (*(.reset)) - __reset_end = .; - *(.time_critical*) - *(.text*) - . = ALIGN(4); - *(.init) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - } > RAM - - .rodata : { - . = ALIGN(4); - *(.rodata*) - *(.srodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > RAM - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > RAM - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > RAM - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > RAM - __binary_info_end = .; - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM - PROVIDE(__data_end__ = .); - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} - +INCLUDE "sections_no_flash.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld new file mode 100644 index 00000000..e69de29b diff --git a/src/rp2_common/pico_crt0/rp2350/memory_flash.ld b/src/rp2_common/pico_crt0/rp2350/memory_flash.ld new file mode 100644 index 00000000..669fe00e --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/memory_flash.ld @@ -0,0 +1,4 @@ +MEMORY +{ + INCLUDE "pico_flash_region.ld" +} diff --git a/src/rp2_common/pico_crt0/rp2350/memory_ram.ld b/src/rp2_common/pico_crt0/rp2350/memory_ram.ld new file mode 100644 index 00000000..434cdab9 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/memory_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k +} diff --git a/src/rp2_common/pico_crt0/rp2350/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2350/memory_scratch.ld new file mode 100644 index 00000000..246bbf05 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/memory_scratch.ld @@ -0,0 +1,5 @@ +MEMORY +{ + SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k + SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k +} diff --git a/src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld b/src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld new file mode 100644 index 00000000..e94479b5 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + XIP_RAM(rwx) : ORIGIN = 0x13FFC000, LENGTH = 16k +} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld new file mode 100644 index 00000000..9cc60b10 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld @@ -0,0 +1,298 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* On Arm, the bootrom expects a VT at the start of the + image by default; on RISC-V, the default is to enter the image at its + lowest address, so an IMAGE_DEF item is required to specify the + nondefault entry point. */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + /* The bootrom will enter the image at the point indicated in your + IMAGE_DEF, which is usually the reset handler of your vector table. + + The debugger will use the ELF entry point, which is the _entry_point + symbol, and in our case is *different from the bootrom's entry point.* + This is used to go back through the bootrom on debugger launches only, + to perform the same initial flash setup that would be performed on a + cold boot. + */ + + .flashtext : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + . = ALIGN(4); + } > FLASH + + /* Note the boot2 section is optional, and should be discarded if there is + no reference to it *inside* the binary, as it is not called by the + bootrom. (The bootrom performs a simple best-effort XIP setup and + leaves it to the binary to do anything more sophisticated.) However + there is still a size limit of 256 bytes, to ensure the boot2 can be + stored in boot RAM. + + Really this is a "XIP setup function" -- the name boot2 is historic and + refers to its dual-purpose on RP2040, where it also handled vectoring + from the bootrom into the user image. + */ + + .boot2 : { + __boot2_start__ = .; + *(.boot2) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ <= 256, + "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") + + .rodata : { + /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + /* Vector table goes first in RAM, to avoid large alignment hole */ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .text : { + __ram_text_start__ = .; + *(.init) + *(.text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + __ram_text_end__ = .; + } > RAM AT> FLASH + __ram_text_source__ = LOADADDR(.text); + . = ALIGN(4); + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + . = ALIGN(4); + *(.rodata*) + *(.srodata*) + . = ALIGN(4); + + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + .flash_end : { + KEEP(*(.embedded_end_block*)) + PROVIDE(__flash_binary_end = .); + } > FLASH =0xaa + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") + ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") + + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_default.ld b/src/rp2_common/pico_crt0/rp2350/sections_default.ld new file mode 100644 index 00000000..cb2c6e11 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/sections_default.ld @@ -0,0 +1,291 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + /* The bootrom will enter the image at the point indicated in your + IMAGE_DEF, which is usually the reset handler of your vector table. + + The debugger will use the ELF entry point, which is the _entry_point + symbol, and in our case is *different from the bootrom's entry point.* + This is used to go back through the bootrom on debugger launches only, + to perform the same initial flash setup that would be performed on a + cold boot. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + *libgcc.a:cmse_nonsecure_call.o + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH + + /* Note the boot2 section is optional, and should be discarded if there is + no reference to it *inside* the binary, as it is not called by the + bootrom. (The bootrom performs a simple best-effort XIP setup and + leaves it to the binary to do anything more sophisticated.) However + there is still a size limit of 256 bytes, to ensure the boot2 can be + stored in boot RAM. + + Really this is a "XIP setup function" -- the name boot2 is historic and + refers to its dual-purpose on RP2040, where it also handled vectoring + from the bootrom into the user image. + */ + + .boot2 : { + __boot2_start__ = .; + *(.boot2) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ <= 256, + "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + .flash_end : { + KEEP(*(.embedded_end_block*)) + PROVIDE(__flash_binary_end = .); + } > FLASH =0xaa + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") + ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") + + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld new file mode 100644 index 00000000..869d8643 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld @@ -0,0 +1,246 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* Note unlike RP2040, we start the image with a vector table even for + NO_FLASH builds. On Arm, the bootrom expects a VT at the start of the + image by default; on RISC-V, the default is to enter the image at its + lowest address, so an IMAGE_DEF item is required to specify the + nondefault entry point. */ + + .text : { + __logical_binary_start = .; + /* Vectors require 512-byte alignment on v8-M when >48 IRQs are used, + so we would waste RAM if the vector table were not at the + start. */ + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + __reset_start = .; + KEEP (*(.reset)) + __reset_end = .; + *(.time_critical*) + *(.text*) + . = ALIGN(4); + *(.init) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + } > RAM + + .rodata : { + . = ALIGN(4); + *(.rodata*) + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > RAM + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > RAM + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > RAM + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > RAM + __binary_info_end = .; + . = ALIGN(4); + + .data : { + __data_start__ = .; + *(vtable) + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM + PROVIDE(__data_end__ = .); + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") + ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") + + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index c16968bb..5905d3da 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -124,9 +124,12 @@ if (NOT TARGET pico_standard_link) #math(EXPR PICO_FLASH_SIZE_BYTES_STRING "${PICO_FLASH_SIZE_BYTES}" OUTPUT_FORMAT HEXADECIMAL) set(PICO_FLASH_SIZE_BYTES_STRING "${PICO_FLASH_SIZE_BYTES}") configure_file(${CMAKE_CURRENT_LIST_DIR}/pico_flash_region.template.ld ${CMAKE_BINARY_DIR}/pico_flash_region.ld) - # add include path for linker scripts + # add include path for linker scripts to find it target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_BINARY_DIR}") + # add include path for main linker script sections + target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}") + # LINKER script will be PICO_TARGET_LINKER_SCRIPT if set on target, or ${CMAKE_CURRENT_LIST_DIR}/memmap_foo.ld # if PICO_TARGET_BINARY_TYPE is set to foo on the target, otherwise ${CMAKE_CURRENT_LIST_DIR}/memmap_${PICO_DEFAULT_BINARY_TYPE).ld set(_LINKER_SCRIPT_EXPRESSION "$>,$,${PICO_LINKER_SCRIPT_PATH}/memmap_$,>,${PICO_DEFAULT_BINARY_TYPE},$>.ld>") From 6dc06e6d1d70d9e7ad7bb785cf57360515072b31 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 1 Dec 2025 20:40:45 +0000 Subject: [PATCH 02/15] Add customisable heap location, with pico_set_linker_script_var function --- .../pico_crt0/rp2040/sections_copy_to_ram.ld | 4 ++-- src/rp2_common/pico_crt0/rp2040/sections_default.ld | 4 ++-- src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld | 4 ++-- .../pico_crt0/rp2350/sections_copy_to_ram.ld | 4 ++-- src/rp2_common/pico_crt0/rp2350/sections_default.ld | 4 ++-- src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld | 4 ++-- src/rp2_common/pico_standard_link/CMakeLists.txt | 12 ++++++++++++ 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld index 5557ee1c..1777f660 100644 --- a/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld @@ -199,7 +199,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -207,7 +207,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_crt0/rp2040/sections_default.ld b/src/rp2_common/pico_crt0/rp2040/sections_default.ld index 57984e46..2e72b83b 100644 --- a/src/rp2_common/pico_crt0/rp2040/sections_default.ld +++ b/src/rp2_common/pico_crt0/rp2040/sections_default.ld @@ -198,7 +198,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -206,7 +206,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld index 9e082d53..c71ee3b0 100644 --- a/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld @@ -167,7 +167,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -175,7 +175,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld index 9cc60b10..4b76bc04 100644 --- a/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld @@ -219,7 +219,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -227,7 +227,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_crt0/rp2350/sections_default.ld b/src/rp2_common/pico_crt0/rp2350/sections_default.ld index cb2c6e11..eaeee272 100644 --- a/src/rp2_common/pico_crt0/rp2350/sections_default.ld +++ b/src/rp2_common/pico_crt0/rp2350/sections_default.ld @@ -212,7 +212,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -220,7 +220,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld index 869d8643..595d6977 100644 --- a/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld @@ -172,7 +172,7 @@ SECTIONS __bss_end__ = .; } > RAM - .heap (NOLOAD): + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): { __end__ = .; end = __end__; @@ -180,7 +180,7 @@ SECTIONS } > RAM /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = ORIGIN(RAM) + LENGTH(RAM); + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); /* Start and end symbols must be word-aligned */ .scratch_x : { diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 5905d3da..5dd40909 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -70,6 +70,15 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_LINKER_SCRIPT ${LDSCRIPT}) endfunction() + # pico_set_linker_script_var(TARGET NAME VALUE) + # \brief\ Set the linker script for the target + # + # \param\ NAME Name of varAible to set + # \param\ VALUE Value of variable to set + function(pico_set_linker_script_var TARGET NAME VALUE) + set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_VARS "--defsym=${NAME}=${VALUE}") + endfunction() + # pico_set_binary_type(TARGET TYPE) # \brief\ Set the binary type for the target # @@ -130,6 +139,9 @@ if (NOT TARGET pico_standard_link) # add include path for main linker script sections target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}") + # add variables set by pico_set_linker_script_var function + target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") + # LINKER script will be PICO_TARGET_LINKER_SCRIPT if set on target, or ${CMAKE_CURRENT_LIST_DIR}/memmap_foo.ld # if PICO_TARGET_BINARY_TYPE is set to foo on the target, otherwise ${CMAKE_CURRENT_LIST_DIR}/memmap_${PICO_DEFAULT_BINARY_TYPE).ld set(_LINKER_SCRIPT_EXPRESSION "$>,$,${PICO_LINKER_SCRIPT_PATH}/memmap_$,>,${PICO_DEFAULT_BINARY_TYPE},$>.ld>") From 727cabd4d0c1d9ffda7ec1bd456ee160527508aa Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 1 Dec 2025 20:41:39 +0000 Subject: [PATCH 03/15] Add kitchen sink test of custom linker scripts --- test/kitchen_sink/CMakeLists.txt | 8 ++++++++ test/kitchen_sink/memmap_custom.ld | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/kitchen_sink/memmap_custom.ld diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 1d6110f4..71b8a58b 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -214,6 +214,14 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) pico_add_extra_outputs(kitchen_sink_blocked_ram) target_compile_definitions(kitchen_sink_blocked_ram PRIVATE KITCHEN_SINK_ID="blocked-ram binary") endif() + + add_executable(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + # Have heap start from 0x20030000, and custom linker script + pico_set_linker_script(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/memmap_custom.ld) + pico_set_linker_script_var(kitchen_sink_memmap_custom HEAP_LOC 0x20030000) + target_link_libraries(kitchen_sink_memmap_custom kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_memmap_custom) + target_compile_definitions(kitchen_sink_memmap_custom PRIVATE KITCHEN_SINK_ID="custom memmap binary") endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/memmap_custom.ld b/test/kitchen_sink/memmap_custom.ld new file mode 100644 index 00000000..081913e5 --- /dev/null +++ b/test/kitchen_sink/memmap_custom.ld @@ -0,0 +1,12 @@ +INCLUDE "memory_flash.ld" +INCLUDE "memory_scratch.ld" + +/* Only use 128k of SRAM, starting at 0x20020000 */ +MEMORY +{ + RAM(rwx) : ORIGIN = 0x20020000, LENGTH = 128k +} + +ENTRY(_entry_point) + +INCLUDE "sections_default.ld" From 3a83dc7838de5688aee3fbcc49787c0203403034 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Dec 2025 14:48:02 +0000 Subject: [PATCH 04/15] Separate out rp2_common and platform-specific linker script sections --- .../pico_crt0/rp2040/memmap_blocked_ram.ld | 14 +- .../pico_crt0/rp2040/memmap_copy_to_ram.ld | 8 +- .../pico_crt0/rp2040/memmap_default.ld | 8 +- .../pico_crt0/rp2040/memmap_no_flash.ld | 7 +- .../{ => platform}/memory_blocked_ram.ld | 0 .../rp2040/{ => platform}/memory_ram.ld | 0 .../rp2040/{ => platform}/memory_scratch.ld | 0 .../platform/section_copy_to_ram_data.ld | 79 +++++ .../platform/section_copy_to_ram_text.ld | 101 ++++++ .../rp2040/platform/section_default_data.ld | 70 ++++ .../rp2040/platform/section_default_text.ld | 109 +++++++ .../rp2040/platform/section_no_flash_data.ld | 79 +++++ .../rp2040/platform/section_no_flash_text.ld | 71 +++++ .../rp2040/platform/section_platform_end.ld | 50 +++ .../pico_crt0/rp2040/sections_copy_to_ram.ld | 276 ---------------- .../pico_crt0/rp2040/sections_default.ld | 275 ---------------- .../pico_crt0/rp2040/sections_no_flash.ld | 239 -------------- .../pico_crt0/rp2350/memmap_copy_to_ram.ld | 8 +- .../pico_crt0/rp2350/memmap_default.ld | 8 +- .../pico_crt0/rp2350/memmap_no_flash.ld | 7 +- .../pico_crt0/rp2350/memory_copy_to_ram.ld | 0 .../pico_crt0/rp2350/memory_flash.ld | 4 - .../rp2350/{ => platform}/memory_ram.ld | 0 .../rp2350/{ => platform}/memory_scratch.ld | 0 .../rp2350/{ => platform}/memory_xip_ram.ld | 0 .../platform/section_copy_to_ram_data.ld | 83 +++++ .../platform/section_copy_to_ram_text.ld | 117 +++++++ .../rp2350/platform/section_default_data.ld | 72 +++++ .../rp2350/platform/section_default_text.ld | 121 +++++++ .../rp2350/platform/section_no_flash_data.ld | 82 +++++ .../rp2350/platform/section_no_flash_text.ld | 73 +++++ .../rp2350/platform/section_platform_end.ld | 7 + .../pico_crt0/rp2350/sections_copy_to_ram.ld | 298 ------------------ .../pico_crt0/rp2350/sections_default.ld | 291 ----------------- .../pico_crt0/rp2350/sections_no_flash.ld | 246 --------------- .../pico_standard_link/CMakeLists.txt | 1 + .../scripts/rp2_common/memmap_copy_to_ram.ld | 13 + .../scripts/rp2_common/memmap_default.ld | 13 + .../scripts/rp2_common/memmap_no_flash.ld | 12 + .../rp2_common/memory_aliases_default.ld | 3 + .../rp2_common/memory_aliases_no_flash.ld | 3 + .../scripts/rp2_common}/memory_flash.ld | 0 .../scripts/rp2_common/section_end.ld | 49 +++ .../scripts/rp2_common/section_flash_end.ld | 7 + .../scripts/rp2_common/section_heap.ld | 12 + .../scripts/rp2_common/section_scratch.ld | 37 +++ .../rp2_common/sections_copy_to_ram.ld | 7 + .../scripts/rp2_common/sections_default.ld | 7 + .../scripts/rp2_common/sections_no_flash.ld | 6 + test/kitchen_sink/memmap_custom.ld | 12 +- 50 files changed, 1309 insertions(+), 1676 deletions(-) rename src/rp2_common/pico_crt0/rp2040/{ => platform}/memory_blocked_ram.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{ => platform}/memory_ram.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{ => platform}/memory_scratch.ld (100%) create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/sections_default.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/memory_flash.ld rename src/rp2_common/pico_crt0/rp2350/{ => platform}/memory_ram.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{ => platform}/memory_scratch.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{ => platform}/memory_xip_ram.ld (100%) create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/sections_default.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld rename src/rp2_common/{pico_crt0/rp2040 => pico_standard_link/scripts/rp2_common}/memory_flash.ld (100%) create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index 150176eb..330e9bde 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -1,7 +1,13 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_blocked_ram.ld" -INCLUDE "memory_scratch.ld" +/* Include memory regions used */ +INCLUDE "rp2_common/memory_flash.ld" +INCLUDE "platform/memory_blocked_ram.ld" +INCLUDE "platform/memory_scratch.ld" +/* Include aliases for storage memory regions */ +INCLUDE "rp2_common/memory_aliases_default.ld" + +/* Define entry point symbol */ ENTRY(_entry_point) -INCLUDE "sections_default.ld" +/* Include default sections */ +INCLUDE "rp2_common/sections_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld index 7b99a774..6a1647d4 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld @@ -1,7 +1 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_copy_to_ram.ld" +INCLUDE "rp2_common/memmap_copy_to_ram.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld index 75fd340d..8e207371 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_default.ld @@ -1,7 +1 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_default.ld" +INCLUDE "rp2_common/memmap_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld index cde63059..b8d1dcf3 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld @@ -1,6 +1 @@ -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_no_flash.ld" +INCLUDE "rp2_common/memmap_no_flash.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memory_blocked_ram.ld rename to src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memory_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memory_ram.ld rename to src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memory_scratch.ld rename to src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld new file mode 100644 index 00000000..661b4df0 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld @@ -0,0 +1,79 @@ +SECTIONS +{ + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld new file mode 100644 index 00000000..77a45941 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld @@ -0,0 +1,101 @@ +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Raspberry Pi Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .flashtext : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + } + + .rodata : { + /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + /* Vector table goes first in RAM, to avoid large alignment hole */ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .text : { + __ram_text_start__ = .; + *(.init) + *(.text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + __ram_text_end__ = .; + } > RAM AT> FLASH + __ram_text_source__ = LOADADDR(.text); + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld new file mode 100644 index 00000000..482c3fa5 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld @@ -0,0 +1,70 @@ +SECTIONS +{ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld new file mode 100644 index 00000000..7aa5c939 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld @@ -0,0 +1,109 @@ +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Raspberry Pi Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld new file mode 100644 index 00000000..a6634f74 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld @@ -0,0 +1,79 @@ +SECTIONS +{ + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM + PROVIDE(__data_end__ = .); + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld new file mode 100644 index 00000000..b4ad44ba --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld @@ -0,0 +1,71 @@ +SECTIONS +{ + /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger + entry (ELF entry point), are *first* in the image, and the vector table + follows immediately afterward. This is because the bootrom enters RAM + binaries directly at their lowest address (preferring main RAM over XIP + cache-as-SRAM if both are used). + */ + + .text : { + __logical_binary_start = .; + __reset_start = .; + KEEP (*(.reset)) + __reset_end = .; + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + . = ALIGN(256); + KEEP (*(.vectors)) + *(.text*) + . = ALIGN(4); + *(.init) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + } > RAM + + .rodata : { + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > RAM + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > RAM + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > RAM + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > RAM + __binary_info_end = .; + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld new file mode 100644 index 00000000..2d0165aa --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld @@ -0,0 +1,50 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld deleted file mode 100644 index 1777f660..00000000 --- a/src/rp2_common/pico_crt0/rp2040/sections_copy_to_ram.ld +++ /dev/null @@ -1,276 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .flashtext : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - } - - .rodata : { - /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - /* Vector table goes first in RAM, to avoid large alignment hole */ - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .text : { - __ram_text_start__ = .; - *(.init) - *(.text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - __ram_text_end__ = .; - } > RAM AT> FLASH - __ram_text_source__ = LOADADDR(.text); - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_default.ld b/src/rp2_common/pico_crt0/rp2040/sections_default.ld deleted file mode 100644 index 2e72b83b..00000000 --- a/src/rp2_common/pico_crt0/rp2040/sections_default.ld +++ /dev/null @@ -1,275 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Raspberry Pi Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld deleted file mode 100644 index c71ee3b0..00000000 --- a/src/rp2_common/pico_crt0/rp2040/sections_no_flash.ld +++ /dev/null @@ -1,239 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger - entry (ELF entry point), are *first* in the image, and the vector table - follows immediately afterward. This is because the bootrom enters RAM - binaries directly at their lowest address (preferring main RAM over XIP - cache-as-SRAM if both are used). - */ - - .text : { - __logical_binary_start = .; - __reset_start = .; - KEEP (*(.reset)) - __reset_end = .; - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - . = ALIGN(256); - KEEP (*(.vectors)) - *(.time_critical*) - *(.text*) - . = ALIGN(4); - *(.init) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - } > RAM - - .rodata : { - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > RAM - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > RAM - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > RAM - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > RAM - __binary_info_end = .; - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM - PROVIDE(__data_end__ = .); - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld index 7b99a774..6a1647d4 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld @@ -1,7 +1 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_copy_to_ram.ld" +INCLUDE "rp2_common/memmap_copy_to_ram.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld index 75fd340d..8e207371 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_default.ld @@ -1,7 +1 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_default.ld" +INCLUDE "rp2_common/memmap_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld index cde63059..b8d1dcf3 100644 --- a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld +++ b/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld @@ -1,6 +1 @@ -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" - -ENTRY(_entry_point) - -INCLUDE "sections_no_flash.ld" +INCLUDE "rp2_common/memmap_no_flash.ld" diff --git a/src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/memory_copy_to_ram.ld deleted file mode 100644 index e69de29b..00000000 diff --git a/src/rp2_common/pico_crt0/rp2350/memory_flash.ld b/src/rp2_common/pico_crt0/rp2350/memory_flash.ld deleted file mode 100644 index 669fe00e..00000000 --- a/src/rp2_common/pico_crt0/rp2350/memory_flash.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - INCLUDE "pico_flash_region.ld" -} diff --git a/src/rp2_common/pico_crt0/rp2350/memory_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memory_ram.ld rename to src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2350/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memory_scratch.ld rename to src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld diff --git a/src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memory_xip_ram.ld rename to src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld new file mode 100644 index 00000000..19082589 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld @@ -0,0 +1,83 @@ +SECTIONS +{ + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + . = ALIGN(4); + *(.rodata*) + *(.srodata*) + . = ALIGN(4); + + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld new file mode 100644 index 00000000..d35f7209 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld @@ -0,0 +1,117 @@ +SECTIONS +{ + /* On Arm, the bootrom expects a VT at the start of the + image by default; on RISC-V, the default is to enter the image at its + lowest address, so an IMAGE_DEF item is required to specify the + nondefault entry point. */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + /* The bootrom will enter the image at the point indicated in your + IMAGE_DEF, which is usually the reset handler of your vector table. + + The debugger will use the ELF entry point, which is the _entry_point + symbol, and in our case is *different from the bootrom's entry point.* + This is used to go back through the bootrom on debugger launches only, + to perform the same initial flash setup that would be performed on a + cold boot. + */ + + .flashtext : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + . = ALIGN(4); + } > FLASH + + /* Note the boot2 section is optional, and should be discarded if there is + no reference to it *inside* the binary, as it is not called by the + bootrom. (The bootrom performs a simple best-effort XIP setup and + leaves it to the binary to do anything more sophisticated.) However + there is still a size limit of 256 bytes, to ensure the boot2 can be + stored in boot RAM. + + Really this is a "XIP setup function" -- the name boot2 is historic and + refers to its dual-purpose on RP2040, where it also handled vectoring + from the bootrom into the user image. + */ + + .boot2 : { + __boot2_start__ = .; + *(.boot2) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ <= 256, + "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") + + .rodata : { + /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); + + /* Vector table goes first in RAM, to avoid large alignment hole */ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .text : { + __ram_text_start__ = .; + *(.init) + *(.text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + __ram_text_end__ = .; + } > RAM AT> FLASH + __ram_text_source__ = LOADADDR(.text); + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld new file mode 100644 index 00000000..9ffa5d16 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld @@ -0,0 +1,72 @@ +SECTIONS +{ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM AT> FLASH + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM AT> FLASH + PROVIDE(__data_end__ = .); + + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld new file mode 100644 index 00000000..fdd96332 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld @@ -0,0 +1,121 @@ +SECTIONS +{ + .flash_begin : { + __flash_binary_start = .; + } > FLASH + + /* The bootrom will enter the image at the point indicated in your + IMAGE_DEF, which is usually the reset handler of your vector table. + + The debugger will use the ELF entry point, which is the _entry_point + symbol, and in our case is *different from the bootrom's entry point.* + This is used to go back through the bootrom on debugger launches only, + to perform the same initial flash setup that would be performed on a + cold boot. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + *libgcc.a:cmse_nonsecure_call.o + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH + + /* Note the boot2 section is optional, and should be discarded if there is + no reference to it *inside* the binary, as it is not called by the + bootrom. (The bootrom performs a simple best-effort XIP setup and + leaves it to the binary to do anything more sophisticated.) However + there is still a size limit of 256 bytes, to ensure the boot2 can be + stored in boot RAM. + + Really this is a "XIP setup function" -- the name boot2 is historic and + refers to its dual-purpose on RP2040, where it also handled vectoring + from the bootrom into the user image. + */ + + .boot2 : { + __boot2_start__ = .; + *(.boot2) + __boot2_end__ = .; + } > FLASH + + ASSERT(__boot2_end__ - __boot2_start__ <= 256, + "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH + __binary_info_end = .; + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld new file mode 100644 index 00000000..5658d8a4 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld @@ -0,0 +1,82 @@ +SECTIONS +{ + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + *(.data*) + *(.sdata*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + } > RAM + + .tdata : { + . = ALIGN(4); + *(.tdata .tdata.* .gnu.linkonce.td.*) + /* All data end */ + __tdata_end = .; + } > RAM + PROVIDE(__data_end__ = .); + + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ + __etext = LOADADDR(.data); + + .tbss (NOLOAD) : { + . = ALIGN(4); + __bss_start__ = .; + __tls_base = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) + *(.tcommon) + + __tls_end = .; + } > RAM + + .bss (NOLOAD) : { + . = ALIGN(4); + __tbss_end = .; + + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + PROVIDE(__global_pointer$ = . + 2K); + *(.sbss*) + . = ALIGN(4); + __bss_end__ = .; + } > RAM +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld new file mode 100644 index 00000000..833d8c42 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld @@ -0,0 +1,73 @@ +SECTIONS +{ + /* Note unlike RP2040, we start the image with a vector table even for + NO_FLASH builds. On Arm, the bootrom expects a VT at the start of the + image by default; on RISC-V, the default is to enter the image at its + lowest address, so an IMAGE_DEF item is required to specify the + nondefault entry point. */ + + .text : { + __logical_binary_start = .; + /* Vectors require 512-byte alignment on v8-M when >48 IRQs are used, + so we would waste RAM if the vector table were not at the + start. */ + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.embedded_block)) + __embedded_block_end = .; + __reset_start = .; + KEEP (*(.reset)) + __reset_end = .; + *(.text*) + . = ALIGN(4); + *(.init) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + } > RAM + + .rodata : { + . = ALIGN(4); + *(.rodata*) + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > RAM + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > RAM + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > RAM + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > RAM + __binary_info_end = .; + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld b/src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld new file mode 100644 index 00000000..43cc19ec --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld @@ -0,0 +1,7 @@ +SECTIONS +{ + ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") + ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") + + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld b/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld deleted file mode 100644 index 4b76bc04..00000000 --- a/src/rp2_common/pico_crt0/rp2350/sections_copy_to_ram.ld +++ /dev/null @@ -1,298 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - /* On Arm, the bootrom expects a VT at the start of the - image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGE_DEF item is required to specify the - nondefault entry point. */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - /* The bootrom will enter the image at the point indicated in your - IMAGE_DEF, which is usually the reset handler of your vector table. - - The debugger will use the ELF entry point, which is the _entry_point - symbol, and in our case is *different from the bootrom's entry point.* - This is used to go back through the bootrom on debugger launches only, - to perform the same initial flash setup that would be performed on a - cold boot. - */ - - .flashtext : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - . = ALIGN(4); - } > FLASH - - /* Note the boot2 section is optional, and should be discarded if there is - no reference to it *inside* the binary, as it is not called by the - bootrom. (The bootrom performs a simple best-effort XIP setup and - leaves it to the binary to do anything more sophisticated.) However - there is still a size limit of 256 bytes, to ensure the boot2 can be - stored in boot RAM. - - Really this is a "XIP setup function" -- the name boot2 is historic and - refers to its dual-purpose on RP2040, where it also handled vectoring - from the bootrom into the user image. - */ - - .boot2 : { - __boot2_start__ = .; - *(.boot2) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ <= 256, - "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") - - .rodata : { - /* segments not marked as .flashdata are instead pulled into .data (in RAM) to avoid accidental flash accesses */ - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - /* Vector table goes first in RAM, to avoid large alignment hole */ - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .text : { - __ram_text_start__ = .; - *(.init) - *(.text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - __ram_text_end__ = .; - } > RAM AT> FLASH - __ram_text_source__ = LOADADDR(.text); - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - . = ALIGN(4); - *(.rodata*) - *(.srodata*) - . = ALIGN(4); - - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH =0xaa - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_default.ld b/src/rp2_common/pico_crt0/rp2350/sections_default.ld deleted file mode 100644 index eaeee272..00000000 --- a/src/rp2_common/pico_crt0/rp2350/sections_default.ld +++ /dev/null @@ -1,291 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - .flash_begin : { - __flash_binary_start = .; - } > FLASH - - /* The bootrom will enter the image at the point indicated in your - IMAGE_DEF, which is usually the reset handler of your vector table. - - The debugger will use the ELF entry point, which is the _entry_point - symbol, and in our case is *different from the bootrom's entry point.* - This is used to go back through the bootrom on debugger launches only, - to perform the same initial flash setup that would be performed on a - cold boot. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - *libgcc.a:cmse_nonsecure_call.o - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH - - /* Note the boot2 section is optional, and should be discarded if there is - no reference to it *inside* the binary, as it is not called by the - bootrom. (The bootrom performs a simple best-effort XIP setup and - leaves it to the binary to do anything more sophisticated.) However - there is still a size limit of 256 bytes, to ensure the boot2 can be - stored in boot RAM. - - Really this is a "XIP setup function" -- the name boot2 is historic and - refers to its dual-purpose on RP2040, where it also handled vectoring - from the bootrom into the user image. - */ - - .boot2 : { - __boot2_start__ = .; - *(.boot2) - __boot2_end__ = .; - } > FLASH - - ASSERT(__boot2_end__ - __boot2_start__ <= 256, - "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - *(.srodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH - __binary_info_end = .; - . = ALIGN(4); - - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - .flash_end : { - KEEP(*(.embedded_end_block*)) - PROVIDE(__flash_binary_end = .); - } > FLASH =0xaa - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld b/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld deleted file mode 100644 index 595d6977..00000000 --- a/src/rp2_common/pico_crt0/rp2350/sections_no_flash.ld +++ /dev/null @@ -1,246 +0,0 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -SECTIONS -{ - /* Note unlike RP2040, we start the image with a vector table even for - NO_FLASH builds. On Arm, the bootrom expects a VT at the start of the - image by default; on RISC-V, the default is to enter the image at its - lowest address, so an IMAGE_DEF item is required to specify the - nondefault entry point. */ - - .text : { - __logical_binary_start = .; - /* Vectors require 512-byte alignment on v8-M when >48 IRQs are used, - so we would waste RAM if the vector table were not at the - start. */ - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.embedded_block)) - __embedded_block_end = .; - __reset_start = .; - KEEP (*(.reset)) - __reset_end = .; - *(.time_critical*) - *(.text*) - . = ALIGN(4); - *(.init) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - } > RAM - - .rodata : { - . = ALIGN(4); - *(.rodata*) - *(.srodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > RAM - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > RAM - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > RAM - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > RAM - __binary_info_end = .; - . = ALIGN(4); - - .data : { - __data_start__ = .; - *(vtable) - *(.data*) - *(.sdata*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM - PROVIDE(__data_end__ = .); - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - PROVIDE(__global_pointer$ = . + 2K); - *(.sbss*) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): - { - __end__ = .; - end = __end__; - KEEP(*(.heap*)) - } > RAM - /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however - to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ - __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y - __scratch_y_source__ = LOADADDR(.scratch_y); - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (NOLOAD): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (NOLOAD): - { - KEEP(*(.stack*)) - } > SCRATCH_Y - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* picolibc and LLVM */ - PROVIDE (__heap_start = __end__); - PROVIDE (__heap_end = __HeapLimit); - PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); - PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); - PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); - - /* llvm-libc */ - PROVIDE (_end = __end__); - PROVIDE (__llvm_libc_heap_limit = __HeapLimit); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 1024, "Binary info must be in first 1024 bytes of the binary") - ASSERT( __embedded_block_end - __logical_binary_start <= 4096, "Embedded block must be in first 4096 bytes of the binary") - - /* todo assert on extra code */ -} diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 5dd40909..8fc24034 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -138,6 +138,7 @@ if (NOT TARGET pico_standard_link) # add include path for main linker script sections target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/scripts") # add variables set by pico_set_linker_script_var function target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld new file mode 100644 index 00000000..88127d89 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld @@ -0,0 +1,13 @@ +/* Include memory regions used */ +INCLUDE "rp2_common/memory_flash.ld" +INCLUDE "platform/memory_ram.ld" +INCLUDE "platform/memory_scratch.ld" + +/* Include aliases for storage memory regions */ +INCLUDE "rp2_common/memory_aliases_default.ld" + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include default sections */ +INCLUDE "rp2_common/sections_copy_to_ram.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld new file mode 100644 index 00000000..a8de400d --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld @@ -0,0 +1,13 @@ +/* Include memory regions used */ +INCLUDE "rp2_common/memory_flash.ld" +INCLUDE "platform/memory_ram.ld" +INCLUDE "platform/memory_scratch.ld" + +/* Include aliases for storage memory regions */ +INCLUDE "rp2_common/memory_aliases_default.ld" + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include default sections */ +INCLUDE "rp2_common/sections_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld new file mode 100644 index 00000000..61ae84dc --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld @@ -0,0 +1,12 @@ +/* Include memory regions used */ +INCLUDE "platform/memory_ram.ld" +INCLUDE "platform/memory_scratch.ld" + +/* Include aliases for no_flash storage memory regions (alias to themselves) */ +INCLUDE "rp2_common/memory_aliases_no_flash.ld" + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include no_flash sections */ +INCLUDE "rp2_common/sections_no_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld new file mode 100644 index 00000000..7c56254b --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld @@ -0,0 +1,3 @@ +REGION_ALIAS("RAM_STORE", FLASH); +REGION_ALIAS("SCRATCH_X_STORE", FLASH); +REGION_ALIAS("SCRATCH_Y_STORE", FLASH); diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld new file mode 100644 index 00000000..063b5b6f --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld @@ -0,0 +1,3 @@ +REGION_ALIAS("RAM_STORE", RAM); +REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); +REGION_ALIAS("SCRATCH_Y_STORE", SCRATCH_Y); diff --git a/src/rp2_common/pico_crt0/rp2040/memory_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_flash.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memory_flash.ld rename to src/rp2_common/pico_standard_link/scripts/rp2_common/memory_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld new file mode 100644 index 00000000..53d32817 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld @@ -0,0 +1,49 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +SECTIONS +{ + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* picolibc and LLVM */ + PROVIDE (__heap_start = __end__); + PROVIDE (__heap_end = __HeapLimit); + PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) ); + PROVIDE( __tls_size_align = (__tls_size + __tls_align - 1) & ~(__tls_align - 1)); + PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) ); + + /* llvm-libc */ + PROVIDE (_end = __end__); + PROVIDE (__llvm_libc_heap_limit = __HeapLimit); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + /* todo assert on extra code */ +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld new file mode 100644 index 00000000..8591406f --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld @@ -0,0 +1,7 @@ +SECTIONS +{ + .flash_end : { + KEEP(*(.embedded_end_block*)) + PROVIDE(__flash_binary_end = .); + } > FLASH =0xaa +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld new file mode 100644 index 00000000..1cc9e0de --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld @@ -0,0 +1,12 @@ +SECTIONS +{ + .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): + { + __end__ = .; + end = __end__; + KEEP(*(.heap*)) + } > RAM + /* historically on GCC sbrk was growing past __HeapLimit to __StackLimit, however + to be more compatible, we now set __HeapLimit explicitly to where the end of the heap is */ + __HeapLimit = DEFINED(HEAP_LIMIT) ? HEAP_LIMIT : ORIGIN(RAM) + LENGTH(RAM); +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld new file mode 100644 index 00000000..f61c3963 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld @@ -0,0 +1,37 @@ +SECTIONS +{ + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT> SCRATCH_X_STORE + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT> SCRATCH_Y_STORE + __scratch_y_source__ = LOADADDR(.scratch_y); + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (NOLOAD): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (NOLOAD): + { + KEEP(*(.stack*)) + } > SCRATCH_Y +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld new file mode 100644 index 00000000..0017f385 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld @@ -0,0 +1,7 @@ +INCLUDE "platform/section_copy_to_ram_text.ld" +INCLUDE "platform/section_copy_to_ram_data.ld" +INCLUDE "rp2_common/section_heap.ld" +INCLUDE "rp2_common/section_scratch.ld" +INCLUDE "rp2_common/section_flash_end.ld" +INCLUDE "rp2_common/section_end.ld" +INCLUDE "platform/section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld new file mode 100644 index 00000000..e0138db3 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld @@ -0,0 +1,7 @@ +INCLUDE "platform/section_default_text.ld" +INCLUDE "platform/section_default_data.ld" +INCLUDE "rp2_common/section_heap.ld" +INCLUDE "rp2_common/section_scratch.ld" +INCLUDE "rp2_common/section_flash_end.ld" +INCLUDE "rp2_common/section_end.ld" +INCLUDE "platform/section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld new file mode 100644 index 00000000..ebc062e6 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld @@ -0,0 +1,6 @@ +INCLUDE "platform/section_no_flash_text.ld" +INCLUDE "platform/section_no_flash_data.ld" +INCLUDE "rp2_common/section_heap.ld" +INCLUDE "rp2_common/section_scratch.ld" +INCLUDE "rp2_common/section_end.ld" +INCLUDE "platform/section_platform_end.ld" diff --git a/test/kitchen_sink/memmap_custom.ld b/test/kitchen_sink/memmap_custom.ld index 081913e5..7fe2098f 100644 --- a/test/kitchen_sink/memmap_custom.ld +++ b/test/kitchen_sink/memmap_custom.ld @@ -1,5 +1,6 @@ -INCLUDE "memory_flash.ld" -INCLUDE "memory_scratch.ld" +/* Include memory regions used */ +INCLUDE "rp2_common/memory_flash.ld" +INCLUDE "platform/memory_scratch.ld" /* Only use 128k of SRAM, starting at 0x20020000 */ MEMORY @@ -7,6 +8,11 @@ MEMORY RAM(rwx) : ORIGIN = 0x20020000, LENGTH = 128k } +/* Include aliases for storage memory regions */ +INCLUDE "rp2_common/memory_aliases_default.ld" + +/* Define entry point symbol */ ENTRY(_entry_point) -INCLUDE "sections_default.ld" +/* Include default sections */ +INCLUDE "rp2_common/sections_default.ld" From 4b1a3ec061db2394709e073c5f4659c27fea7def Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Dec 2025 14:56:53 +0000 Subject: [PATCH 05/15] More de-duplication --- .../platform/section_copy_to_ram_data.ld | 79 ------------------- .../rp2040/platform/section_default_data.ld | 70 ---------------- .../rp2040/platform/section_no_flash_data.ld | 79 ------------------- .../rp2_common}/section_copy_to_ram_data.ld | 0 .../rp2_common}/section_default_data.ld | 0 .../rp2_common}/section_no_flash_data.ld | 0 .../rp2_common/sections_copy_to_ram.ld | 2 +- .../scripts/rp2_common/sections_default.ld | 2 +- .../scripts/rp2_common/sections_no_flash.ld | 2 +- 9 files changed, 3 insertions(+), 231 deletions(-) delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld rename src/rp2_common/{pico_crt0/rp2350/platform => pico_standard_link/scripts/rp2_common}/section_copy_to_ram_data.ld (100%) rename src/rp2_common/{pico_crt0/rp2350/platform => pico_standard_link/scripts/rp2_common}/section_default_data.ld (100%) rename src/rp2_common/{pico_crt0/rp2350/platform => pico_standard_link/scripts/rp2_common}/section_no_flash_data.ld (100%) diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld deleted file mode 100644 index 661b4df0..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_data.ld +++ /dev/null @@ -1,79 +0,0 @@ -SECTIONS -{ - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld deleted file mode 100644 index 482c3fa5..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/section_default_data.ld +++ /dev/null @@ -1,70 +0,0 @@ -SECTIONS -{ - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - *(.jcr) - . = ALIGN(4); - } > RAM AT> FLASH - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM AT> FLASH - PROVIDE(__data_end__ = .); - - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld b/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld deleted file mode 100644 index a6634f74..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_data.ld +++ /dev/null @@ -1,79 +0,0 @@ -SECTIONS -{ - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - } > RAM - - .tdata : { - . = ALIGN(4); - *(.tdata .tdata.* .gnu.linkonce.td.*) - /* All data end */ - __tdata_end = .; - } > RAM - PROVIDE(__data_end__ = .); - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - /* __etext is (for backwards compatibility) the name of the .data init source pointer (...) */ - __etext = LOADADDR(.data); - - .tbss (NOLOAD) : { - . = ALIGN(4); - __bss_start__ = .; - __tls_base = .; - *(.tbss .tbss.* .gnu.linkonce.tb.*) - *(.tcommon) - - __tls_end = .; - } > RAM - - .bss (NOLOAD) : { - . = ALIGN(4); - __tbss_end = .; - - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_copy_to_ram_data.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_data.ld rename to src/rp2_common/pico_standard_link/scripts/rp2_common/section_copy_to_ram_data.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_default_data.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_default_data.ld rename to src/rp2_common/pico_standard_link/scripts/rp2_common/section_default_data.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/section_no_flash_data.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_data.ld rename to src/rp2_common/pico_standard_link/scripts/rp2_common/section_no_flash_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld index 0017f385..5e86d7c0 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld @@ -1,5 +1,5 @@ INCLUDE "platform/section_copy_to_ram_text.ld" -INCLUDE "platform/section_copy_to_ram_data.ld" +INCLUDE "rp2_common/section_copy_to_ram_data.ld" INCLUDE "rp2_common/section_heap.ld" INCLUDE "rp2_common/section_scratch.ld" INCLUDE "rp2_common/section_flash_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld index e0138db3..558ec184 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld @@ -1,5 +1,5 @@ INCLUDE "platform/section_default_text.ld" -INCLUDE "platform/section_default_data.ld" +INCLUDE "rp2_common/section_default_data.ld" INCLUDE "rp2_common/section_heap.ld" INCLUDE "rp2_common/section_scratch.ld" INCLUDE "rp2_common/section_flash_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld index ebc062e6..b9b3973b 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld @@ -1,5 +1,5 @@ INCLUDE "platform/section_no_flash_text.ld" -INCLUDE "platform/section_no_flash_data.ld" +INCLUDE "rp2_common/section_no_flash_data.ld" INCLUDE "rp2_common/section_heap.ld" INCLUDE "rp2_common/section_scratch.ld" INCLUDE "rp2_common/section_end.ld" From ae97a2294d6c26eb40fd8f5a92f5ee0906d3dbe3 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Dec 2025 17:31:49 +0000 Subject: [PATCH 06/15] Make overriding ram locations simpler --- .../pico_crt0/rp2040/memmap_blocked_ram.ld | 15 +++------------ .../rp2040/platform/default_locations.ld | 8 ++++++++ .../rp2040/platform/memory_blocked_ram.ld | 4 ---- .../pico_crt0/rp2040/platform/memory_ram.ld | 4 ---- .../rp2040/platform/memory_scratch.ld | 5 ----- .../rp2350/platform/default_locations.ld | 8 ++++++++ .../pico_crt0/rp2350/platform/memory_ram.ld | 4 ---- .../rp2350/platform/memory_scratch.ld | 5 ----- .../rp2350/platform/memory_xip_ram.ld | 4 ---- .../scripts/rp2_common/memmap_copy_to_ram.ld | 7 +++++-- .../scripts/rp2_common/memmap_default.ld | 7 +++++-- .../scripts/rp2_common/memmap_no_flash.ld | 7 +++++-- .../scripts/rp2_common/memory_ram.ld | 4 ++++ .../scripts/rp2_common/memory_scratch.ld | 5 +++++ .../scripts/rp2_common/memory_xip_ram.ld | 4 ++++ test/kitchen_sink/CMakeLists.txt | 15 ++++++++------- test/kitchen_sink/memmap_custom.ld | 18 ------------------ 17 files changed, 55 insertions(+), 69 deletions(-) create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld delete mode 100644 test/kitchen_sink/memmap_custom.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index 330e9bde..a4a52895 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -1,13 +1,4 @@ -/* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_blocked_ram.ld" -INCLUDE "platform/memory_scratch.ld" +/* Use blocked ram */ +RAM_ORIGIN = 0x21000000; -/* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include default sections */ -INCLUDE "rp2_common/sections_default.ld" +INCLUDE "memmap_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld new file mode 100644 index 00000000..684418b7 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld @@ -0,0 +1,8 @@ +RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; +RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 256k; +SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20040000; +SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; +SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20041000; +SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; +XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x15000000; +XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld deleted file mode 100644 index 57cbad6b..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x21000000, LENGTH = 256k -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld deleted file mode 100644 index 1e1515dd..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld deleted file mode 100644 index a4b982b9..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld new file mode 100644 index 00000000..0b1611d4 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld @@ -0,0 +1,8 @@ +RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; +RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 512k; +SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20080000; +SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; +SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20081000; +SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; +XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x13FFC000; +XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld deleted file mode 100644 index 434cdab9..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld deleted file mode 100644 index 246bbf05..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld deleted file mode 100644 index e94479b5..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - XIP_RAM(rwx) : ORIGIN = 0x13FFC000, LENGTH = 16k -} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld index 88127d89..12b7c85a 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld @@ -1,7 +1,10 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for storage memory regions */ INCLUDE "rp2_common/memory_aliases_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld index a8de400d..6b1ccf82 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld @@ -1,7 +1,10 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for storage memory regions */ INCLUDE "rp2_common/memory_aliases_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld index 61ae84dc..8fb49e6b 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld @@ -1,6 +1,9 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for no_flash storage memory regions (alias to themselves) */ INCLUDE "rp2_common/memory_aliases_no_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld new file mode 100644 index 00000000..2b8a88a0 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + RAM(rwx) : ORIGIN = RAM_ORIGIN, LENGTH = RAM_LENGTH +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld new file mode 100644 index 00000000..7ba5d217 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld @@ -0,0 +1,5 @@ +MEMORY +{ + SCRATCH_X(rwx) : ORIGIN = SCRATCH_X_ORIGIN, LENGTH = SCRATCH_X_LENGTH + SCRATCH_Y(rwx) : ORIGIN = SCRATCH_Y_ORIGIN, LENGTH = SCRATCH_Y_LENGTH +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld new file mode 100644 index 00000000..636e9013 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + XIP_RAM(rwx) : ORIGIN = XIP_RAM_ORIGIN, LENGTH = XIP_RAM_LENGTH +} diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 71b8a58b..33e5fbc2 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -215,13 +215,14 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) target_compile_definitions(kitchen_sink_blocked_ram PRIVATE KITCHEN_SINK_ID="blocked-ram binary") endif() - add_executable(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) - # Have heap start from 0x20030000, and custom linker script - pico_set_linker_script(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/memmap_custom.ld) - pico_set_linker_script_var(kitchen_sink_memmap_custom HEAP_LOC 0x20030000) - target_link_libraries(kitchen_sink_memmap_custom kitchen_sink_libs kitchen_sink_options) - pico_add_extra_outputs(kitchen_sink_memmap_custom) - target_compile_definitions(kitchen_sink_memmap_custom PRIVATE KITCHEN_SINK_ID="custom memmap binary") + add_executable(kitchen_sink_ram_custom ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + # Have ram start from 0x20020000 length 128k, and heap start from 0x20030000 + pico_set_linker_script_var(kitchen_sink_ram_custom RAM_ORIGIN 0x20020000) + pico_set_linker_script_var(kitchen_sink_ram_custom RAM_LENGTH 128k) + pico_set_linker_script_var(kitchen_sink_ram_custom HEAP_LOC 0x20030000) + target_link_libraries(kitchen_sink_ram_custom kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_ram_custom) + target_compile_definitions(kitchen_sink_ram_custom PRIVATE KITCHEN_SINK_ID="custom ram binary") endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/memmap_custom.ld b/test/kitchen_sink/memmap_custom.ld deleted file mode 100644 index 7fe2098f..00000000 --- a/test/kitchen_sink/memmap_custom.ld +++ /dev/null @@ -1,18 +0,0 @@ -/* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_scratch.ld" - -/* Only use 128k of SRAM, starting at 0x20020000 */ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20020000, LENGTH = 128k -} - -/* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include default sections */ -INCLUDE "rp2_common/sections_default.ld" From 3811e671d54c0198dad8b04f5249b36b8e9ddfd0 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 4 Dec 2025 10:14:26 +0000 Subject: [PATCH 07/15] Make it possible to reference default locations in pico_set_linker_script_var variables Means that CMake doesn't need to know the default memory addresses for different platforms --- .../rp2040/platform/default_locations.ld | 16 ++++++++-------- .../rp2350/platform/default_locations.ld | 16 ++++++++-------- src/rp2_common/pico_standard_link/CMakeLists.txt | 3 +++ .../scripts/rp2_common/memmap_copy_to_ram.ld | 2 +- .../scripts/rp2_common/memmap_default.ld | 2 +- .../scripts/rp2_common/memmap_no_flash.ld | 2 +- .../scripts/rp2_common/set_memory_locations.ld | 8 ++++++++ 7 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld index 684418b7..03144ea0 100644 --- a/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld +++ b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld @@ -1,8 +1,8 @@ -RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; -RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 256k; -SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20040000; -SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; -SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20041000; -SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; -XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x15000000; -XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; +RAM_ORIGIN_DEFAULT = 0x20000000; +RAM_LENGTH_DEFAULT = 256k; +SCRATCH_X_ORIGIN_DEFAULT = 0x20040000; +SCRATCH_X_LENGTH_DEFAULT = 4k; +SCRATCH_Y_ORIGIN_DEFAULT = 0x20041000; +SCRATCH_Y_LENGTH_DEFAULT = 4k; +XIP_RAM_ORIGIN_DEFAULT = 0x15000000; +XIP_RAM_LENGTH_DEFAULT = 16k; diff --git a/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld index 0b1611d4..15ddc737 100644 --- a/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld +++ b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld @@ -1,8 +1,8 @@ -RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; -RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 512k; -SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20080000; -SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; -SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20081000; -SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; -XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x13FFC000; -XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; +RAM_ORIGIN_DEFAULT = 0x20000000; +RAM_LENGTH_DEFAULT = 512k; +SCRATCH_X_ORIGIN_DEFAULT = 0x20080000; +SCRATCH_X_LENGTH_DEFAULT = 4k; +SCRATCH_Y_ORIGIN_DEFAULT = 0x20081000; +SCRATCH_Y_LENGTH_DEFAULT = 4k; +XIP_RAM_ORIGIN_DEFAULT = 0x13FFC000; +XIP_RAM_LENGTH_DEFAULT = 16k; diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 8fc24034..69f5751e 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -140,6 +140,9 @@ if (NOT TARGET pico_standard_link) target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}") target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/scripts") + # add default locations script, so they can be referenced by pico_set_linker_script_var variables + target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/platform/default_locations.ld") + # add variables set by pico_set_linker_script_var function target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld index 12b7c85a..1cb8f759 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld @@ -1,5 +1,5 @@ /* Include platform memory locations */ -INCLUDE "platform/default_locations.ld" +INCLUDE "rp2_common/set_memory_locations.ld" /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld index 6b1ccf82..2c8f3ffa 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld @@ -1,5 +1,5 @@ /* Include platform memory locations */ -INCLUDE "platform/default_locations.ld" +INCLUDE "rp2_common/set_memory_locations.ld" /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld index 8fb49e6b..2e3695ef 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld @@ -1,5 +1,5 @@ /* Include platform memory locations */ -INCLUDE "platform/default_locations.ld" +INCLUDE "rp2_common/set_memory_locations.ld" /* Include memory regions used */ INCLUDE "rp2_common/memory_ram.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld new file mode 100644 index 00000000..a9110eb5 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld @@ -0,0 +1,8 @@ +RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : RAM_ORIGIN_DEFAULT; +RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : RAM_LENGTH_DEFAULT; +SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : SCRATCH_X_ORIGIN_DEFAULT; +SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : SCRATCH_X_LENGTH_DEFAULT; +SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : SCRATCH_Y_ORIGIN_DEFAULT; +SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : SCRATCH_Y_LENGTH_DEFAULT; +XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : XIP_RAM_ORIGIN_DEFAULT; +XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : XIP_RAM_LENGTH_DEFAULT; From a20f86a7e7bfa377bb4a8a28e8c8db9171f6efdd Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 11 Feb 2026 18:57:12 +0000 Subject: [PATCH 08/15] Add pico_add_linker_script_override_path to make overriding individual files easier Restructured so that it includes the platform-specific files before common ones, so common ones can be overridden --- .../pico_crt0/rp2040/memmap_blocked_ram.ld | 2 +- .../default_locations.ld | 0 .../section_copy_to_ram_text.ld | 0 .../section_default_text.ld | 0 .../section_no_flash_text.ld | 0 .../section_platform_end.ld | 0 .../default_locations.ld | 0 .../section_copy_to_ram_text.ld | 0 .../section_default_text.ld | 0 .../section_no_flash_text.ld | 0 .../section_platform_end.ld | 0 .../pico_standard_link/CMakeLists.txt | 27 ++++++++++++++++--- .../memory_aliases_default.ld | 0 .../memory_aliases_no_flash.ld | 0 .../scripts/{rp2_common => }/memory_flash.ld | 0 .../scripts/{rp2_common => }/memory_ram.ld | 0 .../{rp2_common => }/memory_scratch.ld | 0 .../{rp2_common => }/memory_xip_ram.ld | 0 .../scripts/rp2_common/memmap_copy_to_ram.ld | 12 ++++----- .../scripts/rp2_common/memmap_default.ld | 12 ++++----- .../scripts/rp2_common/memmap_no_flash.ld | 10 +++---- .../rp2_common/sections_copy_to_ram.ld | 7 ----- .../scripts/rp2_common/sections_default.ld | 7 ----- .../scripts/rp2_common/sections_no_flash.ld | 6 ----- .../section_copy_to_ram_data.ld | 0 .../{rp2_common => }/section_default_data.ld | 0 .../scripts/{rp2_common => }/section_end.ld | 0 .../{rp2_common => }/section_flash_end.ld | 0 .../scripts/{rp2_common => }/section_heap.ld | 0 .../{rp2_common => }/section_no_flash_data.ld | 0 .../{rp2_common => }/section_scratch.ld | 0 .../scripts/sections_copy_to_ram.ld | 7 +++++ .../scripts/sections_default.ld | 7 +++++ .../scripts/sections_no_flash.ld | 6 +++++ .../{rp2_common => }/set_memory_locations.ld | 0 test/kitchen_sink/CMakeLists.txt | 6 +++++ test/kitchen_sink/kitchen_sink.c | 12 +++++++++ .../sections_default.ld | 19 +++++++++++++ 38 files changed, 99 insertions(+), 41 deletions(-) rename src/rp2_common/pico_crt0/rp2040/{platform => scripts}/default_locations.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{platform => scripts}/section_copy_to_ram_text.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{platform => scripts}/section_default_text.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{platform => scripts}/section_no_flash_text.ld (100%) rename src/rp2_common/pico_crt0/rp2040/{platform => scripts}/section_platform_end.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{platform => scripts}/default_locations.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{platform => scripts}/section_copy_to_ram_text.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{platform => scripts}/section_default_text.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{platform => scripts}/section_no_flash_text.ld (100%) rename src/rp2_common/pico_crt0/rp2350/{platform => scripts}/section_platform_end.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_aliases_default.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_aliases_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_flash.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_ram.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_scratch.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memory_xip_ram.ld (100%) delete mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld delete mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld delete mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_copy_to_ram_data.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_default_data.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_end.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_flash_end.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_heap.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_no_flash_data.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/section_scratch.ld (100%) create mode 100644 src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/sections_default.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/set_memory_locations.ld (100%) create mode 100644 test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index a4a52895..15a98861 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -1,4 +1,4 @@ /* Use blocked ram */ RAM_ORIGIN = 0x21000000; -INCLUDE "memmap_default.ld" +INCLUDE "rp2_common/memmap_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2040/scripts/default_locations.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld rename to src/rp2_common/pico_crt0/rp2040/scripts/default_locations.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld b/src/rp2_common/pico_crt0/rp2040/scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/platform/section_copy_to_ram_text.ld rename to src/rp2_common/pico_crt0/rp2040/scripts/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld b/src/rp2_common/pico_crt0/rp2040/scripts/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/platform/section_default_text.ld rename to src/rp2_common/pico_crt0/rp2040/scripts/section_default_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld b/src/rp2_common/pico_crt0/rp2040/scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/platform/section_no_flash_text.ld rename to src/rp2_common/pico_crt0/rp2040/scripts/section_no_flash_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld b/src/rp2_common/pico_crt0/rp2040/scripts/section_platform_end.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/platform/section_platform_end.ld rename to src/rp2_common/pico_crt0/rp2040/scripts/section_platform_end.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2350/scripts/default_locations.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld rename to src/rp2_common/pico_crt0/rp2350/scripts/default_locations.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld b/src/rp2_common/pico_crt0/rp2350/scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_copy_to_ram_text.ld rename to src/rp2_common/pico_crt0/rp2350/scripts/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld b/src/rp2_common/pico_crt0/rp2350/scripts/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_default_text.ld rename to src/rp2_common/pico_crt0/rp2350/scripts/section_default_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld b/src/rp2_common/pico_crt0/rp2350/scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_no_flash_text.ld rename to src/rp2_common/pico_crt0/rp2350/scripts/section_no_flash_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld b/src/rp2_common/pico_crt0/rp2350/scripts/section_platform_end.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/platform/section_platform_end.ld rename to src/rp2_common/pico_crt0/rp2350/scripts/section_platform_end.ld diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 69f5751e..24978fe6 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -73,12 +73,33 @@ if (NOT TARGET pico_standard_link) # pico_set_linker_script_var(TARGET NAME VALUE) # \brief\ Set the linker script for the target # - # \param\ NAME Name of varAible to set + # \param\ NAME Name of variable to set # \param\ VALUE Value of variable to set function(pico_set_linker_script_var TARGET NAME VALUE) set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_VARS "--defsym=${NAME}=${VALUE}") endfunction() + # pico_add_linker_script_override_path(TARGET PATH) + # \brief\ Add an override linker script path to the target + # + # This can be used to override default linker script files with custom versions. + # + # For example, to use custom files in ${CMAKE_CURRENT_LIST_DIR}/extra_scripts instead of the default ones, + # call pico_add_linker_script_override_path(TARGET ${CMAKE_CURRENT_LIST_DIR}/extra_scripts). This will + # include the custom files first, overriding the default ones. + # + # Must be called before target_link_libraries, otherwise it will not override the default linker scripts. + # + # \param\ TARGET The target to add the linker script override path to + # \param\ PATH The path containing the overriding linker scripts + function(pico_add_linker_script_override_path TARGET PATH) + get_target_property(OUT ${TARGET} LINK_LIBRARIES) + if (OUT) + message(WARNING "pico_add_linker_script_override_path does not work when called after target_link_libraries") + endif() + target_link_options(${TARGET} PRIVATE "LINKER:-L${PATH}") + endfunction() + # pico_set_binary_type(TARGET TYPE) # \brief\ Set the binary type for the target # @@ -137,11 +158,11 @@ if (NOT TARGET pico_standard_link) target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_BINARY_DIR}") # add include path for main linker script sections - target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}/scripts") target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/scripts") # add default locations script, so they can be referenced by pico_set_linker_script_var variables - target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/platform/default_locations.ld") + target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/scripts/default_locations.ld") # add variables set by pico_set_linker_script_var function target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld b/src/rp2_common/pico_standard_link/scripts/memory_aliases_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_default.ld rename to src/rp2_common/pico_standard_link/scripts/memory_aliases_default.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/memory_aliases_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_aliases_no_flash.ld rename to src/rp2_common/pico_standard_link/scripts/memory_aliases_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_flash.ld b/src/rp2_common/pico_standard_link/scripts/memory_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_flash.ld rename to src/rp2_common/pico_standard_link/scripts/memory_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld b/src/rp2_common/pico_standard_link/scripts/memory_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld rename to src/rp2_common/pico_standard_link/scripts/memory_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld b/src/rp2_common/pico_standard_link/scripts/memory_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld rename to src/rp2_common/pico_standard_link/scripts/memory_scratch.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/scripts/memory_xip_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld rename to src/rp2_common/pico_standard_link/scripts/memory_xip_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld index 1cb8f759..eb2c5ffd 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld @@ -1,16 +1,16 @@ /* Include platform memory locations */ -INCLUDE "rp2_common/set_memory_locations.ld" +INCLUDE "set_memory_locations.ld" /* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "rp2_common/memory_ram.ld" -INCLUDE "rp2_common/memory_scratch.ld" +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" /* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" +INCLUDE "memory_aliases_default.ld" /* Define entry point symbol */ ENTRY(_entry_point) /* Include default sections */ -INCLUDE "rp2_common/sections_copy_to_ram.ld" +INCLUDE "sections_copy_to_ram.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld index 2c8f3ffa..04acbefb 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld @@ -1,16 +1,16 @@ /* Include platform memory locations */ -INCLUDE "rp2_common/set_memory_locations.ld" +INCLUDE "set_memory_locations.ld" /* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "rp2_common/memory_ram.ld" -INCLUDE "rp2_common/memory_scratch.ld" +INCLUDE "memory_flash.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" /* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" +INCLUDE "memory_aliases_default.ld" /* Define entry point symbol */ ENTRY(_entry_point) /* Include default sections */ -INCLUDE "rp2_common/sections_default.ld" +INCLUDE "sections_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld index 2e3695ef..958915a7 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld @@ -1,15 +1,15 @@ /* Include platform memory locations */ -INCLUDE "rp2_common/set_memory_locations.ld" +INCLUDE "set_memory_locations.ld" /* Include memory regions used */ -INCLUDE "rp2_common/memory_ram.ld" -INCLUDE "rp2_common/memory_scratch.ld" +INCLUDE "memory_ram.ld" +INCLUDE "memory_scratch.ld" /* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "rp2_common/memory_aliases_no_flash.ld" +INCLUDE "memory_aliases_no_flash.ld" /* Define entry point symbol */ ENTRY(_entry_point) /* Include no_flash sections */ -INCLUDE "rp2_common/sections_no_flash.ld" +INCLUDE "sections_no_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld deleted file mode 100644 index 5e86d7c0..00000000 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_copy_to_ram.ld +++ /dev/null @@ -1,7 +0,0 @@ -INCLUDE "platform/section_copy_to_ram_text.ld" -INCLUDE "rp2_common/section_copy_to_ram_data.ld" -INCLUDE "rp2_common/section_heap.ld" -INCLUDE "rp2_common/section_scratch.ld" -INCLUDE "rp2_common/section_flash_end.ld" -INCLUDE "rp2_common/section_end.ld" -INCLUDE "platform/section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld deleted file mode 100644 index 558ec184..00000000 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_default.ld +++ /dev/null @@ -1,7 +0,0 @@ -INCLUDE "platform/section_default_text.ld" -INCLUDE "rp2_common/section_default_data.ld" -INCLUDE "rp2_common/section_heap.ld" -INCLUDE "rp2_common/section_scratch.ld" -INCLUDE "rp2_common/section_flash_end.ld" -INCLUDE "rp2_common/section_end.ld" -INCLUDE "platform/section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld deleted file mode 100644 index b9b3973b..00000000 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/sections_no_flash.ld +++ /dev/null @@ -1,6 +0,0 @@ -INCLUDE "platform/section_no_flash_text.ld" -INCLUDE "rp2_common/section_no_flash_data.ld" -INCLUDE "rp2_common/section_heap.ld" -INCLUDE "rp2_common/section_scratch.ld" -INCLUDE "rp2_common/section_end.ld" -INCLUDE "platform/section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_copy_to_ram_data.ld b/src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_copy_to_ram_data.ld rename to src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_default_data.ld b/src/rp2_common/pico_standard_link/scripts/section_default_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_default_data.ld rename to src/rp2_common/pico_standard_link/scripts/section_default_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld b/src/rp2_common/pico_standard_link/scripts/section_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_end.ld rename to src/rp2_common/pico_standard_link/scripts/section_end.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld b/src/rp2_common/pico_standard_link/scripts/section_flash_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_flash_end.ld rename to src/rp2_common/pico_standard_link/scripts/section_flash_end.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld b/src/rp2_common/pico_standard_link/scripts/section_heap.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_heap.ld rename to src/rp2_common/pico_standard_link/scripts/section_heap.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_no_flash_data.ld b/src/rp2_common/pico_standard_link/scripts/section_no_flash_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_no_flash_data.ld rename to src/rp2_common/pico_standard_link/scripts/section_no_flash_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld b/src/rp2_common/pico_standard_link/scripts/section_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/section_scratch.ld rename to src/rp2_common/pico_standard_link/scripts/section_scratch.ld diff --git a/src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld new file mode 100644 index 00000000..fe7caf54 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld @@ -0,0 +1,7 @@ +INCLUDE "section_copy_to_ram_text.ld" +INCLUDE "section_copy_to_ram_data.ld" +INCLUDE "section_heap.ld" +INCLUDE "section_scratch.ld" +INCLUDE "section_flash_end.ld" +INCLUDE "section_end.ld" +INCLUDE "section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/sections_default.ld b/src/rp2_common/pico_standard_link/scripts/sections_default.ld new file mode 100644 index 00000000..f22558a9 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/sections_default.ld @@ -0,0 +1,7 @@ +INCLUDE "section_default_text.ld" +INCLUDE "section_default_data.ld" +INCLUDE "section_heap.ld" +INCLUDE "section_scratch.ld" +INCLUDE "section_flash_end.ld" +INCLUDE "section_end.ld" +INCLUDE "section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld new file mode 100644 index 00000000..77bad234 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld @@ -0,0 +1,6 @@ +INCLUDE "section_no_flash_text.ld" +INCLUDE "section_no_flash_data.ld" +INCLUDE "section_heap.ld" +INCLUDE "section_scratch.ld" +INCLUDE "section_end.ld" +INCLUDE "section_platform_end.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld b/src/rp2_common/pico_standard_link/scripts/set_memory_locations.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/set_memory_locations.ld rename to src/rp2_common/pico_standard_link/scripts/set_memory_locations.ld diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 33e5fbc2..594f1b0a 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -223,6 +223,12 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) target_link_libraries(kitchen_sink_ram_custom kitchen_sink_libs kitchen_sink_options) pico_add_extra_outputs(kitchen_sink_ram_custom) target_compile_definitions(kitchen_sink_ram_custom PRIVATE KITCHEN_SINK_ID="custom ram binary") + + add_executable(kitchen_sink_ram_section ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + pico_add_linker_script_override_path(kitchen_sink_ram_section ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_ram_section_scripts) + target_link_libraries(kitchen_sink_ram_section kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_ram_section) + target_compile_definitions(kitchen_sink_ram_section PRIVATE KITCHEN_SINK_ID="ram section binary" EXTRA_DATA_SECTION=1) endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/kitchen_sink.c b/test/kitchen_sink/kitchen_sink.c index 7bc2bcd1..16c9a34b 100644 --- a/test/kitchen_sink/kitchen_sink.c +++ b/test/kitchen_sink/kitchen_sink.c @@ -85,6 +85,18 @@ int main(void) { hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL)); hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL)); printf("%f\n", foox(1.3f, 2.6f)); +#ifdef EXTRA_DATA_SECTION + static int extra_data __attribute__((section(".extra_data"))) = 12345678; + printf("extra_data before load = %d\n", extra_data); + + extern uint32_t __extra_data_source__; + extern uint32_t __extra_data_start__; + extern uint32_t __extra_data_end__; + uint32_t stored_words = (uint32_t)(&__extra_data_end__ - &__extra_data_start__); + memcpy(&__extra_data_start__, &__extra_data_source__, 4 * stored_words); + + printf("extra_data after load = %d\n", extra_data); +#endif #ifndef __riscv // this should compile as we are Cortex M0+ pico_default_asm ("SVC #3"); diff --git a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld new file mode 100644 index 00000000..9ffef1a2 --- /dev/null +++ b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld @@ -0,0 +1,19 @@ +INCLUDE "section_default_text.ld" +INCLUDE "section_default_data.ld" + +SECTIONS +{ + .extra_data : { + __extra_data_start__ = .; + *(.extra_data*) + . = ALIGN(4); + __extra_data_end__ = .; + } > RAM AT> RAM_STORE + __extra_data_source__ = LOADADDR(.extra_data); +} + +INCLUDE "section_heap.ld" +INCLUDE "section_scratch.ld" +INCLUDE "section_flash_end.ld" +INCLUDE "section_end.ld" +INCLUDE "section_platform_end.ld" \ No newline at end of file From 6bd9e5b3210f6deff0d404c89ad109889b4f45c0 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 26 Feb 2026 11:58:34 +0000 Subject: [PATCH 09/15] Add simple overlay demo --- test/kitchen_sink/CMakeLists.txt | 9 +++++++ test/kitchen_sink/kitchen_sink.c | 24 +++++++++++++++++++ .../sections_default.ld | 24 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 594f1b0a..245e2690 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -229,6 +229,15 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) target_link_libraries(kitchen_sink_ram_section kitchen_sink_libs kitchen_sink_options) pico_add_extra_outputs(kitchen_sink_ram_section) target_compile_definitions(kitchen_sink_ram_section PRIVATE KITCHEN_SINK_ID="ram section binary" EXTRA_DATA_SECTION=1) + + if (NOT PICO_C_COMPILER_IS_CLANG) + # Clang does not support overlay sections + add_executable(kitchen_sink_simple_overlay ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + pico_add_linker_script_override_path(kitchen_sink_simple_overlay ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_simple_overlay_scripts) + target_link_libraries(kitchen_sink_simple_overlay kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_simple_overlay) + target_compile_definitions(kitchen_sink_simple_overlay PRIVATE KITCHEN_SINK_ID="simple overlay binary" EXTRA_DATA_SECTION=2) + endif() endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/kitchen_sink.c b/test/kitchen_sink/kitchen_sink.c index 16c9a34b..6a3a5fbe 100644 --- a/test/kitchen_sink/kitchen_sink.c +++ b/test/kitchen_sink/kitchen_sink.c @@ -86,6 +86,29 @@ int main(void) { hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL)); printf("%f\n", foox(1.3f, 2.6f)); #ifdef EXTRA_DATA_SECTION +#if EXTRA_DATA_SECTION > 1 + extern uint32_t __overlays_start__; + uint32_t stored_words; + + static int overlay_first __attribute__((section(".overlay_first"))) = 12345678; + printf("overlay_first before load = %d\n", overlay_first); + static int overlay_second_one __attribute__((section(".overlay_second"))) = 34567890; + static int overlay_second_two __attribute__((section(".overlay_second"))) = 56789012; + printf("overlay_second before load = %d, %d\n", overlay_second_one, overlay_second_two); + + extern uint32_t __load_start_overlay_second; + extern uint32_t __load_stop_overlay_second; + stored_words = (uint32_t)(&__load_stop_overlay_second - &__load_start_overlay_second); + memcpy(&__overlays_start__, &__load_start_overlay_second, 4 * stored_words); + printf("overlay_second after load = %d, %d\n", overlay_second_one, overlay_second_two); + + extern uint32_t __load_start_overlay_first; + extern uint32_t __load_stop_overlay_first; + stored_words = (uint32_t)(&__load_stop_overlay_first - &__load_start_overlay_first); + memcpy(&__overlays_start__, &__load_start_overlay_first, 4 * stored_words); + printf("overlay_first after load = %d\n", overlay_first); + printf("overlay_second after overlay_first load = %d, %d\n", overlay_second_one, overlay_second_two); +#else static int extra_data __attribute__((section(".extra_data"))) = 12345678; printf("extra_data before load = %d\n", extra_data); @@ -97,6 +120,7 @@ int main(void) { printf("extra_data after load = %d\n", extra_data); #endif +#endif #ifndef __riscv // this should compile as we are Cortex M0+ pico_default_asm ("SVC #3"); diff --git a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld new file mode 100644 index 00000000..9a69c883 --- /dev/null +++ b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld @@ -0,0 +1,24 @@ +INCLUDE "section_default_text.ld" +INCLUDE "section_default_data.ld" + +SECTIONS +{ + PROVIDE(__overlays_start__ = .); + OVERLAY : { + .overlay_first { + KEEP (*(.first*)) + . = ALIGN(4); + } + .overlay_second { + KEEP (*(.second*)) + . = ALIGN(4); + } + } > RAM AT> RAM_STORE + PROVIDE(__overlays_end__ = .); +} + +INCLUDE "section_heap.ld" +INCLUDE "section_scratch.ld" +INCLUDE "section_flash_end.ld" +INCLUDE "section_end.ld" +INCLUDE "section_platform_end.ld" From 2bf8555fd4a3549346624ab4c9ab67d47030cef8 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 27 Feb 2026 10:49:07 +0000 Subject: [PATCH 10/15] Add scripts to bazel build Use new include_linker_script_dir and use_linker_script_file functions to add the linker arguments --- bazel/util/pico_linker_scripts.bzl | 49 +++++++++++++++ src/rp2_common/pico_crt0/rp2040/BUILD.bazel | 46 +++++++++++--- .../pico_crt0/rp2040/scripts/BUILD.bazel | 31 ++++++++++ src/rp2_common/pico_crt0/rp2350/BUILD.bazel | 40 ++++++++++-- .../pico_crt0/rp2350/scripts/BUILD.bazel | 31 ++++++++++ .../pico_standard_link/scripts/BUILD.bazel | 61 +++++++++++++++++++ 6 files changed, 244 insertions(+), 14 deletions(-) create mode 100644 bazel/util/pico_linker_scripts.bzl create mode 100644 src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel create mode 100644 src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel create mode 100644 src/rp2_common/pico_standard_link/scripts/BUILD.bazel diff --git a/bazel/util/pico_linker_scripts.bzl b/bazel/util/pico_linker_scripts.bzl new file mode 100644 index 00000000..f453b076 --- /dev/null +++ b/bazel/util/pico_linker_scripts.bzl @@ -0,0 +1,49 @@ +load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain") + +def _include_linker_script_dir_impl(ctx): + link_include_dir = str(ctx.label.package) + depset_direct = ["-L" + str(link_include_dir)] + if len(ctx.files.use_scripts): + for script in ctx.files.use_scripts: + depset_direct.append("-T" + str(script.path)) + + linking_inputs = cc_common.create_linker_input( + owner = ctx.label, + user_link_flags = depset( + direct = depset_direct, + ), + ) + return [ + CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))), + ] + +include_linker_script_dir = rule( + implementation = _include_linker_script_dir_impl, + attrs = { + "use_scripts": attr.label_list(allow_files = [".ld"]), + }, + toolchains = use_cpp_toolchain(), + fragments = ["cpp"], +) + +def _use_linker_script_file_impl(ctx): + link_file = ctx.file.script.path + + linking_inputs = cc_common.create_linker_input( + owner = ctx.label, + user_link_flags = depset( + direct = ["-T" + str(link_file)], + ), + ) + return [ + CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))), + ] + +use_linker_script_file = rule( + implementation = _use_linker_script_file_impl, + attrs = { + "script": attr.label(mandatory = True, allow_single_file = [".ld"]), + }, + toolchains = use_cpp_toolchain(), + fragments = ["cpp"], +) diff --git a/src/rp2_common/pico_crt0/rp2040/BUILD.bazel b/src/rp2_common/pico_crt0/rp2040/BUILD.bazel index 44912f0c..77cd2729 100644 --- a/src/rp2_common/pico_crt0/rp2040/BUILD.bazel +++ b/src/rp2_common/pico_crt0/rp2040/BUILD.bazel @@ -2,6 +2,8 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") package(default_visibility = ["//visibility:public"]) +load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file") + exports_files( [ "memmap_blocked_ram.ld", @@ -11,6 +13,26 @@ exports_files( ], ) +use_linker_script_file( + name = "memmap_default_args", + script = "memmap_default.ld", +) + +use_linker_script_file( + name = "memmap_blocked_ram_args", + script = "memmap_blocked_ram.ld", +) + +use_linker_script_file( + name = "memmap_copy_to_ram_args", + script = "memmap_copy_to_ram.ld", +) + +use_linker_script_file( + name = "memmap_no_flash_args", + script = "memmap_no_flash.ld", +) + # It's possible to set linker scripts globally or on a per-binary basis. # # Setting globally: @@ -22,12 +44,14 @@ exports_files( # * Manually add your desired linker script to each cc_binary. cc_library( name = "default_linker_script", - linkopts = ["-T$(location memmap_default.ld)"], target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ - "memmap_default.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_default.ld", + "memmap_default_args", ], ) @@ -35,12 +59,14 @@ cc_library( cc_library( name = "blocked_ram_linker_script", defines = ["PICO_USE_BLOCKED_RAM=1"], - linkopts = ["-T$(location memmap_blocked_ram.ld)"], target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ - "memmap_blocked_ram.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_blocked_ram.ld", + "memmap_blocked_ram_args", ], ) @@ -48,12 +74,14 @@ cc_library( cc_library( name = "copy_to_ram_linker_script", defines = ["PICO_COPY_TO_RAM=1"], - linkopts = ["-T$(location memmap_copy_to_ram.ld)"], target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ - "memmap_copy_to_ram.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_copy_to_ram.ld", + "memmap_copy_to_ram_args", ], ) @@ -61,10 +89,12 @@ cc_library( cc_library( name = "no_flash_linker_script", defines = ["PICO_NO_FLASH=1"], - linkopts = ["-T$(location memmap_no_flash.ld)"], target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ - "memmap_no_flash.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "memmap_no_flash.ld", + "memmap_no_flash_args", ], ) diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel b/src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel new file mode 100644 index 00000000..49284256 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") + +exports_files( + [ + "default_locations.ld", + "section_copy_to_ram_text.ld", + "section_default_text.ld", + "section_no_flash_text.ld", + "section_platform_end.ld", + ] +) + +include_linker_script_dir( + name = "rp2040_linker_script_args", + use_scripts = ["default_locations.ld"], +) + +cc_library( + name = "rp2040_linker_scripts", + target_compatible_with = ["//bazel/constraint:rp2040"], + deps = [ + "default_locations.ld", + "section_copy_to_ram_text.ld", + "section_default_text.ld", + "section_no_flash_text.ld", + "section_platform_end.ld", + "rp2040_linker_script_args", + ], +) \ No newline at end of file diff --git a/src/rp2_common/pico_crt0/rp2350/BUILD.bazel b/src/rp2_common/pico_crt0/rp2350/BUILD.bazel index b0f1ca7d..aae30de8 100644 --- a/src/rp2_common/pico_crt0/rp2350/BUILD.bazel +++ b/src/rp2_common/pico_crt0/rp2350/BUILD.bazel @@ -2,6 +2,8 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") package(default_visibility = ["//visibility:public"]) +load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file") + exports_files( [ "memmap_copy_to_ram.ld", @@ -10,6 +12,26 @@ exports_files( ], ) +use_linker_script_file( + name = "memmap_default_args", + script = "memmap_default.ld", +) + +use_linker_script_file( + name = "memmap_blocked_ram_args", + script = "memmap_blocked_ram.ld", +) + +use_linker_script_file( + name = "memmap_copy_to_ram_args", + script = "memmap_copy_to_ram.ld", +) + +use_linker_script_file( + name = "memmap_no_flash_args", + script = "memmap_no_flash.ld", +) + # It's possible to set linker scripts globally or on a per-binary basis. # # Setting globally: @@ -21,12 +43,14 @@ exports_files( # * Manually add your desired linker script to each cc_binary. cc_library( name = "default_linker_script", - linkopts = ["-T$(location memmap_default.ld)"], target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ - "memmap_default.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_default.ld", + "memmap_default_args", ], ) @@ -34,12 +58,14 @@ cc_library( cc_library( name = "copy_to_ram_linker_script", defines = ["PICO_COPY_TO_RAM=1"], - linkopts = ["-T$(location memmap_copy_to_ram.ld)"], target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ - "memmap_copy_to_ram.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_copy_to_ram.ld", + "memmap_copy_to_ram_args", ], ) @@ -47,10 +73,12 @@ cc_library( cc_library( name = "no_flash_linker_script", defines = ["PICO_NO_FLASH=1"], - linkopts = ["-T$(location memmap_no_flash.ld)"], target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ - "memmap_no_flash.ld", "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "memmap_no_flash.ld", + "memmap_no_flash_args", ], ) diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel b/src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel new file mode 100644 index 00000000..9c9aa732 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") + +exports_files( + [ + "default_locations.ld", + "section_copy_to_ram_text.ld", + "section_default_text.ld", + "section_no_flash_text.ld", + "section_platform_end.ld", + ] +) + +include_linker_script_dir( + name = "rp2350_linker_script_args", + use_scripts = ["default_locations.ld"], +) + +cc_library( + name = "rp2350_linker_scripts", + target_compatible_with = ["//bazel/constraint:rp2350"], + deps = [ + "default_locations.ld", + "section_copy_to_ram_text.ld", + "section_default_text.ld", + "section_no_flash_text.ld", + "section_platform_end.ld", + "rp2350_linker_script_args", + ], +) \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/scripts/BUILD.bazel b/src/rp2_common/pico_standard_link/scripts/BUILD.bazel new file mode 100644 index 00000000..ac6239a1 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/BUILD.bazel @@ -0,0 +1,61 @@ +load("//bazel:defs.bzl", "compatible_with_rp2") +load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") + +package(default_visibility = ["//visibility:public"]) + +exports_files( + [ + "memory_aliases_default.ld", + "memory_aliases_no_flash.ld", + "memory_flash.ld", + "memory_ram.ld", + "memory_scratch.ld", + "memory_xip_ram.ld", + "section_copy_to_ram_data.ld", + "section_default_data.ld", + "section_end.ld", + "section_flash_end.ld", + "section_heap.ld", + "section_no_flash_data.ld", + "sections_copy_to_ram.ld", + "section_scratch.ld", + "sections_default.ld", + "sections_no_flash.ld", + "set_memory_locations.ld", + "rp2_common/memmap_default.ld", + "rp2_common/memmap_no_flash.ld", + "rp2_common/memmap_copy_to_ram.ld", + ] +) + +include_linker_script_dir( + name = "rp2_linker_script_args", +) + +cc_library( + name = "rp2_linker_scripts", + target_compatible_with = compatible_with_rp2(), + deps = [ + "rp2_linker_script_args", + "memory_aliases_default.ld", + "memory_aliases_no_flash.ld", + "memory_flash.ld", + "memory_ram.ld", + "memory_scratch.ld", + "memory_xip_ram.ld", + "section_copy_to_ram_data.ld", + "section_default_data.ld", + "section_end.ld", + "section_flash_end.ld", + "section_heap.ld", + "section_no_flash_data.ld", + "sections_copy_to_ram.ld", + "section_scratch.ld", + "sections_default.ld", + "sections_no_flash.ld", + "set_memory_locations.ld", + "rp2_common/memmap_default.ld", + "rp2_common/memmap_no_flash.ld", + "rp2_common/memmap_copy_to_ram.ld", + ], +) \ No newline at end of file From fe2d56b68fe9597a05abba9203585c2f7d7a30a1 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 6 Mar 2026 11:29:14 +0000 Subject: [PATCH 11/15] Move linker scripts out of crt0 Breaking change for Bazel builds using different binary types, instead of setting PICO_DEFAULT_LINKER_SCRIPT to eg `//src/rp2_common/pico_crt0:no_flash_linker_script` it is now `//src/rp2_common/pico_standard_link:no_flash_linker_script` --- bazel/config/BUILD.bazel | 4 +- src/cmake/rp2_common.cmake | 1 + .../pico_platform_link}/BUILD.bazel | 8 ++-- src/rp2040/pico_platform_link/CMakeLists.txt | 6 +++ .../pico_platform_link}/memmap_blocked_ram.ld | 0 .../pico_platform_link}/memmap_copy_to_ram.ld | 0 .../pico_platform_link}/memmap_default.ld | 0 .../pico_platform_link}/memmap_no_flash.ld | 0 .../pico_platform_link}/scripts/BUILD.bazel | 0 .../scripts/default_locations.ld | 0 .../scripts/section_copy_to_ram_text.ld | 0 .../scripts/section_default_text.ld | 0 .../scripts/section_no_flash_text.ld | 0 .../scripts/section_platform_end.ld | 0 .../pico_platform_link}/BUILD.bazel | 6 +-- src/rp2350/pico_platform_link/CMakeLists.txt | 6 +++ .../pico_platform_link}/memmap_copy_to_ram.ld | 0 .../pico_platform_link}/memmap_default.ld | 0 .../pico_platform_link}/memmap_no_flash.ld | 0 .../pico_platform_link}/scripts/BUILD.bazel | 0 .../scripts/default_locations.ld | 0 .../scripts/section_copy_to_ram_text.ld | 0 .../scripts/section_default_text.ld | 0 .../scripts/section_no_flash_text.ld | 0 .../scripts/section_platform_end.ld | 0 src/rp2_common/pico_crt0/BUILD.bazel | 37 +------------------ src/rp2_common/pico_crt0/CMakeLists.txt | 5 --- src/rp2_common/pico_standard_link/BUILD.bazel | 35 ++++++++++++++++++ 28 files changed, 58 insertions(+), 50 deletions(-) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/BUILD.bazel (91%) create mode 100644 src/rp2040/pico_platform_link/CMakeLists.txt rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/memmap_blocked_ram.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/memmap_copy_to_ram.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/memmap_default.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/memmap_no_flash.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/BUILD.bazel (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/default_locations.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/section_copy_to_ram_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/section_default_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/section_no_flash_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2040 => rp2040/pico_platform_link}/scripts/section_platform_end.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/BUILD.bazel (91%) create mode 100644 src/rp2350/pico_platform_link/CMakeLists.txt rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/memmap_copy_to_ram.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/memmap_default.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/memmap_no_flash.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/BUILD.bazel (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/default_locations.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/section_copy_to_ram_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/section_default_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/section_no_flash_text.ld (100%) rename src/{rp2_common/pico_crt0/rp2350 => rp2350/pico_platform_link}/scripts/section_platform_end.ld (100%) diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index 84eac746..6b5b1f7c 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -217,10 +217,10 @@ string_flag( build_setting_default = "Debug", ) -# PICO_BAZEL_CONFIG: PICO_DEFAULT_LINKER_SCRIPT, [Bazel only] The library that provides a linker script to link into all binaries, default=//src/rp2_common/pico_crt0:default_linker_script, group=pico_standard_link +# PICO_BAZEL_CONFIG: PICO_DEFAULT_LINKER_SCRIPT, [Bazel only] The library that provides a linker script to link into all binaries, default=//src/rp2_common/pico_standard_link:default_linker_script, group=pico_standard_link label_flag( name = "PICO_DEFAULT_LINKER_SCRIPT", - build_setting_default = "//src/rp2_common/pico_crt0:default_linker_script", + build_setting_default = "//src/rp2_common/pico_standard_link:default_linker_script", ) # PICO_BAZEL_CONFIG: PICO_NO_TARGET_NAME, Don't define PICO_TARGET_NAME, type=bool, default=0, group=build diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index 273839f7..f608e5c0 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -28,6 +28,7 @@ pico_add_subdirectory(common/hardware_claim) # # RP2040/RP2350 specific From standard build variants pico_add_subdirectory(${RP2_VARIANT_DIR}/pico_platform) +pico_add_subdirectory(${RP2_VARIANT_DIR}/pico_platform_link) pico_add_subdirectory(${RP2_VARIANT_DIR}/hardware_regs) pico_add_subdirectory(${RP2_VARIANT_DIR}/hardware_structs) pico_add_subdirectory(${RP2_VARIANT_DIR}/boot_stage2) diff --git a/src/rp2_common/pico_crt0/rp2040/BUILD.bazel b/src/rp2040/pico_platform_link/BUILD.bazel similarity index 91% rename from src/rp2_common/pico_crt0/rp2040/BUILD.bazel rename to src/rp2040/pico_platform_link/BUILD.bazel index 77cd2729..34e0ff71 100644 --- a/src/rp2_common/pico_crt0/rp2040/BUILD.bazel +++ b/src/rp2040/pico_platform_link/BUILD.bazel @@ -47,7 +47,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", @@ -62,7 +62,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_blocked_ram.ld", @@ -77,7 +77,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", @@ -92,7 +92,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2040/scripts:rp2040_linker_scripts", + "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", diff --git a/src/rp2040/pico_platform_link/CMakeLists.txt b/src/rp2040/pico_platform_link/CMakeLists.txt new file mode 100644 index 00000000..af6943eb --- /dev/null +++ b/src/rp2040/pico_platform_link/CMakeLists.txt @@ -0,0 +1,6 @@ +pico_register_common_scope_var(PICO_LINKER_SCRIPT_PATH) +if (NOT PICO_LINKER_SCRIPT_PATH) + set(PICO_LINKER_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}) +endif() + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2040/pico_platform_link/memmap_blocked_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld rename to src/rp2040/pico_platform_link/memmap_blocked_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld b/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memmap_copy_to_ram.ld rename to src/rp2040/pico_platform_link/memmap_copy_to_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_default.ld b/src/rp2040/pico_platform_link/memmap_default.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memmap_default.ld rename to src/rp2040/pico_platform_link/memmap_default.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld b/src/rp2040/pico_platform_link/memmap_no_flash.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/memmap_no_flash.ld rename to src/rp2040/pico_platform_link/memmap_no_flash.ld diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel b/src/rp2040/pico_platform_link/scripts/BUILD.bazel similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/BUILD.bazel rename to src/rp2040/pico_platform_link/scripts/BUILD.bazel diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/default_locations.ld b/src/rp2040/pico_platform_link/scripts/default_locations.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/default_locations.ld rename to src/rp2040/pico_platform_link/scripts/default_locations.ld diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/section_copy_to_ram_text.ld b/src/rp2040/pico_platform_link/scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/section_copy_to_ram_text.ld rename to src/rp2040/pico_platform_link/scripts/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/section_default_text.ld b/src/rp2040/pico_platform_link/scripts/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/section_default_text.ld rename to src/rp2040/pico_platform_link/scripts/section_default_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/section_no_flash_text.ld b/src/rp2040/pico_platform_link/scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/section_no_flash_text.ld rename to src/rp2040/pico_platform_link/scripts/section_no_flash_text.ld diff --git a/src/rp2_common/pico_crt0/rp2040/scripts/section_platform_end.ld b/src/rp2040/pico_platform_link/scripts/section_platform_end.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2040/scripts/section_platform_end.ld rename to src/rp2040/pico_platform_link/scripts/section_platform_end.ld diff --git a/src/rp2_common/pico_crt0/rp2350/BUILD.bazel b/src/rp2350/pico_platform_link/BUILD.bazel similarity index 91% rename from src/rp2_common/pico_crt0/rp2350/BUILD.bazel rename to src/rp2350/pico_platform_link/BUILD.bazel index aae30de8..0b630064 100644 --- a/src/rp2_common/pico_crt0/rp2350/BUILD.bazel +++ b/src/rp2350/pico_platform_link/BUILD.bazel @@ -46,7 +46,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", @@ -61,7 +61,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", @@ -76,7 +76,7 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2_common/pico_crt0/rp2350/scripts:rp2350_linker_scripts", + "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", diff --git a/src/rp2350/pico_platform_link/CMakeLists.txt b/src/rp2350/pico_platform_link/CMakeLists.txt new file mode 100644 index 00000000..af6943eb --- /dev/null +++ b/src/rp2350/pico_platform_link/CMakeLists.txt @@ -0,0 +1,6 @@ +pico_register_common_scope_var(PICO_LINKER_SCRIPT_PATH) +if (NOT PICO_LINKER_SCRIPT_PATH) + set(PICO_LINKER_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}) +endif() + +pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld b/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memmap_copy_to_ram.ld rename to src/rp2350/pico_platform_link/memmap_copy_to_ram.ld diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_default.ld b/src/rp2350/pico_platform_link/memmap_default.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memmap_default.ld rename to src/rp2350/pico_platform_link/memmap_default.ld diff --git a/src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld b/src/rp2350/pico_platform_link/memmap_no_flash.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/memmap_no_flash.ld rename to src/rp2350/pico_platform_link/memmap_no_flash.ld diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel b/src/rp2350/pico_platform_link/scripts/BUILD.bazel similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/BUILD.bazel rename to src/rp2350/pico_platform_link/scripts/BUILD.bazel diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/default_locations.ld b/src/rp2350/pico_platform_link/scripts/default_locations.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/default_locations.ld rename to src/rp2350/pico_platform_link/scripts/default_locations.ld diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/section_copy_to_ram_text.ld b/src/rp2350/pico_platform_link/scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/section_copy_to_ram_text.ld rename to src/rp2350/pico_platform_link/scripts/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/section_default_text.ld b/src/rp2350/pico_platform_link/scripts/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/section_default_text.ld rename to src/rp2350/pico_platform_link/scripts/section_default_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/section_no_flash_text.ld b/src/rp2350/pico_platform_link/scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/section_no_flash_text.ld rename to src/rp2350/pico_platform_link/scripts/section_no_flash_text.ld diff --git a/src/rp2_common/pico_crt0/rp2350/scripts/section_platform_end.ld b/src/rp2350/pico_platform_link/scripts/section_platform_end.ld similarity index 100% rename from src/rp2_common/pico_crt0/rp2350/scripts/section_platform_end.ld rename to src/rp2350/pico_platform_link/scripts/section_platform_end.ld diff --git a/src/rp2_common/pico_crt0/BUILD.bazel b/src/rp2_common/pico_crt0/BUILD.bazel index b47b9c6c..99c9244b 100644 --- a/src/rp2_common/pico_crt0/BUILD.bazel +++ b/src/rp2_common/pico_crt0/BUILD.bazel @@ -3,48 +3,13 @@ load("//bazel:defs.bzl", "compatible_with_rp2") package(default_visibility = ["//visibility:public"]) -alias( - name = "default_linker_script", - actual = select({ - "//bazel/constraint:rp2040": "//src/rp2_common/pico_crt0/rp2040:default_linker_script", - "//bazel/constraint:rp2350": "//src/rp2_common/pico_crt0/rp2350:default_linker_script", - "//conditions:default": "//bazel:incompatible_cc_lib", - }), -) - -alias( - name = "blocked_ram_linker_script", - actual = select({ - "//bazel/constraint:rp2040": "//src/rp2_common/pico_crt0/rp2040:blocked_ram_linker_script", - "//conditions:default": "//bazel:incompatible_cc_lib", - }), -) - -alias( - name = "copy_to_ram_linker_script", - actual = select({ - "//bazel/constraint:rp2040": "//src/rp2_common/pico_crt0/rp2040:copy_to_ram_linker_script", - "//bazel/constraint:rp2350": "//src/rp2_common/pico_crt0/rp2350:copy_to_ram_linker_script", - "//conditions:default": "//bazel:incompatible_cc_lib", - }), -) - -alias( - name = "no_flash_linker_script", - actual = select({ - "//bazel/constraint:rp2040": "//src/rp2_common/pico_crt0/rp2040:no_flash_linker_script", - "//bazel/constraint:rp2350": "//src/rp2_common/pico_crt0/rp2350:no_flash_linker_script", - "//conditions:default": "//bazel:incompatible_cc_lib", - }), -) - cc_library( name = "no_warn_rwx_flag", linkopts = select({ "//bazel/constraint:pico_toolchain_gcc_enabled": ["-Wl,--no-warn-rwx-segments"], "//conditions:default": [], }), - visibility = [":__subpackages__"], + visibility = ["//src:__subpackages__"], ) cc_library( diff --git a/src/rp2_common/pico_crt0/CMakeLists.txt b/src/rp2_common/pico_crt0/CMakeLists.txt index bd415693..1bbbac74 100644 --- a/src/rp2_common/pico_crt0/CMakeLists.txt +++ b/src/rp2_common/pico_crt0/CMakeLists.txt @@ -11,9 +11,4 @@ if (NOT TARGET pico_crt0) target_link_libraries(pico_crt0 INTERFACE boot_picobin_headers pico_bootrom_headers) endif() -pico_register_common_scope_var(PICO_LINKER_SCRIPT_PATH) -if (NOT PICO_LINKER_SCRIPT_PATH) - set(PICO_LINKER_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}/${PICO_CHIP}) -endif() - pico_promote_common_scope_vars() \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/BUILD.bazel b/src/rp2_common/pico_standard_link/BUILD.bazel index 4c8ff249..6c84336b 100644 --- a/src/rp2_common/pico_standard_link/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/BUILD.bazel @@ -18,6 +18,41 @@ generated_pico_flash_region( }), ) +alias( + name = "default_linker_script", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform_link:default_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform_link:default_linker_script", + "//conditions:default": "//bazel:incompatible_cc_lib", + }), +) + +alias( + name = "blocked_ram_linker_script", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform_link:blocked_ram_linker_script", + "//conditions:default": "//bazel:incompatible_cc_lib", + }), +) + +alias( + name = "copy_to_ram_linker_script", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform_link:copy_to_ram_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform_link:copy_to_ram_linker_script", + "//conditions:default": "//bazel:incompatible_cc_lib", + }), +) + +alias( + name = "no_flash_linker_script", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform_link:no_flash_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform_link:no_flash_linker_script", + "//conditions:default": "//bazel:incompatible_cc_lib", + }), +) + cc_library( name = "pico_standard_link", target_compatible_with = compatible_with_rp2(), From 1bd7089eb4c395b48bf5293899ad7901306c957b Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 6 Mar 2026 11:43:57 +0000 Subject: [PATCH 12/15] Make rp2350 text sections the default Treat rp2040 layout (boot2 instead of embedded blocks) as the outlier --- .../pico_platform_link/memmap_blocked_ram.ld | 2 +- .../pico_platform_link/memmap_copy_to_ram.ld | 2 +- .../pico_platform_link/memmap_default.ld | 2 +- .../pico_platform_link/memmap_no_flash.ld | 2 +- .../pico_platform_link/memmap_copy_to_ram.ld | 2 +- .../pico_platform_link/memmap_default.ld | 2 +- .../pico_platform_link/memmap_no_flash.ld | 2 +- .../pico_platform_link/scripts/BUILD.bazel | 6 ------ .../pico_standard_link/scripts/BUILD.bazel | 18 ++++++++++++------ .../{rp2_common => }/memmap_copy_to_ram.ld | 0 .../scripts/{rp2_common => }/memmap_default.ld | 0 .../{rp2_common => }/memmap_no_flash.ld | 0 .../scripts/section_copy_to_ram_text.ld | 0 .../scripts/section_default_text.ld | 0 .../scripts/section_no_flash_text.ld | 0 15 files changed, 19 insertions(+), 19 deletions(-) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memmap_copy_to_ram.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memmap_default.ld (100%) rename src/rp2_common/pico_standard_link/scripts/{rp2_common => }/memmap_no_flash.ld (100%) rename src/{rp2350/pico_platform_link => rp2_common/pico_standard_link}/scripts/section_copy_to_ram_text.ld (100%) rename src/{rp2350/pico_platform_link => rp2_common/pico_standard_link}/scripts/section_default_text.ld (100%) rename src/{rp2350/pico_platform_link => rp2_common/pico_standard_link}/scripts/section_no_flash_text.ld (100%) diff --git a/src/rp2040/pico_platform_link/memmap_blocked_ram.ld b/src/rp2040/pico_platform_link/memmap_blocked_ram.ld index 15a98861..a4a52895 100644 --- a/src/rp2040/pico_platform_link/memmap_blocked_ram.ld +++ b/src/rp2040/pico_platform_link/memmap_blocked_ram.ld @@ -1,4 +1,4 @@ /* Use blocked ram */ RAM_ORIGIN = 0x21000000; -INCLUDE "rp2_common/memmap_default.ld" +INCLUDE "memmap_default.ld" diff --git a/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld b/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld index 6a1647d4..cd51ceea 100644 --- a/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld +++ b/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_copy_to_ram.ld" +INCLUDE "memmap_copy_to_ram.ld" diff --git a/src/rp2040/pico_platform_link/memmap_default.ld b/src/rp2040/pico_platform_link/memmap_default.ld index 8e207371..c256a907 100644 --- a/src/rp2040/pico_platform_link/memmap_default.ld +++ b/src/rp2040/pico_platform_link/memmap_default.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_default.ld" +INCLUDE "memmap_default.ld" diff --git a/src/rp2040/pico_platform_link/memmap_no_flash.ld b/src/rp2040/pico_platform_link/memmap_no_flash.ld index b8d1dcf3..3e5be9e0 100644 --- a/src/rp2040/pico_platform_link/memmap_no_flash.ld +++ b/src/rp2040/pico_platform_link/memmap_no_flash.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_no_flash.ld" +INCLUDE "memmap_no_flash.ld" diff --git a/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld b/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld index 6a1647d4..cd51ceea 100644 --- a/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld +++ b/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_copy_to_ram.ld" +INCLUDE "memmap_copy_to_ram.ld" diff --git a/src/rp2350/pico_platform_link/memmap_default.ld b/src/rp2350/pico_platform_link/memmap_default.ld index 8e207371..c256a907 100644 --- a/src/rp2350/pico_platform_link/memmap_default.ld +++ b/src/rp2350/pico_platform_link/memmap_default.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_default.ld" +INCLUDE "memmap_default.ld" diff --git a/src/rp2350/pico_platform_link/memmap_no_flash.ld b/src/rp2350/pico_platform_link/memmap_no_flash.ld index b8d1dcf3..3e5be9e0 100644 --- a/src/rp2350/pico_platform_link/memmap_no_flash.ld +++ b/src/rp2350/pico_platform_link/memmap_no_flash.ld @@ -1 +1 @@ -INCLUDE "rp2_common/memmap_no_flash.ld" +INCLUDE "memmap_no_flash.ld" diff --git a/src/rp2350/pico_platform_link/scripts/BUILD.bazel b/src/rp2350/pico_platform_link/scripts/BUILD.bazel index 9c9aa732..5161b096 100644 --- a/src/rp2350/pico_platform_link/scripts/BUILD.bazel +++ b/src/rp2350/pico_platform_link/scripts/BUILD.bazel @@ -5,9 +5,6 @@ load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") exports_files( [ "default_locations.ld", - "section_copy_to_ram_text.ld", - "section_default_text.ld", - "section_no_flash_text.ld", "section_platform_end.ld", ] ) @@ -22,9 +19,6 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "default_locations.ld", - "section_copy_to_ram_text.ld", - "section_default_text.ld", - "section_no_flash_text.ld", "section_platform_end.ld", "rp2350_linker_script_args", ], diff --git a/src/rp2_common/pico_standard_link/scripts/BUILD.bazel b/src/rp2_common/pico_standard_link/scripts/BUILD.bazel index ac6239a1..b0e51da9 100644 --- a/src/rp2_common/pico_standard_link/scripts/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/scripts/BUILD.bazel @@ -12,19 +12,22 @@ exports_files( "memory_scratch.ld", "memory_xip_ram.ld", "section_copy_to_ram_data.ld", + "section_copy_to_ram_text.ld", "section_default_data.ld", + "section_default_text.ld", "section_end.ld", "section_flash_end.ld", "section_heap.ld", "section_no_flash_data.ld", + "section_no_flash_text.ld", "sections_copy_to_ram.ld", "section_scratch.ld", "sections_default.ld", "sections_no_flash.ld", "set_memory_locations.ld", - "rp2_common/memmap_default.ld", - "rp2_common/memmap_no_flash.ld", - "rp2_common/memmap_copy_to_ram.ld", + "memmap_default.ld", + "memmap_no_flash.ld", + "memmap_copy_to_ram.ld", ] ) @@ -44,18 +47,21 @@ cc_library( "memory_scratch.ld", "memory_xip_ram.ld", "section_copy_to_ram_data.ld", + "section_copy_to_ram_text.ld", "section_default_data.ld", + "section_default_text.ld", "section_end.ld", "section_flash_end.ld", "section_heap.ld", "section_no_flash_data.ld", + "section_no_flash_text.ld", "sections_copy_to_ram.ld", "section_scratch.ld", "sections_default.ld", "sections_no_flash.ld", "set_memory_locations.ld", - "rp2_common/memmap_default.ld", - "rp2_common/memmap_no_flash.ld", - "rp2_common/memmap_copy_to_ram.ld", + "memmap_default.ld", + "memmap_no_flash.ld", + "memmap_copy_to_ram.ld", ], ) \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/scripts/memmap_copy_to_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/memmap_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld rename to src/rp2_common/pico_standard_link/scripts/memmap_default.ld diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/memmap_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld rename to src/rp2_common/pico_standard_link/scripts/memmap_no_flash.ld diff --git a/src/rp2350/pico_platform_link/scripts/section_copy_to_ram_text.ld b/src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2350/pico_platform_link/scripts/section_copy_to_ram_text.ld rename to src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_text.ld diff --git a/src/rp2350/pico_platform_link/scripts/section_default_text.ld b/src/rp2_common/pico_standard_link/scripts/section_default_text.ld similarity index 100% rename from src/rp2350/pico_platform_link/scripts/section_default_text.ld rename to src/rp2_common/pico_standard_link/scripts/section_default_text.ld diff --git a/src/rp2350/pico_platform_link/scripts/section_no_flash_text.ld b/src/rp2_common/pico_standard_link/scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2350/pico_platform_link/scripts/section_no_flash_text.ld rename to src/rp2_common/pico_standard_link/scripts/section_no_flash_text.ld From 72adb670c15675ae3d124b6dc0bd8306e4c09d22 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 6 Mar 2026 11:49:41 +0000 Subject: [PATCH 13/15] Rename scripts include directories to standard_scripts and platform_scripts --- src/rp2040/pico_platform_link/BUILD.bazel | 16 ++++++++-------- .../{scripts => platform_scripts}/BUILD.bazel | 0 .../default_locations.ld | 0 .../section_copy_to_ram_text.ld | 0 .../section_default_text.ld | 0 .../section_no_flash_text.ld | 0 .../section_platform_end.ld | 0 src/rp2350/pico_platform_link/BUILD.bazel | 12 ++++++------ .../{scripts => platform_scripts}/BUILD.bazel | 0 .../default_locations.ld | 0 .../section_platform_end.ld | 0 src/rp2_common/pico_standard_link/CMakeLists.txt | 6 +++--- .../{scripts => standard_scripts}/BUILD.bazel | 0 .../memmap_copy_to_ram.ld | 0 .../memmap_default.ld | 0 .../memmap_no_flash.ld | 0 .../memory_aliases_default.ld | 0 .../memory_aliases_no_flash.ld | 0 .../memory_flash.ld | 0 .../{scripts => standard_scripts}/memory_ram.ld | 0 .../memory_scratch.ld | 0 .../memory_xip_ram.ld | 0 .../section_copy_to_ram_data.ld | 0 .../section_copy_to_ram_text.ld | 0 .../section_default_data.ld | 0 .../section_default_text.ld | 0 .../{scripts => standard_scripts}/section_end.ld | 0 .../section_flash_end.ld | 0 .../section_heap.ld | 0 .../section_no_flash_data.ld | 0 .../section_no_flash_text.ld | 0 .../section_scratch.ld | 0 .../sections_copy_to_ram.ld | 0 .../sections_default.ld | 0 .../sections_no_flash.ld | 0 .../set_memory_locations.ld | 0 36 files changed, 17 insertions(+), 17 deletions(-) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/BUILD.bazel (100%) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/default_locations.ld (100%) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/section_copy_to_ram_text.ld (100%) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/section_default_text.ld (100%) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/section_no_flash_text.ld (100%) rename src/rp2040/pico_platform_link/{scripts => platform_scripts}/section_platform_end.ld (100%) rename src/rp2350/pico_platform_link/{scripts => platform_scripts}/BUILD.bazel (100%) rename src/rp2350/pico_platform_link/{scripts => platform_scripts}/default_locations.ld (100%) rename src/rp2350/pico_platform_link/{scripts => platform_scripts}/section_platform_end.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/BUILD.bazel (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memmap_copy_to_ram.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memmap_default.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memmap_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_aliases_default.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_aliases_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_flash.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_ram.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_scratch.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/memory_xip_ram.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_copy_to_ram_data.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_copy_to_ram_text.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_default_data.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_default_text.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_end.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_flash_end.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_heap.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_no_flash_data.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_no_flash_text.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/section_scratch.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/sections_copy_to_ram.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/sections_default.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/sections_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{scripts => standard_scripts}/set_memory_locations.ld (100%) diff --git a/src/rp2040/pico_platform_link/BUILD.bazel b/src/rp2040/pico_platform_link/BUILD.bazel index 34e0ff71..147cba5e 100644 --- a/src/rp2040/pico_platform_link/BUILD.bazel +++ b/src/rp2040/pico_platform_link/BUILD.bazel @@ -47,8 +47,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", "memmap_default_args", @@ -62,8 +62,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_blocked_ram.ld", "memmap_blocked_ram_args", @@ -77,8 +77,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", "memmap_copy_to_ram_args", @@ -92,8 +92,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", ], diff --git a/src/rp2040/pico_platform_link/scripts/BUILD.bazel b/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel similarity index 100% rename from src/rp2040/pico_platform_link/scripts/BUILD.bazel rename to src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel diff --git a/src/rp2040/pico_platform_link/scripts/default_locations.ld b/src/rp2040/pico_platform_link/platform_scripts/default_locations.ld similarity index 100% rename from src/rp2040/pico_platform_link/scripts/default_locations.ld rename to src/rp2040/pico_platform_link/platform_scripts/default_locations.ld diff --git a/src/rp2040/pico_platform_link/scripts/section_copy_to_ram_text.ld b/src/rp2040/pico_platform_link/platform_scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/scripts/section_copy_to_ram_text.ld rename to src/rp2040/pico_platform_link/platform_scripts/section_copy_to_ram_text.ld diff --git a/src/rp2040/pico_platform_link/scripts/section_default_text.ld b/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/scripts/section_default_text.ld rename to src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld diff --git a/src/rp2040/pico_platform_link/scripts/section_no_flash_text.ld b/src/rp2040/pico_platform_link/platform_scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/scripts/section_no_flash_text.ld rename to src/rp2040/pico_platform_link/platform_scripts/section_no_flash_text.ld diff --git a/src/rp2040/pico_platform_link/scripts/section_platform_end.ld b/src/rp2040/pico_platform_link/platform_scripts/section_platform_end.ld similarity index 100% rename from src/rp2040/pico_platform_link/scripts/section_platform_end.ld rename to src/rp2040/pico_platform_link/platform_scripts/section_platform_end.ld diff --git a/src/rp2350/pico_platform_link/BUILD.bazel b/src/rp2350/pico_platform_link/BUILD.bazel index 0b630064..355002d0 100644 --- a/src/rp2350/pico_platform_link/BUILD.bazel +++ b/src/rp2350/pico_platform_link/BUILD.bazel @@ -46,8 +46,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", "memmap_default_args", @@ -61,8 +61,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", "memmap_copy_to_ram_args", @@ -76,8 +76,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", ], diff --git a/src/rp2350/pico_platform_link/scripts/BUILD.bazel b/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel similarity index 100% rename from src/rp2350/pico_platform_link/scripts/BUILD.bazel rename to src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel diff --git a/src/rp2350/pico_platform_link/scripts/default_locations.ld b/src/rp2350/pico_platform_link/platform_scripts/default_locations.ld similarity index 100% rename from src/rp2350/pico_platform_link/scripts/default_locations.ld rename to src/rp2350/pico_platform_link/platform_scripts/default_locations.ld diff --git a/src/rp2350/pico_platform_link/scripts/section_platform_end.ld b/src/rp2350/pico_platform_link/platform_scripts/section_platform_end.ld similarity index 100% rename from src/rp2350/pico_platform_link/scripts/section_platform_end.ld rename to src/rp2350/pico_platform_link/platform_scripts/section_platform_end.ld diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 24978fe6..d1ae1cd2 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -158,11 +158,11 @@ if (NOT TARGET pico_standard_link) target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_BINARY_DIR}") # add include path for main linker script sections - target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}/scripts") - target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/scripts") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}/platform_scripts") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/standard_scripts") # add default locations script, so they can be referenced by pico_set_linker_script_var variables - target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/scripts/default_locations.ld") + target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/platform_scripts/default_locations.ld") # add variables set by pico_set_linker_script_var function target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") diff --git a/src/rp2_common/pico_standard_link/scripts/BUILD.bazel b/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/BUILD.bazel rename to src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel diff --git a/src/rp2_common/pico_standard_link/scripts/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/standard_scripts/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memmap_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memmap_copy_to_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memmap_default.ld b/src/rp2_common/pico_standard_link/standard_scripts/memmap_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memmap_default.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memmap_default.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/standard_scripts/memmap_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memmap_no_flash.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memmap_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_aliases_default.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_aliases_default.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_default.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_aliases_no_flash.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_aliases_no_flash.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_flash.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_flash.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_ram.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_ram.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_scratch.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_scratch.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_scratch.ld diff --git a/src/rp2_common/pico_standard_link/scripts/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/standard_scripts/memory_xip_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/memory_xip_ram.ld rename to src/rp2_common/pico_standard_link/standard_scripts/memory_xip_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_data.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_data.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_text.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_copy_to_ram_text.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_default_data.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_default_data.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_default_text.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_default_text.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_end.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_end.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_end.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_flash_end.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_flash_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_flash_end.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_flash_end.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_heap.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_heap.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_heap.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_heap.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_no_flash_data.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_no_flash_data.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_data.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_no_flash_text.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_no_flash_text.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_text.ld diff --git a/src/rp2_common/pico_standard_link/scripts/section_scratch.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/section_scratch.ld rename to src/rp2_common/pico_standard_link/standard_scripts/section_scratch.ld diff --git a/src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/standard_scripts/sections_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/sections_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/standard_scripts/sections_copy_to_ram.ld diff --git a/src/rp2_common/pico_standard_link/scripts/sections_default.ld b/src/rp2_common/pico_standard_link/standard_scripts/sections_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/sections_default.ld rename to src/rp2_common/pico_standard_link/standard_scripts/sections_default.ld diff --git a/src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld b/src/rp2_common/pico_standard_link/standard_scripts/sections_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/sections_no_flash.ld rename to src/rp2_common/pico_standard_link/standard_scripts/sections_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/scripts/set_memory_locations.ld b/src/rp2_common/pico_standard_link/standard_scripts/set_memory_locations.ld similarity index 100% rename from src/rp2_common/pico_standard_link/scripts/set_memory_locations.ld rename to src/rp2_common/pico_standard_link/standard_scripts/set_memory_locations.ld From e47fe099bdfaf90fbffbd08b9a509209bdff8abc Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 6 Mar 2026 12:04:33 +0000 Subject: [PATCH 14/15] Move and add example to Bazel docs for changing linker scripts --- src/rp2040/pico_platform_link/BUILD.bazel | 9 --------- src/rp2350/pico_platform_link/BUILD.bazel | 9 --------- src/rp2_common/pico_standard_link/BUILD.bazel | 9 +++++++++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/rp2040/pico_platform_link/BUILD.bazel b/src/rp2040/pico_platform_link/BUILD.bazel index 147cba5e..0a355624 100644 --- a/src/rp2040/pico_platform_link/BUILD.bazel +++ b/src/rp2040/pico_platform_link/BUILD.bazel @@ -33,15 +33,6 @@ use_linker_script_file( script = "memmap_no_flash.ld", ) -# It's possible to set linker scripts globally or on a per-binary basis. -# -# Setting globally: -# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT to point to your -# desired linker script. -# -# Setting per-binary: -# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT=@pico-sdk//bazel:empty_cc_lib -# * Manually add your desired linker script to each cc_binary. cc_library( name = "default_linker_script", target_compatible_with = ["//bazel/constraint:rp2040"], diff --git a/src/rp2350/pico_platform_link/BUILD.bazel b/src/rp2350/pico_platform_link/BUILD.bazel index 355002d0..d3aae916 100644 --- a/src/rp2350/pico_platform_link/BUILD.bazel +++ b/src/rp2350/pico_platform_link/BUILD.bazel @@ -32,15 +32,6 @@ use_linker_script_file( script = "memmap_no_flash.ld", ) -# It's possible to set linker scripts globally or on a per-binary basis. -# -# Setting globally: -# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT to point to your -# desired linker script. -# -# Setting per-binary: -# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT=@pico-sdk//bazel:empty_cc_lib -# * Manually add your desired linker script to each cc_binary. cc_library( name = "default_linker_script", target_compatible_with = ["//bazel/constraint:rp2350"], diff --git a/src/rp2_common/pico_standard_link/BUILD.bazel b/src/rp2_common/pico_standard_link/BUILD.bazel index 6c84336b..924358d5 100644 --- a/src/rp2_common/pico_standard_link/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/BUILD.bazel @@ -18,6 +18,15 @@ generated_pico_flash_region( }), ) +# It's possible to set linker scripts globally or on a per-binary basis. +# +# Setting globally: +# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT to point to your +# desired linker script (eg @pico-sdk//src/pico_standard_link:no_flash_linker_script) +# +# Setting per-binary: +# * Set --@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT=@pico-sdk//bazel:empty_cc_lib +# * Manually add your desired linker script to each cc_binary. alias( name = "default_linker_script", actual = select({ From 9c0ed0cc453fd2ad31facfa1368a01c3e31a2c55 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 6 Mar 2026 15:41:32 +0000 Subject: [PATCH 15/15] Add cc_library load to new bazel files --- src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel | 2 ++ src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel | 2 ++ src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel | 1 + 3 files changed, 5 insertions(+) diff --git a/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel b/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel index 49284256..337252e6 100644 --- a/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel +++ b/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + package(default_visibility = ["//visibility:public"]) load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") diff --git a/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel b/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel index 5161b096..5b234a01 100644 --- a/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel +++ b/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") + package(default_visibility = ["//visibility:public"]) load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") diff --git a/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel b/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel index b0e51da9..04a1af5d 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_cc//cc:cc_library.bzl", "cc_library") load("//bazel:defs.bzl", "compatible_with_rp2") load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir")