From b8f699f6ff4aaf16c7cb9641f4041aace9f3bc61 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 1 Dec 2025 19:32:27 +0000 Subject: [PATCH 01/60] 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 6f5000566..150176eba 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 842ebfd3c..7b99a7745 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 51254012d..75fd340d5 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 dbf006a8c..cde630592 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 000000000..57cbad6b7 --- /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 000000000..669fe00e3 --- /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 000000000..1e1515dd3 --- /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 000000000..a4b982b92 --- /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 000000000..5557ee1cb --- /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 000000000..57984e46b --- /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 000000000..9e082d53c --- /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 44c69f3b9..7b99a7745 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 bce316d14..75fd340d5 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 5bedf6d21..cde630592 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 000000000..e69de29bb 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 000000000..669fe00e3 --- /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 000000000..434cdab97 --- /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 000000000..246bbf050 --- /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 000000000..e94479b54 --- /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 000000000..9cc60b10a --- /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 000000000..cb2c6e114 --- /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 000000000..869d86436 --- /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 c16968bba..5905d3da1 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/60] 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 5557ee1cb..1777f6604 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 57984e46b..2e72b83b1 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 9e082d53c..c71ee3b01 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 9cc60b10a..4b76bc04c 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 cb2c6e114..eaeee2723 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 869d86436..595d69778 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 5905d3da1..5dd40909d 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/60] 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 1d6110f4c..71b8a58b6 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 000000000..081913e58 --- /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/60] 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 150176eba..330e9bde3 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 7b99a7745..6a1647d4a 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 75fd340d5..8e2073718 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 cde630592..b8d1dcf36 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 000000000..661b4df00 --- /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 000000000..77a45941b --- /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 000000000..482c3fa5a --- /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 000000000..7aa5c9399 --- /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 000000000..a6634f74d --- /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 000000000..b4ad44ba7 --- /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 000000000..2d0165aa4 --- /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 1777f6604..000000000 --- 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 2e72b83b1..000000000 --- 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 c71ee3b01..000000000 --- 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 7b99a7745..6a1647d4a 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 75fd340d5..8e2073718 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 cde630592..b8d1dcf36 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 e69de29bb..000000000 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 669fe00e3..000000000 --- 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 000000000..19082589c --- /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 000000000..d35f7209e --- /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 000000000..9ffa5d163 --- /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 000000000..fdd963321 --- /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 000000000..5658d8a4b --- /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 000000000..833d8c42b --- /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 000000000..43cc19ecd --- /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 4b76bc04c..000000000 --- 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 eaeee2723..000000000 --- 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 595d69778..000000000 --- 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 5dd40909d..8fc240346 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 000000000..88127d894 --- /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 000000000..a8de400d9 --- /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 000000000..61ae84dc7 --- /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 000000000..7c56254bd --- /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 000000000..063b5b6fc --- /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 000000000..53d328174 --- /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 000000000..8591406ff --- /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 000000000..1cc9e0de1 --- /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 000000000..f61c39639 --- /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 000000000..0017f385b --- /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 000000000..e0138db34 --- /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 000000000..ebc062e6a --- /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 081913e58..7fe2098f1 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/60] 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 661b4df00..000000000 --- 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 482c3fa5a..000000000 --- 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 a6634f74d..000000000 --- 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 0017f385b..5e86d7c0c 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 e0138db34..558ec1848 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 ebc062e6a..b9b3973b2 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/60] 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 330e9bde3..a4a528950 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 000000000..684418b73 --- /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 57cbad6b7..000000000 --- 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 1e1515dd3..000000000 --- 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 a4b982b92..000000000 --- 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 000000000..0b1611d40 --- /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 434cdab97..000000000 --- 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 246bbf050..000000000 --- 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 e94479b54..000000000 --- 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 88127d894..12b7c85ab 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 a8de400d9..6b1ccf827 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 61ae84dc7..8fb49e6bd 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 000000000..2b8a88a06 --- /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 000000000..7ba5d2172 --- /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 000000000..636e90137 --- /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 71b8a58b6..33e5fbc24 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 7fe2098f1..000000000 --- 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/60] 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 684418b73..03144ea07 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 0b1611d40..15ddc7374 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 8fc240346..69f5751ef 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 12b7c85ab..1cb8f7597 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 6b1ccf827..2c8f3ffa1 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 8fb49e6bd..2e3695ef9 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 000000000..a9110eb59 --- /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/60] 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 a4a528950..15a98861d 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 69f5751ef..24978fe68 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 1cb8f7597..eb2c5ffd9 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 2c8f3ffa1..04acbefbb 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 2e3695ef9..958915a71 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 5e86d7c0c..000000000 --- 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 558ec1848..000000000 --- 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 b9b3973b2..000000000 --- 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 000000000..fe7caf546 --- /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 000000000..f22558a9f --- /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 000000000..77bad234e --- /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 33e5fbc24..594f1b0a1 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 7bc2bcd11..16c9a34b9 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 000000000..9ffef1a28 --- /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/60] 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 594f1b0a1..245e26904 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 16c9a34b9..6a3a5fbee 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 000000000..9a69c883a --- /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/60] 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 000000000..f453b0761 --- /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 44912f0c8..77cd27297 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 000000000..492842565 --- /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 b0f1ca7dd..aae30de87 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 000000000..9c9aa7329 --- /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 000000000..ac6239a11 --- /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/60] 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 84eac746e..6b5b1f7c8 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 273839f70..f608e5c05 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 77cd27297..34e0ff71b 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 000000000..af6943ebd --- /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 aae30de87..0b630064f 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 000000000..af6943ebd --- /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 b47b9c6cf..99c9244bd 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 bd4156932..1bbbac742 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 4c8ff249a..6c84336bf 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/60] 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 15a98861d..a4a528950 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 6a1647d4a..cd51ceeaa 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 8e2073718..c256a9071 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 b8d1dcf36..3e5be9e01 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 6a1647d4a..cd51ceeaa 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 8e2073718..c256a9071 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 b8d1dcf36..3e5be9e01 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 9c9aa7329..5161b096b 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 ac6239a11..b0e51da98 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/60] 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 34e0ff71b..147cba5e2 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 0b630064f..355002d04 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 24978fe68..d1ae1cd2a 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/60] 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 147cba5e2..0a3556242 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 355002d04..d3aae9161 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 6c84336bf..924358d50 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/60] 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 492842565..337252e6c 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 5161b096b..5b234a016 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 b0e51da98..04a1af5d9 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") From e44bdea25f2b1c24cd37d96ee7461aab9046ee6a Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 16 Mar 2026 12:45:28 +0000 Subject: [PATCH 16/60] Add excludes.ld files for default memmap Allows overriding what to exclude from .text/.rodata and put in .data --- .../platform_scripts/section_default_text.ld | 4 ++-- .../pico_standard_link/standard_scripts/BUILD.bazel | 4 ++++ .../standard_scripts/section_default_data.ld | 2 +- .../standard_scripts/section_default_rodata_excludes.ld | 1 + .../standard_scripts/section_default_text.ld | 4 ++-- .../standard_scripts/section_default_text_excludes.ld | 1 + 6 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld create mode 100644 src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld diff --git a/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld b/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld index 7aa5c9399..2f25a1d4d 100644 --- a/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld +++ b/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld @@ -37,7 +37,7 @@ SECTIONS /* 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*) + INCLUDE "section_default_text_excludes.ld" *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -78,7 +78,7 @@ SECTIONS } > FLASH .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + INCLUDE "section_default_rodata_excludes.ld" . = ALIGN(4); *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) . = ALIGN(4); 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 04a1af5d9..ba56b59d3 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel @@ -16,6 +16,8 @@ exports_files( "section_copy_to_ram_text.ld", "section_default_data.ld", "section_default_text.ld", + "section_default_text_excludes.ld", + "section_default_rodata_excludes.ld", "section_end.ld", "section_flash_end.ld", "section_heap.ld", @@ -51,6 +53,8 @@ cc_library( "section_copy_to_ram_text.ld", "section_default_data.ld", "section_default_text.ld", + "section_default_text_excludes.ld", + "section_default_rodata_excludes.ld", "section_end.ld", "section_flash_end.ld", "section_heap.ld", diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld index 9ffa5d163..5bd1cf569 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld @@ -15,7 +15,7 @@ SECTIONS *(.time_critical*) - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + /* remaining .text and .rodata; i.e. stuff we exclude in ..._excludes files because we want it in RAM */ *(.text*) . = ALIGN(4); *(.rodata*) diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld new file mode 100644 index 000000000..3d57435bb --- /dev/null +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld @@ -0,0 +1 @@ +*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld index fdd963321..ab86ade78 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld @@ -27,7 +27,7 @@ SECTIONS * 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*) + INCLUDE "section_default_text_excludes.ld" *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -89,7 +89,7 @@ SECTIONS "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*) + INCLUDE "section_default_rodata_excludes.ld" *(.srodata*) . = ALIGN(4); *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld new file mode 100644 index 000000000..69bc10cdb --- /dev/null +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld @@ -0,0 +1 @@ +*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) \ No newline at end of file From dc3a2e861adebdff1b7009f950580f1f719366d1 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 16 Mar 2026 14:19:26 +0000 Subject: [PATCH 17/60] Put mem functions in SRAM These were being placed in Flash due to a missing space, and also are under libc on some compilers --- .../standard_scripts/section_default_rodata_excludes.ld | 2 +- .../standard_scripts/section_default_text_excludes.ld | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld index 3d57435bb..920e30383 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld @@ -1 +1 @@ -*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) \ No newline at end of file +*(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib*_a-mem*.o *libm.a:) .rodata*) \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld index 69bc10cdb..e81ae31bf 100644 --- a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld +++ b/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld @@ -1 +1 @@ -*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) \ No newline at end of file +*(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib*_a-mem*.o *libm.a:) .text*) \ No newline at end of file From 8b9d9ec6389ee3b3bfbddfa8c86153c6d80ca273 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 10:25:06 +0000 Subject: [PATCH 18/60] Rename standard_scripts and platform_scripts to script_include --- src/rp2040/pico_platform_link/BUILD.bazel | 16 ++++++++-------- .../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 ++++++------ .../BUILD.bazel | 0 .../default_locations.ld | 0 .../section_platform_end.ld | 0 src/rp2_common/pico_standard_link/CMakeLists.txt | 6 +++--- .../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 .../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_rodata_excludes.ld | 0 .../section_default_text.ld | 0 .../section_default_text_excludes.ld | 0 .../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 38 files changed, 17 insertions(+), 17 deletions(-) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/BUILD.bazel (100%) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/default_locations.ld (100%) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/section_copy_to_ram_text.ld (100%) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/section_default_text.ld (100%) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/section_no_flash_text.ld (100%) rename src/rp2040/pico_platform_link/{platform_scripts => script_include}/section_platform_end.ld (100%) rename src/rp2350/pico_platform_link/{platform_scripts => script_include}/BUILD.bazel (100%) rename src/rp2350/pico_platform_link/{platform_scripts => script_include}/default_locations.ld (100%) rename src/rp2350/pico_platform_link/{platform_scripts => script_include}/section_platform_end.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/BUILD.bazel (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memmap_copy_to_ram.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memmap_default.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memmap_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_aliases_default.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_aliases_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_flash.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_ram.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_scratch.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/memory_xip_ram.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_copy_to_ram_data.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_copy_to_ram_text.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_default_data.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_default_rodata_excludes.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_default_text.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_default_text_excludes.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_end.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_flash_end.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_heap.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_no_flash_data.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_no_flash_text.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/section_scratch.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/sections_copy_to_ram.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/sections_default.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/sections_no_flash.ld (100%) rename src/rp2_common/pico_standard_link/{standard_scripts => script_include}/set_memory_locations.ld (100%) diff --git a/src/rp2040/pico_platform_link/BUILD.bazel b/src/rp2040/pico_platform_link/BUILD.bazel index 0a3556242..d35bfaf1d 100644 --- a/src/rp2040/pico_platform_link/BUILD.bazel +++ b/src/rp2040/pico_platform_link/BUILD.bazel @@ -38,8 +38,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", "memmap_default_args", @@ -53,8 +53,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_blocked_ram.ld", "memmap_blocked_ram_args", @@ -68,8 +68,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", "memmap_copy_to_ram_args", @@ -83,8 +83,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2040"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/platform_scripts:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", ], diff --git a/src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel b/src/rp2040/pico_platform_link/script_include/BUILD.bazel similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/BUILD.bazel rename to src/rp2040/pico_platform_link/script_include/BUILD.bazel diff --git a/src/rp2040/pico_platform_link/platform_scripts/default_locations.ld b/src/rp2040/pico_platform_link/script_include/default_locations.ld similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/default_locations.ld rename to src/rp2040/pico_platform_link/script_include/default_locations.ld diff --git a/src/rp2040/pico_platform_link/platform_scripts/section_copy_to_ram_text.ld b/src/rp2040/pico_platform_link/script_include/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/section_copy_to_ram_text.ld rename to src/rp2040/pico_platform_link/script_include/section_copy_to_ram_text.ld diff --git a/src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld b/src/rp2040/pico_platform_link/script_include/section_default_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/section_default_text.ld rename to src/rp2040/pico_platform_link/script_include/section_default_text.ld diff --git a/src/rp2040/pico_platform_link/platform_scripts/section_no_flash_text.ld b/src/rp2040/pico_platform_link/script_include/section_no_flash_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/section_no_flash_text.ld rename to src/rp2040/pico_platform_link/script_include/section_no_flash_text.ld diff --git a/src/rp2040/pico_platform_link/platform_scripts/section_platform_end.ld b/src/rp2040/pico_platform_link/script_include/section_platform_end.ld similarity index 100% rename from src/rp2040/pico_platform_link/platform_scripts/section_platform_end.ld rename to src/rp2040/pico_platform_link/script_include/section_platform_end.ld diff --git a/src/rp2350/pico_platform_link/BUILD.bazel b/src/rp2350/pico_platform_link/BUILD.bazel index d3aae9161..31bc624f4 100644 --- a/src/rp2350/pico_platform_link/BUILD.bazel +++ b/src/rp2350/pico_platform_link/BUILD.bazel @@ -37,8 +37,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_default.ld", "memmap_default_args", @@ -52,8 +52,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "//src/rp2_common/pico_standard_link:default_flash_region", "memmap_copy_to_ram.ld", "memmap_copy_to_ram_args", @@ -67,8 +67,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/platform_scripts:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/standard_scripts:rp2_linker_scripts", + "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", "memmap_no_flash.ld", "memmap_no_flash_args", ], diff --git a/src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel b/src/rp2350/pico_platform_link/script_include/BUILD.bazel similarity index 100% rename from src/rp2350/pico_platform_link/platform_scripts/BUILD.bazel rename to src/rp2350/pico_platform_link/script_include/BUILD.bazel diff --git a/src/rp2350/pico_platform_link/platform_scripts/default_locations.ld b/src/rp2350/pico_platform_link/script_include/default_locations.ld similarity index 100% rename from src/rp2350/pico_platform_link/platform_scripts/default_locations.ld rename to src/rp2350/pico_platform_link/script_include/default_locations.ld diff --git a/src/rp2350/pico_platform_link/platform_scripts/section_platform_end.ld b/src/rp2350/pico_platform_link/script_include/section_platform_end.ld similarity index 100% rename from src/rp2350/pico_platform_link/platform_scripts/section_platform_end.ld rename to src/rp2350/pico_platform_link/script_include/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 d1ae1cd2a..af51a69ea 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}/platform_scripts") - target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/standard_scripts") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}/script_include") + target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/script_include") # 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_scripts/default_locations.ld") + target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_SCRIPT_PATH}/script_include/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/standard_scripts/BUILD.bazel b/src/rp2_common/pico_standard_link/script_include/BUILD.bazel similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/BUILD.bazel rename to src/rp2_common/pico_standard_link/script_include/BUILD.bazel diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memmap_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memmap_default.ld b/src/rp2_common/pico_standard_link/script_include/memmap_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memmap_default.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_default.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memmap_no_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_default.ld b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_default.ld rename to src/rp2_common/pico_standard_link/script_include/memory_aliases_default.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_aliases_no_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_flash.ld b/src/rp2_common/pico_standard_link/script_include/memory_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memory_flash.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_ram.ld b/src/rp2_common/pico_standard_link/script_include/memory_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memory_ram.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_scratch.ld b/src/rp2_common/pico_standard_link/script_include/memory_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_scratch.ld rename to src/rp2_common/pico_standard_link/script_include/memory_scratch.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/script_include/memory_xip_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/memory_xip_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memory_xip_ram.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_data.ld b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_text.ld b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_copy_to_ram_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld b/src/rp2_common/pico_standard_link/script_include/section_default_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_default_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_data.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld b/src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_default_rodata_excludes.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld b/src/rp2_common/pico_standard_link/script_include/section_default_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_default_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_text.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld b/src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_default_text_excludes.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_end.ld b/src/rp2_common/pico_standard_link/script_include/section_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_end.ld rename to src/rp2_common/pico_standard_link/script_include/section_end.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_flash_end.ld b/src/rp2_common/pico_standard_link/script_include/section_flash_end.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_flash_end.ld rename to src/rp2_common/pico_standard_link/script_include/section_flash_end.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_heap.ld b/src/rp2_common/pico_standard_link/script_include/section_heap.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_heap.ld rename to src/rp2_common/pico_standard_link/script_include/section_heap.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_data.ld b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_no_flash_data.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_text.ld b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_no_flash_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_no_flash_text.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/section_scratch.ld b/src/rp2_common/pico_standard_link/script_include/section_scratch.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/section_scratch.ld rename to src/rp2_common/pico_standard_link/script_include/section_scratch.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/sections_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/sections_default.ld b/src/rp2_common/pico_standard_link/script_include/sections_default.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/sections_default.ld rename to src/rp2_common/pico_standard_link/script_include/sections_default.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/sections_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/sections_no_flash.ld rename to src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld diff --git a/src/rp2_common/pico_standard_link/standard_scripts/set_memory_locations.ld b/src/rp2_common/pico_standard_link/script_include/set_memory_locations.ld similarity index 100% rename from src/rp2_common/pico_standard_link/standard_scripts/set_memory_locations.ld rename to src/rp2_common/pico_standard_link/script_include/set_memory_locations.ld From 91c3a9a2d735eb11d9e312cc14402a4f02d65424 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 10:38:36 +0000 Subject: [PATCH 19/60] Move pico_platform_link stuff into pico_plaftorm --- src/cmake/rp2_common.cmake | 1 - src/rp2040/pico_platform/BUILD.bazel | 100 ++++++++++++++++++ src/rp2040/pico_platform/CMakeLists.txt | 6 ++ .../memmap_blocked_ram.ld | 0 .../memmap_copy_to_ram.ld | 0 .../memmap_default.ld | 0 .../memmap_no_flash.ld | 0 .../script_include/BUILD.bazel | 0 .../script_include/default_locations.ld | 0 .../section_copy_to_ram_text.ld | 0 .../script_include/section_default_text.ld | 0 .../script_include/section_no_flash_text.ld | 0 .../script_include/section_platform_end.ld | 0 src/rp2040/pico_platform_link/BUILD.bazel | 91 ---------------- src/rp2040/pico_platform_link/CMakeLists.txt | 6 -- src/rp2350/pico_platform/BUILD.bazel | 81 ++++++++++++++ src/rp2350/pico_platform/CMakeLists.txt | 7 ++ .../memmap_copy_to_ram.ld | 0 .../memmap_default.ld | 0 .../memmap_no_flash.ld | 0 .../script_include/BUILD.bazel | 0 .../script_include/default_locations.ld | 0 .../script_include/section_platform_end.ld | 0 src/rp2350/pico_platform_link/BUILD.bazel | 75 ------------- src/rp2350/pico_platform_link/CMakeLists.txt | 6 -- src/rp2_common/pico_standard_link/BUILD.bazel | 14 +-- 26 files changed, 201 insertions(+), 186 deletions(-) rename src/rp2040/{pico_platform_link => pico_platform}/memmap_blocked_ram.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/memmap_copy_to_ram.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/memmap_default.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/memmap_no_flash.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/BUILD.bazel (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/default_locations.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/section_copy_to_ram_text.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/section_default_text.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/section_no_flash_text.ld (100%) rename src/rp2040/{pico_platform_link => pico_platform}/script_include/section_platform_end.ld (100%) delete mode 100644 src/rp2040/pico_platform_link/BUILD.bazel delete mode 100644 src/rp2040/pico_platform_link/CMakeLists.txt rename src/rp2350/{pico_platform_link => pico_platform}/memmap_copy_to_ram.ld (100%) rename src/rp2350/{pico_platform_link => pico_platform}/memmap_default.ld (100%) rename src/rp2350/{pico_platform_link => pico_platform}/memmap_no_flash.ld (100%) rename src/rp2350/{pico_platform_link => pico_platform}/script_include/BUILD.bazel (100%) rename src/rp2350/{pico_platform_link => pico_platform}/script_include/default_locations.ld (100%) rename src/rp2350/{pico_platform_link => pico_platform}/script_include/section_platform_end.ld (100%) delete mode 100644 src/rp2350/pico_platform_link/BUILD.bazel delete mode 100644 src/rp2350/pico_platform_link/CMakeLists.txt diff --git a/src/cmake/rp2_common.cmake b/src/cmake/rp2_common.cmake index f608e5c05..273839f70 100644 --- a/src/cmake/rp2_common.cmake +++ b/src/cmake/rp2_common.cmake @@ -28,7 +28,6 @@ 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/rp2040/pico_platform/BUILD.bazel b/src/rp2040/pico_platform/BUILD.bazel index dd4412b02..2af1c7750 100644 --- a/src/rp2040/pico_platform/BUILD.bazel +++ b/src/rp2040/pico_platform/BUILD.bazel @@ -54,3 +54,103 @@ cc_library( "//src/rp2_common/pico_standard_link", ], ) + +load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file") + +exports_files( + [ + "memmap_blocked_ram.ld", + "memmap_copy_to_ram.ld", + "memmap_default.ld", + "memmap_no_flash.ld", + ], +) + +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", +) + +cc_library( + name = "default_linker_script", + target_compatible_with = ["//bazel/constraint:rp2040"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2040/pico_platform/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_default.ld", + "memmap_default_args", + ], +) + +# PICO_BUILD_DEFINE: PICO_USE_BLOCKED_RAM, whether this is a 'blocked_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "blocked_ram_linker_script", + defines = ["PICO_USE_BLOCKED_RAM=1"], + target_compatible_with = ["//bazel/constraint:rp2040"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2040/pico_platform/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_blocked_ram.ld", + "memmap_blocked_ram_args", + ], +) + +# PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "copy_to_ram_linker_script", + defines = ["PICO_COPY_TO_RAM=1"], + target_compatible_with = ["//bazel/constraint:rp2040"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2040/pico_platform/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_copy_to_ram.ld", + "memmap_copy_to_ram_args", + ], +) + +# PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "no_flash_linker_script", + defines = ["PICO_NO_FLASH=1"], + target_compatible_with = ["//bazel/constraint:rp2040"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2040/pico_platform/script_include:rp2040_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "memmap_no_flash.ld", + "memmap_no_flash_args", + ], +) diff --git a/src/rp2040/pico_platform/CMakeLists.txt b/src/rp2040/pico_platform/CMakeLists.txt index 9c91df3ea..5fcba5a44 100644 --- a/src/rp2040/pico_platform/CMakeLists.txt +++ b/src/rp2040/pico_platform/CMakeLists.txt @@ -22,6 +22,12 @@ if (NOT TARGET pico_platform) pico_platform_panic pico_platform_sections ) + + 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() endif() function(pico_add_platform_library TARGET) diff --git a/src/rp2040/pico_platform_link/memmap_blocked_ram.ld b/src/rp2040/pico_platform/memmap_blocked_ram.ld similarity index 100% rename from src/rp2040/pico_platform_link/memmap_blocked_ram.ld rename to src/rp2040/pico_platform/memmap_blocked_ram.ld diff --git a/src/rp2040/pico_platform_link/memmap_copy_to_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2040/pico_platform_link/memmap_copy_to_ram.ld rename to src/rp2040/pico_platform/memmap_copy_to_ram.ld diff --git a/src/rp2040/pico_platform_link/memmap_default.ld b/src/rp2040/pico_platform/memmap_default.ld similarity index 100% rename from src/rp2040/pico_platform_link/memmap_default.ld rename to src/rp2040/pico_platform/memmap_default.ld diff --git a/src/rp2040/pico_platform_link/memmap_no_flash.ld b/src/rp2040/pico_platform/memmap_no_flash.ld similarity index 100% rename from src/rp2040/pico_platform_link/memmap_no_flash.ld rename to src/rp2040/pico_platform/memmap_no_flash.ld diff --git a/src/rp2040/pico_platform_link/script_include/BUILD.bazel b/src/rp2040/pico_platform/script_include/BUILD.bazel similarity index 100% rename from src/rp2040/pico_platform_link/script_include/BUILD.bazel rename to src/rp2040/pico_platform/script_include/BUILD.bazel diff --git a/src/rp2040/pico_platform_link/script_include/default_locations.ld b/src/rp2040/pico_platform/script_include/default_locations.ld similarity index 100% rename from src/rp2040/pico_platform_link/script_include/default_locations.ld rename to src/rp2040/pico_platform/script_include/default_locations.ld diff --git a/src/rp2040/pico_platform_link/script_include/section_copy_to_ram_text.ld b/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/script_include/section_copy_to_ram_text.ld rename to src/rp2040/pico_platform/script_include/section_copy_to_ram_text.ld diff --git a/src/rp2040/pico_platform_link/script_include/section_default_text.ld b/src/rp2040/pico_platform/script_include/section_default_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/script_include/section_default_text.ld rename to src/rp2040/pico_platform/script_include/section_default_text.ld diff --git a/src/rp2040/pico_platform_link/script_include/section_no_flash_text.ld b/src/rp2040/pico_platform/script_include/section_no_flash_text.ld similarity index 100% rename from src/rp2040/pico_platform_link/script_include/section_no_flash_text.ld rename to src/rp2040/pico_platform/script_include/section_no_flash_text.ld diff --git a/src/rp2040/pico_platform_link/script_include/section_platform_end.ld b/src/rp2040/pico_platform/script_include/section_platform_end.ld similarity index 100% rename from src/rp2040/pico_platform_link/script_include/section_platform_end.ld rename to src/rp2040/pico_platform/script_include/section_platform_end.ld diff --git a/src/rp2040/pico_platform_link/BUILD.bazel b/src/rp2040/pico_platform_link/BUILD.bazel deleted file mode 100644 index d35bfaf1d..000000000 --- a/src/rp2040/pico_platform_link/BUILD.bazel +++ /dev/null @@ -1,91 +0,0 @@ -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", - "memmap_copy_to_ram.ld", - "memmap_default.ld", - "memmap_no_flash.ld", - ], -) - -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", -) - -cc_library( - name = "default_linker_script", - target_compatible_with = ["//bazel/constraint:rp2040"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", - "//src/rp2_common/pico_standard_link:default_flash_region", - "memmap_default.ld", - "memmap_default_args", - ], -) - -# PICO_BUILD_DEFINE: PICO_USE_BLOCKED_RAM, whether this is a 'blocked_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link -cc_library( - name = "blocked_ram_linker_script", - defines = ["PICO_USE_BLOCKED_RAM=1"], - target_compatible_with = ["//bazel/constraint:rp2040"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", - "//src/rp2_common/pico_standard_link:default_flash_region", - "memmap_blocked_ram.ld", - "memmap_blocked_ram_args", - ], -) - -# PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link -cc_library( - name = "copy_to_ram_linker_script", - defines = ["PICO_COPY_TO_RAM=1"], - target_compatible_with = ["//bazel/constraint:rp2040"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", - "//src/rp2_common/pico_standard_link:default_flash_region", - "memmap_copy_to_ram.ld", - "memmap_copy_to_ram_args", - ], -) - -# PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link -cc_library( - name = "no_flash_linker_script", - defines = ["PICO_NO_FLASH=1"], - target_compatible_with = ["//bazel/constraint:rp2040"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2040/pico_platform_link/script_include:rp2040_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include: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 deleted file mode 100644 index af6943ebd..000000000 --- a/src/rp2040/pico_platform_link/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -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/rp2350/pico_platform/BUILD.bazel b/src/rp2350/pico_platform/BUILD.bazel index f6182b90a..3e5dfde8d 100644 --- a/src/rp2350/pico_platform/BUILD.bazel +++ b/src/rp2350/pico_platform/BUILD.bazel @@ -54,3 +54,84 @@ cc_library( "//src/rp2_common/pico_standard_link", ], ) + +load("//bazel/util:pico_linker_scripts.bzl", "use_linker_script_file") + +exports_files( + [ + "memmap_copy_to_ram.ld", + "memmap_default.ld", + "memmap_no_flash.ld", + ], +) + +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", +) + +cc_library( + name = "default_linker_script", + target_compatible_with = ["//bazel/constraint:rp2350"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2350/pico_platform/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_default.ld", + "memmap_default_args", + ], +) + +# PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "copy_to_ram_linker_script", + defines = ["PICO_COPY_TO_RAM=1"], + target_compatible_with = ["//bazel/constraint:rp2350"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2350/pico_platform/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_flash_region", + "memmap_copy_to_ram.ld", + "memmap_copy_to_ram_args", + ], +) + +# PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "no_flash_linker_script", + defines = ["PICO_NO_FLASH=1"], + target_compatible_with = ["//bazel/constraint:rp2350"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2350/pico_platform/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "memmap_no_flash.ld", + "memmap_no_flash_args", + ], +) diff --git a/src/rp2350/pico_platform/CMakeLists.txt b/src/rp2350/pico_platform/CMakeLists.txt index 7f875bf32..0877c0ddb 100644 --- a/src/rp2350/pico_platform/CMakeLists.txt +++ b/src/rp2350/pico_platform/CMakeLists.txt @@ -33,6 +33,13 @@ if (NOT TARGET pico_platform) if (PICO_RISCV) pico_mirrored_target_link_libraries(pico_platform INTERFACE hardware_hazard3) 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}) + endif() + + pico_promote_common_scope_vars() endif() function(pico_add_platform_library TARGET) diff --git a/src/rp2350/pico_platform_link/memmap_copy_to_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram.ld similarity index 100% rename from src/rp2350/pico_platform_link/memmap_copy_to_ram.ld rename to src/rp2350/pico_platform/memmap_copy_to_ram.ld diff --git a/src/rp2350/pico_platform_link/memmap_default.ld b/src/rp2350/pico_platform/memmap_default.ld similarity index 100% rename from src/rp2350/pico_platform_link/memmap_default.ld rename to src/rp2350/pico_platform/memmap_default.ld diff --git a/src/rp2350/pico_platform_link/memmap_no_flash.ld b/src/rp2350/pico_platform/memmap_no_flash.ld similarity index 100% rename from src/rp2350/pico_platform_link/memmap_no_flash.ld rename to src/rp2350/pico_platform/memmap_no_flash.ld diff --git a/src/rp2350/pico_platform_link/script_include/BUILD.bazel b/src/rp2350/pico_platform/script_include/BUILD.bazel similarity index 100% rename from src/rp2350/pico_platform_link/script_include/BUILD.bazel rename to src/rp2350/pico_platform/script_include/BUILD.bazel diff --git a/src/rp2350/pico_platform_link/script_include/default_locations.ld b/src/rp2350/pico_platform/script_include/default_locations.ld similarity index 100% rename from src/rp2350/pico_platform_link/script_include/default_locations.ld rename to src/rp2350/pico_platform/script_include/default_locations.ld diff --git a/src/rp2350/pico_platform_link/script_include/section_platform_end.ld b/src/rp2350/pico_platform/script_include/section_platform_end.ld similarity index 100% rename from src/rp2350/pico_platform_link/script_include/section_platform_end.ld rename to src/rp2350/pico_platform/script_include/section_platform_end.ld diff --git a/src/rp2350/pico_platform_link/BUILD.bazel b/src/rp2350/pico_platform_link/BUILD.bazel deleted file mode 100644 index 31bc624f4..000000000 --- a/src/rp2350/pico_platform_link/BUILD.bazel +++ /dev/null @@ -1,75 +0,0 @@ -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", - "memmap_default.ld", - "memmap_no_flash.ld", - ], -) - -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", -) - -cc_library( - name = "default_linker_script", - target_compatible_with = ["//bazel/constraint:rp2350"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", - "//src/rp2_common/pico_standard_link:default_flash_region", - "memmap_default.ld", - "memmap_default_args", - ], -) - -# PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link -cc_library( - name = "copy_to_ram_linker_script", - defines = ["PICO_COPY_TO_RAM=1"], - target_compatible_with = ["//bazel/constraint:rp2350"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", - "//src/rp2_common/pico_standard_link:default_flash_region", - "memmap_copy_to_ram.ld", - "memmap_copy_to_ram_args", - ], -) - -# PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link -cc_library( - name = "no_flash_linker_script", - defines = ["PICO_NO_FLASH=1"], - target_compatible_with = ["//bazel/constraint:rp2350"], - deps = [ - "//src/rp2_common/pico_crt0:no_warn_rwx_flag", - "//src/rp2350/pico_platform_link/script_include:rp2350_linker_scripts", - "//src/rp2_common/pico_standard_link/script_include: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 deleted file mode 100644 index af6943ebd..000000000 --- a/src/rp2350/pico_platform_link/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -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_standard_link/BUILD.bazel b/src/rp2_common/pico_standard_link/BUILD.bazel index 924358d50..8817018a8 100644 --- a/src/rp2_common/pico_standard_link/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/BUILD.bazel @@ -30,8 +30,8 @@ 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", + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform:default_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform:default_linker_script", "//conditions:default": "//bazel:incompatible_cc_lib", }), ) @@ -39,7 +39,7 @@ alias( alias( name = "blocked_ram_linker_script", actual = select({ - "//bazel/constraint:rp2040": "//src/rp2040/pico_platform_link:blocked_ram_linker_script", + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform:blocked_ram_linker_script", "//conditions:default": "//bazel:incompatible_cc_lib", }), ) @@ -47,8 +47,8 @@ alias( 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", + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform:copy_to_ram_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform:copy_to_ram_linker_script", "//conditions:default": "//bazel:incompatible_cc_lib", }), ) @@ -56,8 +56,8 @@ alias( 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", + "//bazel/constraint:rp2040": "//src/rp2040/pico_platform:no_flash_linker_script", + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform:no_flash_linker_script", "//conditions:default": "//bazel:incompatible_cc_lib", }), ) From 614f7f064fb7df5d740eef966d89c840325ba161 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 11:20:03 +0000 Subject: [PATCH 20/60] Remove rigidity from linker include paths Add PICO_LINKER_SCRIPT_INCLUDE_DIRS and PICO_LINKER_DEFAULT_LOCATIONS_PATH, instead of hardcoded paths under PICO_LINKER_SCRIPT_PATH Also improve pico_set_linker_script_var and pico_add_linker_script_override_path to better utilise generator expressions --- src/rp2040/pico_platform/CMakeLists.txt | 9 +++++++ src/rp2350/pico_platform/CMakeLists.txt | 8 ++++++ .../pico_standard_link/CMakeLists.txt | 27 +++++++++++++------ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/rp2040/pico_platform/CMakeLists.txt b/src/rp2040/pico_platform/CMakeLists.txt index 5fcba5a44..d43f96b91 100644 --- a/src/rp2040/pico_platform/CMakeLists.txt +++ b/src/rp2040/pico_platform/CMakeLists.txt @@ -27,6 +27,15 @@ if (NOT TARGET pico_platform) if (NOT PICO_LINKER_SCRIPT_PATH) set(PICO_LINKER_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}) endif() + + pico_register_common_scope_var(PICO_LINKER_DEFAULT_LOCATIONS_PATH) + if (NOT PICO_LINKER_DEFAULT_LOCATIONS_PATH) + set(PICO_LINKER_DEFAULT_LOCATIONS_PATH ${CMAKE_CURRENT_LIST_DIR}/script_include/default_locations.ld) + endif() + + pico_register_common_scope_var(PICO_LINKER_SCRIPT_INCLUDE_DIRS) + list(APPEND PICO_LINKER_SCRIPT_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/script_include) + pico_promote_common_scope_vars() endif() diff --git a/src/rp2350/pico_platform/CMakeLists.txt b/src/rp2350/pico_platform/CMakeLists.txt index 0877c0ddb..636f3fe83 100644 --- a/src/rp2350/pico_platform/CMakeLists.txt +++ b/src/rp2350/pico_platform/CMakeLists.txt @@ -39,6 +39,14 @@ if (NOT TARGET pico_platform) set(PICO_LINKER_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR}) endif() + pico_register_common_scope_var(PICO_LINKER_DEFAULT_LOCATIONS_PATH) + if (NOT PICO_LINKER_DEFAULT_LOCATIONS_PATH) + set(PICO_LINKER_DEFAULT_LOCATIONS_PATH ${CMAKE_CURRENT_LIST_DIR}/script_include/default_locations.ld) + endif() + + pico_register_common_scope_var(PICO_LINKER_SCRIPT_INCLUDE_DIRS) + list(APPEND PICO_LINKER_SCRIPT_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/script_include) + pico_promote_common_scope_vars() endif() diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index af51a69ea..9db70b1e6 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -5,6 +5,11 @@ if (NOT TARGET pico_standard_link) target_link_libraries(pico_standard_link INTERFACE boot_stage2_headers) endif() + pico_register_common_scope_var(PICO_LINKER_SCRIPT_INCLUDE_DIRS) + + # add the default linker script include directories + list(APPEND PICO_LINKER_SCRIPT_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/script_include) + # pico_add_link_depend(TARGET dependency) # \brief\ Add a link time dependency to the target # @@ -76,7 +81,7 @@ if (NOT TARGET pico_standard_link) # \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}") + set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_VARS "${NAME}=${VALUE}") endfunction() # pico_add_linker_script_override_path(TARGET PATH) @@ -89,6 +94,7 @@ if (NOT TARGET pico_standard_link) # 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. + # It will also not override prior paths set by pico_add_linker_script_override_path. # # \param\ TARGET The target to add the linker script override path to # \param\ PATH The path containing the overriding linker scripts @@ -97,7 +103,7 @@ if (NOT TARGET pico_standard_link) 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}") + set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_OVERRIDE_PATHS "${PATH}") endfunction() # pico_set_binary_type(TARGET TYPE) @@ -155,17 +161,22 @@ if (NOT TARGET pico_standard_link) 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 to find it - target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_BINARY_DIR}") + list(APPEND PICO_LINKER_SCRIPT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}) + pico_promote_common_scope_vars() + + # add override paths from PICO_TARGET_LINKER_SCRIPT_OVERRIDE_PATHS + target_link_options(pico_standard_link INTERFACE "LINKER:$<$>:-L$,,-L>>") - # add include path for main linker script sections - target_link_options(pico_standard_link INTERFACE "LINKER:-L${PICO_LINKER_SCRIPT_PATH}/script_include") - target_link_options(pico_standard_link INTERFACE "LINKER:-L${CMAKE_CURRENT_LIST_DIR}/script_include") + # add include paths from PICO_LINKER_SCRIPT_INCLUDE_DIRS + foreach(DIR IN LISTS PICO_LINKER_SCRIPT_INCLUDE_DIRS) + target_link_options(pico_standard_link INTERFACE "LINKER:-L${DIR}") + endforeach() # 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}/script_include/default_locations.ld") + target_link_options(pico_standard_link INTERFACE "LINKER:--script=${PICO_LINKER_DEFAULT_LOCATIONS_PATH}") # add variables set by pico_set_linker_script_var function - target_link_options(pico_standard_link INTERFACE "LINKER:$,,>") + target_link_options(pico_standard_link INTERFACE "LINKER:$<$>:--defsym=$,,--defsym=>>") # 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 From da23cf426a434fc997f609daaf408e40a117e740 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 11:46:06 +0000 Subject: [PATCH 21/60] Rename all linker scripts intended to be included to .incl Required changes to the way bazel views these files --- .../pico_platform/memmap_blocked_ram.ld | 2 +- .../pico_platform/memmap_copy_to_ram.ld | 2 +- src/rp2040/pico_platform/memmap_default.ld | 2 +- src/rp2040/pico_platform/memmap_no_flash.ld | 2 +- .../pico_platform/script_include/BUILD.bazel | 20 +++--- ..._text.ld => section_copy_to_ram_text.incl} | 0 ...ault_text.ld => section_default_text.incl} | 4 +- ...ash_text.ld => section_no_flash_text.incl} | 0 ...tform_end.ld => section_platform_end.incl} | 0 .../pico_platform/memmap_copy_to_ram.ld | 2 +- src/rp2350/pico_platform/memmap_default.ld | 2 +- src/rp2350/pico_platform/memmap_no_flash.ld | 2 +- .../pico_platform/script_include/BUILD.bazel | 14 +++-- ...tform_end.ld => section_platform_end.incl} | 0 .../script_include/BUILD.bazel | 61 +++---------------- ...map_default.ld => memmap_copy_to_ram.incl} | 12 ++-- ...map_copy_to_ram.ld => memmap_default.incl} | 12 ++-- ...emmap_no_flash.ld => memmap_no_flash.incl} | 10 +-- ...default.ld => memory_aliases_default.incl} | 0 ..._flash.ld => memory_aliases_no_flash.incl} | 0 .../{memory_flash.ld => memory_flash.incl} | 0 .../{memory_ram.ld => memory_ram.incl} | 0 ...{memory_scratch.ld => memory_scratch.incl} | 0 ...{memory_xip_ram.ld => memory_xip_ram.incl} | 0 ..._data.ld => section_copy_to_ram_data.incl} | 0 ..._text.ld => section_copy_to_ram_text.incl} | 0 ...ault_data.ld => section_default_data.incl} | 0 ...d => section_default_rodata_excludes.incl} | 0 ...ault_text.ld => section_default_text.incl} | 4 +- ....ld => section_default_text_excludes.incl} | 0 .../{section_end.ld => section_end.incl} | 0 ...on_flash_end.ld => section_flash_end.incl} | 0 .../{section_heap.ld => section_heap.incl} | 0 ...ash_data.ld => section_no_flash_data.incl} | 0 ...ash_text.ld => section_no_flash_text.incl} | 0 ...ection_scratch.ld => section_scratch.incl} | 0 .../script_include/sections_copy_to_ram.incl | 7 +++ .../script_include/sections_copy_to_ram.ld | 7 --- .../script_include/sections_default.incl | 7 +++ .../script_include/sections_default.ld | 7 --- .../script_include/sections_no_flash.incl | 6 ++ .../script_include/sections_no_flash.ld | 6 -- ...locations.ld => set_memory_locations.incl} | 0 .../sections_default.incl | 19 ++++++ .../sections_default.ld | 19 ------ ...tions_default.ld => sections_default.incl} | 14 ++--- 46 files changed, 98 insertions(+), 145 deletions(-) rename src/rp2040/pico_platform/script_include/{section_copy_to_ram_text.ld => section_copy_to_ram_text.incl} (100%) rename src/rp2040/pico_platform/script_include/{section_default_text.ld => section_default_text.incl} (96%) rename src/rp2040/pico_platform/script_include/{section_no_flash_text.ld => section_no_flash_text.incl} (100%) rename src/rp2040/pico_platform/script_include/{section_platform_end.ld => section_platform_end.incl} (100%) rename src/rp2350/pico_platform/script_include/{section_platform_end.ld => section_platform_end.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memmap_default.ld => memmap_copy_to_ram.incl} (51%) rename src/rp2_common/pico_standard_link/script_include/{memmap_copy_to_ram.ld => memmap_default.incl} (52%) rename src/rp2_common/pico_standard_link/script_include/{memmap_no_flash.ld => memmap_no_flash.incl} (59%) rename src/rp2_common/pico_standard_link/script_include/{memory_aliases_default.ld => memory_aliases_default.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memory_aliases_no_flash.ld => memory_aliases_no_flash.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memory_flash.ld => memory_flash.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memory_ram.ld => memory_ram.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memory_scratch.ld => memory_scratch.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{memory_xip_ram.ld => memory_xip_ram.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_copy_to_ram_data.ld => section_copy_to_ram_data.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_copy_to_ram_text.ld => section_copy_to_ram_text.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_default_data.ld => section_default_data.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_default_rodata_excludes.ld => section_default_rodata_excludes.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_default_text.ld => section_default_text.incl} (97%) rename src/rp2_common/pico_standard_link/script_include/{section_default_text_excludes.ld => section_default_text_excludes.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_end.ld => section_end.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_flash_end.ld => section_flash_end.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_heap.ld => section_heap.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_no_flash_data.ld => section_no_flash_data.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_no_flash_text.ld => section_no_flash_text.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_scratch.ld => section_scratch.incl} (100%) create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_default.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/sections_default.ld create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld rename src/rp2_common/pico_standard_link/script_include/{set_memory_locations.ld => set_memory_locations.incl} (100%) create mode 100644 test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl delete mode 100644 test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld rename test/kitchen_sink/kitchen_sink_simple_overlay_scripts/{sections_default.ld => sections_default.incl} (57%) diff --git a/src/rp2040/pico_platform/memmap_blocked_ram.ld b/src/rp2040/pico_platform/memmap_blocked_ram.ld index a4a528950..26955f209 100644 --- a/src/rp2040/pico_platform/memmap_blocked_ram.ld +++ b/src/rp2040/pico_platform/memmap_blocked_ram.ld @@ -1,4 +1,4 @@ /* Use blocked ram */ RAM_ORIGIN = 0x21000000; -INCLUDE "memmap_default.ld" +INCLUDE "memmap_default.incl" diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram.ld index cd51ceeaa..f0eb74d9f 100644 --- a/src/rp2040/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2040/pico_platform/memmap_copy_to_ram.ld @@ -1 +1 @@ -INCLUDE "memmap_copy_to_ram.ld" +INCLUDE "memmap_copy_to_ram.incl" diff --git a/src/rp2040/pico_platform/memmap_default.ld b/src/rp2040/pico_platform/memmap_default.ld index c256a9071..ddb81aae3 100644 --- a/src/rp2040/pico_platform/memmap_default.ld +++ b/src/rp2040/pico_platform/memmap_default.ld @@ -1 +1 @@ -INCLUDE "memmap_default.ld" +INCLUDE "memmap_default.incl" diff --git a/src/rp2040/pico_platform/memmap_no_flash.ld b/src/rp2040/pico_platform/memmap_no_flash.ld index 3e5be9e01..cbc400e66 100644 --- a/src/rp2040/pico_platform/memmap_no_flash.ld +++ b/src/rp2040/pico_platform/memmap_no_flash.ld @@ -1 +1 @@ -INCLUDE "memmap_no_flash.ld" +INCLUDE "memmap_no_flash.incl" diff --git a/src/rp2040/pico_platform/script_include/BUILD.bazel b/src/rp2040/pico_platform/script_include/BUILD.bazel index 337252e6c..afb7fb221 100644 --- a/src/rp2040/pico_platform/script_include/BUILD.bazel +++ b/src/rp2040/pico_platform/script_include/BUILD.bazel @@ -4,14 +4,11 @@ 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", - ] +filegroup( + name = "rp2040_linker_script_incls", + srcs = glob([ + "*.incl", + ]), ) include_linker_script_dir( @@ -24,10 +21,9 @@ cc_library( 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", ], + additional_linker_inputs = [ + "rp2040_linker_script_incls", + ], ) \ No newline at end of file diff --git a/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.ld b/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl similarity index 100% rename from src/rp2040/pico_platform/script_include/section_copy_to_ram_text.ld rename to src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl diff --git a/src/rp2040/pico_platform/script_include/section_default_text.ld b/src/rp2040/pico_platform/script_include/section_default_text.incl similarity index 96% rename from src/rp2040/pico_platform/script_include/section_default_text.ld rename to src/rp2040/pico_platform/script_include/section_default_text.incl index 2f25a1d4d..6ea15e65c 100644 --- a/src/rp2040/pico_platform/script_include/section_default_text.ld +++ b/src/rp2040/pico_platform/script_include/section_default_text.incl @@ -37,7 +37,7 @@ SECTIONS /* 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) - INCLUDE "section_default_text_excludes.ld" + INCLUDE "section_default_text_excludes.incl" *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -78,7 +78,7 @@ SECTIONS } > FLASH .rodata : { - INCLUDE "section_default_rodata_excludes.ld" + INCLUDE "section_default_rodata_excludes.incl" . = ALIGN(4); *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) . = ALIGN(4); diff --git a/src/rp2040/pico_platform/script_include/section_no_flash_text.ld b/src/rp2040/pico_platform/script_include/section_no_flash_text.incl similarity index 100% rename from src/rp2040/pico_platform/script_include/section_no_flash_text.ld rename to src/rp2040/pico_platform/script_include/section_no_flash_text.incl diff --git a/src/rp2040/pico_platform/script_include/section_platform_end.ld b/src/rp2040/pico_platform/script_include/section_platform_end.incl similarity index 100% rename from src/rp2040/pico_platform/script_include/section_platform_end.ld rename to src/rp2040/pico_platform/script_include/section_platform_end.incl diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram.ld index cd51ceeaa..f0eb74d9f 100644 --- a/src/rp2350/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2350/pico_platform/memmap_copy_to_ram.ld @@ -1 +1 @@ -INCLUDE "memmap_copy_to_ram.ld" +INCLUDE "memmap_copy_to_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_default.ld b/src/rp2350/pico_platform/memmap_default.ld index c256a9071..ddb81aae3 100644 --- a/src/rp2350/pico_platform/memmap_default.ld +++ b/src/rp2350/pico_platform/memmap_default.ld @@ -1 +1 @@ -INCLUDE "memmap_default.ld" +INCLUDE "memmap_default.incl" diff --git a/src/rp2350/pico_platform/memmap_no_flash.ld b/src/rp2350/pico_platform/memmap_no_flash.ld index 3e5be9e01..cbc400e66 100644 --- a/src/rp2350/pico_platform/memmap_no_flash.ld +++ b/src/rp2350/pico_platform/memmap_no_flash.ld @@ -1 +1 @@ -INCLUDE "memmap_no_flash.ld" +INCLUDE "memmap_no_flash.incl" diff --git a/src/rp2350/pico_platform/script_include/BUILD.bazel b/src/rp2350/pico_platform/script_include/BUILD.bazel index 5b234a016..64e844b56 100644 --- a/src/rp2350/pico_platform/script_include/BUILD.bazel +++ b/src/rp2350/pico_platform/script_include/BUILD.bazel @@ -4,11 +4,11 @@ package(default_visibility = ["//visibility:public"]) load("//bazel/util:pico_linker_scripts.bzl", "include_linker_script_dir") -exports_files( - [ - "default_locations.ld", - "section_platform_end.ld", - ] +filegroup( + name = "rp2350_linker_script_incls", + srcs = glob([ + "*.incl", + ]), ) include_linker_script_dir( @@ -21,7 +21,9 @@ cc_library( target_compatible_with = ["//bazel/constraint:rp2350"], deps = [ "default_locations.ld", - "section_platform_end.ld", "rp2350_linker_script_args", ], + additional_linker_inputs = [ + "rp2350_linker_script_incls", + ], ) \ No newline at end of file diff --git a/src/rp2350/pico_platform/script_include/section_platform_end.ld b/src/rp2350/pico_platform/script_include/section_platform_end.incl similarity index 100% rename from src/rp2350/pico_platform/script_include/section_platform_end.ld rename to src/rp2350/pico_platform/script_include/section_platform_end.incl diff --git a/src/rp2_common/pico_standard_link/script_include/BUILD.bazel b/src/rp2_common/pico_standard_link/script_include/BUILD.bazel index ba56b59d3..4afcce951 100644 --- a/src/rp2_common/pico_standard_link/script_include/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/script_include/BUILD.bazel @@ -4,34 +4,11 @@ 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_copy_to_ram_text.ld", - "section_default_data.ld", - "section_default_text.ld", - "section_default_text_excludes.ld", - "section_default_rodata_excludes.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", - "memmap_default.ld", - "memmap_no_flash.ld", - "memmap_copy_to_ram.ld", - ] +filegroup( + name = "rp2_linker_script_incls", + srcs = glob([ + "*.incl", + ]), ) include_linker_script_dir( @@ -43,30 +20,8 @@ cc_library( 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_copy_to_ram_text.ld", - "section_default_data.ld", - "section_default_text.ld", - "section_default_text_excludes.ld", - "section_default_rodata_excludes.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", - "memmap_default.ld", - "memmap_no_flash.ld", - "memmap_copy_to_ram.ld", ], + additional_linker_inputs = [ + "rp2_linker_script_incls", + ] ) \ No newline at end of file diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_default.ld b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl similarity index 51% rename from src/rp2_common/pico_standard_link/script_include/memmap_default.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl index 04acbefbb..f2b8e7159 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_default.ld +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl @@ -1,16 +1,16 @@ /* Include platform memory locations */ -INCLUDE "set_memory_locations.ld" +INCLUDE "set_memory_locations.incl" /* Include memory regions used */ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" +INCLUDE "memory_flash.incl" +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" /* Include aliases for storage memory regions */ -INCLUDE "memory_aliases_default.ld" +INCLUDE "memory_aliases_default.incl" /* Define entry point symbol */ ENTRY(_entry_point) /* Include default sections */ -INCLUDE "sections_default.ld" +INCLUDE "sections_copy_to_ram.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl similarity index 52% rename from src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_default.incl index eb2c5ffd9..791d4ef2b 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl @@ -1,16 +1,16 @@ /* Include platform memory locations */ -INCLUDE "set_memory_locations.ld" +INCLUDE "set_memory_locations.incl" /* Include memory regions used */ -INCLUDE "memory_flash.ld" -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" +INCLUDE "memory_flash.incl" +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" /* Include aliases for storage memory regions */ -INCLUDE "memory_aliases_default.ld" +INCLUDE "memory_aliases_default.incl" /* Define entry point symbol */ ENTRY(_entry_point) /* Include default sections */ -INCLUDE "sections_copy_to_ram.ld" +INCLUDE "sections_default.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl similarity index 59% rename from src/rp2_common/pico_standard_link/script_include/memmap_no_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl index 958915a71..e9578be46 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.ld +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl @@ -1,15 +1,15 @@ /* Include platform memory locations */ -INCLUDE "set_memory_locations.ld" +INCLUDE "set_memory_locations.incl" /* Include memory regions used */ -INCLUDE "memory_ram.ld" -INCLUDE "memory_scratch.ld" +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" /* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "memory_aliases_no_flash.ld" +INCLUDE "memory_aliases_no_flash.incl" /* Define entry point symbol */ ENTRY(_entry_point) /* Include no_flash sections */ -INCLUDE "sections_no_flash.ld" +INCLUDE "sections_no_flash.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.ld b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_aliases_default.ld rename to src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_flash.ld b/src/rp2_common/pico_standard_link/script_include/memory_flash.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_flash.ld rename to src/rp2_common/pico_standard_link/script_include/memory_flash.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_ram.ld b/src/rp2_common/pico_standard_link/script_include/memory_ram.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memory_ram.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_scratch.ld b/src/rp2_common/pico_standard_link/script_include/memory_scratch.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_scratch.ld rename to src/rp2_common/pico_standard_link/script_include/memory_scratch.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/script_include/memory_xip_ram.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/memory_xip_ram.ld rename to src/rp2_common/pico_standard_link/script_include/memory_xip_ram.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.ld b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.ld b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_data.ld b/src/rp2_common/pico_standard_link/script_include/section_default_data.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_default_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_data.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.ld b/src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text.ld b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl similarity index 97% rename from src/rp2_common/pico_standard_link/script_include/section_default_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_text.incl index ab86ade78..49c113db4 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_text.ld +++ b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl @@ -27,7 +27,7 @@ SECTIONS * FLASH ... we will include any thing excluded here in .data below by default */ *(.init) *libgcc.a:cmse_nonsecure_call.o - INCLUDE "section_default_text_excludes.ld" + INCLUDE "section_default_text_excludes.incl" *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -89,7 +89,7 @@ SECTIONS "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") .rodata : { - INCLUDE "section_default_rodata_excludes.ld" + INCLUDE "section_default_rodata_excludes.incl" *(.srodata*) . = ALIGN(4); *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.ld b/src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.ld rename to src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_end.ld b/src/rp2_common/pico_standard_link/script_include/section_end.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_end.ld rename to src/rp2_common/pico_standard_link/script_include/section_end.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_flash_end.ld b/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_flash_end.ld rename to src/rp2_common/pico_standard_link/script_include/section_flash_end.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_heap.ld b/src/rp2_common/pico_standard_link/script_include/section_heap.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_heap.ld rename to src/rp2_common/pico_standard_link/script_include/section_heap.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.ld b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_no_flash_data.ld rename to src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.ld b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_no_flash_text.ld rename to src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_scratch.ld b/src/rp2_common/pico_standard_link/script_include/section_scratch.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_scratch.ld rename to src/rp2_common/pico_standard_link/script_include/section_scratch.incl diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl new file mode 100644 index 000000000..397311e63 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -0,0 +1,7 @@ +INCLUDE "section_copy_to_ram_text.incl" +INCLUDE "section_copy_to_ram_data.incl" +INCLUDE "section_heap.incl" +INCLUDE "section_scratch.incl" +INCLUDE "section_flash_end.incl" +INCLUDE "section_end.incl" +INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld deleted file mode 100644 index fe7caf546..000000000 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.ld +++ /dev/null @@ -1,7 +0,0 @@ -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/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl new file mode 100644 index 000000000..e00725155 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -0,0 +1,7 @@ +INCLUDE "section_default_text.incl" +INCLUDE "section_default_data.incl" +INCLUDE "section_heap.incl" +INCLUDE "section_scratch.incl" +INCLUDE "section_flash_end.incl" +INCLUDE "section_end.incl" +INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.ld b/src/rp2_common/pico_standard_link/script_include/sections_default.ld deleted file mode 100644 index f22558a9f..000000000 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.ld +++ /dev/null @@ -1,7 +0,0 @@ -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/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl new file mode 100644 index 000000000..2a043dfe3 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -0,0 +1,6 @@ +INCLUDE "section_no_flash_text.incl" +INCLUDE "section_no_flash_data.incl" +INCLUDE "section_heap.incl" +INCLUDE "section_scratch.incl" +INCLUDE "section_end.incl" +INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld deleted file mode 100644 index 77bad234e..000000000 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.ld +++ /dev/null @@ -1,6 +0,0 @@ -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/script_include/set_memory_locations.ld b/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/set_memory_locations.ld rename to src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl diff --git a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl new file mode 100644 index 000000000..2bc78925a --- /dev/null +++ b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl @@ -0,0 +1,19 @@ +INCLUDE "section_default_text.incl" +INCLUDE "section_default_data.incl" + +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.incl" +INCLUDE "section_scratch.incl" +INCLUDE "section_flash_end.incl" +INCLUDE "section_end.incl" +INCLUDE "section_platform_end.incl" \ No newline at end of file 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 deleted file mode 100644 index 9ffef1a28..000000000 --- a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.ld +++ /dev/null @@ -1,19 +0,0 @@ -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 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.incl similarity index 57% rename from test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld rename to test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl index 9a69c883a..9e3060e70 100644 --- a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.ld +++ b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl @@ -1,5 +1,5 @@ -INCLUDE "section_default_text.ld" -INCLUDE "section_default_data.ld" +INCLUDE "section_default_text.incl" +INCLUDE "section_default_data.incl" SECTIONS { @@ -17,8 +17,8 @@ SECTIONS 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" +INCLUDE "section_heap.incl" +INCLUDE "section_scratch.incl" +INCLUDE "section_flash_end.incl" +INCLUDE "section_end.incl" +INCLUDE "section_platform_end.incl" From 780c05e254a546968ab29ae8978f5c6284d5f709 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 13:01:34 +0000 Subject: [PATCH 22/60] Separate into section_... files which do only contain one section, and sections_... which contain multiple Only exceptions are section_..._data and section_bss, as these contain data/bss and tdata/tbss - these are kept together as they are treated as a single section --- .../script_include/section_boot2.incl | 16 +++ .../section_copy_to_ram_text.incl | 101 ---------------- .../script_include/section_default_text.incl | 109 ------------------ .../sections_copy_to_ram_text.incl | 9 ++ .../script_include/sections_default_text.incl | 8 ++ src/rp2350/pico_platform/BUILD.bazel | 5 - ...udes.incl => default_rodata_excludes.incl} | 0 ...cludes.incl => default_text_excludes.incl} | 0 .../memory_aliases_default.incl | 1 + .../memory_aliases_no_flash.incl | 1 + .../script_include/section_binary_info.incl | 13 +++ .../script_include/section_boot2.incl | 23 ++++ .../script_include/section_bss.incl | 24 ++++ .../section_copy_to_ram_data.incl | 26 +---- .../section_copy_to_ram_flashtext.incl | 23 ++++ .../section_copy_to_ram_rodata.incl | 8 ++ .../section_copy_to_ram_text.incl | 92 +-------------- .../script_include/section_default_data.incl | 35 +----- .../section_default_rodata.incl | 10 ++ .../script_include/section_default_text.incl | 60 +--------- .../script_include/section_flash_begin.incl | 6 + .../script_include/section_flash_end.incl | 2 +- .../script_include/section_no_flash_data.incl | 26 ----- .../section_no_flash_rodata.incl | 11 ++ .../script_include/section_no_flash_text.incl | 32 ----- .../section_ram_vector_table.incl | 6 + .../section_uninitialized_data.incl | 7 ++ .../script_include/sections_arm_ex.incl | 14 +++ .../script_include/sections_copy_to_ram.incl | 6 +- .../sections_copy_to_ram_data.incl | 2 + .../sections_copy_to_ram_text.incl | 9 ++ .../script_include/sections_default.incl | 6 +- .../script_include/sections_default_data.incl | 4 + .../script_include/sections_default_text.incl | 6 + .../script_include/sections_no_flash.incl | 6 +- .../sections_no_flash_data.incl | 3 + .../sections_no_flash_text.incl | 4 + ...ion_scratch.incl => sections_scratch.incl} | 0 .../sections_default.incl | 6 +- .../sections_default.incl | 6 +- 40 files changed, 231 insertions(+), 495 deletions(-) create mode 100644 src/rp2040/pico_platform/script_include/section_boot2.incl delete mode 100644 src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl delete mode 100644 src/rp2040/pico_platform/script_include/section_default_text.incl create mode 100644 src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl create mode 100644 src/rp2040/pico_platform/script_include/sections_default_text.incl rename src/rp2_common/pico_standard_link/script_include/{section_default_rodata_excludes.incl => default_rodata_excludes.incl} (100%) rename src/rp2_common/pico_standard_link/script_include/{section_default_text_excludes.incl => default_text_excludes.incl} (100%) create mode 100644 src/rp2_common/pico_standard_link/script_include/section_binary_info.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_boot2.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_bss.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_rodata.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_default_rodata.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_no_flash_rodata.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_default_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_default_text.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl rename src/rp2_common/pico_standard_link/script_include/{section_scratch.incl => sections_scratch.incl} (100%) diff --git a/src/rp2040/pico_platform/script_include/section_boot2.incl b/src/rp2040/pico_platform/script_include/section_boot2.incl new file mode 100644 index 000000000..b6afc3763 --- /dev/null +++ b/src/rp2040/pico_platform/script_include/section_boot2.incl @@ -0,0 +1,16 @@ +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 + */ + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > TEXT_STORE + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") +} diff --git a/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl b/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl deleted file mode 100644 index 77a45941b..000000000 --- a/src/rp2040/pico_platform/script_include/section_copy_to_ram_text.incl +++ /dev/null @@ -1,101 +0,0 @@ -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/rp2040/pico_platform/script_include/section_default_text.incl b/src/rp2040/pico_platform/script_include/section_default_text.incl deleted file mode 100644 index 6ea15e65c..000000000 --- a/src/rp2040/pico_platform/script_include/section_default_text.incl +++ /dev/null @@ -1,109 +0,0 @@ -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) - INCLUDE "section_default_text_excludes.incl" - *(.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 : { - INCLUDE "section_default_rodata_excludes.incl" - . = 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/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl b/src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl new file mode 100644 index 000000000..0fdd197b8 --- /dev/null +++ b/src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl @@ -0,0 +1,9 @@ +INCLUDE "section_flash_begin.incl" +INCLUDE "section_boot2.incl" +INCLUDE "section_copy_to_ram_flashtext.incl" +INCLUDE "section_copy_to_ram_rodata.incl" +INCLUDE "sections_arm_ex.incl" +INCLUDE "section_binary_info.incl" +INCLUDE "section_ram_vector_table.incl" +INCLUDE "section_uninitialized_data.incl" +INCLUDE "section_copy_to_ram_text.incl" diff --git a/src/rp2040/pico_platform/script_include/sections_default_text.incl b/src/rp2040/pico_platform/script_include/sections_default_text.incl new file mode 100644 index 000000000..af0bce686 --- /dev/null +++ b/src/rp2040/pico_platform/script_include/sections_default_text.incl @@ -0,0 +1,8 @@ +# This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 + +INCLUDE "section_flash_begin.incl" +INCLUDE "section_boot2.incl" +INCLUDE "section_default_text.incl" +INCLUDE "section_default_rodata.incl" +INCLUDE "sections_arm_ex.incl" +INCLUDE "section_binary_info.incl" diff --git a/src/rp2350/pico_platform/BUILD.bazel b/src/rp2350/pico_platform/BUILD.bazel index 3e5dfde8d..e2e2c382d 100644 --- a/src/rp2350/pico_platform/BUILD.bazel +++ b/src/rp2350/pico_platform/BUILD.bazel @@ -70,11 +70,6 @@ use_linker_script_file( 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", diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.incl b/src/rp2_common/pico_standard_link/script_include/default_rodata_excludes.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_default_rodata_excludes.incl rename to src/rp2_common/pico_standard_link/script_include/default_rodata_excludes.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.incl b/src/rp2_common/pico_standard_link/script_include/default_text_excludes.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_default_text_excludes.incl rename to src/rp2_common/pico_standard_link/script_include/default_text_excludes.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl index 7c56254bd..4c16d41be 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl @@ -1,3 +1,4 @@ +REGION_ALIAS("TEXT_STORE", FLASH); 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/script_include/memory_aliases_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl index 063b5b6fc..9190b32ab 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl @@ -1,3 +1,4 @@ +REGION_ALIAS("TEXT_STORE", RAM); 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_standard_link/script_include/section_binary_info.incl b/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl new file mode 100644 index 000000000..f7238d09a --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl @@ -0,0 +1,13 @@ +SECTIONS +{ + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > TEXT_STORE + __binary_info_end = .; + . = ALIGN(4); +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_boot2.incl b/src/rp2_common/pico_standard_link/script_include/section_boot2.incl new file mode 100644 index 000000000..14e362776 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_boot2.incl @@ -0,0 +1,23 @@ +SECTIONS +{ + /* 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__ = .; + } > TEXT_STORE + + ASSERT(__boot2_end__ - __boot2_start__ <= 256, + "ERROR: Pico second stage bootloader must be no more than 256 bytes in size") +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_bss.incl b/src/rp2_common/pico_standard_link/script_include/section_bss.incl new file mode 100644 index 000000000..172436df6 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_bss.incl @@ -0,0 +1,24 @@ +SECTIONS +{ + .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_standard_link/script_include/section_copy_to_ram_data.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl index 19082589c..82084a70b 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl @@ -46,38 +46,16 @@ SECTIONS *(.jcr) . = ALIGN(4); - } > RAM AT> FLASH + } > RAM AT> RAM_STORE .tdata : { . = ALIGN(4); *(.tdata .tdata.* .gnu.linkonce.td.*) /* All data end */ __tdata_end = .; - } > RAM AT> FLASH + } > RAM AT> RAM_STORE 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_standard_link/script_include/section_copy_to_ram_flashtext.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl new file mode 100644 index 000000000..a0c794eb9 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl @@ -0,0 +1,23 @@ +SECTIONS +{ + /* 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); + } > TEXT_STORE +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_rodata.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_rodata.incl new file mode 100644 index 000000000..a6de46efc --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_rodata.incl @@ -0,0 +1,8 @@ +SECTIONS +{ + .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); + } > TEXT_STORE +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl index d35f7209e..7d6eb9d17 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl @@ -1,95 +1,5 @@ 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) @@ -111,7 +21,7 @@ SECTIONS *(.eh_frame*) . = ALIGN(4); __ram_text_end__ = .; - } > RAM AT> FLASH + } > RAM AT> RAM_STORE __ram_text_source__ = LOADADDR(.text); . = ALIGN(4); } diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_data.incl b/src/rp2_common/pico_standard_link/script_include/section_default_data.incl index 5bd1cf569..a1f759b39 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_default_data.incl @@ -1,14 +1,5 @@ SECTIONS { - .ram_vector_table (NOLOAD): { - *(.ram_vector_table) - } > RAM - - .uninitialized_data (NOLOAD): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - .data : { __data_start__ = .; *(vtable) @@ -35,38 +26,16 @@ SECTIONS *(.jcr) . = ALIGN(4); - } > RAM AT> FLASH + } > RAM AT> RAM_STORE .tdata : { . = ALIGN(4); *(.tdata .tdata.* .gnu.linkonce.td.*) /* All data end */ __tdata_end = .; - } > RAM AT> FLASH + } > RAM AT> RAM_STORE 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_standard_link/script_include/section_default_rodata.incl b/src/rp2_common/pico_standard_link/script_include/section_default_rodata.incl new file mode 100644 index 000000000..2df23bbf2 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_default_rodata.incl @@ -0,0 +1,10 @@ +SECTIONS +{ + .rodata : { + INCLUDE "default_rodata_excludes.incl" + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > TEXT_STORE +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl index 49c113db4..63905474b 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl @@ -1,9 +1,5 @@ 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. @@ -27,7 +23,7 @@ SECTIONS * FLASH ... we will include any thing excluded here in .data below by default */ *(.init) *libgcc.a:cmse_nonsecure_call.o - INCLUDE "section_default_text_excludes.incl" + INCLUDE "default_text_excludes.incl" *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -65,57 +61,5 @@ SECTIONS *(.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 : { - INCLUDE "section_default_rodata_excludes.incl" - *(.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); + } > TEXT_STORE } diff --git a/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl b/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl new file mode 100644 index 000000000..fdff1ad09 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl @@ -0,0 +1,6 @@ +SECTIONS +{ + .flash_begin : { + __flash_binary_start = .; + } > TEXT_STORE +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl b/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl index 8591406ff..92a3e7dff 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl @@ -3,5 +3,5 @@ SECTIONS .flash_end : { KEEP(*(.embedded_end_block*)) PROVIDE(__flash_binary_end = .); - } > FLASH =0xaa + } > TEXT_STORE =0xaa } diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl index 5658d8a4b..e1c5ee909 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl @@ -51,32 +51,6 @@ SECTIONS } > 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_standard_link/script_include/section_no_flash_rodata.incl b/src/rp2_common/pico_standard_link/script_include/section_no_flash_rodata.incl new file mode 100644 index 000000000..9e5ae119d --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_no_flash_rodata.incl @@ -0,0 +1,11 @@ +SECTIONS +{ + .rodata : { + . = ALIGN(4); + *(.rodata*) + *(.srodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > RAM +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl index 833d8c42b..912aa13d2 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl @@ -38,36 +38,4 @@ SECTIONS *(.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_standard_link/script_include/section_ram_vector_table.incl b/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl new file mode 100644 index 000000000..1e5818110 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl @@ -0,0 +1,6 @@ +SECTIONS +{ + .ram_vector_table (NOLOAD): { + *(.ram_vector_table) + } > RAM +} diff --git a/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl b/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl new file mode 100644 index 000000000..6167314be --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl @@ -0,0 +1,7 @@ +SECTIONS +{ + .uninitialized_data (NOLOAD): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM +} diff --git a/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl b/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl new file mode 100644 index 000000000..6b6ee8d0a --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl @@ -0,0 +1,14 @@ +SECTIONS +{ + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > TEXT_STORE + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > TEXT_STORE + __exidx_end = .; +} diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index 397311e63..beb231348 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -1,7 +1,7 @@ -INCLUDE "section_copy_to_ram_text.incl" -INCLUDE "section_copy_to_ram_data.incl" +INCLUDE "sections_copy_to_ram_text.incl" +INCLUDE "sections_copy_to_ram_data.incl" INCLUDE "section_heap.incl" -INCLUDE "section_scratch.incl" +INCLUDE "sections_scratch.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl new file mode 100644 index 000000000..b0de72ede --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl @@ -0,0 +1,2 @@ +INCLUDE "section_copy_to_ram_data.incl" +INCLUDE "section_bss.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl new file mode 100644 index 000000000..f19c1aab3 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl @@ -0,0 +1,9 @@ +INCLUDE "section_flash_begin.incl" +INCLUDE "section_copy_to_ram_flashtext.incl" +INCLUDE "section_boot2.incl" +INCLUDE "section_copy_to_ram_rodata.incl" +INCLUDE "sections_arm_ex.incl" +INCLUDE "section_binary_info.incl" +INCLUDE "section_ram_vector_table.incl" +INCLUDE "section_uninitialized_data.incl" +INCLUDE "section_copy_to_ram_text.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index e00725155..05f09f12b 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -1,7 +1,7 @@ -INCLUDE "section_default_text.incl" -INCLUDE "section_default_data.incl" +INCLUDE "sections_default_text.incl" +INCLUDE "sections_default_data.incl" INCLUDE "section_heap.incl" -INCLUDE "section_scratch.incl" +INCLUDE "sections_scratch.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl new file mode 100644 index 000000000..e61f35527 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl @@ -0,0 +1,4 @@ +INCLUDE "section_ram_vector_table.incl" +INCLUDE "section_uninitialized_data.incl" +INCLUDE "section_default_data.incl" +INCLUDE "section_bss.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl new file mode 100644 index 000000000..5959a5b5d --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl @@ -0,0 +1,6 @@ +INCLUDE "section_flash_begin.incl" +INCLUDE "section_default_text.incl" +INCLUDE "section_boot2.incl" +INCLUDE "section_default_rodata.incl" +INCLUDE "sections_arm_ex.incl" +INCLUDE "section_binary_info.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index 2a043dfe3..87760c03f 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -1,6 +1,6 @@ -INCLUDE "section_no_flash_text.incl" -INCLUDE "section_no_flash_data.incl" +INCLUDE "sections_no_flash_text.incl" +INCLUDE "sections_no_flash_data.incl" INCLUDE "section_heap.incl" -INCLUDE "section_scratch.incl" +INCLUDE "sections_scratch.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl new file mode 100644 index 000000000..084fbda4f --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl @@ -0,0 +1,3 @@ +INCLUDE "section_no_flash_data.incl" +INCLUDE "section_uninitialized_data.incl" +INCLUDE "section_bss.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl new file mode 100644 index 000000000..65de1fa12 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl @@ -0,0 +1,4 @@ +INCLUDE "section_no_flash_text.incl" +INCLUDE "section_no_flash_rodata.incl" +INCLUDE "sections_arm_ex.incl" +INCLUDE "section_binary_info.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/section_scratch.incl b/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl similarity index 100% rename from src/rp2_common/pico_standard_link/script_include/section_scratch.incl rename to src/rp2_common/pico_standard_link/script_include/sections_scratch.incl diff --git a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl index 2bc78925a..15e94dac0 100644 --- a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl +++ b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl @@ -1,5 +1,5 @@ -INCLUDE "section_default_text.incl" -INCLUDE "section_default_data.incl" +INCLUDE "sections_default_text.incl" +INCLUDE "sections_default_data.incl" SECTIONS { @@ -13,7 +13,7 @@ SECTIONS } INCLUDE "section_heap.incl" -INCLUDE "section_scratch.incl" +INCLUDE "sections_scratch.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" \ No newline at end of file diff --git a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl index 9e3060e70..00db2605d 100644 --- a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl +++ b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl @@ -1,5 +1,5 @@ -INCLUDE "section_default_text.incl" -INCLUDE "section_default_data.incl" +INCLUDE "sections_default_text.incl" +INCLUDE "sections_default_data.incl" SECTIONS { @@ -18,7 +18,7 @@ SECTIONS } INCLUDE "section_heap.incl" -INCLUDE "section_scratch.incl" +INCLUDE "sections_scratch.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" From 2e7ca673a003db70a19d727bf40e79910b97dcba Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 14:44:29 +0000 Subject: [PATCH 23/60] Add section_extra files to make adding extra sections simpler --- .../script_include/section_no_flash_text.incl | 31 ------------------- .../script_include/sections_default_text.incl | 2 +- .../section_extra_post_data.incl | 3 ++ .../section_extra_post_scratch.incl | 3 ++ .../section_extra_post_text.incl | 3 ++ .../script_include/sections_copy_to_ram.incl | 4 +++ .../script_include/sections_default.incl | 4 +++ .../script_include/sections_no_flash.incl | 4 +++ .../script_include/sections_scratch.incl | 18 ----------- .../script_include/sections_stack.incl | 20 ++++++++++++ test/kitchen_sink/CMakeLists.txt | 2 ++ .../section_extra_post_data.incl | 10 ++++++ .../sections_default.incl | 19 ------------ ...ault.incl => section_extra_post_data.incl} | 9 ------ 14 files changed, 54 insertions(+), 78 deletions(-) create mode 100644 src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_stack.incl create mode 100644 test/kitchen_sink/kitchen_sink_ram_section_scripts/section_extra_post_data.incl delete mode 100644 test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl rename test/kitchen_sink/kitchen_sink_simple_overlay_scripts/{sections_default.incl => section_extra_post_data.incl} (57%) diff --git a/src/rp2040/pico_platform/script_include/section_no_flash_text.incl b/src/rp2040/pico_platform/script_include/section_no_flash_text.incl index b4ad44ba7..43fbfa783 100644 --- a/src/rp2040/pico_platform/script_include/section_no_flash_text.incl +++ b/src/rp2040/pico_platform/script_include/section_no_flash_text.incl @@ -37,35 +37,4 @@ SECTIONS *(.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/rp2040/pico_platform/script_include/sections_default_text.incl b/src/rp2040/pico_platform/script_include/sections_default_text.incl index af0bce686..c00c93429 100644 --- a/src/rp2040/pico_platform/script_include/sections_default_text.incl +++ b/src/rp2040/pico_platform/script_include/sections_default_text.incl @@ -1,4 +1,4 @@ -# This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 +/* This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 */ INCLUDE "section_flash_begin.incl" INCLUDE "section_boot2.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl new file mode 100644 index 000000000..584a11e64 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl @@ -0,0 +1,3 @@ +/* Empty file - can be overriden + This file is included between the end of data/bss and the start of the heap +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl new file mode 100644 index 000000000..b306a920e --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl @@ -0,0 +1,3 @@ +/* Empty file - can be overriden + This file is included between the end of scratch and the start of the stack +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl new file mode 100644 index 000000000..3d8214675 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl @@ -0,0 +1,3 @@ +/* Empty file - can be overriden + This file is included between the end of text and the start of data +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index beb231348..9b0ef9660 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -1,7 +1,11 @@ INCLUDE "sections_copy_to_ram_text.incl" +INCLUDE "section_extra_post_text.incl" INCLUDE "sections_copy_to_ram_data.incl" +INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_extra_post_scratch.incl" +INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index 05f09f12b..e25f8042e 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -1,7 +1,11 @@ INCLUDE "sections_default_text.incl" +INCLUDE "section_extra_post_text.incl" INCLUDE "sections_default_data.incl" +INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_extra_post_scratch.incl" +INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index 87760c03f..0ab32a9a8 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -1,6 +1,10 @@ INCLUDE "sections_no_flash_text.incl" +INCLUDE "section_extra_post_text.incl" INCLUDE "sections_no_flash_data.incl" +INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_extra_post_scratch.incl" +INCLUDE "sections_stack.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl b/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl index f61c39639..21f99e4e3 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl @@ -16,22 +16,4 @@ SECTIONS __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/script_include/sections_stack.incl b/src/rp2_common/pico_standard_link/script_include/sections_stack.incl new file mode 100644 index 000000000..15aaa8572 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_stack.incl @@ -0,0 +1,20 @@ +SECTIONS +{ + /* .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/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 245e26904..80b157736 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -226,6 +226,8 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) 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) + # Also add this directory to test that multiple override paths work (although it doesn't override anything, as it's the same file) + pico_add_linker_script_override_path(kitchen_sink_ram_section ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_simple_overlay_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) diff --git a/test/kitchen_sink/kitchen_sink_ram_section_scripts/section_extra_post_data.incl b/test/kitchen_sink/kitchen_sink_ram_section_scripts/section_extra_post_data.incl new file mode 100644 index 000000000..458bd6b26 --- /dev/null +++ b/test/kitchen_sink/kitchen_sink_ram_section_scripts/section_extra_post_data.incl @@ -0,0 +1,10 @@ +SECTIONS +{ + .extra_data : { + __extra_data_start__ = .; + *(.extra_data*) + . = ALIGN(4); + __extra_data_end__ = .; + } > RAM AT> RAM_STORE + __extra_data_source__ = LOADADDR(.extra_data); +} diff --git a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl b/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl deleted file mode 100644 index 15e94dac0..000000000 --- a/test/kitchen_sink/kitchen_sink_ram_section_scripts/sections_default.incl +++ /dev/null @@ -1,19 +0,0 @@ -INCLUDE "sections_default_text.incl" -INCLUDE "sections_default_data.incl" - -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.incl" -INCLUDE "sections_scratch.incl" -INCLUDE "section_flash_end.incl" -INCLUDE "section_end.incl" -INCLUDE "section_platform_end.incl" \ No newline at end of file diff --git a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/section_extra_post_data.incl similarity index 57% rename from test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl rename to test/kitchen_sink/kitchen_sink_simple_overlay_scripts/section_extra_post_data.incl index 00db2605d..d5b3d95bd 100644 --- a/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/sections_default.incl +++ b/test/kitchen_sink/kitchen_sink_simple_overlay_scripts/section_extra_post_data.incl @@ -1,6 +1,3 @@ -INCLUDE "sections_default_text.incl" -INCLUDE "sections_default_data.incl" - SECTIONS { PROVIDE(__overlays_start__ = .); @@ -16,9 +13,3 @@ SECTIONS } > RAM AT> RAM_STORE PROVIDE(__overlays_end__ = .); } - -INCLUDE "section_heap.incl" -INCLUDE "sections_scratch.incl" -INCLUDE "section_flash_end.incl" -INCLUDE "section_end.incl" -INCLUDE "section_platform_end.incl" From 4180427fba4e1ba5730729b09e185ef8555552e3 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 15:59:45 +0000 Subject: [PATCH 24/60] Fix comments, and add some more extra files --- .../script_include/section_boot2.incl | 2 +- .../script_include/section_no_flash_text.incl | 7 +++ .../script_include/section_platform_end.incl | 46 ------------------- .../sections_copy_to_ram_text.incl | 2 + .../script_include/section_platform_end.incl | 2 - .../script_include/memmap_copy_to_ram.incl | 1 + .../script_include/memmap_default.incl | 1 + .../script_include/memmap_no_flash.incl | 1 + .../memory_aliases_default.incl | 2 + .../memory_aliases_no_flash.incl | 2 + .../script_include/memory_extra.incl | 17 +++++++ .../script_include/section_binary_info.incl | 4 ++ .../script_include/section_boot2.incl | 4 ++ .../script_include/section_bss.incl | 7 +++ .../section_copy_to_ram_data.incl | 10 ++++ .../section_copy_to_ram_flashtext.incl | 8 ++++ .../section_copy_to_ram_text.incl | 4 ++ .../script_include/section_default_data.incl | 6 +++ .../script_include/section_default_text.incl | 11 +++++ .../script_include/section_end.incl | 26 ++--------- .../section_extra_post_data.incl | 7 ++- .../section_extra_post_end.incl | 7 +++ .../section_extra_post_scratch.incl | 7 ++- .../section_extra_post_text.incl | 7 ++- .../script_include/section_flash_begin.incl | 4 ++ .../script_include/section_flash_end.incl | 4 ++ .../script_include/section_heap.incl | 4 ++ .../script_include/section_no_flash_data.incl | 10 ++++ .../script_include/section_no_flash_text.incl | 16 +++++-- .../script_include/sections_arm_ex.incl | 4 ++ .../script_include/sections_copy_to_ram.incl | 3 ++ .../sections_copy_to_ram_data.incl | 2 + .../sections_copy_to_ram_text.incl | 2 + .../script_include/sections_default.incl | 3 ++ .../script_include/sections_default_data.incl | 2 + .../script_include/sections_default_text.incl | 2 + .../script_include/sections_no_flash.incl | 3 ++ .../sections_no_flash_data.incl | 2 + .../sections_no_flash_text.incl | 2 + .../script_include/sections_scratch.incl | 5 ++ .../script_include/set_memory_locations.incl | 2 + 41 files changed, 180 insertions(+), 81 deletions(-) create mode 100644 src/rp2_common/pico_standard_link/script_include/memory_extra.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl diff --git a/src/rp2040/pico_platform/script_include/section_boot2.incl b/src/rp2040/pico_platform/script_include/section_boot2.incl index b6afc3763..8a8a6bea7 100644 --- a/src/rp2040/pico_platform/script_include/section_boot2.incl +++ b/src/rp2040/pico_platform/script_include/section_boot2.incl @@ -12,5 +12,5 @@ SECTIONS } > TEXT_STORE ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") + "ERROR: Pico second stage bootloader must be exactly 256 bytes in size for RP2040") } diff --git a/src/rp2040/pico_platform/script_include/section_no_flash_text.incl b/src/rp2040/pico_platform/script_include/section_no_flash_text.incl index 43fbfa783..57cd4cfc3 100644 --- a/src/rp2040/pico_platform/script_include/section_no_flash_text.incl +++ b/src/rp2040/pico_platform/script_include/section_no_flash_text.incl @@ -1,3 +1,10 @@ +/* Defines the following symbols for use by code: + __logical_binary_start + __binary_info_header_end + __embedded_block_end + __reset_start, __reset_end +*/ + SECTIONS { /* Note in NO_FLASH builds the entry point for both the bootrom, and debugger diff --git a/src/rp2040/pico_platform/script_include/section_platform_end.incl b/src/rp2040/pico_platform/script_include/section_platform_end.incl index 2d0165aa4..cccfc262d 100644 --- a/src/rp2040/pico_platform/script_include/section_platform_end.incl +++ b/src/rp2040/pico_platform/script_include/section_platform_end.incl @@ -1,50 +1,4 @@ -/* 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/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl b/src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl index 0fdd197b8..be47abb6f 100644 --- a/src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl +++ b/src/rp2040/pico_platform/script_include/sections_copy_to_ram_text.incl @@ -1,3 +1,5 @@ +/* This swaps section_boot2 and section_default_text, because RP2040 binaries must begin with boot2 */ + INCLUDE "section_flash_begin.incl" INCLUDE "section_boot2.incl" INCLUDE "section_copy_to_ram_flashtext.incl" diff --git a/src/rp2350/pico_platform/script_include/section_platform_end.incl b/src/rp2350/pico_platform/script_include/section_platform_end.incl index 43cc19ecd..9503fa173 100644 --- a/src/rp2350/pico_platform/script_include/section_platform_end.incl +++ b/src/rp2350/pico_platform/script_include/section_platform_end.incl @@ -2,6 +2,4 @@ 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_standard_link/script_include/memmap_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl index f2b8e7159..b886383ec 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_extra.incl" /* Include aliases for storage memory regions */ INCLUDE "memory_aliases_default.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl index 791d4ef2b..3a0fb8ea7 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_extra.incl" /* Include aliases for storage memory regions */ INCLUDE "memory_aliases_default.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl index e9578be46..294477788 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl @@ -4,6 +4,7 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_extra.incl" /* Include aliases for no_flash storage memory regions (alias to themselves) */ INCLUDE "memory_aliases_no_flash.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl index 4c16d41be..370b63ed1 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl @@ -1,3 +1,5 @@ +/* Store everything in flash */ + REGION_ALIAS("TEXT_STORE", FLASH); REGION_ALIAS("RAM_STORE", FLASH); REGION_ALIAS("SCRATCH_X_STORE", FLASH); diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl index 9190b32ab..258072736 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl @@ -1,3 +1,5 @@ +/* Store everything where it came from (ram/scratch) */ + REGION_ALIAS("TEXT_STORE", RAM); REGION_ALIAS("RAM_STORE", RAM); REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); diff --git a/src/rp2_common/pico_standard_link/script_include/memory_extra.incl b/src/rp2_common/pico_standard_link/script_include/memory_extra.incl new file mode 100644 index 000000000..cdd16166c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memory_extra.incl @@ -0,0 +1,17 @@ +/* Empty file + + This file can be overridden to add extra memory regions. + + For example, to add a PSRAM region, you would replace + this file with: + + MEMORY + { + PSRAM(rwx) : ORIGIN = 0x11000000, LENGTH = 8M + } + + Or to include a XIP_RAM region, you would replace + this file with: + + INCLUDE "memory_xip_ram.incl" +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl b/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl index f7238d09a..7c76c03e9 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __binary_info_start, __binary_info_end +*/ + SECTIONS { /* Machine inspectable binary information */ diff --git a/src/rp2_common/pico_standard_link/script_include/section_boot2.incl b/src/rp2_common/pico_standard_link/script_include/section_boot2.incl index 14e362776..7423819c4 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_boot2.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_boot2.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __boot2_start__, __boot2_end__ +*/ + SECTIONS { /* Note the boot2 section is optional, and should be discarded if there is diff --git a/src/rp2_common/pico_standard_link/script_include/section_bss.incl b/src/rp2_common/pico_standard_link/script_include/section_bss.incl index 172436df6..38de94018 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_bss.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_bss.incl @@ -1,3 +1,10 @@ +/* Defines the following symbols for use by code: + __bss_start__, __bss_end__ + __tls_base, __tls_end + __tbss_end + __global_pointer$ +*/ + SECTIONS { .tbss (NOLOAD) : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl index 82084a70b..60890c885 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_data.incl @@ -1,3 +1,13 @@ +/* Defines the following symbols for use by code: + __data_start__, __data_end__ + __mutex_array_start, __mutex_array_end + __preinit_array_start, __preinit_array_end + __init_array_start, __init_array_end + __fini_array_start, __fini_array_end + __tdata_end + __etext +*/ + SECTIONS { .data : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl index a0c794eb9..12d79dbe4 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl @@ -1,7 +1,15 @@ +/* Defines the following symbols for use by code: + __logical_binary_start + __binary_info_header_end + __embedded_block_end +*/ + SECTIONS { /* The bootrom will enter the image at the point indicated in your IMAGE_DEF, which is usually the reset handler of your vector table. + If there is no point indicated in the IMAGE_DEF, it expects a VT at + the start of the image, and will use the entry point from that. 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.* diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl index 7d6eb9d17..a9e36bbb1 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_text.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __ram_text_start__, __ram_text_end__, __ram_text_source__ +*/ + SECTIONS { .text : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_data.incl b/src/rp2_common/pico_standard_link/script_include/section_default_data.incl index a1f759b39..114b3c493 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_default_data.incl @@ -1,3 +1,9 @@ +/* Defines the following symbols for use by code: + __data_start__, __data_end__ + __mutex_array_start, __mutex_array_end + __etext +*/ + SECTIONS { .data : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl index 63905474b..a11f7b5e4 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl @@ -1,7 +1,18 @@ +/* Defines the following symbols for use by code: + __logical_binary_start + __binary_info_header_end + __embedded_block_end + __preinit_array_start, __preinit_array_end + __init_array_start, __init_array_end + __fini_array_start, __fini_array_end +*/ + SECTIONS { /* The bootrom will enter the image at the point indicated in your IMAGE_DEF, which is usually the reset handler of your vector table. + If there is no point indicated in the IMAGE_DEF, it expects a VT at + the start of the image, and will use the entry point from that. 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.* diff --git a/src/rp2_common/pico_standard_link/script_include/section_end.incl b/src/rp2_common/pico_standard_link/script_include/section_end.incl index 53d328174..6de5ead43 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_end.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_end.incl @@ -1,24 +1,10 @@ -/* 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 +/* Defines the following symbols for use by code: __StackLimit - __StackTop + __StackOneTop, __StackOneBottom + __StackTop, __StackBottom __stack (== StackTop) + + Also defines additional symbols for other compilers/libcs */ SECTIONS @@ -44,6 +30,4 @@ SECTIONS /* 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/script_include/section_extra_post_data.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl index 584a11e64..00360c637 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl @@ -1,3 +1,6 @@ -/* Empty file - can be overriden - This file is included between the end of data/bss and the start of the heap +/* Empty file + + This file is included between the end of data/bss and the start of the heap. + + It can be overridden to add extra sections into ram. */ diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl new file mode 100644 index 000000000..6e28eacb4 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl @@ -0,0 +1,7 @@ +/* Empty file + + This file is included after the section_end and section_platform_end files. + + It can be overridden to override any symbols provided by the linker scripts, + or to add custom asserts. +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl index b306a920e..245c039ee 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl @@ -1,3 +1,6 @@ -/* Empty file - can be overriden - This file is included between the end of scratch and the start of the stack +/* Empty file + + This file is included between the end of scratch and the start of the stack. + + It can be overridden to add extra sections in the scratch memory, before the stack. */ diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl index 3d8214675..e21811e4c 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl @@ -1,3 +1,6 @@ -/* Empty file - can be overriden - This file is included between the end of text and the start of data +/* Empty file + + This file is included between the end of text and the start of data. + + It can be overridden to add extra sections into flash. */ diff --git a/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl b/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl index fdff1ad09..48492a926 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_flash_begin.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __flash_binary_start +*/ + SECTIONS { .flash_begin : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl b/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl index 92a3e7dff..38d3481d7 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_flash_end.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __flash_binary_end +*/ + SECTIONS { .flash_end : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_heap.incl b/src/rp2_common/pico_standard_link/script_include/section_heap.incl index 1cc9e0de1..240e118d4 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_heap.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_heap.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __HeapLimit +*/ + SECTIONS { .heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD): diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl index e1c5ee909..57c38782f 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl @@ -1,3 +1,13 @@ +/* Defines the following symbols for use by code: + __data_start__, __data_end__ + __mutex_array_start, __mutex_array_end + __preinit_array_start, __preinit_array_end + __init_array_start, __init_array_end + __fini_array_start, __fini_array_end + __tdata_end + __etext +*/ + SECTIONS { .data : { diff --git a/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl index 912aa13d2..e7ec24187 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl @@ -1,10 +1,16 @@ +/* Defines the following symbols for use by code: + __logical_binary_start + __binary_info_header_end + __embedded_block_end + __reset_start, __reset_end +*/ + 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. */ + /* 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 = .; diff --git a/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl b/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl index 6b6ee8d0a..cf4cb4dee 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl @@ -1,3 +1,7 @@ +/* Defines the following symbols for use by code: + __exidx_start, __exidx_end +*/ + SECTIONS { .ARM.extab : diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index 9b0ef9660..fbebab43c 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -1,3 +1,5 @@ +/* Main section list for copy_to_ram binaries */ + INCLUDE "sections_copy_to_ram_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_copy_to_ram_data.incl" @@ -9,3 +11,4 @@ INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl index b0de72ede..ff90005e1 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl @@ -1,2 +1,4 @@ +/* Sub-section list for read/write sections in copy_to_ram binaries */ + INCLUDE "section_copy_to_ram_data.incl" INCLUDE "section_bss.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl index f19c1aab3..7dcb9c1cf 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_text.incl @@ -1,3 +1,5 @@ +/* Sub-section list for read-only sections in copy_to_ram binaries */ + INCLUDE "section_flash_begin.incl" INCLUDE "section_copy_to_ram_flashtext.incl" INCLUDE "section_boot2.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index e25f8042e..858c4afa6 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -1,3 +1,5 @@ +/* Main section list for default binaries */ + INCLUDE "sections_default_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_default_data.incl" @@ -9,3 +11,4 @@ INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl index e61f35527..cfa77cb2f 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl @@ -1,3 +1,5 @@ +/* Sub-section list for read/write sections in default binaries */ + INCLUDE "section_ram_vector_table.incl" INCLUDE "section_uninitialized_data.incl" INCLUDE "section_default_data.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl index 5959a5b5d..cc1985309 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default_text.incl @@ -1,3 +1,5 @@ +/* Sub-section list for read-only sections in default binaries */ + INCLUDE "section_flash_begin.incl" INCLUDE "section_default_text.incl" INCLUDE "section_boot2.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index 0ab32a9a8..5e1042727 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -1,3 +1,5 @@ +/* Main section list for no_flash binaries */ + INCLUDE "sections_no_flash_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_no_flash_data.incl" @@ -8,3 +10,4 @@ INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl index 084fbda4f..6a55a1481 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl @@ -1,3 +1,5 @@ +/* Sub-section list for read/write sections in no_flash binaries */ + INCLUDE "section_no_flash_data.incl" INCLUDE "section_uninitialized_data.incl" INCLUDE "section_bss.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl index 65de1fa12..0217b33c5 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl @@ -1,3 +1,5 @@ +/* Sub-section list for read-only sections in no_flash binaries */ + INCLUDE "section_no_flash_text.incl" INCLUDE "section_no_flash_rodata.incl" INCLUDE "sections_arm_ex.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl b/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl index 21f99e4e3..7505ca627 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl @@ -1,3 +1,8 @@ +/* Defines the following symbols for use by code: + __scratch_x_start__, __scratch_x_end__, __scratch_x_source__ + __scratch_y_start__, __scratch_y_end__, __scratch_y_source__ +*/ + SECTIONS { /* Start and end symbols must be word-aligned */ diff --git a/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl b/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl index a9110eb59..a2341f42a 100644 --- a/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl +++ b/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl @@ -1,3 +1,5 @@ +/* Set memory locations either to the already defined value, or to the default value from default_locations.ld */ + 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; From c122bf7280ba6d5ae87b7e9f0bf6f81e9647f48e Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 16:12:49 +0000 Subject: [PATCH 25/60] Add generated override files - currently unused, but can be overridden in the future by CMake/bazel functions --- .../pico_standard_link/script_include/memmap_copy_to_ram.incl | 1 + .../pico_standard_link/script_include/memmap_default.incl | 1 + .../pico_standard_link/script_include/memmap_no_flash.incl | 1 + .../pico_standard_link/script_include/memory_generated.incl | 4 ++++ .../script_include/section_generated_post_data.incl | 4 ++++ .../script_include/section_generated_post_end.incl | 4 ++++ .../script_include/section_generated_post_scratch.incl | 4 ++++ .../script_include/section_generated_post_text.incl | 4 ++++ .../script_include/sections_copy_to_ram.incl | 4 ++++ .../pico_standard_link/script_include/sections_default.incl | 4 ++++ .../pico_standard_link/script_include/sections_no_flash.incl | 4 ++++ 11 files changed, 35 insertions(+) create mode 100644 src/rp2_common/pico_standard_link/script_include/memory_generated.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_generated_post_data.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_generated_post_end.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_generated_post_scratch.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_generated_post_text.incl diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl index b886383ec..d16c16ed6 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" /* Include aliases for storage memory regions */ diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl index 3a0fb8ea7..1367ee18e 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" /* Include aliases for storage memory regions */ diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl index 294477788..c043470e9 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl @@ -4,6 +4,7 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" /* Include aliases for no_flash storage memory regions (alias to themselves) */ diff --git a/src/rp2_common/pico_standard_link/script_include/memory_generated.incl b/src/rp2_common/pico_standard_link/script_include/memory_generated.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memory_generated.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_generated_post_data.incl b/src/rp2_common/pico_standard_link/script_include/section_generated_post_data.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_generated_post_data.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_generated_post_end.incl b/src/rp2_common/pico_standard_link/script_include/section_generated_post_end.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_generated_post_end.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_generated_post_scratch.incl b/src/rp2_common/pico_standard_link/script_include/section_generated_post_scratch.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_generated_post_scratch.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_generated_post_text.incl b/src/rp2_common/pico_standard_link/script_include/section_generated_post_text.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_generated_post_text.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index fbebab43c..a4baa85aa 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -1,14 +1,18 @@ /* Main section list for copy_to_ram binaries */ INCLUDE "sections_copy_to_ram_text.incl" +INCLUDE "section_generated_post_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_copy_to_ram_data.incl" +INCLUDE "section_generated_post_data.incl" INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index 858c4afa6..0c9493e73 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -1,14 +1,18 @@ /* Main section list for default binaries */ INCLUDE "sections_default_text.incl" +INCLUDE "section_generated_post_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_default_data.incl" +INCLUDE "section_generated_post_data.incl" INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index 5e1042727..941bf3121 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -1,13 +1,17 @@ /* Main section list for no_flash binaries */ INCLUDE "sections_no_flash_text.incl" +INCLUDE "section_generated_post_text.incl" INCLUDE "section_extra_post_text.incl" INCLUDE "sections_no_flash_data.incl" +INCLUDE "section_generated_post_data.incl" INCLUDE "section_extra_post_data.incl" INCLUDE "section_heap.incl" INCLUDE "sections_scratch.incl" +INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_end.incl" INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" From ea8320b1c6d69bb2842df61203e751868b6d9658 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 17:21:28 +0000 Subject: [PATCH 26/60] pico_add_linker_script_override_path can now be called after target_link_libraries, as it uses generator expressions Also add more checks to kitchen_sink --- src/rp2_common/pico_standard_link/CMakeLists.txt | 7 +------ test/kitchen_sink/CMakeLists.txt | 7 +++++-- test/kitchen_sink/kitchen_sink.c | 2 ++ .../section_extra_post_end.incl | 4 ++++ 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 test/kitchen_sink/kitchen_sink_extra_end_scripts/section_extra_post_end.incl diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 9db70b1e6..b327c9d40 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -93,16 +93,11 @@ if (NOT TARGET pico_standard_link) # 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. - # It will also not override prior paths set by pico_add_linker_script_override_path. + # It will not override prior paths set by pico_add_linker_script_override_path. # # \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() set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_OVERRIDE_PATHS "${PATH}") endfunction() diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 80b157736..ed039d87e 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -220,14 +220,16 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) 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) + # Also swap scratch x and scratch y, to test using defaults + pico_set_linker_script_var(kitchen_sink_ram_custom SCRATCH_X_ORIGIN SCRATCH_Y_ORIGIN_DEFAULT) + pico_set_linker_script_var(kitchen_sink_ram_custom SCRATCH_Y_ORIGIN SCRATCH_X_ORIGIN_DEFAULT) 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) - # Also add this directory to test that multiple override paths work (although it doesn't override anything, as it's the same file) - pico_add_linker_script_override_path(kitchen_sink_ram_section ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_simple_overlay_scripts) + pico_add_linker_script_override_path(kitchen_sink_ram_section ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_extra_end_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) @@ -236,6 +238,7 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) # 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) + pico_add_linker_script_override_path(kitchen_sink_simple_overlay ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_extra_end_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) diff --git a/test/kitchen_sink/kitchen_sink.c b/test/kitchen_sink/kitchen_sink.c index 6a3a5fbee..ba5fe7613 100644 --- a/test/kitchen_sink/kitchen_sink.c +++ b/test/kitchen_sink/kitchen_sink.c @@ -86,6 +86,8 @@ int main(void) { hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL)); printf("%f\n", foox(1.3f, 2.6f)); #ifdef EXTRA_DATA_SECTION + extern uint32_t __extra_end_variable__; + printf("__extra_end_variable__ = %p\n", (void *)&__extra_end_variable__); #if EXTRA_DATA_SECTION > 1 extern uint32_t __overlays_start__; uint32_t stored_words; diff --git a/test/kitchen_sink/kitchen_sink_extra_end_scripts/section_extra_post_end.incl b/test/kitchen_sink/kitchen_sink_extra_end_scripts/section_extra_post_end.incl new file mode 100644 index 000000000..52fe92ddd --- /dev/null +++ b/test/kitchen_sink/kitchen_sink_extra_end_scripts/section_extra_post_end.incl @@ -0,0 +1,4 @@ +SECTIONS +{ + PROVIDE(__extra_end_variable__ = 4M); +} From ad35ad81b2ff6291c975e27a033390c4f7f8005e Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 17:29:42 +0000 Subject: [PATCH 27/60] Add extra post_platform_end sections Intended for platform specific overrides, whereas post_end is for cross-platform overrides, similar to section_end vs section_platform_end --- .../script_include/section_extra_post_end.incl | 2 +- .../script_include/section_extra_post_platform_end.incl | 9 +++++++++ .../section_generated_post_platform_end.incl | 4 ++++ .../script_include/sections_copy_to_ram.incl | 4 +++- .../script_include/sections_default.incl | 4 +++- .../script_include/sections_no_flash.incl | 4 +++- 6 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/rp2_common/pico_standard_link/script_include/section_extra_post_platform_end.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_generated_post_platform_end.incl diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl index 6e28eacb4..24a964de1 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl @@ -1,6 +1,6 @@ /* Empty file - This file is included after the section_end and section_platform_end files. + This file is included after the section_end file. It can be overridden to override any symbols provided by the linker scripts, or to add custom asserts. diff --git a/src/rp2_common/pico_standard_link/script_include/section_extra_post_platform_end.incl b/src/rp2_common/pico_standard_link/script_include/section_extra_post_platform_end.incl new file mode 100644 index 000000000..7be81fcd5 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_extra_post_platform_end.incl @@ -0,0 +1,9 @@ +/* Empty file + + This file is included after the section_platform_end file. + + It can be overridden to override any symbols provided by the linker scripts, + or to add custom asserts. + + It is intended to be used for platform specific overrides. +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/section_generated_post_platform_end.incl b/src/rp2_common/pico_standard_link/script_include/section_generated_post_platform_end.incl new file mode 100644 index 000000000..2060e314c --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_generated_post_platform_end.incl @@ -0,0 +1,4 @@ +/* DO NOT OVERRIDE THIS FILE + + This file is provided for the SDK to override +*/ diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index a4baa85aa..0c3c7d42e 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -13,6 +13,8 @@ INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" -INCLUDE "section_platform_end.incl" INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" +INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_platform_end.incl" +INCLUDE "section_extra_post_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index 0c9493e73..4e07b3968 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -13,6 +13,8 @@ INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" -INCLUDE "section_platform_end.incl" INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" +INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_platform_end.incl" +INCLUDE "section_extra_post_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index 941bf3121..e9ba353df 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -12,6 +12,8 @@ INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "section_end.incl" -INCLUDE "section_platform_end.incl" INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" +INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_platform_end.incl" +INCLUDE "section_extra_post_platform_end.incl" From 8e3aca507c2f413d0484251bb33746f96d6821a8 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 19 Mar 2026 17:47:00 +0000 Subject: [PATCH 28/60] review fixups --- .../script_include/section_copy_to_ram_flashtext.incl | 6 +++--- .../script_include/section_default_text.incl | 6 +++--- .../pico_standard_link/script_include/section_end.incl | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl index 12d79dbe4..8c0792d0e 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_copy_to_ram_flashtext.incl @@ -6,10 +6,10 @@ SECTIONS { - /* The bootrom will enter the image at the point indicated in your + /* The bootrom will enter the image at the entry point indicated in your IMAGE_DEF, which is usually the reset handler of your vector table. - If there is no point indicated in the IMAGE_DEF, it expects a VT at - the start of the image, and will use the entry point from that. + If there is no entry point indicated in the IMAGE_DEF, it expects a VT + at the start of the image, and will use the entry point from that. 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.* diff --git a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl index a11f7b5e4..911cafab2 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_default_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_default_text.incl @@ -9,10 +9,10 @@ SECTIONS { - /* The bootrom will enter the image at the point indicated in your + /* The bootrom will enter the image at the entry point indicated in your IMAGE_DEF, which is usually the reset handler of your vector table. - If there is no point indicated in the IMAGE_DEF, it expects a VT at - the start of the image, and will use the entry point from that. + If there is no entry point indicated in the IMAGE_DEF, it expects a VT + at the start of the image, and will use the entry point from that. 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.* diff --git a/src/rp2_common/pico_standard_link/script_include/section_end.incl b/src/rp2_common/pico_standard_link/script_include/section_end.incl index 6de5ead43..3ffddcabd 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_end.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_end.incl @@ -2,7 +2,7 @@ __StackLimit __StackOneTop, __StackOneBottom __StackTop, __StackBottom - __stack (== StackTop) + __stack (== __StackTop) Also defines additional symbols for other compilers/libcs */ From 737e8ba30ed12fc455fcc56e27038a3f466801ba Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 18 Sep 2025 12:41:01 +0100 Subject: [PATCH 29/60] Save/restore XIP cache state around flash functions --- src/rp2_common/hardware_flash/flash.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index fbca8de2c..5526db827 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -10,6 +10,7 @@ #if PICO_RP2040 #include "hardware/structs/io_qspi.h" #include "hardware/structs/ssi.h" +#include "hardware/structs/xip.h" #else #include "hardware/structs/qmi.h" #include "hardware/regs/otp_data.h" @@ -127,7 +128,9 @@ static void __no_inline_not_in_flash_func(flash_rp2350_restore_qmi_cs1)(const fl typedef struct flash_hardware_save_state { -#if !PICO_RP2040 +#if PICO_RP2040 + uint32_t xip_ctrl; +#else flash_rp2350_qmi_save_state_t qmi_save; #endif uint32_t qspi_pads[count_of(pads_qspi_hw->io)]; @@ -139,7 +142,9 @@ static void __no_inline_not_in_flash_func(flash_save_hardware_state)(flash_hardw for (size_t i = 0; i < count_of(pads_qspi_hw->io); ++i) { state->qspi_pads[i] = pads_qspi_hw->io[i]; } -#if !PICO_RP2040 +#if PICO_RP2040 + state->xip_ctrl = xip_ctrl_hw->ctrl; +#else flash_rp2350_save_qmi_cs1(&state->qmi_save); #endif } @@ -148,7 +153,9 @@ static void __no_inline_not_in_flash_func(flash_restore_hardware_state)(flash_ha for (size_t i = 0; i < count_of(pads_qspi_hw->io); ++i) { pads_qspi_hw->io[i] = state->qspi_pads[i]; } -#if !PICO_RP2040 +#if PICO_RP2040 + xip_ctrl_hw->ctrl = state->xip_ctrl; +#else // Tail call! flash_rp2350_restore_qmi_cs1(&state->qmi_save); #endif From ae5122aa228181b3939931c01f13cf3032ef9cf3 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 4 Sep 2025 10:31:38 +0100 Subject: [PATCH 30/60] Fix PICO_USE_SW_SPIN_LOCKS=0 on RP2350 Use spinlock IDs that are unaffected by E2 --- .../include/hardware/sync/spin_lock.h | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h index 2be493d6f..83ba1e6d8 100644 --- a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h +++ b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h @@ -10,7 +10,7 @@ #include "pico.h" #include "hardware/sync.h" -// PICO_CONFIG: PICO_USE_SW_SPIN_LOCKS, Use software implementation for spin locks, type=bool, default=1 on RP2350 due to errata, group=hardware_sync +// PICO_CONFIG: PICO_USE_SW_SPIN_LOCKS, Use software implementation for spin locks, type=bool, default=1 on RP2350 due to errata E2, group=hardware_sync #ifndef PICO_USE_SW_SPIN_LOCKS #if PICO_RP2350 #define PICO_USE_SW_SPIN_LOCKS 1 @@ -19,53 +19,93 @@ // PICO_CONFIG: PICO_SPINLOCK_ID_IRQ, Spinlock ID for IRQ protection, min=0, max=31, default=9, group=hardware_sync #ifndef PICO_SPINLOCK_ID_IRQ +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_IRQ 5 +#else #define PICO_SPINLOCK_ID_IRQ 9 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_TIMER, Spinlock ID for Timer protection, min=0, max=31, default=10, group=hardware_sync #ifndef PICO_SPINLOCK_ID_TIMER +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_TIMER 6 +#else #define PICO_SPINLOCK_ID_TIMER 10 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_HARDWARE_CLAIM, Spinlock ID for Hardware claim protection, min=0, max=31, default=11, group=hardware_sync #ifndef PICO_SPINLOCK_ID_HARDWARE_CLAIM +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_HARDWARE_CLAIM 7 +#else #define PICO_SPINLOCK_ID_HARDWARE_CLAIM 11 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_RAND, Spinlock ID for Random Number Generator, min=0, max=31, default=12, group=hardware_sync #ifndef PICO_SPINLOCK_ID_RAND +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_RAND 10 +#else #define PICO_SPINLOCK_ID_RAND 12 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_ATOMIC, Spinlock ID for atomics, min=0, max=31, default=13, group=hardware_sync #ifndef PICO_SPINLOCK_ID_ATOMIC +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_ATOMIC 11 +#else #define PICO_SPINLOCK_ID_ATOMIC 13 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_OS1, First Spinlock ID reserved for use by low level OS style software, min=0, max=31, default=14, group=hardware_sync #ifndef PICO_SPINLOCK_ID_OS1 +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_OS1 18 +#else #define PICO_SPINLOCK_ID_OS1 14 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_OS2, Second Spinlock ID reserved for use by low level OS style software, min=0, max=31, default=15, group=hardware_sync #ifndef PICO_SPINLOCK_ID_OS2 +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_OS2 19 +#else #define PICO_SPINLOCK_ID_OS2 15 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_STRIPED_FIRST, Lowest Spinlock ID in the 'striped' range, min=0, max=31, default=16, group=hardware_sync #ifndef PICO_SPINLOCK_ID_STRIPED_FIRST +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_STRIPED_FIRST 20 +#else #define PICO_SPINLOCK_ID_STRIPED_FIRST 16 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_STRIPED_LAST, Highest Spinlock ID in the 'striped' range, min=0, max=31, default=23, group=hardware_sync #ifndef PICO_SPINLOCK_ID_STRIPED_LAST +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_STRIPED_LAST 25 +#else #define PICO_SPINLOCK_ID_STRIPED_LAST 23 #endif +#endif // PICO_CONFIG: PICO_SPINLOCK_ID_CLAIM_FREE_FIRST, Lowest Spinlock ID in the 'claim free' range, min=0, max=31, default=24, group=hardware_sync #ifndef PICO_SPINLOCK_ID_CLAIM_FREE_FIRST +#if PICO_RP2350 && !PICO_USE_SW_SPIN_LOCKS +#define PICO_SPINLOCK_ID_CLAIM_FREE_FIRST 26 +#else #define PICO_SPINLOCK_ID_CLAIM_FREE_FIRST 24 #endif +#endif #ifdef PICO_SPINLOCK_ID_CLAIM_FREE_END #warning PICO_SPINLOCK_ID_CLAIM_FREE_END has been renamed to PICO_SPINLOCK_ID_CLAIM_FREE_LAST From 220086e7f362e2a05a2196237389e926ae265b30 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 3 Dec 2025 16:42:51 +0000 Subject: [PATCH 31/60] Working XIP SRAM binaries --- .../memmap_copy_to_ram_using_xip_ram.ld | 1 + .../memmap_no_flash_using_xip_ram.ld | 1 + .../memmap_copy_to_ram_using_xip_ram.ld | 1 + .../memmap_no_flash_using_xip_ram.ld | 1 + src/rp2350/pico_platform/memmap_xip_ram.ld | 1 + .../include/hardware/sync/spin_lock.h | 2 +- src/rp2_common/pico_crt0/crt0.S | 45 ++++- src/rp2_common/pico_crt0/crt0_riscv.S | 29 +++- .../pico_crt0/embedded_start_block.inc.S | 14 ++ .../include/pico/platform/sections.h | 4 +- .../pico_standard_link/CMakeLists.txt | 14 +- .../memmap_copy_to_ram_using_xip_ram.incl | 20 +++ .../memmap_no_flash_using_xip_ram.incl | 19 +++ .../script_include/memmap_xip_ram.incl | 28 ++++ .../section_time_critical_xip_ram_text.incl | 11 ++ .../sections_copy_to_ram_using_xip_ram.incl | 21 +++ .../sections_no_flash_using_xip_ram.incl | 20 +++ test/CMakeLists.txt | 1 + test/pico_xip_sram_test/CMakeLists.txt | 29 ++++ .../pico_critical_xip_sram_test.c | 158 ++++++++++++++++++ test/pico_xip_sram_test/pico_xip_sram_test.c | 16 ++ tools/check_source_files_in_bazel_build.py | 2 + 22 files changed, 428 insertions(+), 10 deletions(-) create mode 100644 src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld create mode 100644 src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld create mode 100644 src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld create mode 100644 src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld create mode 100644 src/rp2350/pico_platform/memmap_xip_ram.ld create mode 100644 src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl create mode 100644 test/pico_xip_sram_test/CMakeLists.txt create mode 100644 test/pico_xip_sram_test/pico_critical_xip_sram_test.c create mode 100644 test/pico_xip_sram_test/pico_xip_sram_test.c diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld new file mode 100644 index 000000000..e993da842 --- /dev/null +++ b/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld @@ -0,0 +1 @@ +INCLUDE "memmap_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld b/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld new file mode 100644 index 000000000..6b7b38169 --- /dev/null +++ b/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld @@ -0,0 +1 @@ +INCLUDE "memmap_no_flash_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld new file mode 100644 index 000000000..e993da842 --- /dev/null +++ b/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld @@ -0,0 +1 @@ +INCLUDE "memmap_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld b/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld new file mode 100644 index 000000000..6b7b38169 --- /dev/null +++ b/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld @@ -0,0 +1 @@ +INCLUDE "memmap_no_flash_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld new file mode 100644 index 000000000..10118e764 --- /dev/null +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -0,0 +1 @@ +INCLUDE "memmap_xip_ram.incl" diff --git a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h index 83ba1e6d8..5b88e870b 100644 --- a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h +++ b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h @@ -13,7 +13,7 @@ // PICO_CONFIG: PICO_USE_SW_SPIN_LOCKS, Use software implementation for spin locks, type=bool, default=1 on RP2350 due to errata E2, group=hardware_sync #ifndef PICO_USE_SW_SPIN_LOCKS #if PICO_RP2350 -#define PICO_USE_SW_SPIN_LOCKS 1 +#define PICO_USE_SW_SPIN_LOCKS !PICO_XIP_RAM #endif #endif diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index ea3b99a5a..ffce46e6f 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -11,6 +11,7 @@ #include "hardware/regs/addressmap.h" #include "hardware/regs/sio.h" +#include "hardware/regs/xip.h" #include "pico/binary_info/defs.h" #include "boot/picobin.h" #include "pico/bootrom.h" @@ -20,6 +21,20 @@ #define PICO_CRT0_NEAR_CALLS 0 #endif +// PICO_CONFIG: PICO_CRT0_NO_DATA_COPY, Whether crt0 should perform the data copies - usually copying from flash into sram, default=1 for no_flash builds, 0 otherwise, type=bool, group=pico_crt0 +#ifndef PICO_CRT0_NO_DATA_COPY +#if PICO_RP2040 +#define PICO_CRT0_NO_DATA_COPY (PICO_NO_FLASH && !PICO_USING_XIP_RAM) +#else +#define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH +#endif +#endif + +// PICO_CONFIG: PICO_USE_XIP_CACHE_AS_RAM, Whether to use xip cache as ram, default=1 for xip_ram and xxx_using_xip_ram builds, 0 otherwise, type=bool, group=pico_crt0 +#ifndef PICO_USE_XIP_CACHE_AS_RAM +#define PICO_USE_XIP_CACHE_AS_RAM (PICO_XIP_RAM || PICO_USING_XIP_RAM) +#endif + #ifdef NDEBUG #ifndef COLLAPSE_IRQS #define COLLAPSE_IRQS @@ -457,6 +472,14 @@ hold_non_core0_in_bootrom: b _enter_vtable_in_r0 1: +#if PICO_RP2040 && PICO_USE_XIP_CACHE_AS_RAM +_disable_xip_cache: + // Disable the XIP cache on RP2040 making its SRAM available for use + ldr r0, =(REG_ALIAS_CLR_BITS + XIP_CTRL_BASE + XIP_CTRL_OFFSET) + movs r1, #XIP_CTRL_EN_BITS + str r1, [r0] +#endif + #if !PICO_RP2040 && PICO_EMBED_XIP_SETUP && !PICO_NO_FLASH // Execute boot2 on the core 0 stack (it also gets copied into BOOTRAM due // to inclusion in the data copy table below). Note the reference @@ -477,7 +500,7 @@ _call_xip_setup: // In a NO_FLASH binary, don't perform .data etc copy, since it's loaded // in-place by the SRAM load. Still need to clear .bss -#if !PICO_NO_FLASH +#if !PICO_CRT0_NO_DATA_COPY adr r4, data_cpy_table // assume there is at least one entry @@ -522,11 +545,21 @@ platform_entry: // symbol for stack traces b 1b -#if !PICO_NO_FLASH +#if !PICO_CRT0_NO_DATA_COPY +#if PICO_NO_FLASH +data_cpy: + // skip copies with same source and destination + cmp r1, r2 + bne data_cpy_start + bx lr +#else + // go straight into the copy + #define data_cpy_start data_cpy +#endif data_cpy_loop: ldm r1!, {r0} stm r2!, {r0} -data_cpy: +data_cpy_start: cmp r2, r3 blo data_cpy_loop bx lr @@ -560,6 +593,12 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ +#if PICO_USING_XIP_RAM +.word __xip_ram_text_source__ +.word __xip_ram_text_start__ +.word __xip_ram_text_end__ +#endif + .word 0 // null terminator // ---------------------------------------------------------------------------- diff --git a/src/rp2_common/pico_crt0/crt0_riscv.S b/src/rp2_common/pico_crt0/crt0_riscv.S index e9fc7d94c..3ffd8c3f2 100644 --- a/src/rp2_common/pico_crt0/crt0_riscv.S +++ b/src/rp2_common/pico_crt0/crt0_riscv.S @@ -30,6 +30,14 @@ #define PICO_CRT0_INCLUDE_PICOBIN_END_BLOCK (PICO_CRT0_INCLUDE_PICOBIN_BLOCK && !PICO_NO_FLASH) #endif +#ifndef PICO_CRT0_NO_DATA_COPY +#define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH +#endif + +#ifndef PICO_USE_XIP_CACHE_AS_RAM +#define PICO_USE_XIP_CACHE_AS_RAM (PICO_XIP_RAM || PICO_USING_XIP_RAM) +#endif + // If vectors are in RAM, we put them in the .data section, so that they are // preloaded by _reset_handler (assuming this is not a loaded-in-place // binary). @@ -340,7 +348,7 @@ _call_xip_setup: // In a NO_FLASH binary, don't perform .data etc copy, since it's loaded // in-place by the SRAM load. Still need to clear .bss -#if !PICO_NO_FLASH +#if !PICO_CRT0_NO_DATA_COPY la a4, data_cpy_table // assume there is at least one entry @@ -379,14 +387,25 @@ platform_entry: // symbol for stack traces ebreak j 1b +#if !PICO_CRT0_NO_DATA_COPY +#if PICO_NO_FLASH +data_cpy: + // skip copies with same source and destination + bne a0, a1, data_cpy_start + ret +#else + // go straight into the copy + #define data_cpy_start data_cpy +#endif data_cpy_loop: lw a0, (a1) sw a0, (a2) addi a1, a1, 4 addi a2, a2, 4 -data_cpy: +data_cpy_start: bltu a2, a3, data_cpy_loop ret +#endif .align 2 data_cpy_table: @@ -412,6 +431,12 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ +#if PICO_USING_XIP_RAM +.word __xip_ram_text_source__ +.word __xip_ram_text_start__ +.word __xip_ram_text_end__ +#endif + .word 0 // null terminator // ---------------------------------------------------------------------------- diff --git a/src/rp2_common/pico_crt0/embedded_start_block.inc.S b/src/rp2_common/pico_crt0/embedded_start_block.inc.S index b76b34c79..7ba76eddf 100644 --- a/src/rp2_common/pico_crt0/embedded_start_block.inc.S +++ b/src/rp2_common/pico_crt0/embedded_start_block.inc.S @@ -38,6 +38,10 @@ #define PICO_CRT0_IMAGE_TYPE_TBYB 0 #endif +#ifndef PICO_CRT0_PIN_XIP_SRAM +#define PICO_CRT0_PIN_XIP_SRAM PICO_USE_XIP_CACHE_AS_RAM +#endif + #if PICO_CRT0_IMAGE_TYPE_TBYB #define CRT0_TBYB_FLAG PICOBIN_IMAGE_TYPE_EXE_TBYB_BITS #else @@ -120,6 +124,16 @@ embedded_block: .word __vectors #endif +#if PICO_CRT0_PIN_XIP_SRAM +.byte PICOBIN_BLOCK_ITEM_LOAD_MAP +.byte 0x04 // word size +.byte 0 // pad +.byte 0x01 // number of entries +.word 0 // clear +.word XIP_SRAM_BASE +.word 0 // size +#endif + .byte PICOBIN_BLOCK_ITEM_2BS_LAST .hword (embedded_block_end - embedded_block - 16 ) / 4 // total size of all .byte 0 diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index e85700295..0f59ff33b 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -145,12 +145,12 @@ * * void __time_critical_func(my_func)(int some_arg) { * - * The function is placed in the `.time_critical.` linker section + * The function is placed in the `.time_critical.text.` linker section * * \see __not_in_flash_func */ #ifndef __time_critical_func -#define __time_critical_func(func_name) __not_in_flash_func(func_name) +#define __time_critical_func(func_name) __noinline __attribute__((section(".time_critical.text." __STRING(func_name)))) func_name #endif /*! \brief Indicate a function should not be stored in flash and should not be inlined diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index b327c9d40..5f3076417 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -182,15 +182,25 @@ if (NOT TARGET pico_standard_link) pico_add_link_depend(pico_standard_link ${_LINKER_SCRIPT_EXPRESSION}) unset(_LINKER_SCRIPT_EXPRESSION) + set(NO_FLASH_BINARY_TYPES no_flash no_flash_using_xip_ram xip_ram) + set(COPY_TO_RAM_BINARY_TYPES copy_to_ram copy_to_ram_using_xip_ram) + set(USING_XIP_RAM_BINARY_TYPES no_flash_using_xip_ram copy_to_ram_using_xip_ram) + # PICO_NO_FLASH will be set based on PICO_TARGET_BUILD_TYPE target property being equal to no_flash if set, otherwise to the value of the PICO_NO_FLASH cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_NO_FLASH=$,no_flash>,1,$,$>>>) + target_compile_definitions(pico_standard_link INTERFACE PICO_NO_FLASH=$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>) # PICO_USE_BLOCKED_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to use_blocked_ram if set, otherwise to the value of the PICO_USE_BLOCKED_RAM cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_USE_BLOCKED_RAM, whether this is a 'blocked_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link target_compile_definitions(pico_standard_link INTERFACE PICO_USE_BLOCKED_RAM=$,use_blocked_ram>,1,$,$>>>) # PICO_COPY_TO_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to copy_to_ram if set, otherwise to the value of the PICO_COPY_TO_RAM cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_COPY_TO_RAM=$,copy_to_ram>,1,$,$>>>) + target_compile_definitions(pico_standard_link INTERFACE PICO_COPY_TO_RAM=$,${COPY_TO_RAM_BINARY_TYPES}>,1,$,$>>>) + # PICO_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to xip_ram if set, otherwise to the value of the PICO_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_BUILD_DEFINE: PICO_XIP_RAM, whether this is a 'xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link + target_compile_definitions(pico_standard_link INTERFACE PICO_XIP_RAM=$,xip_ram>,1,$,$>>>) + # PICO_USING_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to xxx_using_xip_ram if set, otherwise to the value of the PICO_USING_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_BUILD_DEFINE: PICO_USING_XIP_RAM, whether this is a 'xxx_using_xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link + target_compile_definitions(pico_standard_link INTERFACE PICO_USING_XIP_RAM=$,${USING_XIP_RAM_BINARY_TYPES}>,1,$,$>>>) target_compile_definitions(pico_standard_link INTERFACE PICO_CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") if (PICO_DEOPTIMIZED_DEBUG AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl new file mode 100644 index 000000000..5fbd7259e --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl @@ -0,0 +1,20 @@ +/* Include platform memory locations */ +INCLUDE "set_memory_locations.incl" + +/* Include memory regions used */ +INCLUDE "memory_flash.incl" +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" +INCLUDE "memory_xip_ram.incl" +INCLUDE "memory_generated.incl" +INCLUDE "memory_extra.incl" + +/* Include aliases for storage memory regions */ +INCLUDE "memory_aliases_default.incl" +REGION_ALIAS("XIP_RAM_STORE", FLASH); + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include copy_to_ram sections */ +INCLUDE "sections_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl new file mode 100644 index 000000000..d3164b30f --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl @@ -0,0 +1,19 @@ +/* Include platform memory locations */ +INCLUDE "set_memory_locations.incl" + +/* Include memory regions used */ +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" +INCLUDE "memory_xip_ram.incl" +INCLUDE "memory_generated.incl" +INCLUDE "memory_extra.incl" + +/* Include aliases for no_flash storage memory regions (alias to themselves) */ +INCLUDE "memory_aliases_no_flash.incl" +REGION_ALIAS("XIP_RAM_STORE", XIP_RAM); + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include no_flash sections */ +INCLUDE "sections_no_flash_using_xip_ram.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl new file mode 100644 index 000000000..4bd284628 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -0,0 +1,28 @@ +/* Include platform memory locations */ +INCLUDE "set_memory_locations.incl" + +/* Allow customisation of XIP_RAM_SCRATCH_SIZE */ +XIP_RAM_SCRATCH_SIZE = DEFINED(XIP_RAM_SCRATCH_SIZE) ? XIP_RAM_SCRATCH_SIZE : 2k; + +/* Split XIP_RAM into RAM and SCRATCH */ +RAM_ORIGIN = XIP_RAM_ORIGIN; +RAM_LENGTH = XIP_RAM_LENGTH - (XIP_RAM_SCRATCH_SIZE*2); +SCRATCH_X_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - (XIP_RAM_SCRATCH_SIZE*2); +SCRATCH_X_LENGTH = XIP_RAM_SCRATCH_SIZE; +SCRATCH_Y_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - XIP_RAM_SCRATCH_SIZE; +SCRATCH_Y_LENGTH = XIP_RAM_SCRATCH_SIZE; + +/* Include memory regions used */ +INCLUDE "memory_ram.incl" +INCLUDE "memory_scratch.incl" +INCLUDE "memory_generated.incl" +INCLUDE "memory_extra.incl" + +/* Include aliases for no_flash storage memory regions (alias to themselves) */ +INCLUDE "memory_aliases_no_flash.incl" + +/* Define entry point symbol */ +ENTRY(_entry_point) + +/* Include no_flash sections */ +INCLUDE "sections_no_flash.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl new file mode 100644 index 000000000..d5d083b64 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl @@ -0,0 +1,11 @@ +SECTIONS +{ + .xip_ram_text : { + __xip_ram_text_start__ = .; + . = ALIGN(4); + *(.time_critical.text*) + . = ALIGN(4); + __xip_ram_text_end__ = .; + } > XIP_RAM AT> XIP_RAM_STORE + __xip_ram_text_source__ = LOADADDR(.xip_ram_text); +} diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl new file mode 100644 index 000000000..4bbd58705 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl @@ -0,0 +1,21 @@ +/* Identical to sections_copy_to_ram, except for section_time_critical_xip_ram_text added after text */ + +INCLUDE "sections_copy_to_ram_text.incl" +INCLUDE "section_time_critical_xip_ram_text.incl" +INCLUDE "section_generated_post_text.incl" +INCLUDE "section_extra_post_text.incl" +INCLUDE "sections_copy_to_ram_data.incl" +INCLUDE "section_generated_post_data.incl" +INCLUDE "section_extra_post_data.incl" +INCLUDE "section_heap.incl" +INCLUDE "sections_scratch.incl" +INCLUDE "section_generated_post_scratch.incl" +INCLUDE "section_extra_post_scratch.incl" +INCLUDE "sections_stack.incl" +INCLUDE "section_flash_end.incl" +INCLUDE "section_end.incl" +INCLUDE "section_generated_post_end.incl" +INCLUDE "section_extra_post_end.incl" +INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_platform_end.incl" +INCLUDE "section_extra_post_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl new file mode 100644 index 000000000..9a5356d92 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl @@ -0,0 +1,20 @@ +/* Identical to sections_no_flash, except for section_time_critical_xip_ram_text added after text */ + +INCLUDE "sections_no_flash_text.incl" +INCLUDE "section_time_critical_xip_ram_text.incl" +INCLUDE "section_generated_post_text.incl" +INCLUDE "section_extra_post_text.incl" +INCLUDE "sections_no_flash_data.incl" +INCLUDE "section_generated_post_data.incl" +INCLUDE "section_extra_post_data.incl" +INCLUDE "section_heap.incl" +INCLUDE "sections_scratch.incl" +INCLUDE "section_generated_post_scratch.incl" +INCLUDE "section_extra_post_scratch.incl" +INCLUDE "sections_stack.incl" +INCLUDE "section_end.incl" +INCLUDE "section_generated_post_end.incl" +INCLUDE "section_extra_post_end.incl" +INCLUDE "section_platform_end.incl" +INCLUDE "section_generated_post_platform_end.incl" +INCLUDE "section_extra_post_platform_end.incl" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 81647ee93..812786eb7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,4 +13,5 @@ if (PICO_ON_DEVICE) add_subdirectory(cmsis_test) add_subdirectory(pico_sem_test) add_subdirectory(pico_sha256_test) + add_subdirectory(pico_xip_sram_test) endif() diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt new file mode 100644 index 000000000..5bac97a80 --- /dev/null +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -0,0 +1,29 @@ +# Use XIP SRAM for time critical functions +add_executable(pico_critical_xip_sram_test pico_critical_xip_sram_test.c) +target_link_libraries(pico_critical_xip_sram_test PRIVATE pico_stdlib pico_multicore hardware_dma) +if (NOT PICO_RP2040) + target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer) +endif() +pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram_using_xip_ram) +pico_enable_stdio_usb(pico_critical_xip_sram_test 1) # test with USB as that invokes flash functions +pico_add_extra_outputs(pico_critical_xip_sram_test) + +# Use XIP SRAM for time critical functions (no_flash build) +add_executable(pico_critical_xip_sram_test_no_flash pico_critical_xip_sram_test.c) +target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib pico_multicore hardware_dma) +if (NOT PICO_RP2040) + target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE hardware_riscv_platform_timer) +endif() +pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash_using_xip_ram) +pico_enable_stdio_usb(pico_critical_xip_sram_test 1) +pico_add_extra_outputs(pico_critical_xip_sram_test_no_flash) + +if (NOT PICO_RP2040) + # XIP SRAM only binary + add_executable(pico_xip_sram_test pico_xip_sram_test.c) + target_link_libraries(pico_xip_sram_test PRIVATE pico_stdlib) + pico_set_binary_type(pico_xip_sram_test xip_ram) + pico_minimize_runtime(pico_xip_sram_test INCLUDE PRINTF PRINTF_MINIMAL DEFAULT_ALARM_POOL PANIC FLOAT) + target_compile_definitions(pico_xip_sram_test PRIVATE PICO_HEAP_SIZE=0x200) + pico_add_extra_outputs(pico_xip_sram_test) +endif() \ No newline at end of file diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c new file mode 100644 index 000000000..d29b050ff --- /dev/null +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c @@ -0,0 +1,158 @@ +#include +#include "pico/stdlib.h" +#include "pico/multicore.h" +#include "hardware/dma.h" +#if PICO_RP2040 +#include "hardware/structs/systick.h" +#else +#include "hardware/riscv_platform_timer.h" +#endif +#include "hardware/structs/busctrl.h" + + +int __time_critical_func(test_func_xip)(void) { +#if PICO_RP2040 + systick_hw->rvr = 0x00ffffff; + systick_hw->cvr = 0; +#else + riscv_timer_set_mtimecmp(0xffffffffffffffff); + riscv_timer_set_mtime(0); +#endif + + volatile uint32_t i = 0; + i += 4; + i += i; + +#if PICO_RP2040 + return systick_hw->rvr - systick_hw->cvr; +#else + return riscv_timer_get_mtime(); +#endif +} + +int __no_inline_not_in_flash_func(test_func_sram)(void) { +#if PICO_RP2040 + systick_hw->rvr = 0x00ffffff; + systick_hw->cvr = 0; +#else + riscv_timer_set_mtimecmp(0xffffffffffffffff); + riscv_timer_set_mtime(0); +#endif + + volatile uint32_t i = 0; + i += 4; + i += i; + +#if PICO_RP2040 + return systick_hw->rvr - systick_hw->cvr; +#else + return riscv_timer_get_mtime(); +#endif +} + + +void core1_entry() { +#ifndef __riscv + // Just read memory repeatedly + pico_default_asm_volatile( + "1:\n" + "ldr r0, =%c0\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "ldmia r0!, {r1-r4}\n" + "b 1b\n" + : : "i" (SRAM_BASE) : "r0", "r1", "r2", "r3", "r4" + ); +#else + pico_default_asm_volatile( + "1:\n" + "li a0, %0\n" + "lw a1, 0(a0)\n" + "lw a2, 4(a0)\n" + "lw a3, 8(a0)\n" + "lw a4, 12(a0)\n" + "addi a0, a0, 16\n" + "lw a1, 0(a0)\n" + "lw a2, 4(a0)\n" + "lw a3, 8(a0)\n" + "lw a4, 12(a0)\n" + "addi a0, a0, 16\n" + "lw a1, 0(a0)\n" + "lw a2, 4(a0)\n" + "lw a3, 8(a0)\n" + "lw a4, 12(a0)\n" + "addi a0, a0, 16\n" + "j 1b\n" + : : "i" (SRAM_BASE) : "a0", "a1", "a2", "a3", "a4" + ); +#endif +} + + +void trigger_dma(void) { + int dat[8]; + for (int i = 0; i < count_of(dat); i++) { + int chan = dma_claim_unused_channel(true); + dma_channel_config c = dma_channel_get_default_config(chan); + channel_config_set_transfer_data_size(&c, DMA_SIZE_32); + channel_config_set_read_increment(&c, true); + channel_config_set_write_increment(&c, true); + uint32_t from = SRAM_BASE; + uint32_t to = SRAM_BASE + ((SRAM4_BASE - SRAM_BASE) / 2); + uint32_t size = ((SRAM4_BASE - SRAM_BASE) / 2) / 4; + dma_channel_configure(chan, &c, (uint32_t*)to, (uint32_t*)from, size, true); + dat[i] = chan; + } + for (int i = 0; i < count_of(dat); i++) { + dma_channel_unclaim(dat[i]); + } +} + + +int main(void) { + stdio_init_all(); + printf("pico_xip_sram_test begins\n"); + + multicore_launch_core1(core1_entry); + +#if PICO_RP2040 + systick_hw->csr = 0x4 | 0x1; // clock source and enable +#else + riscv_timer_set_fullspeed(true); + riscv_timer_set_enabled(true); + riscv_timer_set_mtimecmp(0xffffffffffffffff); +#endif + + // Give core1 and DMA high priority + hw_set_bits(&busctrl_hw->priority, BUSCTRL_BUS_PRIORITY_PROC1_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS | BUSCTRL_BUS_PRIORITY_DMA_W_BITS); + hw_clear_bits(&busctrl_hw->priority, BUSCTRL_BUS_PRIORITY_PROC0_BITS); + + int test_func_xip_cycles = 0; + int test_func_sram_cycles = 0; + for (int i = 0; i < 5; i++) { + printf("running... %d\n", i); + trigger_dma(); + int tmp = test_func_xip(); + test_func_xip_cycles += tmp; + printf("test_func_xip: %d\n", tmp); + tmp = test_func_sram(); + test_func_sram_cycles += tmp; + printf("test_func_sram: %d\n", tmp); + sleep_ms(500); + } + + if (test_func_xip_cycles >= test_func_sram_cycles) { + printf("ERROR: test_func_xip_cycles (%d) >= test_func_sram_cycles (%d)\n", test_func_xip_cycles, test_func_sram_cycles); + return 1; + } else { + printf("SUCCESS: test_func_xip_cycles (%d) < test_func_sram_cycles (%d)\n", test_func_xip_cycles, test_func_sram_cycles); + } + + printf("pico_xip_sram_test ends\n"); + return 0; +} diff --git a/test/pico_xip_sram_test/pico_xip_sram_test.c b/test/pico_xip_sram_test/pico_xip_sram_test.c new file mode 100644 index 000000000..aa3610843 --- /dev/null +++ b/test/pico_xip_sram_test/pico_xip_sram_test.c @@ -0,0 +1,16 @@ +#include +#include "pico/stdlib.h" + + +int main(void) { + stdio_init_all(); + printf("pico_xip_sram_test begins\n"); + + for (int i = 0; i < 5; i++) { + printf("running... %d\n", i); + sleep_ms(500); + } + + printf("pico_xip_sram_test ends\n"); + return 0; +} diff --git a/tools/check_source_files_in_bazel_build.py b/tools/check_source_files_in_bazel_build.py index 5717916d9..b9b455de3 100755 --- a/tools/check_source_files_in_bazel_build.py +++ b/tools/check_source_files_in_bazel_build.py @@ -60,6 +60,8 @@ # Doxygen only files. "**/index.h", "**/doc.h", + # Not supported in Bazel build + "test/pico_xip_sram_test/*", ) From c88dd9b9d6ff8bc8edeb8a1b1fadad6faa170391 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 May 2026 10:30:49 +0100 Subject: [PATCH 32/60] Change implementation to use pico_use_xip_sram_for_time_critical instead of new binary types Adds pico_include_in_generated_section to fill section_generated_... files with lists of include files, and pico_set_compile_definition to allow setting the same definition multiple times on a target without getting warnings --- bazel/config/BUILD.bazel | 1 + bazel/constraint/BUILD.bazel | 5 ++ src/common/pico_base_headers/BUILD.bazel | 1 + .../pico_platform/memmap_blocked_ram.ld | 1 + .../pico_platform/memmap_copy_to_ram.ld | 1 + .../memmap_copy_to_ram_using_xip_ram.ld | 1 - src/rp2040/pico_platform/memmap_default.ld | 1 + src/rp2040/pico_platform/memmap_no_flash.ld | 1 + .../memmap_no_flash_using_xip_ram.ld | 1 - src/rp2350/pico_platform/BUILD.bazel | 24 ++++++ .../pico_platform/memmap_copy_to_ram.ld | 1 + .../memmap_copy_to_ram_using_xip_ram.ld | 1 - src/rp2350/pico_platform/memmap_default.ld | 1 + src/rp2350/pico_platform/memmap_no_flash.ld | 1 + .../memmap_no_flash_using_xip_ram.ld | 1 - src/rp2350/pico_platform/memmap_xip_ram.ld | 41 +++++++++ .../hardware_riscv_platform_timer/BUILD.bazel | 4 +- src/rp2_common/pico_crt0/crt0.S | 20 ++--- src/rp2_common/pico_crt0/crt0_riscv.S | 10 +-- src/rp2_common/pico_standard_link/BUILD.bazel | 9 ++ .../pico_standard_link/CMakeLists.txt | 49 ++++++++--- .../script_include/memmap_copy_to_ram.incl | 1 + .../memmap_copy_to_ram_using_xip_ram.incl | 20 ----- .../script_include/memmap_default.incl | 1 + .../script_include/memmap_no_flash.incl | 1 + .../memmap_no_flash_using_xip_ram.incl | 19 ----- .../script_include/memmap_xip_ram.incl | 2 +- .../memory_aliases_default.incl | 6 -- .../script_include/memory_aliases_flash.incl | 1 + .../memory_aliases_no_flash.incl | 1 + .../memory_aliases_xip_ram_only.incl | 6 ++ .../section_time_critical_xip_ram_text.incl | 12 ++- .../sections_copy_to_ram_using_xip_ram.incl | 21 ----- .../sections_no_flash_using_xip_ram.incl | 20 ----- test/pico_xip_sram_test/BUILD.bazel | 83 +++++++++++++++++++ test/pico_xip_sram_test/CMakeLists.txt | 10 ++- .../BUILD.bazel | 8 ++ .../section_extra_post_text.incl | 1 + tools/bazel_build.py | 1 + tools/check_source_files_in_bazel_build.py | 2 - 40 files changed, 263 insertions(+), 128 deletions(-) delete mode 100644 src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld delete mode 100644 src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld delete mode 100644 src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld delete mode 100644 src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld delete mode 100644 src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl delete mode 100644 src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl create mode 100644 test/pico_xip_sram_test/BUILD.bazel create mode 100644 test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel create mode 100644 test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index 16289db41..aefd8a672 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -226,6 +226,7 @@ string_flag( "no_flash", "copy_to_ram", "blocked_ram", + "xip_ram", ], ) diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel index 571bb9696..630167d72 100644 --- a/bazel/constraint/BUILD.bazel +++ b/bazel/constraint/BUILD.bazel @@ -293,3 +293,8 @@ config_setting( name = "pico_binary_type_blocked_ram", flag_values = {"//bazel/config:PICO_DEFAULT_BINARY_TYPE": "blocked_ram"}, ) + +config_setting( + name = "pico_binary_type_xip_ram", + flag_values = {"//bazel/config:PICO_DEFAULT_BINARY_TYPE": "xip_ram"}, +) diff --git a/src/common/pico_base_headers/BUILD.bazel b/src/common/pico_base_headers/BUILD.bazel index e988e7bde..b54e999aa 100644 --- a/src/common/pico_base_headers/BUILD.bazel +++ b/src/common/pico_base_headers/BUILD.bazel @@ -78,6 +78,7 @@ cc_library( "//bazel/constraint:pico_binary_type_no_flash": ["PICO_NO_FLASH=1"], "//bazel/constraint:pico_binary_type_copy_to_ram": ["PICO_COPY_TO_RAM=1"], "//bazel/constraint:pico_binary_type_blocked_ram": ["PICO_USE_BLOCKED_RAM=1"], + "//bazel/constraint:pico_binary_type_xip_ram": ["PICO_XIP_RAM=1"], "//conditions:default": [], }), ) diff --git a/src/rp2040/pico_platform/memmap_blocked_ram.ld b/src/rp2040/pico_platform/memmap_blocked_ram.ld index 345036962..dbcf47065 100644 --- a/src/rp2040/pico_platform/memmap_blocked_ram.ld +++ b/src/rp2040/pico_platform/memmap_blocked_ram.ld @@ -14,6 +14,7 @@ INCLUDE "memmap_default.incl" * ├── memory_flash.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram.ld index a9e541e8d..6d997c812 100644 --- a/src/rp2040/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2040/pico_platform/memmap_copy_to_ram.ld @@ -11,6 +11,7 @@ INCLUDE "memmap_copy_to_ram.incl" * ├── memory_flash.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld deleted file mode 100644 index e993da842..000000000 --- a/src/rp2040/pico_platform/memmap_copy_to_ram_using_xip_ram.ld +++ /dev/null @@ -1 +0,0 @@ -INCLUDE "memmap_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2040/pico_platform/memmap_default.ld b/src/rp2040/pico_platform/memmap_default.ld index f7e561e7c..76df54f21 100644 --- a/src/rp2040/pico_platform/memmap_default.ld +++ b/src/rp2040/pico_platform/memmap_default.ld @@ -11,6 +11,7 @@ INCLUDE "memmap_default.incl" * ├── memory_flash.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_no_flash.ld b/src/rp2040/pico_platform/memmap_no_flash.ld index 9e86b518d..b0533d0b7 100644 --- a/src/rp2040/pico_platform/memmap_no_flash.ld +++ b/src/rp2040/pico_platform/memmap_no_flash.ld @@ -10,6 +10,7 @@ INCLUDE "memmap_no_flash.incl" * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld b/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld deleted file mode 100644 index 6b7b38169..000000000 --- a/src/rp2040/pico_platform/memmap_no_flash_using_xip_ram.ld +++ /dev/null @@ -1 +0,0 @@ -INCLUDE "memmap_no_flash_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/BUILD.bazel b/src/rp2350/pico_platform/BUILD.bazel index 4efa080e5..65d4adc6a 100644 --- a/src/rp2350/pico_platform/BUILD.bazel +++ b/src/rp2350/pico_platform/BUILD.bazel @@ -61,6 +61,7 @@ exports_files( "memmap_copy_to_ram.ld", "memmap_default.ld", "memmap_no_flash.ld", + "memmap_xip_ram.ld", ], ) @@ -79,6 +80,11 @@ linker_scripts( link_scripts = ["memmap_no_flash.ld"], ) +linker_scripts( + name = "memmap_xip_ram", + link_scripts = ["memmap_xip_ram.ld"], +) + cc_library( name = "default_linker_script", target_compatible_with = ["//bazel/constraint:rp2350"], @@ -133,3 +139,21 @@ cc_library( "memmap_no_flash", ], ) + +# PICO_BUILD_DEFINE: PICO_XIP_RAM, whether this is a 'xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link +cc_library( + name = "xip_ram_linker_script", + target_compatible_with = ["//bazel/constraint:rp2350"], + visibility = [ + "//src/rp2_common/pico_standard_link:__pkg__", + ], + # The order of the linker scripts below is important. + # Prevent buildifier from reordering them. + # buildifier: leave-alone + deps = [ + "//src/rp2_common/pico_crt0:no_warn_rwx_flag", + "//src/rp2350/pico_platform/script_include:rp2350_linker_scripts", + "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "memmap_xip_ram", + ], +) diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram.ld index d8c1d8bec..2728c0d4b 100644 --- a/src/rp2350/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2350/pico_platform/memmap_copy_to_ram.ld @@ -11,6 +11,7 @@ INCLUDE "memmap_copy_to_ram.incl" * ├── memory_flash.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld deleted file mode 100644 index e993da842..000000000 --- a/src/rp2350/pico_platform/memmap_copy_to_ram_using_xip_ram.ld +++ /dev/null @@ -1 +0,0 @@ -INCLUDE "memmap_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_default.ld b/src/rp2350/pico_platform/memmap_default.ld index b1d5121df..a53587f6c 100644 --- a/src/rp2350/pico_platform/memmap_default.ld +++ b/src/rp2350/pico_platform/memmap_default.ld @@ -11,6 +11,7 @@ INCLUDE "memmap_default.incl" * ├── memory_flash.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_no_flash.ld b/src/rp2350/pico_platform/memmap_no_flash.ld index 34b3a33e7..c7c11b2ab 100644 --- a/src/rp2350/pico_platform/memmap_no_flash.ld +++ b/src/rp2350/pico_platform/memmap_no_flash.ld @@ -10,6 +10,7 @@ INCLUDE "memmap_no_flash.incl" * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld b/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld deleted file mode 100644 index 6b7b38169..000000000 --- a/src/rp2350/pico_platform/memmap_no_flash_using_xip_ram.ld +++ /dev/null @@ -1 +0,0 @@ -INCLUDE "memmap_no_flash_using_xip_ram.incl" diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 10118e764..8d1b17307 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -1 +1,42 @@ INCLUDE "memmap_xip_ram.incl" + +/* BEGIN_MEMMAP_INCLUDE_TREE + * This is the default include tree for this file (generated by tools/memmap_annotate.py + * and tools/memmap_include_tree.py). To override any files in this tree, see the + * pico_add_linker_script_override_path CMake function under pico_standard_link. + * + * memmap_xip_ram.ld rp2350/pico_platform + * └── memmap_xip_ram.incl rp2_common/pico_standard_link + * ├── set_memory_locations.incl rp2_common/pico_standard_link + * ├── memory_ram.incl rp2_common/pico_standard_link + * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_generated.incl rp2_common/pico_standard_link + * ├── memory_extra.incl rp2_common/pico_standard_link + * ├── memory_aliases_xip_ram_only.incl rp2_common/pico_standard_link + * └── sections_no_flash.incl rp2_common/pico_standard_link + * ├── sections_no_flash_text.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_text.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_rodata.incl rp2_common/pico_standard_link + * │ ├── sections_arm_ex.incl rp2_common/pico_standard_link + * │ └── section_binary_info.incl rp2_common/pico_standard_link + * ├── section_generated_post_text.incl rp2_common/pico_standard_link + * ├── section_extra_post_text.incl rp2_common/pico_standard_link + * ├── sections_no_flash_data.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_data.incl rp2_common/pico_standard_link + * │ ├── section_uninitialized_data.incl rp2_common/pico_standard_link + * │ ├── section_bss.incl rp2_common/pico_standard_link + * │ └── section_persistent_data.incl rp2_common/pico_standard_link + * ├── section_generated_post_data.incl rp2_common/pico_standard_link + * ├── section_extra_post_data.incl rp2_common/pico_standard_link + * ├── section_heap.incl rp2_common/pico_standard_link + * ├── sections_scratch.incl rp2_common/pico_standard_link + * ├── section_generated_post_scratch.incl rp2_common/pico_standard_link + * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link + * ├── sections_stack.incl rp2_common/pico_standard_link + * ├── section_end.incl rp2_common/pico_standard_link + * ├── section_generated_post_end.incl rp2_common/pico_standard_link + * ├── section_extra_post_end.incl rp2_common/pico_standard_link + * ├── section_platform_end.incl rp2350/pico_platform + * ├── section_generated_post_platform_end.incl rp2_common/pico_standard_link + * └── section_extra_post_platform_end.incl rp2_common/pico_standard_link + * END_MEMMAP_INCLUDE_TREE */ diff --git a/src/rp2_common/hardware_riscv_platform_timer/BUILD.bazel b/src/rp2_common/hardware_riscv_platform_timer/BUILD.bazel index 790be1e40..943e0504d 100644 --- a/src/rp2_common/hardware_riscv_platform_timer/BUILD.bazel +++ b/src/rp2_common/hardware_riscv_platform_timer/BUILD.bazel @@ -1,5 +1,5 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") -load("//bazel:defs.bzl", "compatible_with_rp2") +load("//bazel:defs.bzl", "compatible_with_rp2", "incompatible_with_config") package(default_visibility = ["//visibility:public"]) @@ -7,7 +7,7 @@ cc_library( name = "hardware_riscv_platform_timer", hdrs = ["include/hardware/riscv_platform_timer.h"], includes = ["include"], - target_compatible_with = compatible_with_rp2() + ["@platforms//cpu:riscv32"], + target_compatible_with = compatible_with_rp2() + incompatible_with_config("//bazel/constraint:rp2040"), deps = [ "//src/rp2_common:hardware_structs", "//src/rp2_common:pico_platform", diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index b3a4fa8aa..39b6e8303 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -25,20 +25,20 @@ #define PICO_CRT0_NEAR_CALLS 0 #endif +// PICO_CONFIG: PICO_USE_XIP_CACHE_AS_RAM, Whether to use xip cache as ram, default=PICO_XIP_RAM, type=bool, group=pico_crt0 +#ifndef PICO_USE_XIP_CACHE_AS_RAM +#define PICO_USE_XIP_CACHE_AS_RAM PICO_XIP_RAM +#endif + // PICO_CONFIG: PICO_CRT0_NO_DATA_COPY, Whether crt0 should perform the data copies - usually copying from flash into sram, default=1 for no_flash builds, 0 otherwise, type=bool, group=pico_crt0 #ifndef PICO_CRT0_NO_DATA_COPY #if PICO_RP2040 -#define PICO_CRT0_NO_DATA_COPY (PICO_NO_FLASH && !PICO_USING_XIP_RAM) +#define PICO_CRT0_NO_DATA_COPY (PICO_NO_FLASH && !PICO_USE_XIP_CACHE_AS_RAM) #else #define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH #endif #endif -// PICO_CONFIG: PICO_USE_XIP_CACHE_AS_RAM, Whether to use xip cache as ram, default=1 for xip_ram and xxx_using_xip_ram builds, 0 otherwise, type=bool, group=pico_crt0 -#ifndef PICO_USE_XIP_CACHE_AS_RAM -#define PICO_USE_XIP_CACHE_AS_RAM (PICO_XIP_RAM || PICO_USING_XIP_RAM) -#endif - #ifdef NDEBUG #ifndef COLLAPSE_IRQS #define COLLAPSE_IRQS @@ -662,10 +662,10 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ -#if PICO_USING_XIP_RAM -.word __xip_ram_text_source__ -.word __xip_ram_text_start__ -.word __xip_ram_text_end__ +#if PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM +.word __xip_ram_time_critical_text_source__ +.word __xip_ram_time_critical_text_start__ +.word __xip_ram_time_critical_text_end__ #endif .word 0 // null terminator diff --git a/src/rp2_common/pico_crt0/crt0_riscv.S b/src/rp2_common/pico_crt0/crt0_riscv.S index 5641b5f42..e13f32d96 100644 --- a/src/rp2_common/pico_crt0/crt0_riscv.S +++ b/src/rp2_common/pico_crt0/crt0_riscv.S @@ -39,7 +39,7 @@ #endif #ifndef PICO_USE_XIP_CACHE_AS_RAM -#define PICO_USE_XIP_CACHE_AS_RAM (PICO_XIP_RAM || PICO_USING_XIP_RAM) +#define PICO_USE_XIP_CACHE_AS_RAM PICO_XIP_RAM #endif // If vectors are in RAM, we put them in the .data section, so that they are @@ -496,10 +496,10 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ -#if PICO_USING_XIP_RAM -.word __xip_ram_text_source__ -.word __xip_ram_text_start__ -.word __xip_ram_text_end__ +#if PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM +.word __xip_ram_time_critical_text_source__ +.word __xip_ram_time_critical_text_start__ +.word __xip_ram_time_critical_text_end__ #endif .word 0 // null terminator diff --git a/src/rp2_common/pico_standard_link/BUILD.bazel b/src/rp2_common/pico_standard_link/BUILD.bazel index 4ebfdd428..5047fe72c 100644 --- a/src/rp2_common/pico_standard_link/BUILD.bazel +++ b/src/rp2_common/pico_standard_link/BUILD.bazel @@ -35,6 +35,7 @@ alias( "//bazel/constraint:pico_binary_type_no_flash": "//src/rp2_common/pico_standard_link:no_flash_linker_script", "//bazel/constraint:pico_binary_type_copy_to_ram": "//src/rp2_common/pico_standard_link:copy_to_ram_linker_script", "//bazel/constraint:pico_binary_type_blocked_ram": "//src/rp2_common/pico_standard_link:blocked_ram_linker_script", + "//bazel/constraint:pico_binary_type_xip_ram": "//src/rp2_common/pico_standard_link:xip_ram_linker_script", # Then for the default type "//bazel/constraint:rp2040": "//src/rp2040/pico_platform:default_linker_script", "//bazel/constraint:rp2350": "//src/rp2350/pico_platform:default_linker_script", @@ -68,6 +69,14 @@ alias( }), ) +alias( + name = "xip_ram_linker_script", + actual = select({ + "//bazel/constraint:rp2350": "//src/rp2350/pico_platform:xip_ram_linker_script", + "//conditions:default": "//bazel:incompatible_cc_lib", + }), +) + cc_library( name = "pico_standard_link", target_compatible_with = compatible_with_rp2(), diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 448ec58e9..720608dba 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -109,6 +109,38 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE}) endfunction() + function(pico_include_in_generated_section TARGET SECTION FILE) + get_target_property(already_generated ${TARGET} PICO_TARGET_LINKER_SCRIPT_INCLUDE_${SECTION}) + set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_INCLUDE_${SECTION} "${FILE}") + # Make sure directory is empty before generating files, to avoid stale overrides + file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/generated/pico_standard_link/${TARGET}) + if (NOT already_generated) + file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/generated/pico_standard_link/${TARGET}/section_generated_${SECTION}.incl + CONTENT "INCLUDE \"$,\"\nINCLUDE \">\"" + ) + pico_add_linker_script_override_path(${TARGET} ${CMAKE_BINARY_DIR}/generated/pico_standard_link/${TARGET}) + endif() + endfunction() + + function(pico_set_compile_definition TARGET DEFINE VALUE) + # To avoid redefined warnings + get_target_property(already_set ${TARGET} PICO_TARGET_DEFINITION_${DEFINE}) + if (already_set MATCHES "NOTFOUND") + set_target_properties(${TARGET} PROPERTIES PICO_TARGET_DEFINITION_${DEFINE} ${VALUE}) + target_compile_definitions(${TARGET} PRIVATE ${DEFINE}=${VALUE}) + else() + if (NOT ${VALUE} STREQUAL ${already_set}) + message(FATAL_ERROR "Multiple calls to pico_set_compile_definition for ${DEFINE} with different values (${already_set} vs ${VALUE})") + endif() + endif() + endfunction() + + function(pico_use_xip_sram_for_time_critical TARGET) + target_compile_definitions(${TARGET} PRIVATE PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1) + pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) # may be set elsewhere too + pico_include_in_generated_section(${TARGET} post_text "section_time_critical_xip_ram_text.incl") + endfunction() + # PICO_CMAKE_CONFIG: PICO_DEFAULT_BINARY_TYPE, The default binary type to use, type=string, default=default, group=build # slightly messy as we support both the preferred PICO_DEFAULT_BINARY_TYPE and the individual variables if (NOT PICO_DEFAULT_BINARY_TYPE) @@ -184,25 +216,22 @@ if (NOT TARGET pico_standard_link) pico_add_link_depend(pico_standard_link ${_LINKER_SCRIPT_EXPRESSION}) unset(_LINKER_SCRIPT_EXPRESSION) - set(NO_FLASH_BINARY_TYPES no_flash no_flash_using_xip_ram xip_ram) - set(COPY_TO_RAM_BINARY_TYPES copy_to_ram copy_to_ram_using_xip_ram) - set(USING_XIP_RAM_BINARY_TYPES no_flash_using_xip_ram copy_to_ram_using_xip_ram) + set(NO_FLASH_BINARY_TYPES no_flash xip_ram) + set(COPY_TO_RAM_BINARY_TYPES copy_to_ram) + set(XIP_RAM_BINARY_TYPES xip_ram) - # PICO_NO_FLASH will be set based on PICO_TARGET_BUILD_TYPE target property being equal to no_flash if set, otherwise to the value of the PICO_NO_FLASH cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_NO_FLASH will be set based on PICO_TARGET_BUILD_TYPE target property being in NO_FLASH_BINARY_TYPES if set, otherwise to the value of the PICO_NO_FLASH cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link target_compile_definitions(pico_standard_link INTERFACE PICO_NO_FLASH=$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>) # PICO_USE_BLOCKED_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to use_blocked_ram if set, otherwise to the value of the PICO_USE_BLOCKED_RAM cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_USE_BLOCKED_RAM, whether this is a 'blocked_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link target_compile_definitions(pico_standard_link INTERFACE PICO_USE_BLOCKED_RAM=$,use_blocked_ram>,1,$,$>>>) - # PICO_COPY_TO_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to copy_to_ram if set, otherwise to the value of the PICO_COPY_TO_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_COPY_TO_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being in COPY_TO_RAM_BINARY_TYPES if set, otherwise to the value of the PICO_COPY_TO_RAM cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link target_compile_definitions(pico_standard_link INTERFACE PICO_COPY_TO_RAM=$,${COPY_TO_RAM_BINARY_TYPES}>,1,$,$>>>) - # PICO_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to xip_ram if set, otherwise to the value of the PICO_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being in XIP_RAM_BINARY_TYPES if set, otherwise to the value of the PICO_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else # PICO_BUILD_DEFINE: PICO_XIP_RAM, whether this is a 'xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_XIP_RAM=$,xip_ram>,1,$,$>>>) - # PICO_USING_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to xxx_using_xip_ram if set, otherwise to the value of the PICO_USING_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else - # PICO_BUILD_DEFINE: PICO_USING_XIP_RAM, whether this is a 'xxx_using_xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_USING_XIP_RAM=$,${USING_XIP_RAM_BINARY_TYPES}>,1,$,$>>>) + target_compile_definitions(pico_standard_link INTERFACE PICO_XIP_RAM=$,${XIP_RAM_BINARY_TYPES}>,1,$,$>>>) target_compile_definitions(pico_standard_link INTERFACE PICO_CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") if (PICO_DEOPTIMIZED_DEBUG AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl index f54a3e833..90f3f700b 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl deleted file mode 100644 index 5fbd7259e..000000000 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram_using_xip_ram.incl +++ /dev/null @@ -1,20 +0,0 @@ -/* Include platform memory locations */ -INCLUDE "set_memory_locations.incl" - -/* Include memory regions used */ -INCLUDE "memory_flash.incl" -INCLUDE "memory_ram.incl" -INCLUDE "memory_scratch.incl" -INCLUDE "memory_xip_ram.incl" -INCLUDE "memory_generated.incl" -INCLUDE "memory_extra.incl" - -/* Include aliases for storage memory regions */ -INCLUDE "memory_aliases_default.incl" -REGION_ALIAS("XIP_RAM_STORE", FLASH); - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include copy_to_ram sections */ -INCLUDE "sections_copy_to_ram_using_xip_ram.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl index 4f3233509..3c4645620 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl @@ -5,6 +5,7 @@ INCLUDE "set_memory_locations.incl" INCLUDE "memory_flash.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl index c043470e9..c6771e0da 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl @@ -4,6 +4,7 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl deleted file mode 100644 index d3164b30f..000000000 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash_using_xip_ram.incl +++ /dev/null @@ -1,19 +0,0 @@ -/* Include platform memory locations */ -INCLUDE "set_memory_locations.incl" - -/* Include memory regions used */ -INCLUDE "memory_ram.incl" -INCLUDE "memory_scratch.incl" -INCLUDE "memory_xip_ram.incl" -INCLUDE "memory_generated.incl" -INCLUDE "memory_extra.incl" - -/* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "memory_aliases_no_flash.incl" -REGION_ALIAS("XIP_RAM_STORE", XIP_RAM); - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include no_flash sections */ -INCLUDE "sections_no_flash_using_xip_ram.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl index 4bd284628..64c4c912a 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -19,7 +19,7 @@ INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" /* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "memory_aliases_no_flash.incl" +INCLUDE "memory_aliases_xip_ram_only.incl" /* Define entry point symbol */ ENTRY(_entry_point) diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl deleted file mode 100644 index 370b63ed1..000000000 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_default.incl +++ /dev/null @@ -1,6 +0,0 @@ -/* Store everything in flash */ - -REGION_ALIAS("TEXT_STORE", FLASH); -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/script_include/memory_aliases_flash.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_flash.incl index 370b63ed1..200d878bb 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_flash.incl @@ -2,5 +2,6 @@ REGION_ALIAS("TEXT_STORE", FLASH); REGION_ALIAS("RAM_STORE", FLASH); +REGION_ALIAS("XIP_RAM_STORE", FLASH); REGION_ALIAS("SCRATCH_X_STORE", FLASH); REGION_ALIAS("SCRATCH_Y_STORE", FLASH); diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl index 258072736..2d48e870f 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl @@ -2,5 +2,6 @@ REGION_ALIAS("TEXT_STORE", RAM); REGION_ALIAS("RAM_STORE", RAM); +REGION_ALIAS("XIP_RAM_STORE", XIP_RAM); REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); REGION_ALIAS("SCRATCH_Y_STORE", SCRATCH_Y); diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl new file mode 100644 index 000000000..258072736 --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl @@ -0,0 +1,6 @@ +/* Store everything where it came from (ram/scratch) */ + +REGION_ALIAS("TEXT_STORE", RAM); +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_standard_link/script_include/section_time_critical_xip_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl index d5d083b64..5d933adcc 100644 --- a/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl +++ b/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl @@ -1,11 +1,15 @@ +/* Defines the following symbols for use by code: + __xip_ram_time_critical_text_start__, __xip_ram_time_critical_text_end__, __xip_ram_time_critical_text_source__ +*/ + SECTIONS { - .xip_ram_text : { - __xip_ram_text_start__ = .; + .xip_ram_time_critical_text : { + __xip_ram_time_critical_text_start__ = .; . = ALIGN(4); *(.time_critical.text*) . = ALIGN(4); - __xip_ram_text_end__ = .; + __xip_ram_time_critical_text_end__ = .; } > XIP_RAM AT> XIP_RAM_STORE - __xip_ram_text_source__ = LOADADDR(.xip_ram_text); + __xip_ram_time_critical_text_source__ = LOADADDR(.xip_ram_time_critical_text); } diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl deleted file mode 100644 index 4bbd58705..000000000 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_using_xip_ram.incl +++ /dev/null @@ -1,21 +0,0 @@ -/* Identical to sections_copy_to_ram, except for section_time_critical_xip_ram_text added after text */ - -INCLUDE "sections_copy_to_ram_text.incl" -INCLUDE "section_time_critical_xip_ram_text.incl" -INCLUDE "section_generated_post_text.incl" -INCLUDE "section_extra_post_text.incl" -INCLUDE "sections_copy_to_ram_data.incl" -INCLUDE "section_generated_post_data.incl" -INCLUDE "section_extra_post_data.incl" -INCLUDE "section_heap.incl" -INCLUDE "sections_scratch.incl" -INCLUDE "section_generated_post_scratch.incl" -INCLUDE "section_extra_post_scratch.incl" -INCLUDE "sections_stack.incl" -INCLUDE "section_flash_end.incl" -INCLUDE "section_end.incl" -INCLUDE "section_generated_post_end.incl" -INCLUDE "section_extra_post_end.incl" -INCLUDE "section_platform_end.incl" -INCLUDE "section_generated_post_platform_end.incl" -INCLUDE "section_extra_post_platform_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl deleted file mode 100644 index 9a5356d92..000000000 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash_using_xip_ram.incl +++ /dev/null @@ -1,20 +0,0 @@ -/* Identical to sections_no_flash, except for section_time_critical_xip_ram_text added after text */ - -INCLUDE "sections_no_flash_text.incl" -INCLUDE "section_time_critical_xip_ram_text.incl" -INCLUDE "section_generated_post_text.incl" -INCLUDE "section_extra_post_text.incl" -INCLUDE "sections_no_flash_data.incl" -INCLUDE "section_generated_post_data.incl" -INCLUDE "section_extra_post_data.incl" -INCLUDE "section_heap.incl" -INCLUDE "sections_scratch.incl" -INCLUDE "section_generated_post_scratch.incl" -INCLUDE "section_extra_post_scratch.incl" -INCLUDE "sections_stack.incl" -INCLUDE "section_end.incl" -INCLUDE "section_generated_post_end.incl" -INCLUDE "section_extra_post_end.incl" -INCLUDE "section_platform_end.incl" -INCLUDE "section_generated_post_platform_end.incl" -INCLUDE "section_extra_post_platform_end.incl" diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel new file mode 100644 index 000000000..996ccfa32 --- /dev/null +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -0,0 +1,83 @@ +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("//bazel:defs.bzl", "compatible_with_rp2") +load("//bazel/util:transition.bzl", "pico_set_binary_type", "pico_set_linker_script") + +package(default_visibility = ["//visibility:public"]) + +alias( + name = "pico_critical_xip_sram_test_extra_link", + actual = select({ + "//bazel/constraint:rp2040": "//bazel:empty_cc_lib", + "//conditions:default": "//src/rp2_common/hardware_riscv_platform_timer", + }), + visibility = ["//visibility:private"], +) + +cc_binary( + name = "pico_critical_xip_sram_test_actual", + testonly = True, + srcs = ["pico_critical_xip_sram_test.c"], + tags = ["manual"], # Built via pico_critical_xip_sram_test + deps = [ + ":pico_critical_xip_sram_test_extra_link", + "//src/rp2_common/hardware_dma", + "//src/rp2_common/pico_multicore", + "//src/rp2_common/pico_stdlib", + ], +) + +# pico_use_xip_sram_for_time_critical isn't implemented in Bazel, so manually +# do that function with this linker script +cc_library( + name = "pico_critical_xip_sram_test_linker_script", + defines = [ + "PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", + "PICO_USE_XIP_CACHE_AS_RAM=1", + ], + # The order of the linker scripts below is important. + # Prevent buildifier from reordering them. + # buildifier: leave-alone + deps = [ + "//test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts", + "//src/rp2_common/pico_standard_link:default_linker_script", + ], +) + +pico_set_binary_type( + name = "pico_critical_xip_sram_test_typed", + testonly = True, + src = ":pico_critical_xip_sram_test_actual", + binary_type = "copy_to_ram", + target_compatible_with = compatible_with_rp2(), +) + +pico_set_linker_script( + name = "pico_critical_xip_sram_test", + testonly = True, + src = ":pico_critical_xip_sram_test_typed", + linker_script = "//test/pico_xip_sram_test:pico_critical_xip_sram_test_linker_script", + target_compatible_with = compatible_with_rp2(), +) + +# Currently doesn't fit, because bazel doesn't have a pico_minimize_runtime equivalent +exports_files(["pico_xip_sram_test.c"]) +# cc_binary( +# name = "pico_xip_sram_test_actual", +# testonly = True, +# srcs = ["pico_xip_sram_test.c"], +# tags = ["manual"], # Built via pico_xip_sram_test +# deps = [ +# "//src/rp2_common/pico_stdlib", +# "//src/rp2_common/pico_multicore", +# "//src/rp2_common/hardware_dma", +# ], +# ) +# +# pico_set_binary_type( +# name = "pico_xip_sram_test", +# testonly = True, +# src = ":pico_xip_sram_test_actual", +# binary_type = "xip_ram", +# target_compatible_with = compatible_with_rp2() + incompatible_with_config("//bazel/constraint:rp2040"), +# ) diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index 5bac97a80..e91e09659 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -4,7 +4,8 @@ target_link_libraries(pico_critical_xip_sram_test PRIVATE pico_stdlib pico_multi if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer) endif() -pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram_using_xip_ram) +pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram) +pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test) pico_enable_stdio_usb(pico_critical_xip_sram_test 1) # test with USB as that invokes flash functions pico_add_extra_outputs(pico_critical_xip_sram_test) @@ -14,12 +15,13 @@ target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib p if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE hardware_riscv_platform_timer) endif() -pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash_using_xip_ram) +pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash) +pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test_no_flash) pico_enable_stdio_usb(pico_critical_xip_sram_test 1) pico_add_extra_outputs(pico_critical_xip_sram_test_no_flash) -if (NOT PICO_RP2040) - # XIP SRAM only binary +if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) + # XIP SRAM only binary, clang version is too big add_executable(pico_xip_sram_test pico_xip_sram_test.c) target_link_libraries(pico_xip_sram_test PRIVATE pico_stdlib) pico_set_binary_type(pico_xip_sram_test xip_ram) diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel new file mode 100644 index 000000000..2132016fd --- /dev/null +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel @@ -0,0 +1,8 @@ +load("//bazel/util:pico_linker_scripts.bzl", "linker_scripts") + +package(default_visibility = ["//test/pico_xip_sram_test:__pkg__"]) + +linker_scripts( + name = "pico_critical_xip_sram_test_scripts", + include_scripts = glob(["*.incl"]), +) diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl new file mode 100644 index 000000000..41fa5962b --- /dev/null +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl @@ -0,0 +1 @@ +INCLUDE "section_time_critical_xip_ram_text.incl" \ No newline at end of file diff --git a/tools/bazel_build.py b/tools/bazel_build.py index 7aa18173b..f14c968bf 100755 --- a/tools/bazel_build.py +++ b/tools/bazel_build.py @@ -57,6 +57,7 @@ "//test/pico_low_power_test:low_power_test_simple", "//test/pico_low_power_test:external_sleep_timer", "//test/pico_async_context_test:pico_async_context_test", + "//test/pico_xip_sram_test:pico_critical_xip_sram_test", # Pretty much only Picotool and pioasm build on Windows. "//..." if os.name == "nt" else "", diff --git a/tools/check_source_files_in_bazel_build.py b/tools/check_source_files_in_bazel_build.py index b9b455de3..5717916d9 100755 --- a/tools/check_source_files_in_bazel_build.py +++ b/tools/check_source_files_in_bazel_build.py @@ -60,8 +60,6 @@ # Doxygen only files. "**/index.h", "**/doc.h", - # Not supported in Bazel build - "test/pico_xip_sram_test/*", ) From 31fc9682ddce6ca13b49197ee1a9baaff792195a Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 May 2026 10:56:01 +0100 Subject: [PATCH 33/60] Add some CMake function docs --- .../pico_standard_link/CMakeLists.txt | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 720608dba..e8586aa48 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -109,6 +109,17 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE}) endfunction() + # pico_include_in_generated_section(TARGET SECTION FILE) + # \brief\ Append a linker script include file to a generated section of the linker script + # + # Arranges for FILE to be INCLUDEd inside the generated SECTION of the target's linker script. + # + # This is primarily intended for internal SDK use - users should instead override the + # section_extra_SECTION.incl files, using pico_add_linker_script_override_path. + # + # \param\ TARGET The target whose linker script should be modified + # \param\ SECTION The linker script section name to append to (e.g. post_text) + # \param\ FILE Path to the linker script fragment to INCLUDE function(pico_include_in_generated_section TARGET SECTION FILE) get_target_property(already_generated ${TARGET} PICO_TARGET_LINKER_SCRIPT_INCLUDE_${SECTION}) set_property(TARGET ${TARGET} APPEND PROPERTY PICO_TARGET_LINKER_SCRIPT_INCLUDE_${SECTION} "${FILE}") @@ -122,8 +133,17 @@ if (NOT TARGET pico_standard_link) endif() endfunction() + # pico_set_compile_definition(TARGET DEFINE VALUE) + # \brief\ Set a compile definition on a target, guarding against conflicting redefinitions + # + # Equivalent to target_compile_definitions(TARGET PRIVATE DEFINE=VALUE) but tracks the value + # as a target property so that a second call with the same DEFINE and the same VALUE is silently + # ignored, while a second call with a different VALUE is a fatal error. + # + # \param\ TARGET The target to add the compile definition to + # \param\ DEFINE The preprocessor symbol name + # \param\ VALUE The value to assign to the symbol function(pico_set_compile_definition TARGET DEFINE VALUE) - # To avoid redefined warnings get_target_property(already_set ${TARGET} PICO_TARGET_DEFINITION_${DEFINE}) if (already_set MATCHES "NOTFOUND") set_target_properties(${TARGET} PROPERTIES PICO_TARGET_DEFINITION_${DEFINE} ${VALUE}) @@ -135,6 +155,18 @@ if (NOT TARGET pico_standard_link) endif() endfunction() + # pico_use_xip_sram_for_time_critical(TARGET) + # \brief\ Place time-critical code for the target into XIP SRAM + # + # Configures the target to run functions marked __time_critical_func() from XIP SRAM rather than + # normal SRAM, as it has dedicated ports which are otherwise unused in no_flash and copy_to_ram + # binaries. This sets PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1, PICO_USE_XIP_CACHE_AS_RAM=1, and + # injects the required linker script fragment via pico_include_in_generated_section. + # + # This should not be used for flash binaries, as the XIP ports are in use there, and therefore + # this will just make time-critical functions slower. + # + # \param\ TARGET The target whose time-critical functions should run from XIP SRAM function(pico_use_xip_sram_for_time_critical TARGET) target_compile_definitions(${TARGET} PRIVATE PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1) pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) # may be set elsewhere too From b8631a789b7f16de16d32e5936f0ee7a4ff7161c Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 May 2026 11:27:24 +0100 Subject: [PATCH 34/60] Fix bazel and RP2350 build Has missed setting PICO_CRT0_PIN_XIP_SRAM --- .../pico_crt0/embedded_start_block.inc.S | 2 +- test/pico_xip_sram_test/BUILD.bazel | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/rp2_common/pico_crt0/embedded_start_block.inc.S b/src/rp2_common/pico_crt0/embedded_start_block.inc.S index 000da904b..52899b861 100644 --- a/src/rp2_common/pico_crt0/embedded_start_block.inc.S +++ b/src/rp2_common/pico_crt0/embedded_start_block.inc.S @@ -39,7 +39,7 @@ #endif #ifndef PICO_CRT0_PIN_XIP_SRAM -#define PICO_CRT0_PIN_XIP_SRAM 0 +#define PICO_CRT0_PIN_XIP_SRAM (PICO_USE_XIP_CACHE_AS_RAM || PICO_XIP_SRAM) #endif #if PICO_CRT0_IMAGE_TYPE_TBYB diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel index 996ccfa32..71cf1bcba 100644 --- a/test/pico_xip_sram_test/BUILD.bazel +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary") load("@rules_cc//cc:cc_library.bzl", "cc_library") load("//bazel:defs.bzl", "compatible_with_rp2") -load("//bazel/util:transition.bzl", "pico_set_binary_type", "pico_set_linker_script") +load("//bazel/util:transition.bzl", "extra_copts_for_all_deps", "pico_set_binary_type", "pico_set_linker_script") package(default_visibility = ["//visibility:public"]) @@ -31,10 +31,6 @@ cc_binary( # do that function with this linker script cc_library( name = "pico_critical_xip_sram_test_linker_script", - defines = [ - "PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", - "PICO_USE_XIP_CACHE_AS_RAM=1", - ], # The order of the linker scripts below is important. # Prevent buildifier from reordering them. # buildifier: leave-alone @@ -52,10 +48,21 @@ pico_set_binary_type( target_compatible_with = compatible_with_rp2(), ) +extra_copts_for_all_deps( + name = "pico_critical_xip_sram_test_optioned", + testonly = True, + src = ":pico_critical_xip_sram_test_typed", + extra_copts = [ + "-DPICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", + "-DPICO_USE_XIP_CACHE_AS_RAM=1", + ], + target_compatible_with = compatible_with_rp2(), +) + pico_set_linker_script( name = "pico_critical_xip_sram_test", testonly = True, - src = ":pico_critical_xip_sram_test_typed", + src = ":pico_critical_xip_sram_test_optioned", linker_script = "//test/pico_xip_sram_test:pico_critical_xip_sram_test_linker_script", target_compatible_with = compatible_with_rp2(), ) From d13ddb497beb39324862defac5687dffa85e1d18 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 13 May 2026 11:44:24 +0100 Subject: [PATCH 35/60] Fix bazel build Ordering of transistions matters --- test/pico_xip_sram_test/BUILD.bazel | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel index 71cf1bcba..a91440a32 100644 --- a/test/pico_xip_sram_test/BUILD.bazel +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -48,22 +48,22 @@ pico_set_binary_type( target_compatible_with = compatible_with_rp2(), ) -extra_copts_for_all_deps( - name = "pico_critical_xip_sram_test_optioned", +pico_set_linker_script( + name = "pico_critical_xip_sram_test_linked", testonly = True, src = ":pico_critical_xip_sram_test_typed", - extra_copts = [ - "-DPICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", - "-DPICO_USE_XIP_CACHE_AS_RAM=1", - ], + linker_script = "//test/pico_xip_sram_test:pico_critical_xip_sram_test_linker_script", target_compatible_with = compatible_with_rp2(), ) -pico_set_linker_script( +extra_copts_for_all_deps( name = "pico_critical_xip_sram_test", testonly = True, - src = ":pico_critical_xip_sram_test_optioned", - linker_script = "//test/pico_xip_sram_test:pico_critical_xip_sram_test_linker_script", + src = ":pico_critical_xip_sram_test_linked", + extra_copts = [ + "-DPICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", + "-DPICO_USE_XIP_CACHE_AS_RAM=1", + ], target_compatible_with = compatible_with_rp2(), ) From 4428d395784e916746ab1c5f2561ed020e02530f Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 May 2026 10:48:49 +0100 Subject: [PATCH 36/60] Improve new __time_critical_func description Special treatment is no longer in the future --- .../include/pico/platform/sections.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index 4f2d1b6c7..e49a58e21 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -162,10 +162,13 @@ * \ingroup pico_platform * * Decorates a function name, such that the function will execute from RAM (assuming it is not inlined - * into a flash function by the compiler) to avoid possible flash latency. Currently this macro is identical + * into a flash function by the compiler) to avoid possible flash latency. By default, this macro is identical * in implementation to `__not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` - * may in the future be treated more specially to reduce the overhead when calling such function from a flash - * function. + * can be treated more specially to reduce the overhead when calling such function. + * + * For binaries that are not executing from flash (eg copy_to_ram and no_flash), one special treatment can be + * using the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the + * XIP ports would be otherwise unused. * * For example a function called my_func taking an int parameter: * From d7b4f6de0c5dce6ef26dc606bdebd001ffd14119 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 May 2026 17:00:52 +0100 Subject: [PATCH 37/60] Add pico_test, and improve SRAM thrashing --- test/pico_xip_sram_test/CMakeLists.txt | 4 +- .../pico_critical_xip_sram_test.c | 84 ++++++++++++------- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index e91e09659..165a9698c 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -1,6 +1,6 @@ # Use XIP SRAM for time critical functions add_executable(pico_critical_xip_sram_test pico_critical_xip_sram_test.c) -target_link_libraries(pico_critical_xip_sram_test PRIVATE pico_stdlib pico_multicore hardware_dma) +target_link_libraries(pico_critical_xip_sram_test PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer) endif() @@ -11,7 +11,7 @@ pico_add_extra_outputs(pico_critical_xip_sram_test) # Use XIP SRAM for time critical functions (no_flash build) add_executable(pico_critical_xip_sram_test_no_flash pico_critical_xip_sram_test.c) -target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib pico_multicore hardware_dma) +target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE hardware_riscv_platform_timer) endif() diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c index d29b050ff..00c1c41ca 100644 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c @@ -1,5 +1,6 @@ #include #include "pico/stdlib.h" +#include "pico/test.h" #include "pico/multicore.h" #include "hardware/dma.h" #if PICO_RP2040 @@ -10,6 +11,9 @@ #include "hardware/structs/busctrl.h" +PICOTEST_MODULE_NAME("XIP_SRAM", "critical xip sram test"); + + int __time_critical_func(test_func_xip)(void) { #if PICO_RP2040 systick_hw->rvr = 0x00ffffff; @@ -22,6 +26,9 @@ int __time_critical_func(test_func_xip)(void) { volatile uint32_t i = 0; i += 4; i += i; + i += 7; + i += i; + i += i; #if PICO_RP2040 return systick_hw->rvr - systick_hw->cvr; @@ -42,6 +49,9 @@ int __no_inline_not_in_flash_func(test_func_sram)(void) { volatile uint32_t i = 0; i += 4; i += i; + i += 7; + i += i; + i += i; #if PICO_RP2040 return systick_hw->rvr - systick_hw->cvr; @@ -52,19 +62,26 @@ int __no_inline_not_in_flash_func(test_func_sram)(void) { void core1_entry() { + // Just read memory from SRAM bank 0 repeatedly + // word-striped across 4 banks, so read every 16 bytes #ifndef __riscv - // Just read memory repeatedly pico_default_asm_volatile( "1:\n" "ldr r0, =%c0\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" - "ldmia r0!, {r1-r4}\n" + "ldr r1, [r0, #0]\n" + "ldr r2, [r0, #16]\n" + "ldr r3, [r0, #32]\n" + "ldr r4, [r0, #48]\n" + "adds r0, #64\n" + "ldr r1, [r0, #0]\n" + "ldr r2, [r0, #16]\n" + "ldr r3, [r0, #32]\n" + "ldr r4, [r0, #48]\n" + "adds r0, #64\n" + "ldr r1, [r0, #0]\n" + "ldr r2, [r0, #16]\n" + "ldr r3, [r0, #32]\n" + "ldr r4, [r0, #48]\n" "b 1b\n" : : "i" (SRAM_BASE) : "r0", "r1", "r2", "r3", "r4" ); @@ -73,20 +90,19 @@ void core1_entry() { "1:\n" "li a0, %0\n" "lw a1, 0(a0)\n" - "lw a2, 4(a0)\n" - "lw a3, 8(a0)\n" - "lw a4, 12(a0)\n" - "addi a0, a0, 16\n" + "lw a2, 16(a0)\n" + "lw a3, 32(a0)\n" + "lw a4, 48(a0)\n" + "addi a0, a0, 64\n" "lw a1, 0(a0)\n" - "lw a2, 4(a0)\n" - "lw a3, 8(a0)\n" - "lw a4, 12(a0)\n" - "addi a0, a0, 16\n" + "lw a2, 16(a0)\n" + "lw a3, 32(a0)\n" + "lw a4, 48(a0)\n" + "addi a0, a0, 64\n" "lw a1, 0(a0)\n" - "lw a2, 4(a0)\n" - "lw a3, 8(a0)\n" - "lw a4, 12(a0)\n" - "addi a0, a0, 16\n" + "lw a2, 16(a0)\n" + "lw a3, 32(a0)\n" + "lw a4, 48(a0)\n" "j 1b\n" : : "i" (SRAM_BASE) : "a0", "a1", "a2", "a3", "a4" ); @@ -105,7 +121,7 @@ void trigger_dma(void) { uint32_t from = SRAM_BASE; uint32_t to = SRAM_BASE + ((SRAM4_BASE - SRAM_BASE) / 2); uint32_t size = ((SRAM4_BASE - SRAM_BASE) / 2) / 4; - dma_channel_configure(chan, &c, (uint32_t*)to, (uint32_t*)from, size, true); + dma_channel_configure(chan, &c, (uint32_t*)to, (uint32_t*)from, dma_encode_transfer_count(size), true); dat[i] = chan; } for (int i = 0; i < count_of(dat); i++) { @@ -118,6 +134,16 @@ int main(void) { stdio_init_all(); printf("pico_xip_sram_test begins\n"); + PICOTEST_START(); + + PICOTEST_START_SECTION("test_func_addresses") + printf("test_func_xip at %p\n", test_func_xip); + printf("test_func_sram at %p\n", test_func_sram); + + PICOTEST_CHECK((uint32_t)test_func_xip >= XIP_SRAM_BASE && (uint32_t)test_func_xip < XIP_SRAM_END, "test_func_xip is not in XIP SRAM"); + PICOTEST_CHECK((uint32_t)test_func_sram >= SRAM_STRIPED_BASE && (uint32_t)test_func_sram < SRAM4_BASE, "test_func_sram is not in SRAM 0-3"); + PICOTEST_END_SECTION() + multicore_launch_core1(core1_entry); #if PICO_RP2040 @@ -132,6 +158,7 @@ int main(void) { hw_set_bits(&busctrl_hw->priority, BUSCTRL_BUS_PRIORITY_PROC1_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS | BUSCTRL_BUS_PRIORITY_DMA_W_BITS); hw_clear_bits(&busctrl_hw->priority, BUSCTRL_BUS_PRIORITY_PROC0_BITS); + PICOTEST_START_SECTION("test_func"); int test_func_xip_cycles = 0; int test_func_sram_cycles = 0; for (int i = 0; i < 5; i++) { @@ -140,19 +167,16 @@ int main(void) { int tmp = test_func_xip(); test_func_xip_cycles += tmp; printf("test_func_xip: %d\n", tmp); + trigger_dma(); tmp = test_func_sram(); test_func_sram_cycles += tmp; printf("test_func_sram: %d\n", tmp); sleep_ms(500); } - if (test_func_xip_cycles >= test_func_sram_cycles) { - printf("ERROR: test_func_xip_cycles (%d) >= test_func_sram_cycles (%d)\n", test_func_xip_cycles, test_func_sram_cycles); - return 1; - } else { - printf("SUCCESS: test_func_xip_cycles (%d) < test_func_sram_cycles (%d)\n", test_func_xip_cycles, test_func_sram_cycles); - } + PICOTEST_CHECK(test_func_xip_cycles < test_func_sram_cycles, "test_func_xip took longer than test_func_sram"); + + PICOTEST_END_SECTION(); - printf("pico_xip_sram_test ends\n"); - return 0; + PICOTEST_END_TEST(); } From 394d9ad7961057da6f373db2d2329dd534c06de5 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 14 May 2026 17:10:37 +0100 Subject: [PATCH 38/60] fix bazel build --- test/pico_xip_sram_test/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel index a91440a32..ef9b49c8e 100644 --- a/test/pico_xip_sram_test/BUILD.bazel +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -24,6 +24,7 @@ cc_binary( "//src/rp2_common/hardware_dma", "//src/rp2_common/pico_multicore", "//src/rp2_common/pico_stdlib", + "//test/pico_test", ], ) From 6a923249f87fd8cc2987cf3b186af5c1bdb5e0ac Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 15 May 2026 14:33:28 +0100 Subject: [PATCH 39/60] fixup merge --- src/rp2350/pico_platform/memmap_xip_ram.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 8d1b17307..56c936fa2 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -24,7 +24,7 @@ INCLUDE "memmap_xip_ram.incl" * ├── sections_no_flash_data.incl rp2_common/pico_standard_link * │ ├── section_no_flash_data.incl rp2_common/pico_standard_link * │ ├── section_uninitialized_data.incl rp2_common/pico_standard_link - * │ ├── section_bss.incl rp2_common/pico_standard_link + * │ ├── section_tls.incl rp2_common/pico_standard_link * │ └── section_persistent_data.incl rp2_common/pico_standard_link * ├── section_generated_post_data.incl rp2_common/pico_standard_link * ├── section_extra_post_data.incl rp2_common/pico_standard_link From 67325b9e4e34e16fc2347d0e15c1584a40684c54 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 15 May 2026 14:37:10 +0100 Subject: [PATCH 40/60] Move memory_xip_ram.incl to match location in other PRs --- src/rp2040/pico_platform/memmap_blocked_ram.ld | 2 +- src/rp2040/pico_platform/memmap_copy_to_ram.ld | 2 +- src/rp2040/pico_platform/memmap_default.ld | 2 +- src/rp2040/pico_platform/memmap_no_flash.ld | 2 +- src/rp2350/pico_platform/memmap_copy_to_ram.ld | 2 +- src/rp2350/pico_platform/memmap_default.ld | 2 +- src/rp2350/pico_platform/memmap_no_flash.ld | 2 +- .../pico_standard_link/script_include/memmap_copy_to_ram.incl | 2 +- .../pico_standard_link/script_include/memmap_default.incl | 2 +- .../pico_standard_link/script_include/memmap_no_flash.incl | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rp2040/pico_platform/memmap_blocked_ram.ld b/src/rp2040/pico_platform/memmap_blocked_ram.ld index ada9c3450..049e0b099 100644 --- a/src/rp2040/pico_platform/memmap_blocked_ram.ld +++ b/src/rp2040/pico_platform/memmap_blocked_ram.ld @@ -12,9 +12,9 @@ INCLUDE "memmap_default.incl" * └── memmap_default.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_flash.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram.ld index 11041c86f..330f17023 100644 --- a/src/rp2040/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2040/pico_platform/memmap_copy_to_ram.ld @@ -9,9 +9,9 @@ INCLUDE "memmap_copy_to_ram.incl" * └── memmap_copy_to_ram.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_flash.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_default.ld b/src/rp2040/pico_platform/memmap_default.ld index 313614a44..b02671ea7 100644 --- a/src/rp2040/pico_platform/memmap_default.ld +++ b/src/rp2040/pico_platform/memmap_default.ld @@ -9,9 +9,9 @@ INCLUDE "memmap_default.incl" * └── memmap_default.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_flash.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_no_flash.ld b/src/rp2040/pico_platform/memmap_no_flash.ld index c060e9c41..1ae20f2de 100644 --- a/src/rp2040/pico_platform/memmap_no_flash.ld +++ b/src/rp2040/pico_platform/memmap_no_flash.ld @@ -8,9 +8,9 @@ INCLUDE "memmap_no_flash.incl" * memmap_no_flash.ld rp2040/pico_platform * └── memmap_no_flash.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram.ld index a8c61b534..b9437c80e 100644 --- a/src/rp2350/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2350/pico_platform/memmap_copy_to_ram.ld @@ -9,9 +9,9 @@ INCLUDE "memmap_copy_to_ram.incl" * └── memmap_copy_to_ram.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_flash.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_default.ld b/src/rp2350/pico_platform/memmap_default.ld index a2ccaebf2..badeb4630 100644 --- a/src/rp2350/pico_platform/memmap_default.ld +++ b/src/rp2350/pico_platform/memmap_default.ld @@ -9,9 +9,9 @@ INCLUDE "memmap_default.incl" * └── memmap_default.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_flash.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_no_flash.ld b/src/rp2350/pico_platform/memmap_no_flash.ld index 432b0e8d9..55e4d085a 100644 --- a/src/rp2350/pico_platform/memmap_no_flash.ld +++ b/src/rp2350/pico_platform/memmap_no_flash.ld @@ -8,9 +8,9 @@ INCLUDE "memmap_no_flash.incl" * memmap_no_flash.ld rp2350/pico_platform * └── memmap_no_flash.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl index 90f3f700b..5d05531f5 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_copy_to_ram.incl @@ -3,9 +3,9 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ INCLUDE "memory_flash.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" -INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl index 3c4645620..27d50deee 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_default.incl @@ -3,9 +3,9 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ INCLUDE "memory_flash.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" -INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl index c6771e0da..8c9cf4ba2 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl @@ -2,9 +2,9 @@ INCLUDE "set_memory_locations.incl" /* Include memory regions used */ +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" -INCLUDE "memory_xip_ram.incl" INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" From 3af197196a32fb2d670a8f3927189c6c448b3fc0 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Mon, 18 May 2026 10:44:27 +0100 Subject: [PATCH 41/60] Review fixups Place RAM_SECTION_NAME in .time_critical.text Typo in __time_critical_func description --- .../pico_platform_sections/include/pico/platform/sections.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index e49a58e21..7b3d251ed 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -164,7 +164,7 @@ * Decorates a function name, such that the function will execute from RAM (assuming it is not inlined * into a flash function by the compiler) to avoid possible flash latency. By default, this macro is identical * in implementation to `__not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` - * can be treated more specially to reduce the overhead when calling such function. + * can be treated more specially to reduce the overhead when calling such a function. * * For binaries that are not executing from flash (eg copy_to_ram and no_flash), one special treatment can be * using the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the @@ -201,7 +201,7 @@ #else #ifndef RAM_SECTION_NAME -#define RAM_SECTION_NAME(x) .time_critical.##x +#define RAM_SECTION_NAME(x) .time_critical.text.##x #endif #ifndef SECTION_NAME From 1c0ad0eec9890c6248443b4c68e99459ab0992c2 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 21 May 2026 13:04:45 +0100 Subject: [PATCH 42/60] fixup merge --- src/rp2350/pico_platform/memmap_xip_ram.ld | 2 ++ .../pico_standard_link/script_include/memmap_xip_ram.incl | 1 + .../script_include/memory_aliases_xip_ram_only.incl | 1 + 3 files changed, 4 insertions(+) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 56c936fa2..613c2b4e9 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -8,6 +8,7 @@ INCLUDE "memmap_xip_ram.incl" * memmap_xip_ram.ld rp2350/pico_platform * └── memmap_xip_ram.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link + * ├── memory_psram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link @@ -33,6 +34,7 @@ INCLUDE "memmap_xip_ram.incl" * ├── section_generated_post_scratch.incl rp2_common/pico_standard_link * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link + * ├── sections_psram.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link * ├── section_extra_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl index 64c4c912a..146bb531d 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -13,6 +13,7 @@ SCRATCH_Y_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - XIP_RAM_SCRATCH_SIZE; SCRATCH_Y_LENGTH = XIP_RAM_SCRATCH_SIZE; /* Include memory regions used */ +INCLUDE "memory_psram.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" INCLUDE "memory_generated.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl index 258072736..27505d4ca 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl @@ -2,5 +2,6 @@ REGION_ALIAS("TEXT_STORE", RAM); REGION_ALIAS("RAM_STORE", RAM); +REGION_ALIAS("PSRAM_STORE", RAM); /* Can't store in PSRAM */ REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); REGION_ALIAS("SCRATCH_Y_STORE", SCRATCH_Y); From 671fb1b41050e63a40b09be375c00a9a42abcb47 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Thu, 21 May 2026 16:23:12 +0100 Subject: [PATCH 43/60] review fixup --- .../pico_platform_sections/include/pico/platform/sections.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index 47226dcd5..61fce381d 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -194,7 +194,7 @@ * * For binaries that are not executing from flash (eg copy_to_ram and no_flash), one special treatment can be * using the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the - * XIP ports would be otherwise unused. + * XIP AHB ports would be otherwise unused. * * For example a function called my_func taking an int parameter: * From 53a5b1b624fb621fa5f4ed19393557f24404ed2f Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 21 May 2026 13:14:12 -0500 Subject: [PATCH 44/60] add memmap_xip_ram.cmake --- src/rp2350/pico_platform/memmap_xip_ram.cmake | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/rp2350/pico_platform/memmap_xip_ram.cmake diff --git a/src/rp2350/pico_platform/memmap_xip_ram.cmake b/src/rp2350/pico_platform/memmap_xip_ram.cmake new file mode 100644 index 000000000..185cd9f8e --- /dev/null +++ b/src/rp2350/pico_platform/memmap_xip_ram.cmake @@ -0,0 +1,38 @@ +# Auto-generated by tools/memmap_annotate.py — do not edit by hand +function(pico_add_memmap_link_depends_internal TARGET) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2350/pico_platform/script_include/section_platform_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_extra.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_generated.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_psram.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_ram.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_scratch.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_platform_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_scratch.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_text.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_generated_post_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_generated_post_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_generated_post_platform_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_generated_post_scratch.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_generated_post_text.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_heap.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_no_flash_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_no_flash_rodata.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_no_flash_text.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_persistent_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_text.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_psram.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_scratch.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_stack.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/set_memory_locations.incl) +endfunction() From 2bc1d3816e37987a6e5f99ad94194fcc6250236c Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Thu, 21 May 2026 13:40:40 -0500 Subject: [PATCH 45/60] some minor cleanup --- src/rp2_common/pico_crt0/crt0.S | 4 ++-- src/rp2_common/pico_crt0/crt0_riscv.S | 4 ++-- .../pico_platform_sections/include/pico/platform/sections.h | 6 +++--- src/rp2_common/pico_standard_link/CMakeLists.txt | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 73ffff82f..f8f2908ea 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -550,8 +550,7 @@ platform_entry: // symbol for stack traces data_cpy: // skip copies with same source and destination cmp r1, r2 - bne data_cpy_start - bx lr + beq data_cpy_done #else // go straight into the copy #define data_cpy_start data_cpy @@ -562,6 +561,7 @@ data_cpy_loop: data_cpy_start: cmp r2, r3 blo data_cpy_loop +data_cpy_done: bx lr #endif diff --git a/src/rp2_common/pico_crt0/crt0_riscv.S b/src/rp2_common/pico_crt0/crt0_riscv.S index ec8ef401d..fbdeb0d0b 100644 --- a/src/rp2_common/pico_crt0/crt0_riscv.S +++ b/src/rp2_common/pico_crt0/crt0_riscv.S @@ -395,8 +395,7 @@ platform_entry: // symbol for stack traces #if PICO_NO_FLASH data_cpy: // skip copies with same source and destination - bne a0, a1, data_cpy_start - ret + beq a0, a1, data_cpy_done #else // go straight into the copy #define data_cpy_start data_cpy @@ -408,6 +407,7 @@ data_cpy_loop: addi a2, a2, 4 data_cpy_start: bltu a2, a3, data_cpy_loop +data_cpy_done: ret #endif diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index 61fce381d..42c24c668 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -192,9 +192,9 @@ * in implementation to `__not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` * can be treated more specially to reduce the overhead when calling such a function. * - * For binaries that are not executing from flash (eg copy_to_ram and no_flash), one special treatment can be - * using the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the - * XIP AHB ports would be otherwise unused. + * For binaries that are not executing from flash (eg copy_to_ram and no_flash), there is the option + * to use the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the + * XIP AHB ports would be otherwise unused. * * For example a function called my_func taking an int parameter: * diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 86c55af89..53da8cbdb 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -30,7 +30,6 @@ if (NOT TARGET pico_standard_link) set_target_properties(${TARGET} PROPERTIES ${PROP} "${_LINK_DEPENDS}") endfunction() - # pico_add_memmap_link_depends(TARGET TYPE) # \brief\ Add link dependencies for the binary type to the target # From 9a1bc1f858e7d3a45e3066598cab86c93082a16b Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 21 May 2026 19:45:35 +0100 Subject: [PATCH 46/60] Doesn't require data copy for no_flash use_xip_cache_as_ram on RP2040 The code is still loaded before boot on rp2040, so doesn't need copying --- src/rp2_common/pico_crt0/crt0.S | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index f8f2908ea..287d2ce88 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -28,12 +28,8 @@ // PICO_CONFIG: PICO_CRT0_NO_DATA_COPY, Whether crt0 should perform the data copies - usually copying from flash into sram, default=1 for no_flash builds, 0 otherwise, type=bool, group=pico_crt0 #ifndef PICO_CRT0_NO_DATA_COPY -#if PICO_RP2040 -#define PICO_CRT0_NO_DATA_COPY (PICO_NO_FLASH && !PICO_USE_XIP_CACHE_AS_RAM) -#else #define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH #endif -#endif #ifdef NDEBUG #ifndef COLLAPSE_IRQS From 5875b1407f94303263475fd0c824f63fb9a12152 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 22 May 2026 10:59:08 +0100 Subject: [PATCH 47/60] remove copy-paste typo --- test/pico_xip_sram_test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index 165a9698c..4d52a73ed 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -17,7 +17,6 @@ if (NOT PICO_RP2040) endif() pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash) pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test_no_flash) -pico_enable_stdio_usb(pico_critical_xip_sram_test 1) pico_add_extra_outputs(pico_critical_xip_sram_test_no_flash) if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) From 586b158a707c45ad0e8f6ff682bd825a554236c4 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 22 May 2026 15:50:36 +0100 Subject: [PATCH 48/60] Fixes for compatibility with low power Skip low power unpinning when PICO_USE_XIP_CACHE_AS_RAM is set Take xip_ram as argument to pico_set_persistent_data_loc, to allow placing normally instead of specifying address Add pico_critical_xip_sram_test_low_power test to check usin xip_ram for both works --- src/rp2_common/pico_low_power/CMakeLists.txt | 10 ++++++++-- .../pico_runtime_init/include/pico/runtime_init.h | 4 ++-- test/pico_xip_sram_test/CMakeLists.txt | 8 ++++++++ test/pico_xip_sram_test/pico_critical_xip_sram_test.c | 10 ++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_low_power/CMakeLists.txt b/src/rp2_common/pico_low_power/CMakeLists.txt index 327d8bbf3..d715caacb 100644 --- a/src/rp2_common/pico_low_power/CMakeLists.txt +++ b/src/rp2_common/pico_low_power/CMakeLists.txt @@ -34,13 +34,19 @@ pico_promote_common_scope_vars() # It also sets PICO_CRT0_PIN_XIP_SRAM=1 to pin the XIP_SRAM, # if the persistent data is stored in XIP_SRAM. # -# \param\ PERSISTENT_DATA_LOC The persistent data location to set +# \param\ PERSISTENT_DATA_LOC The persistent data location to set - optionally pass the memory region name (supports xip_ram) function(pico_set_persistent_data_loc TARGET PERSISTENT_DATA_LOC) if (PICO_RP2040) message(FATAL_ERROR "pico_set_persistent_data_loc is not supported on RP2040") endif() - if (PERSISTENT_DATA_LOC LESS 0x20000000) + if (PERSISTENT_DATA_LOC STREQUAL xip_ram) + # XIP_SRAM, so pin the XIP_SRAM + target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_PIN_XIP_SRAM=1) + set(PERSISTENT_DATA_SECTION "XIP_RAM") + # Clear PERSISTENT_DATA_LOC, so the section is placed normally + unset(PERSISTENT_DATA_LOC) + elseif (PERSISTENT_DATA_LOC LESS 0x20000000) # XIP_SRAM, so pin the XIP_SRAM target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_PIN_XIP_SRAM=1) set(PERSISTENT_DATA_SECTION "XIP_RAM") diff --git a/src/rp2_common/pico_runtime_init/include/pico/runtime_init.h b/src/rp2_common/pico_runtime_init/include/pico/runtime_init.h index bcf10dce5..64f0e5732 100644 --- a/src/rp2_common/pico_runtime_init/include/pico/runtime_init.h +++ b/src/rp2_common/pico_runtime_init/include/pico/runtime_init.h @@ -450,11 +450,11 @@ void runtime_init_bootrom_locking_enable(void); #endif #ifndef PICO_RUNTIME_SKIP_INIT_LOW_POWER_CACHE_UNPIN -#define PICO_RUNTIME_SKIP_INIT_LOW_POWER_CACHE_UNPIN !HAS_POWMAN_TIMER || PICO_NO_FLASH || !PICO_CRT0_PIN_XIP_SRAM +#define PICO_RUNTIME_SKIP_INIT_LOW_POWER_CACHE_UNPIN (!HAS_POWMAN_TIMER || PICO_NO_FLASH || PICO_USE_XIP_CACHE_AS_RAM || !PICO_CRT0_PIN_XIP_SRAM) #endif #ifndef PICO_RUNTIME_NO_INIT_LOW_POWER_CACHE_UNPIN -#define PICO_RUNTIME_NO_INIT_LOW_POWER_CACHE_UNPIN !HAS_POWMAN_TIMER || PICO_NO_FLASH || !PICO_CRT0_PIN_XIP_SRAM +#define PICO_RUNTIME_NO_INIT_LOW_POWER_CACHE_UNPIN (!HAS_POWMAN_TIMER || PICO_NO_FLASH || PICO_USE_XIP_CACHE_AS_RAM || !PICO_CRT0_PIN_XIP_SRAM) #endif // Run user callback if this is a powman reboot - do this later, so user has a full SDK to work with diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index 4d52a73ed..88db94347 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -27,4 +27,12 @@ if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) pico_minimize_runtime(pico_xip_sram_test INCLUDE PRINTF PRINTF_MINIMAL DEFAULT_ALARM_POOL PANIC FLOAT) target_compile_definitions(pico_xip_sram_test PRIVATE PICO_HEAP_SIZE=0x200) pico_add_extra_outputs(pico_xip_sram_test) + + # Low power and critical XIP SRAM + add_executable(pico_critical_xip_sram_test_low_power pico_critical_xip_sram_test.c) + target_link_libraries(pico_critical_xip_sram_test_low_power PRIVATE pico_stdlib pico_multicore hardware_dma pico_test hardware_riscv_platform_timer pico_low_power) + pico_set_binary_type(pico_critical_xip_sram_test_low_power copy_to_ram) + pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test_low_power) + pico_set_persistent_data_loc(pico_critical_xip_sram_test_low_power xip_ram) + pico_add_extra_outputs(pico_critical_xip_sram_test_low_power) endif() \ No newline at end of file diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c index 00c1c41ca..ae260401a 100644 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c @@ -10,6 +10,10 @@ #endif #include "hardware/structs/busctrl.h" +#if LIB_PICO_LOW_POWER +int __persistent_data(some_data); +#endif + PICOTEST_MODULE_NAME("XIP_SRAM", "critical xip sram test"); @@ -135,6 +139,12 @@ int main(void) { printf("pico_xip_sram_test begins\n"); PICOTEST_START(); + + #if LIB_PICO_LOW_POWER + PICOTEST_START_SECTION("test_low_power") + PICOTEST_CHECK(some_data == 0, "persistent some_data is not 0"); + PICOTEST_END_SECTION() + #endif PICOTEST_START_SECTION("test_func_addresses") printf("test_func_xip at %p\n", test_func_xip); From 1b661d7e249e82f437a6ccf3284410e33d971fa1 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Tue, 26 May 2026 17:58:39 +0100 Subject: [PATCH 49/60] Improve pico_set_persistent_data_loc description --- src/rp2_common/pico_low_power/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_low_power/CMakeLists.txt b/src/rp2_common/pico_low_power/CMakeLists.txt index d715caacb..06018e335 100644 --- a/src/rp2_common/pico_low_power/CMakeLists.txt +++ b/src/rp2_common/pico_low_power/CMakeLists.txt @@ -34,7 +34,7 @@ pico_promote_common_scope_vars() # It also sets PICO_CRT0_PIN_XIP_SRAM=1 to pin the XIP_SRAM, # if the persistent data is stored in XIP_SRAM. # -# \param\ PERSISTENT_DATA_LOC The persistent data location to set - optionally pass the memory region name (supports xip_ram) +# \param\ PERSISTENT_DATA_LOC The persistent data location to set (e.g. 0x20040000), or the memory region name (currently supports xip_ram) function(pico_set_persistent_data_loc TARGET PERSISTENT_DATA_LOC) if (PICO_RP2040) message(FATAL_ERROR "pico_set_persistent_data_loc is not supported on RP2040") From 91859e1554b704e75a3b28dfbd3453abe2358d1e Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 26 May 2026 16:52:25 -0500 Subject: [PATCH 50/60] add () inside #define --- .../hardware_sync_spin_lock/include/hardware/sync/spin_lock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h index 5b88e870b..a5b383fc4 100644 --- a/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h +++ b/src/rp2_common/hardware_sync_spin_lock/include/hardware/sync/spin_lock.h @@ -13,7 +13,7 @@ // PICO_CONFIG: PICO_USE_SW_SPIN_LOCKS, Use software implementation for spin locks, type=bool, default=1 on RP2350 due to errata E2, group=hardware_sync #ifndef PICO_USE_SW_SPIN_LOCKS #if PICO_RP2350 -#define PICO_USE_SW_SPIN_LOCKS !PICO_XIP_RAM +#define PICO_USE_SW_SPIN_LOCKS (!PICO_XIP_RAM) #endif #endif From d86a3626c8c993cf22535b8735595476b603808f Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Wed, 27 May 2026 11:50:28 +0100 Subject: [PATCH 51/60] Update memory_extra.incl examples PSRAM and xip_ram are now supported by default --- .../script_include/memory_extra.incl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rp2_common/pico_standard_link/script_include/memory_extra.incl b/src/rp2_common/pico_standard_link/script_include/memory_extra.incl index cdd16166c..d90993a93 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_extra.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_extra.incl @@ -2,16 +2,16 @@ This file can be overridden to add extra memory regions. - For example, to add a PSRAM region, you would replace - this file with: + For example, to add an extra flash region for the second 4MiB + of flash, you could replace this file with: MEMORY { - PSRAM(rwx) : ORIGIN = 0x11000000, LENGTH = 8M + EXTRA_FLASH(rx) : ORIGIN = 0x10400000, LENGTH = 4M } - Or to include a XIP_RAM region, you would replace - this file with: + Or to include the FLASH region in a no_flash build, you could + replace this file with: - INCLUDE "memory_xip_ram.incl" + INCLUDE "memory_flash.incl" */ From 1a972ae13b0b8450110ffee65fb5f622f9486216 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Thu, 28 May 2026 17:47:35 +0100 Subject: [PATCH 52/60] Improve binary type generator expressions Use PICO_DEFAULT_BINARY_TYPE in the generator expressions, to remove need for PICO_NO_FLASH etc, and fixup the legacy variable handling to that effect Now throws an error if both PICO_DEFAULT_BINARY_TYPE and one of PICO_NO_FLASH etc are specified - just use PICO_DEFAULT_BINARY_TYPE --- .../pico_standard_link/CMakeLists.txt | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 53da8cbdb..320a4fe45 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -224,6 +224,13 @@ if (NOT TARGET pico_standard_link) # PICO_CMAKE_CONFIG: PICO_DEFAULT_BINARY_TYPE, The default binary type to use, type=string, default=default, group=build # slightly messy as we support both the preferred PICO_DEFAULT_BINARY_TYPE and the individual variables + # first check that PICO_DEFAULT_BINARY_TYPE hasn't been set along with a legacy variable + if (PICO_DEFAULT_BINARY_TYPE AND (PICO_NO_FLASH OR PICO_USE_BLOCKED_RAM OR PICO_COPY_TO_RAM)) + message(FATAL_ERROR + "Cannot specify both PICO_DEFAULT_BINARY_TYPE and PICO_NO_FLASH/PICO_USE_BLOCKED_RAM/PICO_COPY_TO_RAM - just use PICO_DEFAULT_BINARY_TYPE instead" + ) + endif() + # then propogate legacy variables to PICO_DEFAULT_BINARY_TYPE, defaulting it to `default` if (NOT PICO_DEFAULT_BINARY_TYPE) if (PICO_NO_FLASH) set(PICO_DEFAULT_BINARY_TYPE no_flash) @@ -234,23 +241,12 @@ if (NOT TARGET pico_standard_link) else() set(PICO_DEFAULT_BINARY_TYPE default) endif() - else() - # we must set the individual variables here, as they are used in generator expressions, - # but also for our checks below - if (PICO_DEFAULT_BINARY_TYPE STREQUAL no_flash) - set(PICO_NO_FLASH 1) - endif() - if (PICO_DEFAULT_BINARY_TYPE STREQUAL blocked_ram) - set(PICO_USE_BLOCKED_RAM 1) - endif() - if (PICO_DEFAULT_BINARY_TYPE STREQUAL copy_to_ram) - set(PICO_COPY_TO_RAM 1) - endif() endif() + # finally check multiple legacy variables haven't been set if ((PICO_NO_FLASH AND PICO_USE_BLOCKED_RAM) OR (PICO_USE_BLOCKED_RAM AND PICO_COPY_TO_RAM) OR (PICO_COPY_TO_RAM AND PICO_NO_FLASH)) - message(FATAL_ERROR "Conflicting binary types specified amongst PICO_DEFAULT_BINARY_TYPE, PICO_NO_FLASH, PICO_USE_BLOCKED_RAM and PICO_COPY_TO_RAM") + message(FATAL_ERROR "Conflicting binary types specified amongst PICO_NO_FLASH, PICO_USE_BLOCKED_RAM and PICO_COPY_TO_RAM") endif() # todo only needed if not using a custom linker script @@ -307,23 +303,22 @@ if (NOT TARGET pico_standard_link) pico_add_memmap_link_depends(pico_standard_link ${PICO_DEFAULT_BINARY_TYPE}) - # PICO_NO_FLASH will be set based on PICO_TARGET_BUILD_TYPE target property being equal to no_flash if set, otherwise to the value of the PICO_NO_FLASH cmake variable unless PICO_TARGET_TYPE is set to something else set(NO_FLASH_BINARY_TYPES no_flash xip_ram) set(COPY_TO_RAM_BINARY_TYPES copy_to_ram) set(XIP_RAM_BINARY_TYPES xip_ram) - # PICO_NO_FLASH will be set based on PICO_TARGET_BUILD_TYPE target property being in NO_FLASH_BINARY_TYPES if set, otherwise to the value of the PICO_NO_FLASH cmake variable unless PICO_TARGET_TYPE is set to something else + # PICO_NO_FLASH will be set based on PICO_TARGET_BINARY_TYPE target property being in NO_FLASH_BINARY_TYPES if PICO_TARGET_BINARY_TYPE is set, otherwise it is set based on PICO_DEFAULT_BINARY_TYPE being in NO_FLASH_BINARY_TYPES # PICO_BUILD_DEFINE: PICO_NO_FLASH, whether this is a 'no_flash' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_NO_FLASH=$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>) - # PICO_USE_BLOCKED_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being equal to use_blocked_ram if set, otherwise to the value of the PICO_USE_BLOCKED_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + target_compile_definitions(pico_standard_link INTERFACE PICO_NO_FLASH=$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>) + # PICO_USE_BLOCKED_RAM will be set based on PICO_TARGET_BINARY_TYPE target property being equal to blocked_ram if PICO_TARGET_BINARY_TYPE is set, otherwise it is set based on PICO_DEFAULT_BINARY_TYPE being equal to blocked_ram # PICO_BUILD_DEFINE: PICO_USE_BLOCKED_RAM, whether this is a 'blocked_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_USE_BLOCKED_RAM=$,use_blocked_ram>,1,$,$>>>) - # PICO_COPY_TO_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being in COPY_TO_RAM_BINARY_TYPES if set, otherwise to the value of the PICO_COPY_TO_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + target_compile_definitions(pico_standard_link INTERFACE PICO_USE_BLOCKED_RAM=$,blocked_ram>,1,$,$>>>) + # PICO_COPY_TO_RAM will be set based on PICO_TARGET_BINARY_TYPE target property being in COPY_TO_RAM_BINARY_TYPES if PICO_TARGET_BINARY_TYPE is set, otherwise it is set based on PICO_DEFAULT_BINARY_TYPE being in COPY_TO_RAM_BINARY_TYPES # PICO_BUILD_DEFINE: PICO_COPY_TO_RAM, whether this is a 'copy_to_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_COPY_TO_RAM=$,${COPY_TO_RAM_BINARY_TYPES}>,1,$,$>>>) - # PICO_XIP_RAM will be set based on PICO_TARGET_BUILD_TYPE target property being in XIP_RAM_BINARY_TYPES if set, otherwise to the value of the PICO_XIP_RAM cmake variable unless PICO_TARGET_TYPE is set to something else + target_compile_definitions(pico_standard_link INTERFACE PICO_COPY_TO_RAM=$,${COPY_TO_RAM_BINARY_TYPES}>,1,$,$>>>) + # PICO_XIP_RAM will be set based on PICO_TARGET_BINARY_TYPE target property being in XIP_RAM_BINARY_TYPES if PICO_TARGET_BINARY_TYPE is set, otherwise it is set based on PICO_DEFAULT_BINARY_TYPE being in XIP_RAM_BINARY_TYPES # PICO_BUILD_DEFINE: PICO_XIP_RAM, whether this is a 'xip_ram' build, type=bool, default=0, but dependent on CMake options, group=pico_standard_link - target_compile_definitions(pico_standard_link INTERFACE PICO_XIP_RAM=$,${XIP_RAM_BINARY_TYPES}>,1,$,$>>>) + target_compile_definitions(pico_standard_link INTERFACE PICO_XIP_RAM=$,${XIP_RAM_BINARY_TYPES}>,1,$,$>>>) target_compile_definitions(pico_standard_link INTERFACE PICO_CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}") if (PICO_DEOPTIMIZED_DEBUG AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") @@ -332,10 +327,10 @@ if (NOT TARGET pico_standard_link) # this (arguably wrong) code is restored for 1.5.1 as setting -nostartfiles on many C++ binaries causes link errors. see issue #1368 # -nostartfiles will be added if PICO_NO_FLASH would be defined to 1 - target_link_options(pico_standard_link INTERFACE $<$,no_flash>,1,$,$>>>:-nostartfiles>) + target_link_options(pico_standard_link INTERFACE $<$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>:-nostartfiles>) # boot_stage2 will be linked if PICO_NO_FLASH would be defined to 0; note if boot_stage2 headers not present, then boot_stage2 is omitted from build anyway if (TARGET boot_stage2_headers) - target_link_libraries(pico_standard_link INTERFACE $<$,no_flash>,1,$,$>>>>:$>,$,bs2_default>_library>) + target_link_libraries(pico_standard_link INTERFACE $<$,${NO_FLASH_BINARY_TYPES}>,1,$,$>>>>:$>,$,bs2_default>_library>) endif() # PICO_CMAKE_CONFIG: PICO_USE_DEFAULT_MAX_PAGE_SIZE, Don't shrink linker max page to 4096, type=bool, default=0, advanced=true, group=pico_standard_link From ab6da0ea38bccf1adf19f9754de8b6e541e562d8 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 29 May 2026 11:59:05 +0100 Subject: [PATCH 53/60] Refactor to place functions using compile definitions instead of linker script injections This adds section_xip_ram.incl into every linker script, and provides the __in_xip_ram macro to put stuff there __time_critical_func then uses the PICO_TIME_CRITICAL_PLACEMENT define to select where to place code, so that can be overriden to be __in_xip_ram to place time critical functions in xip_ram Also works for placing time critical functions in scratch x/y --- .../pico_platform/memmap_blocked_ram.cmake | 1 + .../pico_platform/memmap_blocked_ram.ld | 1 + .../pico_platform/memmap_copy_to_ram.cmake | 1 + .../pico_platform/memmap_copy_to_ram.ld | 1 + src/rp2040/pico_platform/memmap_default.cmake | 1 + src/rp2040/pico_platform/memmap_default.ld | 1 + .../pico_platform/memmap_no_flash.cmake | 1 + src/rp2040/pico_platform/memmap_no_flash.ld | 1 + .../pico_platform/include/pico/platform.h | 6 ++ .../pico_platform/memmap_copy_to_ram.cmake | 1 + .../pico_platform/memmap_copy_to_ram.ld | 1 + src/rp2350/pico_platform/memmap_default.cmake | 1 + src/rp2350/pico_platform/memmap_default.ld | 1 + .../pico_platform/memmap_no_flash.cmake | 1 + src/rp2350/pico_platform/memmap_no_flash.ld | 1 + src/rp2350/pico_platform/memmap_xip_ram.cmake | 2 + src/rp2350/pico_platform/memmap_xip_ram.ld | 2 + src/rp2_common/pico_crt0/crt0.S | 13 ++-- src/rp2_common/pico_crt0/crt0_riscv.S | 12 ++-- .../pico_crt0/embedded_start_block.inc.S | 2 +- src/rp2_common/pico_low_power/CMakeLists.txt | 5 +- .../include/pico/platform/sections.h | 64 +++++++++++++++---- .../pico_standard_link/CMakeLists.txt | 40 ++++++++---- .../script_include/memmap_xip_ram.incl | 5 ++ .../memory_aliases_xip_ram_only.incl | 1 + .../section_time_critical_xip_ram_text.incl | 15 ----- .../script_include/section_xip_ram.incl | 15 +++++ .../script_include/sections_copy_to_ram.incl | 1 + .../script_include/sections_default.incl | 1 + .../script_include/sections_no_flash.incl | 1 + .../script_include/sections_psram.incl | 5 ++ test/pico_xip_sram_test/BUILD.bazel | 25 +------- test/pico_xip_sram_test/CMakeLists.txt | 44 ++++++++++++- .../pico_critical_xip_sram_test.c | 11 +++- .../BUILD.bazel | 8 --- .../section_extra_post_text.incl | 1 - 36 files changed, 198 insertions(+), 95 deletions(-) delete mode 100644 src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl create mode 100644 src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl delete mode 100644 test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel delete mode 100644 test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl diff --git a/src/rp2040/pico_platform/memmap_blocked_ram.cmake b/src/rp2040/pico_platform/memmap_blocked_ram.cmake index 019b3963c..13fc170c9 100644 --- a/src/rp2040/pico_platform/memmap_blocked_ram.cmake +++ b/src/rp2040/pico_platform/memmap_blocked_ram.cmake @@ -37,6 +37,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl) diff --git a/src/rp2040/pico_platform/memmap_blocked_ram.ld b/src/rp2040/pico_platform/memmap_blocked_ram.ld index 8ad9dbd67..914f35d77 100644 --- a/src/rp2040/pico_platform/memmap_blocked_ram.ld +++ b/src/rp2040/pico_platform/memmap_blocked_ram.ld @@ -45,6 +45,7 @@ INCLUDE "memmap_default.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2040/pico_platform + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_flash_end.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram.cmake b/src/rp2040/pico_platform/memmap_copy_to_ram.cmake index 170073aa7..49d3ede93 100644 --- a/src/rp2040/pico_platform/memmap_copy_to_ram.cmake +++ b/src/rp2040/pico_platform/memmap_copy_to_ram.cmake @@ -36,6 +36,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl) diff --git a/src/rp2040/pico_platform/memmap_copy_to_ram.ld b/src/rp2040/pico_platform/memmap_copy_to_ram.ld index dfc053a5a..a162d4ac2 100644 --- a/src/rp2040/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2040/pico_platform/memmap_copy_to_ram.ld @@ -41,6 +41,7 @@ INCLUDE "memmap_copy_to_ram.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2040/pico_platform + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_flash_end.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_default.cmake b/src/rp2040/pico_platform/memmap_default.cmake index 019b3963c..13fc170c9 100644 --- a/src/rp2040/pico_platform/memmap_default.cmake +++ b/src/rp2040/pico_platform/memmap_default.cmake @@ -37,6 +37,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl) diff --git a/src/rp2040/pico_platform/memmap_default.ld b/src/rp2040/pico_platform/memmap_default.ld index 3912267c5..40fa181c2 100644 --- a/src/rp2040/pico_platform/memmap_default.ld +++ b/src/rp2040/pico_platform/memmap_default.ld @@ -42,6 +42,7 @@ INCLUDE "memmap_default.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2040/pico_platform + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_flash_end.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2040/pico_platform/memmap_no_flash.cmake b/src/rp2040/pico_platform/memmap_no_flash.cmake index 8957a357c..c4756b811 100644 --- a/src/rp2040/pico_platform/memmap_no_flash.cmake +++ b/src/rp2040/pico_platform/memmap_no_flash.cmake @@ -29,6 +29,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_persistent_data.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl) diff --git a/src/rp2040/pico_platform/memmap_no_flash.ld b/src/rp2040/pico_platform/memmap_no_flash.ld index 3e9109bcb..56910d22a 100644 --- a/src/rp2040/pico_platform/memmap_no_flash.ld +++ b/src/rp2040/pico_platform/memmap_no_flash.ld @@ -36,6 +36,7 @@ INCLUDE "memmap_no_flash.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2040/pico_platform + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link * ├── section_extra_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/include/pico/platform.h b/src/rp2350/pico_platform/include/pico/platform.h index 67cb80ebc..d7d46fb77 100644 --- a/src/rp2350/pico_platform/include/pico/platform.h +++ b/src/rp2350/pico_platform/include/pico/platform.h @@ -20,6 +20,12 @@ #error pico/platform.h should not be included directly; include pico.h instead #endif +// this is used by sections.h, so comes before the includes +// PICO_CONFIG: PICO_USE_XIP_CACHE_AS_RAM, Whether to use xip cache as ram, default=0, type=bool, group=pico_platform +#ifndef PICO_USE_XIP_CACHE_AS_RAM +#define PICO_USE_XIP_CACHE_AS_RAM 0 +#endif + #include "pico/platform/compiler.h" #include "pico/platform/sections.h" #include "pico/platform/panic.h" diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram.cmake b/src/rp2350/pico_platform/memmap_copy_to_ram.cmake index 18de38212..e9d6dd70e 100644 --- a/src/rp2350/pico_platform/memmap_copy_to_ram.cmake +++ b/src/rp2350/pico_platform/memmap_copy_to_ram.cmake @@ -34,6 +34,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram_data.incl) diff --git a/src/rp2350/pico_platform/memmap_copy_to_ram.ld b/src/rp2350/pico_platform/memmap_copy_to_ram.ld index b2f32553a..3c4d5651f 100644 --- a/src/rp2350/pico_platform/memmap_copy_to_ram.ld +++ b/src/rp2350/pico_platform/memmap_copy_to_ram.ld @@ -41,6 +41,7 @@ INCLUDE "memmap_copy_to_ram.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2_common/pico_standard_link + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_flash_end.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_default.cmake b/src/rp2350/pico_platform/memmap_default.cmake index 1f8ce68ea..2ff9bdae4 100644 --- a/src/rp2350/pico_platform/memmap_default.cmake +++ b/src/rp2350/pico_platform/memmap_default.cmake @@ -35,6 +35,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_ram_vector_table.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_default_data.incl) diff --git a/src/rp2350/pico_platform/memmap_default.ld b/src/rp2350/pico_platform/memmap_default.ld index b63a1ae7f..78079ebfe 100644 --- a/src/rp2350/pico_platform/memmap_default.ld +++ b/src/rp2350/pico_platform/memmap_default.ld @@ -42,6 +42,7 @@ INCLUDE "memmap_default.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2_common/pico_standard_link + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_flash_end.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_no_flash.cmake b/src/rp2350/pico_platform/memmap_no_flash.cmake index 08e664cde..a1434dea0 100644 --- a/src/rp2350/pico_platform/memmap_no_flash.cmake +++ b/src/rp2350/pico_platform/memmap_no_flash.cmake @@ -28,6 +28,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_persistent_data.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl) diff --git a/src/rp2350/pico_platform/memmap_no_flash.ld b/src/rp2350/pico_platform/memmap_no_flash.ld index b2517800c..27d943b9c 100644 --- a/src/rp2350/pico_platform/memmap_no_flash.ld +++ b/src/rp2350/pico_platform/memmap_no_flash.ld @@ -36,6 +36,7 @@ INCLUDE "memmap_no_flash.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2_common/pico_standard_link + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link * ├── section_extra_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2350/pico_platform/memmap_xip_ram.cmake b/src/rp2350/pico_platform/memmap_xip_ram.cmake index 185cd9f8e..95bc508a5 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.cmake +++ b/src/rp2350/pico_platform/memmap_xip_ram.cmake @@ -8,6 +8,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_psram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_scratch.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_binary_info.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_end.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_extra_post_data.incl) @@ -27,6 +28,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_persistent_data.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_tls.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_uninitialized_data.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_arm_ex.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/sections_no_flash_data.incl) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 613c2b4e9..6de652719 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -9,6 +9,7 @@ INCLUDE "memmap_xip_ram.incl" * └── memmap_xip_ram.incl rp2_common/pico_standard_link * ├── set_memory_locations.incl rp2_common/pico_standard_link * ├── memory_psram.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link * ├── memory_ram.incl rp2_common/pico_standard_link * ├── memory_scratch.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link @@ -35,6 +36,7 @@ INCLUDE "memmap_xip_ram.incl" * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link * ├── sections_stack.incl rp2_common/pico_standard_link * ├── sections_psram.incl rp2_common/pico_standard_link + * ├── section_xip_ram.incl rp2_common/pico_standard_link * ├── section_end.incl rp2_common/pico_standard_link * ├── section_generated_post_end.incl rp2_common/pico_standard_link * ├── section_extra_post_end.incl rp2_common/pico_standard_link diff --git a/src/rp2_common/pico_crt0/crt0.S b/src/rp2_common/pico_crt0/crt0.S index 287d2ce88..fa656c6e0 100644 --- a/src/rp2_common/pico_crt0/crt0.S +++ b/src/rp2_common/pico_crt0/crt0.S @@ -21,11 +21,6 @@ #define PICO_CRT0_NEAR_CALLS 0 #endif -// PICO_CONFIG: PICO_USE_XIP_CACHE_AS_RAM, Whether to use xip cache as ram, default=PICO_XIP_RAM, type=bool, group=pico_crt0 -#ifndef PICO_USE_XIP_CACHE_AS_RAM -#define PICO_USE_XIP_CACHE_AS_RAM PICO_XIP_RAM -#endif - // PICO_CONFIG: PICO_CRT0_NO_DATA_COPY, Whether crt0 should perform the data copies - usually copying from flash into sram, default=1 for no_flash builds, 0 otherwise, type=bool, group=pico_crt0 #ifndef PICO_CRT0_NO_DATA_COPY #define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH @@ -589,10 +584,10 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ -#if PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM -.word __xip_ram_time_critical_text_source__ -.word __xip_ram_time_critical_text_start__ -.word __xip_ram_time_critical_text_end__ +#if PICO_USE_XIP_CACHE_AS_RAM +.word __xip_ram_source__ +.word __xip_ram_start__ +.word __xip_ram_end__ #endif .word 0 // null terminator diff --git a/src/rp2_common/pico_crt0/crt0_riscv.S b/src/rp2_common/pico_crt0/crt0_riscv.S index fbdeb0d0b..4b1fcebfe 100644 --- a/src/rp2_common/pico_crt0/crt0_riscv.S +++ b/src/rp2_common/pico_crt0/crt0_riscv.S @@ -34,10 +34,6 @@ #define PICO_CRT0_NO_DATA_COPY PICO_NO_FLASH #endif -#ifndef PICO_USE_XIP_CACHE_AS_RAM -#define PICO_USE_XIP_CACHE_AS_RAM PICO_XIP_RAM -#endif - // If vectors are in RAM, we put them in the .data section, so that they are // preloaded by _reset_handler (assuming this is not a loaded-in-place // binary). @@ -435,10 +431,10 @@ data_cpy_table: .word __scratch_y_start__ .word __scratch_y_end__ -#if PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM -.word __xip_ram_time_critical_text_source__ -.word __xip_ram_time_critical_text_start__ -.word __xip_ram_time_critical_text_end__ +#if PICO_USE_XIP_CACHE_AS_RAM +.word __xip_ram_source__ +.word __xip_ram_start__ +.word __xip_ram_end__ #endif .word 0 // null terminator diff --git a/src/rp2_common/pico_crt0/embedded_start_block.inc.S b/src/rp2_common/pico_crt0/embedded_start_block.inc.S index 52899b861..2c1cdc56f 100644 --- a/src/rp2_common/pico_crt0/embedded_start_block.inc.S +++ b/src/rp2_common/pico_crt0/embedded_start_block.inc.S @@ -39,7 +39,7 @@ #endif #ifndef PICO_CRT0_PIN_XIP_SRAM -#define PICO_CRT0_PIN_XIP_SRAM (PICO_USE_XIP_CACHE_AS_RAM || PICO_XIP_SRAM) +#define PICO_CRT0_PIN_XIP_SRAM (PICO_USE_XIP_CACHE_AS_RAM || PICO_XIP_RAM) #endif #if PICO_CRT0_IMAGE_TYPE_TBYB diff --git a/src/rp2_common/pico_low_power/CMakeLists.txt b/src/rp2_common/pico_low_power/CMakeLists.txt index 06018e335..5438eb4e6 100644 --- a/src/rp2_common/pico_low_power/CMakeLists.txt +++ b/src/rp2_common/pico_low_power/CMakeLists.txt @@ -64,6 +64,7 @@ function(pico_set_persistent_data_loc TARGET PERSISTENT_DATA_LOC) endif() # Configure override section_persistent_data.incl for the target - configure_file(${PICO_LOW_POWER_CURRENT_PATH}/section_persistent_data.incl.template ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}/section_persistent_data.incl @ONLY) - pico_add_linker_script_override_path(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET} FILES section_persistent_data.incl) + set(SCRIPT_PATH ${CMAKE_BINARY_DIR}/generated/persistent_data/${TARGET}) + configure_file(${PICO_LOW_POWER_CURRENT_PATH}/section_persistent_data.incl.template ${SCRIPT_PATH}/section_persistent_data.incl @ONLY) + pico_add_linker_script_override_path(${TARGET} ${SCRIPT_PATH} FILES section_persistent_data.incl) endfunction() diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index 42c24c668..25630f0be 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -40,8 +40,11 @@ #ifndef __not_in_flash #define __not_in_flash(group) __attribute__((section(".time_critical." group))) #endif +#ifndef __in_ram +#define __in_ram(group) __not_in_flash(group) +#endif -/*! \brief Section attribute macro for placement in the SRAM bank 4 (known as "scratch X") +/*! \brief Section attribute macro for placement in the penultimate SRAM bank (known as "scratch X") * \ingroup pico_platform * * Scratch X is commonly used for critical data and functions accessed only by one core (when only @@ -59,8 +62,11 @@ #ifndef __scratch_x #define __scratch_x(group) __attribute__((section(".scratch_x." group))) #endif +#ifndef __in_scratch_x +#define __in_scratch_x(group) __scratch_x(group) +#endif -/*! \brief Section attribute macro for placement in the SRAM bank 5 (known as "scratch Y") +/*! \brief Section attribute macro for placement in the final SRAM bank (known as "scratch Y") * \ingroup pico_platform * * Scratch Y is commonly used for critical data and functions accessed only by one core (when only @@ -78,6 +84,9 @@ #ifndef __scratch_y #define __scratch_y(group) __attribute__((section(".scratch_y." group))) #endif +#ifndef __in_scratch_y +#define __in_scratch_y(group) __scratch_y(group) +#endif /*! \brief Section attribute macro for placement in PSRAM * \ingroup pico_platform @@ -105,6 +114,31 @@ #define __uninitialized_psram(group) __attribute__((section(".psram_uninitialised." group))) #endif +/*! \brief Section attribute macro for placement in XIP SRAM + * \ingroup pico_platform + * + * The XIP Cache can be used as SRAM for extra data sections, however it will give a performance + * penalty if your binary runs from Flash (e.g. the default binary type). + * + * For example a `uint32_t` variable placed in XIP SRAM + * + * uint32_t __in_xip_ram("my_group_name") foo = 23; + * + * The section attribute is `.xip_ram.` + * + * \param group a string suffix to use in the section name to distinguish groups that can be linker + * garbage-collected independently + */ +#ifndef __in_xip_ram +#if PICO_USE_XIP_CACHE_AS_RAM +#define __in_xip_ram(group) __attribute__((section(".xip_ram." group))) +#elif PICO_XIP_RAM +#define __in_xip_ram(group) __in_ram(group) +#else +#define __in_xip_ram(group) x; static_assert(false, "Must set PICO_USE_XIP_CACHE_AS_RAM=1 to use the __in_xip_ram macro"); +#endif +#endif + /*! \brief Section attribute macro for data that is to be left uninitialized * \ingroup pico_platform * @@ -183,29 +217,37 @@ #ifndef __not_in_flash_func #define __not_in_flash_func(func_name) __not_in_flash(__STRING(func_name)) func_name #endif +#ifndef __in_ram_func +#define __in_ram_func(func_name) __in_ram(__STRING(func_name)) func_name +#endif /*! \brief Indicates a function is time/latency critical and should not run from flash * \ingroup pico_platform * * Decorates a function name, such that the function will execute from RAM (assuming it is not inlined * into a flash function by the compiler) to avoid possible flash latency. By default, this macro is identical - * in implementation to `__not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` + * in implementation to `__no_inline_not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` * can be treated more specially to reduce the overhead when calling such a function. - * - * For binaries that are not executing from flash (eg copy_to_ram and no_flash), there is the option - * to use the \ref`pico_use_xip_sram_for_time_critical` CMake function to place them in XIP RAM instead, as the - * XIP AHB ports would be otherwise unused. * * For example a function called my_func taking an int parameter: * * void __time_critical_func(my_func)(int some_arg) { * - * The function is placed in the `.time_critical.text.` linker section + * By default, the function is placed in the `.time_critical.` linker section, but this can be + * adjusted using the `PICO_TIME_CRITICAL_PLACEMENT` define. This define can be set using the + * \ref`pico_place_time_critical_functions` CMake function. + * + * For example, for binaries that are not executing from flash (e.g. copy_to_ram and no_flash), there is the option + * to use `pico_place_time_critical_functions(TARGET xip_ram)` to place these functions in XIP RAM, as the XIP AHB + * ports would be otherwise unused. * - * \see __not_in_flash_func + * \see __not_in_flash */ #ifndef __time_critical_func -#define __time_critical_func(func_name) __noinline __attribute__((section(".time_critical.text." __STRING(func_name)))) func_name +#ifndef PICO_TIME_CRITICAL_PLACEMENT +#define PICO_TIME_CRITICAL_PLACEMENT __not_in_flash +#endif +#define __time_critical_func(func_name) __noinline PICO_TIME_CRITICAL_PLACEMENT(__STRING(func_name)) func_name #endif /*! \brief Indicate a function should not be stored in flash and should not be inlined @@ -227,7 +269,7 @@ #else #ifndef RAM_SECTION_NAME -#define RAM_SECTION_NAME(x) .time_critical.text.##x +#define RAM_SECTION_NAME(x) .time_critical.##x #endif #ifndef SECTION_NAME diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 320a4fe45..398cb63f2 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -204,22 +204,36 @@ if (NOT TARGET pico_standard_link) endif() endfunction() - # pico_use_xip_sram_for_time_critical(TARGET) - # \brief\ Place time-critical code for the target into XIP SRAM + # pico_place_time_critical_functions(TARGET MEMORY) + # \brief\ Place time-critical code for the target into # - # Configures the target to run functions marked __time_critical_func() from XIP SRAM rather than - # normal SRAM, as it has dedicated ports which are otherwise unused in no_flash and copy_to_ram - # binaries. This sets PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1, PICO_USE_XIP_CACHE_AS_RAM=1, and - # injects the required linker script fragment via pico_include_in_generated_section. + # Configures the target to run functions marked __time_critical_func() from rather than + # normal SRAM, useful if has dedicated AHB ports which are otherwise unused. For example, + # xip_ram could be used in no_flash and copy_to_ram binaries, as the XIP AHB ports are unused. + # This sets PICO_TIME_CRITICAL_PLACEMENT=__in_, and any necessary defines required to use + # (e.g. PICO_USE_XIP_CACHE_AS_RAM=1 for xip_ram). # - # This should not be used for flash binaries, as the XIP ports are in use there, and therefore - # this will just make time-critical functions slower. + # \param\ TARGET The target whose time-critical functions should run from + # \param\ MEMORY The memory block to place the functions in (e.g. xip_ram, scratch_x, scratch_y) + function(pico_place_time_critical_functions TARGET MEMORY) + target_compile_definitions(${TARGET} PRIVATE PICO_TIME_CRITICAL_PLACEMENT=__in_${MEMORY}) + if (${MEMORY} STREQUAL "xip_ram") + pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) + endif() + endfunction() + + # pico_use_xip_cache_as_sram(TARGET) + # \brief\ Allow placing data for the target into XIP SRAM + # + # Configures the target to use the XIP Cache as SRAM, allowing data to be placed there using the + # __in_xip_ram macro. This sets PICO_USE_XIP_CACHE_AS_RAM=1. + # + # This should not be used for flash binaries, as using the XIP cache as SRAM will have a large + # performance penalty. # - # \param\ TARGET The target whose time-critical functions should run from XIP SRAM - function(pico_use_xip_sram_for_time_critical TARGET) - target_compile_definitions(${TARGET} PRIVATE PICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1) - pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) # may be set elsewhere too - pico_include_in_generated_section(${TARGET} post_text "section_time_critical_xip_ram_text.incl") + # \param\ TARGET The target which can place data into XIP SRAM + function(pico_use_xip_cache_as_sram TARGET) + pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) endfunction() # PICO_CMAKE_CONFIG: PICO_DEFAULT_BINARY_TYPE, The default binary type to use, type=string, default=default, group=build diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl index 146bb531d..4f76db6af 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -12,8 +12,13 @@ SCRATCH_X_LENGTH = XIP_RAM_SCRATCH_SIZE; SCRATCH_Y_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - XIP_RAM_SCRATCH_SIZE; SCRATCH_Y_LENGTH = XIP_RAM_SCRATCH_SIZE; +/* Zero XIP_RAM origin and size to prevent placement there */ +XIP_RAM_ORIGIN = 0; +XIP_RAM_LENGTH = 0; + /* Include memory regions used */ INCLUDE "memory_psram.incl" +INCLUDE "memory_xip_ram.incl" INCLUDE "memory_ram.incl" INCLUDE "memory_scratch.incl" INCLUDE "memory_generated.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl index 27505d4ca..d264f2309 100644 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl +++ b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl @@ -3,5 +3,6 @@ REGION_ALIAS("TEXT_STORE", RAM); REGION_ALIAS("RAM_STORE", RAM); REGION_ALIAS("PSRAM_STORE", RAM); /* Can't store in PSRAM */ +REGION_ALIAS("XIP_RAM_STORE", XIP_RAM); REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); REGION_ALIAS("SCRATCH_Y_STORE", SCRATCH_Y); diff --git a/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl b/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl deleted file mode 100644 index 5d933adcc..000000000 --- a/src/rp2_common/pico_standard_link/script_include/section_time_critical_xip_ram_text.incl +++ /dev/null @@ -1,15 +0,0 @@ -/* Defines the following symbols for use by code: - __xip_ram_time_critical_text_start__, __xip_ram_time_critical_text_end__, __xip_ram_time_critical_text_source__ -*/ - -SECTIONS -{ - .xip_ram_time_critical_text : { - __xip_ram_time_critical_text_start__ = .; - . = ALIGN(4); - *(.time_critical.text*) - . = ALIGN(4); - __xip_ram_time_critical_text_end__ = .; - } > XIP_RAM AT> XIP_RAM_STORE - __xip_ram_time_critical_text_source__ = LOADADDR(.xip_ram_time_critical_text); -} diff --git a/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl new file mode 100644 index 000000000..dba2695ed --- /dev/null +++ b/src/rp2_common/pico_standard_link/script_include/section_xip_ram.incl @@ -0,0 +1,15 @@ +/* Defines the following symbols for use by code: + __xip_ram_start__, __xip_ram_end__, __xip_ram_source__ +*/ + +SECTIONS +{ + .xip_ram : { + __xip_ram_start__ = .; + . = ALIGN(4); + *(.xip_ram*) + . = ALIGN(4); + __xip_ram_end__ = .; + } > XIP_RAM AT> XIP_RAM_STORE + __xip_ram_source__ = LOADADDR(.xip_ram); +} diff --git a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl index c6e586b25..52636cc54 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_copy_to_ram.incl @@ -12,6 +12,7 @@ INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "sections_psram.incl" +INCLUDE "section_xip_ram.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_generated_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_default.incl b/src/rp2_common/pico_standard_link/script_include/sections_default.incl index 8f15074f8..f81e48c04 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_default.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_default.incl @@ -12,6 +12,7 @@ INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "sections_psram.incl" +INCLUDE "section_xip_ram.incl" INCLUDE "section_flash_end.incl" INCLUDE "section_end.incl" INCLUDE "section_generated_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl index a7a467e36..2e68aa234 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_no_flash.incl @@ -12,6 +12,7 @@ INCLUDE "section_generated_post_scratch.incl" INCLUDE "section_extra_post_scratch.incl" INCLUDE "sections_stack.incl" INCLUDE "sections_psram.incl" +INCLUDE "section_xip_ram.incl" INCLUDE "section_end.incl" INCLUDE "section_generated_post_end.incl" INCLUDE "section_extra_post_end.incl" diff --git a/src/rp2_common/pico_standard_link/script_include/sections_psram.incl b/src/rp2_common/pico_standard_link/script_include/sections_psram.incl index 7f986a357..6e753920e 100644 --- a/src/rp2_common/pico_standard_link/script_include/sections_psram.incl +++ b/src/rp2_common/pico_standard_link/script_include/sections_psram.incl @@ -1,3 +1,8 @@ +/* Defines the following symbols for use by code: + __psram_start__, __psram_end__ + __psram_load_start__, __psram_load_end__, __psram_load_source__ +*/ + SECTIONS { .psram_load : { diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel index ef9b49c8e..044ef5463 100644 --- a/test/pico_xip_sram_test/BUILD.bazel +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -28,19 +28,6 @@ cc_binary( ], ) -# pico_use_xip_sram_for_time_critical isn't implemented in Bazel, so manually -# do that function with this linker script -cc_library( - name = "pico_critical_xip_sram_test_linker_script", - # The order of the linker scripts below is important. - # Prevent buildifier from reordering them. - # buildifier: leave-alone - deps = [ - "//test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts", - "//src/rp2_common/pico_standard_link:default_linker_script", - ], -) - pico_set_binary_type( name = "pico_critical_xip_sram_test_typed", testonly = True, @@ -49,20 +36,12 @@ pico_set_binary_type( target_compatible_with = compatible_with_rp2(), ) -pico_set_linker_script( - name = "pico_critical_xip_sram_test_linked", - testonly = True, - src = ":pico_critical_xip_sram_test_typed", - linker_script = "//test/pico_xip_sram_test:pico_critical_xip_sram_test_linker_script", - target_compatible_with = compatible_with_rp2(), -) - extra_copts_for_all_deps( name = "pico_critical_xip_sram_test", testonly = True, - src = ":pico_critical_xip_sram_test_linked", + src = ":pico_critical_xip_sram_test_typed", extra_copts = [ - "-DPICO_TIME_CRITICAL_TEXT_IN_XIP_RAM=1", + "-DPICO_TIME_CRITICAL_PLACEMENT=__in_xip_ram", "-DPICO_USE_XIP_CACHE_AS_RAM=1", ], target_compatible_with = compatible_with_rp2(), diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index 88db94347..e15a4b5e4 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -5,10 +5,48 @@ if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer) endif() pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram) -pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test) +pico_place_time_critical_functions(pico_critical_xip_sram_test xip_ram) pico_enable_stdio_usb(pico_critical_xip_sram_test 1) # test with USB as that invokes flash functions pico_add_extra_outputs(pico_critical_xip_sram_test) +# Use Scratch X for time critical functions (should still be fast, as core1 function doesn't use stack) +add_executable(pico_critical_scratch_x_test pico_critical_xip_sram_test.c) +target_link_libraries(pico_critical_scratch_x_test PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) +if (NOT PICO_RP2040) + target_link_libraries(pico_critical_scratch_x_test PRIVATE hardware_riscv_platform_timer) + target_compile_definitions(pico_critical_scratch_x_test PRIVATE + TEXT_FUNC_XIP_BASE=SRAM_SCRATCH_X_BASE + TEXT_FUNC_XIP_END=SRAM_SCRATCH_Y_BASE + ) +else() + target_compile_definitions(pico_critical_scratch_x_test PRIVATE + TEXT_FUNC_XIP_BASE=SRAM4_BASE + TEXT_FUNC_XIP_END=SRAM5_BASE + ) +endif() +pico_set_binary_type(pico_critical_scratch_x_test copy_to_ram) +pico_place_time_critical_functions(pico_critical_scratch_x_test scratch_x) +pico_add_extra_outputs(pico_critical_scratch_x_test) + +# Use Scratch Y for time critical functions (should still be fast, as this is only used by core0 stack) +add_executable(pico_critical_scratch_y_test pico_critical_xip_sram_test.c) +target_link_libraries(pico_critical_scratch_y_test PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) +if (NOT PICO_RP2040) + target_link_libraries(pico_critical_scratch_y_test PRIVATE hardware_riscv_platform_timer) + target_compile_definitions(pico_critical_scratch_y_test PRIVATE + TEXT_FUNC_XIP_BASE=SRAM_SCRATCH_Y_BASE + TEXT_FUNC_XIP_END=SRAM_END + ) +else() + target_compile_definitions(pico_critical_scratch_y_test PRIVATE + TEXT_FUNC_XIP_BASE=SRAM5_BASE + TEXT_FUNC_XIP_END=SRAM_END + ) +endif() +pico_set_binary_type(pico_critical_scratch_y_test copy_to_ram) +pico_place_time_critical_functions(pico_critical_scratch_y_test scratch_y) +pico_add_extra_outputs(pico_critical_scratch_y_test) + # Use XIP SRAM for time critical functions (no_flash build) add_executable(pico_critical_xip_sram_test_no_flash pico_critical_xip_sram_test.c) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) @@ -16,7 +54,7 @@ if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE hardware_riscv_platform_timer) endif() pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash) -pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test_no_flash) +pico_place_time_critical_functions(pico_critical_xip_sram_test_no_flash xip_ram) pico_add_extra_outputs(pico_critical_xip_sram_test_no_flash) if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) @@ -32,7 +70,7 @@ if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) add_executable(pico_critical_xip_sram_test_low_power pico_critical_xip_sram_test.c) target_link_libraries(pico_critical_xip_sram_test_low_power PRIVATE pico_stdlib pico_multicore hardware_dma pico_test hardware_riscv_platform_timer pico_low_power) pico_set_binary_type(pico_critical_xip_sram_test_low_power copy_to_ram) - pico_use_xip_sram_for_time_critical(pico_critical_xip_sram_test_low_power) + pico_place_time_critical_functions(pico_critical_xip_sram_test_low_power xip_ram) pico_set_persistent_data_loc(pico_critical_xip_sram_test_low_power xip_ram) pico_add_extra_outputs(pico_critical_xip_sram_test_low_power) endif() \ No newline at end of file diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c index ae260401a..cd6ad5505 100644 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c @@ -134,6 +134,15 @@ void trigger_dma(void) { } +#ifndef TEXT_FUNC_XIP_BASE +#define TEXT_FUNC_XIP_BASE XIP_SRAM_BASE +#endif + +#ifndef TEXT_FUNC_XIP_END +#define TEXT_FUNC_XIP_END XIP_SRAM_END +#endif + + int main(void) { stdio_init_all(); printf("pico_xip_sram_test begins\n"); @@ -150,7 +159,7 @@ int main(void) { printf("test_func_xip at %p\n", test_func_xip); printf("test_func_sram at %p\n", test_func_sram); - PICOTEST_CHECK((uint32_t)test_func_xip >= XIP_SRAM_BASE && (uint32_t)test_func_xip < XIP_SRAM_END, "test_func_xip is not in XIP SRAM"); + PICOTEST_CHECK((uint32_t)test_func_xip >= TEXT_FUNC_XIP_BASE && (uint32_t)test_func_xip < TEXT_FUNC_XIP_END, "test_func_xip is not in XIP SRAM"); PICOTEST_CHECK((uint32_t)test_func_sram >= SRAM_STRIPED_BASE && (uint32_t)test_func_sram < SRAM4_BASE, "test_func_sram is not in SRAM 0-3"); PICOTEST_END_SECTION() diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel deleted file mode 100644 index 2132016fd..000000000 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("//bazel/util:pico_linker_scripts.bzl", "linker_scripts") - -package(default_visibility = ["//test/pico_xip_sram_test:__pkg__"]) - -linker_scripts( - name = "pico_critical_xip_sram_test_scripts", - include_scripts = glob(["*.incl"]), -) diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl b/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl deleted file mode 100644 index 41fa5962b..000000000 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test_scripts/section_extra_post_text.incl +++ /dev/null @@ -1 +0,0 @@ -INCLUDE "section_time_critical_xip_ram_text.incl" \ No newline at end of file From 8734ed515c3ca7573edadd94fe245d1e145cdb78 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 29 May 2026 12:11:01 +0100 Subject: [PATCH 54/60] pico_use_xip_cache_as_sram -> pico_use_xip_cache_as_ram for consistency Also re-add note to pico_place_time_critical_functions not to use xip_ram for flash binaries --- src/rp2_common/pico_standard_link/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index 398cb63f2..dbdae6df0 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -213,6 +213,9 @@ if (NOT TARGET pico_standard_link) # This sets PICO_TIME_CRITICAL_PLACEMENT=__in_, and any necessary defines required to use # (e.g. PICO_USE_XIP_CACHE_AS_RAM=1 for xip_ram). # + # The xip_ram memory should not be used for flash binaries, as using the XIP cache as SRAM will + # have a large performance penalty. + # # \param\ TARGET The target whose time-critical functions should run from # \param\ MEMORY The memory block to place the functions in (e.g. xip_ram, scratch_x, scratch_y) function(pico_place_time_critical_functions TARGET MEMORY) @@ -222,7 +225,7 @@ if (NOT TARGET pico_standard_link) endif() endfunction() - # pico_use_xip_cache_as_sram(TARGET) + # pico_use_xip_cache_as_ram(TARGET) # \brief\ Allow placing data for the target into XIP SRAM # # Configures the target to use the XIP Cache as SRAM, allowing data to be placed there using the @@ -232,7 +235,7 @@ if (NOT TARGET pico_standard_link) # performance penalty. # # \param\ TARGET The target which can place data into XIP SRAM - function(pico_use_xip_cache_as_sram TARGET) + function(pico_use_xip_cache_as_ram TARGET) pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) endfunction() From cf4ba5d848907df5fd1e908f8597b3867a8451a4 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 29 May 2026 12:13:27 +0100 Subject: [PATCH 55/60] fix bazel linting --- test/pico_xip_sram_test/BUILD.bazel | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/pico_xip_sram_test/BUILD.bazel b/test/pico_xip_sram_test/BUILD.bazel index 044ef5463..4efe290b8 100644 --- a/test/pico_xip_sram_test/BUILD.bazel +++ b/test/pico_xip_sram_test/BUILD.bazel @@ -1,7 +1,6 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("@rules_cc//cc:cc_library.bzl", "cc_library") load("//bazel:defs.bzl", "compatible_with_rp2") -load("//bazel/util:transition.bzl", "extra_copts_for_all_deps", "pico_set_binary_type", "pico_set_linker_script") +load("//bazel/util:transition.bzl", "extra_copts_for_all_deps", "pico_set_binary_type") package(default_visibility = ["//visibility:public"]) From 59d09c307e381479813517c9abe11e6b7fd11ab5 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 29 May 2026 12:27:22 +0100 Subject: [PATCH 56/60] remove memory_aliases_xip_ram_only now identical to memory_aliases_no_flash --- src/rp2350/pico_platform/memmap_xip_ram.cmake | 2 +- src/rp2350/pico_platform/memmap_xip_ram.ld | 2 +- .../pico_standard_link/script_include/memmap_xip_ram.incl | 2 +- .../script_include/memory_aliases_xip_ram_only.incl | 8 -------- 4 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl diff --git a/src/rp2350/pico_platform/memmap_xip_ram.cmake b/src/rp2350/pico_platform/memmap_xip_ram.cmake index 95bc508a5..1d644e7d9 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.cmake +++ b/src/rp2350/pico_platform/memmap_xip_ram.cmake @@ -2,7 +2,7 @@ function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2350/pico_platform/script_include/section_platform_end.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl) - pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_extra.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_generated.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_psram.incl) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 6de652719..7bb052429 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -14,7 +14,7 @@ INCLUDE "memmap_xip_ram.incl" * ├── memory_scratch.incl rp2_common/pico_standard_link * ├── memory_generated.incl rp2_common/pico_standard_link * ├── memory_extra.incl rp2_common/pico_standard_link - * ├── memory_aliases_xip_ram_only.incl rp2_common/pico_standard_link + * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link * └── sections_no_flash.incl rp2_common/pico_standard_link * ├── sections_no_flash_text.incl rp2_common/pico_standard_link * │ ├── section_no_flash_text.incl rp2_common/pico_standard_link diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl index 4f76db6af..af2ddb3e9 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -25,7 +25,7 @@ INCLUDE "memory_generated.incl" INCLUDE "memory_extra.incl" /* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "memory_aliases_xip_ram_only.incl" +INCLUDE "memory_aliases_no_flash.incl" /* Define entry point symbol */ ENTRY(_entry_point) diff --git a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl b/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl deleted file mode 100644 index d264f2309..000000000 --- a/src/rp2_common/pico_standard_link/script_include/memory_aliases_xip_ram_only.incl +++ /dev/null @@ -1,8 +0,0 @@ -/* Store everything where it came from (ram/scratch) */ - -REGION_ALIAS("TEXT_STORE", RAM); -REGION_ALIAS("RAM_STORE", RAM); -REGION_ALIAS("PSRAM_STORE", RAM); /* Can't store in PSRAM */ -REGION_ALIAS("XIP_RAM_STORE", XIP_RAM); -REGION_ALIAS("SCRATCH_X_STORE", SCRATCH_X); -REGION_ALIAS("SCRATCH_Y_STORE", SCRATCH_Y); From 729bb0e9e58867732624f8da5e73e0ed10b0c4db Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Jun 2026 17:12:42 +0100 Subject: [PATCH 57/60] Re-arrange sections.h to be clearer what everything does All `__in_xxx` macros place directly into linker sections, which are located in the relevant memory `__scratch_x` and `__scratch_y` are kept as aliases to `__in_scratch_x` and `__in_scratch_y` `__not_in_flash` is placed using `PICO_NOT_IN_FLASH_PLACEMENT` which defaults to `__in_ram`, and the same for `__time_critical_func`, so they can be placed separately pico_place_time_critical_functions -> pico_set_time_critical_placement, and add pico_set_not_in_flash_placement --- .../include/pico/platform/sections.h | 132 ++++++++++++------ .../pico_standard_link/CMakeLists.txt | 25 +++- test/pico_xip_sram_test/CMakeLists.txt | 34 ++++- .../pico_critical_xip_sram_test.c | 12 +- 4 files changed, 152 insertions(+), 51 deletions(-) diff --git a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h index 25630f0be..ec703bc51 100644 --- a/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h +++ b/src/rp2_common/pico_platform_sections/include/pico/platform/sections.h @@ -25,23 +25,21 @@ #define __after_data(group) __attribute__((section(".after_data." group))) #endif -/*! \brief Section attribute macro for placement not in flash (i.e in RAM) +/*! \brief Section attribute macro for placement in RAM * \ingroup pico_platform * * For example a 3 element `uint32_t` array placed in RAM (even though it is `static const`) * * static const uint32_t __not_in_flash("my_group_name") an_array[3]; * - * The section attribute is `.time_critical.` + * The section attribute is `.time_critical.`, which is used to maintain compatibility + * with older linker scripts * * \param group a string suffix to use in the section name to distinguish groups that can be linker * garbage-collected independently */ -#ifndef __not_in_flash -#define __not_in_flash(group) __attribute__((section(".time_critical." group))) -#endif #ifndef __in_ram -#define __in_ram(group) __not_in_flash(group) +#define __in_ram(group) __attribute__((section(".time_critical." group))) #endif /*! \brief Section attribute macro for placement in the penultimate SRAM bank (known as "scratch X") @@ -52,18 +50,27 @@ * * For example a `uint32_t` variable placed in "scratch X" * - * uint32_t __scratch_x("my_group_name") foo = 23; + * uint32_t __in_scratch_x("my_group_name") foo = 23; * * The section attribute is `.scratch_x.` * * \param group a string suffix to use in the section name to distinguish groups that can be linker * garbage-collected independently */ -#ifndef __scratch_x -#define __scratch_x(group) __attribute__((section(".scratch_x." group))) -#endif #ifndef __in_scratch_x -#define __in_scratch_x(group) __scratch_x(group) +#define __in_scratch_x(group) __attribute__((section(".scratch_x." group))) +#endif + +/*! \brief Section attribute macro for placement in the penultimate SRAM bank (known as "scratch X") + * \ingroup pico_platform + * + * Alias for \ref __in_scratch_x + * + * \param group a string suffix to use in the section name to distinguish groups that can be linker + * garbage-collected independently + */ +#ifndef __scratch_x +#define __scratch_x(group) __in_scratch_x(group) #endif /*! \brief Section attribute macro for placement in the final SRAM bank (known as "scratch Y") @@ -81,11 +88,20 @@ * \param group a string suffix to use in the section name to distinguish groups that can be linker * garbage-collected independently */ -#ifndef __scratch_y -#define __scratch_y(group) __attribute__((section(".scratch_y." group))) -#endif #ifndef __in_scratch_y -#define __in_scratch_y(group) __scratch_y(group) +#define __in_scratch_y(group) __attribute__((section(".scratch_y." group))) +#endif + +/*! \brief Section attribute macro for placement in the final SRAM bank (known as "scratch Y") + * \ingroup pico_platform + * + * Alias for \ref __in_scratch_y + * + * \param group a string suffix to use in the section name to distinguish groups that can be linker + * garbage-collected independently + */ +#ifndef __scratch_y +#define __scratch_y(group) __in_scratch_y(group) #endif /*! \brief Section attribute macro for placement in PSRAM @@ -110,6 +126,15 @@ #ifndef __in_psram #define __in_psram(group) __attribute__((section(".psram_initialised." group))) #endif + +/*! \brief Section attribute macro for placement in uninitialised PSRAM + * \ingroup pico_platform + * + * The version of \ref __in_psram to use for uninitialised data + * + * \param group a string suffix to use in the section name to distinguish groups that can be linker + * garbage-collected independently + */ #ifndef __uninitialized_psram #define __uninitialized_psram(group) __attribute__((section(".psram_uninitialised." group))) #endif @@ -200,6 +225,30 @@ #define __in_flash(group) __attribute__((section(".flashdata." group))) #endif +/*! \brief Section attribute macro for placement not in flash + * \ingroup pico_platform + * + * For example a 3 element `uint32_t` array placed in RAM (even though it is `static const`) + * + * static const uint32_t __not_in_flash("my_group_name") an_array[3]; + * + * By default, this is identical to \ref __in_ram, but this can be adjusted using the `PICO_NOT_IN_FLASH_PLACEMENT` define. + * This define can be set using the \ref pico_set_not_in_flash_placement CMake function. + * + * For example, for binaries that only use core 0, there is the option to use + * `pico_set_not_in_flash_placement(TARGET scratch_x)` to place this code/data in scratch X to move it + * out of the striped SRAM. + * + * \param group a string suffix to use in the section name to distinguish groups that can be linker + * garbage-collected independently + */ +#ifndef PICO_NOT_IN_FLASH_PLACEMENT +#define PICO_NOT_IN_FLASH_PLACEMENT __in_ram +#endif +#ifndef __not_in_flash +#define __not_in_flash(group) PICO_NOT_IN_FLASH_PLACEMENT(group) +#endif + /*! \brief Indicates a function should not be stored in flash * \ingroup pico_platform * @@ -210,62 +259,59 @@ * * void __not_in_flash_func(my_func)(int some_arg) { * - * The function is placed in the `.time_critical.` linker section + * The function is placed using \ref __not_in_flash, which defaults to \ref __in_ram * * \see __no_inline_not_in_flash_func */ #ifndef __not_in_flash_func #define __not_in_flash_func(func_name) __not_in_flash(__STRING(func_name)) func_name #endif -#ifndef __in_ram_func -#define __in_ram_func(func_name) __in_ram(__STRING(func_name)) func_name + +/*! \brief Indicate a function should not be stored in flash and should not be inlined + * \ingroup pico_platform + * + * Decorates a function name, such that the function will execute from RAM, explicitly marking it as + * noinline to prevent it being inlined into a flash function by the compiler + * + * For example a function called my_func taking an int parameter: + * + * void __no_inline_not_in_flash_func(my_func)(int some_arg) { + * + * The function is placed using \ref __not_in_flash, which defaults to \ref __in_ram + */ +#ifndef __no_inline_not_in_flash_func +#define __no_inline_not_in_flash_func(func_name) __noinline __not_in_flash_func(func_name) #endif + /*! \brief Indicates a function is time/latency critical and should not run from flash * \ingroup pico_platform * - * Decorates a function name, such that the function will execute from RAM (assuming it is not inlined - * into a flash function by the compiler) to avoid possible flash latency. By default, this macro is identical - * in implementation to `__no_inline_not_in_flash_func`, however the semantics are distinct and a `__time_critical_func` - * can be treated more specially to reduce the overhead when calling such a function. + * Decorates a function name, such that the function will execute from RAM to avoid possible flash latency. By default, + * this macro is identical in implementation to `__no_inline_not_in_flash_func`, however the semantics are distinct and + * a `__time_critical_func` can be treated more specially to reduce the overhead when calling such a function. * * For example a function called my_func taking an int parameter: * * void __time_critical_func(my_func)(int some_arg) { * - * By default, the function is placed in the `.time_critical.` linker section, but this can be - * adjusted using the `PICO_TIME_CRITICAL_PLACEMENT` define. This define can be set using the - * \ref`pico_place_time_critical_functions` CMake function. + * By default, the function is placed using \ref __in_ram, but this can be adjusted using the + * `PICO_TIME_CRITICAL_PLACEMENT` define. This define can be set using the \ref pico_set_time_critical_placement + * CMake function. * * For example, for binaries that are not executing from flash (e.g. copy_to_ram and no_flash), there is the option - * to use `pico_place_time_critical_functions(TARGET xip_ram)` to place these functions in XIP RAM, as the XIP AHB + * to use `pico_set_time_critical_placement(TARGET xip_ram)` to place these functions in XIP RAM, as the XIP AHB * ports would be otherwise unused. * * \see __not_in_flash */ #ifndef __time_critical_func #ifndef PICO_TIME_CRITICAL_PLACEMENT -#define PICO_TIME_CRITICAL_PLACEMENT __not_in_flash +#define PICO_TIME_CRITICAL_PLACEMENT __in_ram #endif #define __time_critical_func(func_name) __noinline PICO_TIME_CRITICAL_PLACEMENT(__STRING(func_name)) func_name #endif -/*! \brief Indicate a function should not be stored in flash and should not be inlined - * \ingroup pico_platform - * - * Decorates a function name, such that the function will execute from RAM, explicitly marking it as - * noinline to prevent it being inlined into a flash function by the compiler - * - * For example a function called my_func taking an int parameter: - * - * void __no_inline_not_in_flash_func(my_func)(int some_arg) { - * - * The function is placed in the `.time_critical.` linker section - */ -#ifndef __no_inline_not_in_flash_func -#define __no_inline_not_in_flash_func(func_name) __noinline __not_in_flash_func(func_name) -#endif - #else #ifndef RAM_SECTION_NAME diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index dbdae6df0..432dc1546 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -204,7 +204,7 @@ if (NOT TARGET pico_standard_link) endif() endfunction() - # pico_place_time_critical_functions(TARGET MEMORY) + # pico_set_time_critical_placement(TARGET MEMORY) # \brief\ Place time-critical code for the target into # # Configures the target to run functions marked __time_critical_func() from rather than @@ -218,13 +218,34 @@ if (NOT TARGET pico_standard_link) # # \param\ TARGET The target whose time-critical functions should run from # \param\ MEMORY The memory block to place the functions in (e.g. xip_ram, scratch_x, scratch_y) - function(pico_place_time_critical_functions TARGET MEMORY) + function(pico_set_time_critical_placement TARGET MEMORY) target_compile_definitions(${TARGET} PRIVATE PICO_TIME_CRITICAL_PLACEMENT=__in_${MEMORY}) if (${MEMORY} STREQUAL "xip_ram") pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) endif() endfunction() + # pico_set_not_in_flash_placement(TARGET MEMORY) + # \brief\ Place time-critical code for the target into + # + # Configures the target to place data (and code) marked __not_in_flash() in rather than + # normal SRAM, useful if has dedicated AHB ports which are otherwise unused. For example, + # xip_ram could be used in no_flash and copy_to_ram binaries, as the XIP AHB ports are unused. + # This sets PICO_NOT_IN_FLASH_PLACEMENT=__in_, and any necessary defines required to use + # (e.g. PICO_USE_XIP_CACHE_AS_RAM=1 for xip_ram). + # + # The xip_ram memory should not be used for flash binaries, as using the XIP cache as SRAM will + # have a large performance penalty. + # + # \param\ TARGET The target whose __not_in_flash data should be placed in + # \param\ MEMORY The memory block to place the data in (e.g. xip_ram, scratch_x, scratch_y) + function(pico_set_not_in_flash_placement TARGET MEMORY) + target_compile_definitions(${TARGET} PRIVATE PICO_NOT_IN_FLASH_PLACEMENT=__in_${MEMORY}) + if (${MEMORY} STREQUAL "xip_ram") + pico_set_compile_definition(${TARGET} PICO_USE_XIP_CACHE_AS_RAM 1) + endif() + endfunction() + # pico_use_xip_cache_as_ram(TARGET) # \brief\ Allow placing data for the target into XIP SRAM # diff --git a/test/pico_xip_sram_test/CMakeLists.txt b/test/pico_xip_sram_test/CMakeLists.txt index e15a4b5e4..defdebeca 100644 --- a/test/pico_xip_sram_test/CMakeLists.txt +++ b/test/pico_xip_sram_test/CMakeLists.txt @@ -5,7 +5,7 @@ if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test PRIVATE hardware_riscv_platform_timer) endif() pico_set_binary_type(pico_critical_xip_sram_test copy_to_ram) -pico_place_time_critical_functions(pico_critical_xip_sram_test xip_ram) +pico_set_time_critical_placement(pico_critical_xip_sram_test xip_ram) pico_enable_stdio_usb(pico_critical_xip_sram_test 1) # test with USB as that invokes flash functions pico_add_extra_outputs(pico_critical_xip_sram_test) @@ -25,7 +25,7 @@ else() ) endif() pico_set_binary_type(pico_critical_scratch_x_test copy_to_ram) -pico_place_time_critical_functions(pico_critical_scratch_x_test scratch_x) +pico_set_time_critical_placement(pico_critical_scratch_x_test scratch_x) pico_add_extra_outputs(pico_critical_scratch_x_test) # Use Scratch Y for time critical functions (should still be fast, as this is only used by core0 stack) @@ -44,9 +44,33 @@ else() ) endif() pico_set_binary_type(pico_critical_scratch_y_test copy_to_ram) -pico_place_time_critical_functions(pico_critical_scratch_y_test scratch_y) +pico_set_time_critical_placement(pico_critical_scratch_y_test scratch_y) pico_add_extra_outputs(pico_critical_scratch_y_test) +# Use XIP SRAM for time critical functions and scratch X for not in flash functions +add_executable(pico_critical_xip_sram_no_flash_scratch_x_test pico_critical_xip_sram_test.c) +target_link_libraries(pico_critical_xip_sram_no_flash_scratch_x_test PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) +if (NOT PICO_RP2040) + target_link_libraries(pico_critical_xip_sram_no_flash_scratch_x_test PRIVATE hardware_riscv_platform_timer) + target_compile_definitions(pico_critical_xip_sram_no_flash_scratch_x_test PRIVATE + TEXT_FUNC_SRAM_BASE=SRAM_SCRATCH_X_BASE + TEXT_FUNC_SRAM_END=SRAM_SCRATCH_Y_BASE + ) +else() + target_compile_definitions(pico_critical_xip_sram_no_flash_scratch_x_test PRIVATE + TEXT_FUNC_SRAM_BASE=SRAM4_BASE + TEXT_FUNC_SRAM_END=SRAM5_BASE + ) +endif() +target_compile_definitions(pico_critical_xip_sram_no_flash_scratch_x_test PRIVATE + PICO_CORE1_STACK_SIZE=0x200 +) +pico_set_binary_type(pico_critical_xip_sram_no_flash_scratch_x_test copy_to_ram) +pico_set_not_in_flash_placement(pico_critical_xip_sram_no_flash_scratch_x_test scratch_x) +pico_set_time_critical_placement(pico_critical_xip_sram_no_flash_scratch_x_test xip_ram) +pico_enable_stdio_usb(pico_critical_xip_sram_no_flash_scratch_x_test 1) # test with USB as that invokes flash functions +pico_add_extra_outputs(pico_critical_xip_sram_no_flash_scratch_x_test) + # Use XIP SRAM for time critical functions (no_flash build) add_executable(pico_critical_xip_sram_test_no_flash pico_critical_xip_sram_test.c) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE pico_stdlib pico_multicore hardware_dma pico_test) @@ -54,7 +78,7 @@ if (NOT PICO_RP2040) target_link_libraries(pico_critical_xip_sram_test_no_flash PRIVATE hardware_riscv_platform_timer) endif() pico_set_binary_type(pico_critical_xip_sram_test_no_flash no_flash) -pico_place_time_critical_functions(pico_critical_xip_sram_test_no_flash xip_ram) +pico_set_time_critical_placement(pico_critical_xip_sram_test_no_flash xip_ram) pico_add_extra_outputs(pico_critical_xip_sram_test_no_flash) if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) @@ -70,7 +94,7 @@ if (NOT PICO_RP2040 AND NOT PICO_C_COMPILER_IS_CLANG) add_executable(pico_critical_xip_sram_test_low_power pico_critical_xip_sram_test.c) target_link_libraries(pico_critical_xip_sram_test_low_power PRIVATE pico_stdlib pico_multicore hardware_dma pico_test hardware_riscv_platform_timer pico_low_power) pico_set_binary_type(pico_critical_xip_sram_test_low_power copy_to_ram) - pico_place_time_critical_functions(pico_critical_xip_sram_test_low_power xip_ram) + pico_set_time_critical_placement(pico_critical_xip_sram_test_low_power xip_ram) pico_set_persistent_data_loc(pico_critical_xip_sram_test_low_power xip_ram) pico_add_extra_outputs(pico_critical_xip_sram_test_low_power) endif() \ No newline at end of file diff --git a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c index cd6ad5505..0fb1871f5 100644 --- a/test/pico_xip_sram_test/pico_critical_xip_sram_test.c +++ b/test/pico_xip_sram_test/pico_critical_xip_sram_test.c @@ -142,6 +142,14 @@ void trigger_dma(void) { #define TEXT_FUNC_XIP_END XIP_SRAM_END #endif +#ifndef TEXT_FUNC_SRAM_BASE +#define TEXT_FUNC_SRAM_BASE SRAM_STRIPED_BASE +#endif + +#ifndef TEXT_FUNC_SRAM_END +#define TEXT_FUNC_SRAM_END SRAM4_BASE +#endif + int main(void) { stdio_init_all(); @@ -160,7 +168,7 @@ int main(void) { printf("test_func_sram at %p\n", test_func_sram); PICOTEST_CHECK((uint32_t)test_func_xip >= TEXT_FUNC_XIP_BASE && (uint32_t)test_func_xip < TEXT_FUNC_XIP_END, "test_func_xip is not in XIP SRAM"); - PICOTEST_CHECK((uint32_t)test_func_sram >= SRAM_STRIPED_BASE && (uint32_t)test_func_sram < SRAM4_BASE, "test_func_sram is not in SRAM 0-3"); + PICOTEST_CHECK((uint32_t)test_func_sram >= TEXT_FUNC_SRAM_BASE && (uint32_t)test_func_sram < TEXT_FUNC_SRAM_END, "test_func_sram is not in SRAM 0-3"); PICOTEST_END_SECTION() multicore_launch_core1(core1_entry); @@ -193,7 +201,9 @@ int main(void) { sleep_ms(500); } +#if TEXT_FUNC_SRAM_BASE == SRAM_STRIPED_BASE PICOTEST_CHECK(test_func_xip_cycles < test_func_sram_cycles, "test_func_xip took longer than test_func_sram"); +#endif PICOTEST_END_SECTION(); From 7cccb51691b6ae23139b5b06da6b56bfa1b415e0 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Jun 2026 17:22:10 +0100 Subject: [PATCH 58/60] Make memmap_xip_ram.incl include memmap_no_flash.incl Removes the ability to override XIP_RAM_ORIGIN and XIP_RAM_LENGTH (to prevent duplicate includes, which Clang doesn't like), but that is fine --- src/rp2350/pico_platform/memmap_xip_ram.cmake | 1 + src/rp2350/pico_platform/memmap_xip_ram.ld | 77 ++++++++++--------- .../script_include/memmap_xip_ram.incl | 35 +++------ 3 files changed, 50 insertions(+), 63 deletions(-) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.cmake b/src/rp2350/pico_platform/memmap_xip_ram.cmake index 1d644e7d9..c470f1164 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.cmake +++ b/src/rp2350/pico_platform/memmap_xip_ram.cmake @@ -1,6 +1,7 @@ # Auto-generated by tools/memmap_annotate.py — do not edit by hand function(pico_add_memmap_link_depends_internal TARGET) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2350/pico_platform/script_include/section_platform_end.incl) + pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memmap_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_aliases_no_flash.incl) pico_add_link_depend(${TARGET} ${PICO_SDK_PATH}/src/rp2_common/pico_standard_link/script_include/memory_extra.incl) diff --git a/src/rp2350/pico_platform/memmap_xip_ram.ld b/src/rp2350/pico_platform/memmap_xip_ram.ld index 7bb052429..ba06c4e87 100644 --- a/src/rp2350/pico_platform/memmap_xip_ram.ld +++ b/src/rp2350/pico_platform/memmap_xip_ram.ld @@ -5,42 +5,43 @@ INCLUDE "memmap_xip_ram.incl" * and tools/memmap_include_tree.py). To override any files in this tree, see the * pico_add_linker_script_override_path CMake function under pico_standard_link. * - * memmap_xip_ram.ld rp2350/pico_platform - * └── memmap_xip_ram.incl rp2_common/pico_standard_link - * ├── set_memory_locations.incl rp2_common/pico_standard_link - * ├── memory_psram.incl rp2_common/pico_standard_link - * ├── memory_xip_ram.incl rp2_common/pico_standard_link - * ├── memory_ram.incl rp2_common/pico_standard_link - * ├── memory_scratch.incl rp2_common/pico_standard_link - * ├── memory_generated.incl rp2_common/pico_standard_link - * ├── memory_extra.incl rp2_common/pico_standard_link - * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link - * └── sections_no_flash.incl rp2_common/pico_standard_link - * ├── sections_no_flash_text.incl rp2_common/pico_standard_link - * │ ├── section_no_flash_text.incl rp2_common/pico_standard_link - * │ ├── section_no_flash_rodata.incl rp2_common/pico_standard_link - * │ ├── sections_arm_ex.incl rp2_common/pico_standard_link - * │ └── section_binary_info.incl rp2_common/pico_standard_link - * ├── section_generated_post_text.incl rp2_common/pico_standard_link - * ├── section_extra_post_text.incl rp2_common/pico_standard_link - * ├── sections_no_flash_data.incl rp2_common/pico_standard_link - * │ ├── section_no_flash_data.incl rp2_common/pico_standard_link - * │ ├── section_uninitialized_data.incl rp2_common/pico_standard_link - * │ ├── section_tls.incl rp2_common/pico_standard_link - * │ └── section_persistent_data.incl rp2_common/pico_standard_link - * ├── section_generated_post_data.incl rp2_common/pico_standard_link - * ├── section_extra_post_data.incl rp2_common/pico_standard_link - * ├── section_heap.incl rp2_common/pico_standard_link - * ├── sections_scratch.incl rp2_common/pico_standard_link - * ├── section_generated_post_scratch.incl rp2_common/pico_standard_link - * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link - * ├── sections_stack.incl rp2_common/pico_standard_link - * ├── sections_psram.incl rp2_common/pico_standard_link - * ├── section_xip_ram.incl rp2_common/pico_standard_link - * ├── section_end.incl rp2_common/pico_standard_link - * ├── section_generated_post_end.incl rp2_common/pico_standard_link - * ├── section_extra_post_end.incl rp2_common/pico_standard_link - * ├── section_platform_end.incl rp2350/pico_platform - * ├── section_generated_post_platform_end.incl rp2_common/pico_standard_link - * └── section_extra_post_platform_end.incl rp2_common/pico_standard_link + * memmap_xip_ram.ld rp2350/pico_platform + * └── memmap_xip_ram.incl rp2_common/pico_standard_link + * └── memmap_no_flash.incl rp2_common/pico_standard_link + * ├── set_memory_locations.incl rp2_common/pico_standard_link + * ├── memory_psram.incl rp2_common/pico_standard_link + * ├── memory_xip_ram.incl rp2_common/pico_standard_link + * ├── memory_ram.incl rp2_common/pico_standard_link + * ├── memory_scratch.incl rp2_common/pico_standard_link + * ├── memory_generated.incl rp2_common/pico_standard_link + * ├── memory_extra.incl rp2_common/pico_standard_link + * ├── memory_aliases_no_flash.incl rp2_common/pico_standard_link + * └── sections_no_flash.incl rp2_common/pico_standard_link + * ├── sections_no_flash_text.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_text.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_rodata.incl rp2_common/pico_standard_link + * │ ├── sections_arm_ex.incl rp2_common/pico_standard_link + * │ └── section_binary_info.incl rp2_common/pico_standard_link + * ├── section_generated_post_text.incl rp2_common/pico_standard_link + * ├── section_extra_post_text.incl rp2_common/pico_standard_link + * ├── sections_no_flash_data.incl rp2_common/pico_standard_link + * │ ├── section_no_flash_data.incl rp2_common/pico_standard_link + * │ ├── section_uninitialized_data.incl rp2_common/pico_standard_link + * │ ├── section_tls.incl rp2_common/pico_standard_link + * │ └── section_persistent_data.incl rp2_common/pico_standard_link + * ├── section_generated_post_data.incl rp2_common/pico_standard_link + * ├── section_extra_post_data.incl rp2_common/pico_standard_link + * ├── section_heap.incl rp2_common/pico_standard_link + * ├── sections_scratch.incl rp2_common/pico_standard_link + * ├── section_generated_post_scratch.incl rp2_common/pico_standard_link + * ├── section_extra_post_scratch.incl rp2_common/pico_standard_link + * ├── sections_stack.incl rp2_common/pico_standard_link + * ├── sections_psram.incl rp2_common/pico_standard_link + * ├── section_xip_ram.incl rp2_common/pico_standard_link + * ├── section_end.incl rp2_common/pico_standard_link + * ├── section_generated_post_end.incl rp2_common/pico_standard_link + * ├── section_extra_post_end.incl rp2_common/pico_standard_link + * ├── section_platform_end.incl rp2350/pico_platform + * ├── section_generated_post_platform_end.incl rp2_common/pico_standard_link + * └── section_extra_post_platform_end.incl rp2_common/pico_standard_link * END_MEMMAP_INCLUDE_TREE */ diff --git a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl index af2ddb3e9..538013eac 100644 --- a/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl +++ b/src/rp2_common/pico_standard_link/script_include/memmap_xip_ram.incl @@ -1,34 +1,19 @@ -/* Include platform memory locations */ -INCLUDE "set_memory_locations.incl" - /* Allow customisation of XIP_RAM_SCRATCH_SIZE */ +/* see set_memory_locations.incl for why both these lines are needed */ +PROVIDE( XIP_RAM_SCRATCH_SIZE = 2k); XIP_RAM_SCRATCH_SIZE = DEFINED(XIP_RAM_SCRATCH_SIZE) ? XIP_RAM_SCRATCH_SIZE : 2k; /* Split XIP_RAM into RAM and SCRATCH */ -RAM_ORIGIN = XIP_RAM_ORIGIN; -RAM_LENGTH = XIP_RAM_LENGTH - (XIP_RAM_SCRATCH_SIZE*2); -SCRATCH_X_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - (XIP_RAM_SCRATCH_SIZE*2); +RAM_ORIGIN = XIP_RAM_ORIGIN_DEFAULT; +RAM_LENGTH = XIP_RAM_LENGTH_DEFAULT - (XIP_RAM_SCRATCH_SIZE*2); +SCRATCH_X_ORIGIN = XIP_RAM_ORIGIN_DEFAULT + XIP_RAM_LENGTH_DEFAULT - (XIP_RAM_SCRATCH_SIZE*2); SCRATCH_X_LENGTH = XIP_RAM_SCRATCH_SIZE; -SCRATCH_Y_ORIGIN = XIP_RAM_ORIGIN + XIP_RAM_LENGTH - XIP_RAM_SCRATCH_SIZE; +SCRATCH_Y_ORIGIN = XIP_RAM_ORIGIN_DEFAULT + XIP_RAM_LENGTH_DEFAULT - XIP_RAM_SCRATCH_SIZE; SCRATCH_Y_LENGTH = XIP_RAM_SCRATCH_SIZE; /* Zero XIP_RAM origin and size to prevent placement there */ -XIP_RAM_ORIGIN = 0; -XIP_RAM_LENGTH = 0; - -/* Include memory regions used */ -INCLUDE "memory_psram.incl" -INCLUDE "memory_xip_ram.incl" -INCLUDE "memory_ram.incl" -INCLUDE "memory_scratch.incl" -INCLUDE "memory_generated.incl" -INCLUDE "memory_extra.incl" - -/* Include aliases for no_flash storage memory regions (alias to themselves) */ -INCLUDE "memory_aliases_no_flash.incl" - -/* Define entry point symbol */ -ENTRY(_entry_point) +XIP_RAM_ORIGIN_DEFAULT = 0; +XIP_RAM_LENGTH_DEFAULT = 0; -/* Include no_flash sections */ -INCLUDE "sections_no_flash.incl" +/* Now it is just a normal no_flash binary */ +INCLUDE "memmap_no_flash.incl" From 5a4f08274d722ba30fb1e766411601527486ca9b Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Jun 2026 18:12:31 +0100 Subject: [PATCH 59/60] Fixup bazel build Note that the xip_ram binary type still doesn't work in bazel, as the bazel build doesn't fit in xip_ram --- src/common/pico_base_headers/BUILD.bazel | 2 +- src/rp2350/pico_platform/BUILD.bazel | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/pico_base_headers/BUILD.bazel b/src/common/pico_base_headers/BUILD.bazel index 8f15e44f6..f482a50b8 100644 --- a/src/common/pico_base_headers/BUILD.bazel +++ b/src/common/pico_base_headers/BUILD.bazel @@ -78,7 +78,7 @@ cc_library( "//bazel/constraint:pico_binary_type_no_flash": ["PICO_NO_FLASH=1"], "//bazel/constraint:pico_binary_type_copy_to_ram": ["PICO_COPY_TO_RAM=1"], "//bazel/constraint:pico_binary_type_blocked_ram": ["PICO_USE_BLOCKED_RAM=1"], - "//bazel/constraint:pico_binary_type_xip_ram": ["PICO_XIP_RAM=1"], + "//bazel/constraint:pico_binary_type_xip_ram": ["PICO_XIP_RAM=1", "PICO_NO_FLASH=1"], "//conditions:default": [], }), ) diff --git a/src/rp2350/pico_platform/BUILD.bazel b/src/rp2350/pico_platform/BUILD.bazel index 8d31644e2..65a041431 100644 --- a/src/rp2350/pico_platform/BUILD.bazel +++ b/src/rp2350/pico_platform/BUILD.bazel @@ -157,6 +157,7 @@ cc_library( "//src/rp2_common/pico_crt0:no_warn_rwx_flag", "//src/rp2350/pico_platform/script_include:rp2350_linker_scripts", "//src/rp2_common/pico_standard_link/script_include:rp2_linker_scripts", + "//src/rp2_common/pico_standard_link:default_psram_region", "memmap_xip_ram", ], ) From 9ae9fe5dccdf5b242646ce533b447c9317f31813 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Jun 2026 18:23:27 +0100 Subject: [PATCH 60/60] fix bazel buildifier checks --- src/common/pico_base_headers/BUILD.bazel | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/pico_base_headers/BUILD.bazel b/src/common/pico_base_headers/BUILD.bazel index f482a50b8..ad46a5f67 100644 --- a/src/common/pico_base_headers/BUILD.bazel +++ b/src/common/pico_base_headers/BUILD.bazel @@ -78,7 +78,10 @@ cc_library( "//bazel/constraint:pico_binary_type_no_flash": ["PICO_NO_FLASH=1"], "//bazel/constraint:pico_binary_type_copy_to_ram": ["PICO_COPY_TO_RAM=1"], "//bazel/constraint:pico_binary_type_blocked_ram": ["PICO_USE_BLOCKED_RAM=1"], - "//bazel/constraint:pico_binary_type_xip_ram": ["PICO_XIP_RAM=1", "PICO_NO_FLASH=1"], + "//bazel/constraint:pico_binary_type_xip_ram": [ + "PICO_XIP_RAM=1", + "PICO_NO_FLASH=1", + ], "//conditions:default": [], }), )