From c6cac63a1f6c86b5fcbf681f02e63d72b033381e Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 2 Dec 2025 17:31:49 +0000 Subject: [PATCH] Make overriding ram locations simpler --- .../pico_crt0/rp2040/memmap_blocked_ram.ld | 15 +++------------ .../rp2040/platform/default_locations.ld | 8 ++++++++ .../rp2040/platform/memory_blocked_ram.ld | 4 ---- .../pico_crt0/rp2040/platform/memory_ram.ld | 4 ---- .../rp2040/platform/memory_scratch.ld | 5 ----- .../rp2350/platform/default_locations.ld | 8 ++++++++ .../pico_crt0/rp2350/platform/memory_ram.ld | 4 ---- .../rp2350/platform/memory_scratch.ld | 5 ----- .../rp2350/platform/memory_xip_ram.ld | 4 ---- .../scripts/rp2_common/memmap_copy_to_ram.ld | 7 +++++-- .../scripts/rp2_common/memmap_default.ld | 7 +++++-- .../scripts/rp2_common/memmap_no_flash.ld | 7 +++++-- .../scripts/rp2_common/memory_ram.ld | 4 ++++ .../scripts/rp2_common/memory_scratch.ld | 5 +++++ .../scripts/rp2_common/memory_xip_ram.ld | 4 ++++ test/kitchen_sink/CMakeLists.txt | 15 ++++++++------- test/kitchen_sink/memmap_custom.ld | 18 ------------------ 17 files changed, 55 insertions(+), 69 deletions(-) create mode 100644 src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld create mode 100644 src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld delete mode 100644 src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld create mode 100644 src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld delete mode 100644 test/kitchen_sink/memmap_custom.ld diff --git a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld index 330e9bde..a4a52895 100644 --- a/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld +++ b/src/rp2_common/pico_crt0/rp2040/memmap_blocked_ram.ld @@ -1,13 +1,4 @@ -/* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_blocked_ram.ld" -INCLUDE "platform/memory_scratch.ld" +/* Use blocked ram */ +RAM_ORIGIN = 0x21000000; -/* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include default sections */ -INCLUDE "rp2_common/sections_default.ld" +INCLUDE "memmap_default.ld" diff --git a/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld new file mode 100644 index 00000000..684418b7 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2040/platform/default_locations.ld @@ -0,0 +1,8 @@ +RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; +RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 256k; +SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20040000; +SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; +SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20041000; +SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; +XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x15000000; +XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld deleted file mode 100644 index 57cbad6b..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_blocked_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x21000000, LENGTH = 256k -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld deleted file mode 100644 index 1e1515dd..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} diff --git a/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld deleted file mode 100644 index a4b982b9..00000000 --- a/src/rp2_common/pico_crt0/rp2040/platform/memory_scratch.ld +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld new file mode 100644 index 00000000..0b1611d4 --- /dev/null +++ b/src/rp2_common/pico_crt0/rp2350/platform/default_locations.ld @@ -0,0 +1,8 @@ +RAM_ORIGIN = DEFINED(RAM_ORIGIN) ? RAM_ORIGIN : 0x20000000; +RAM_LENGTH = DEFINED(RAM_LENGTH) ? RAM_LENGTH : 512k; +SCRATCH_X_ORIGIN = DEFINED(SCRATCH_X_ORIGIN) ? SCRATCH_X_ORIGIN : 0x20080000; +SCRATCH_X_LENGTH = DEFINED(SCRATCH_X_LENGTH) ? SCRATCH_X_LENGTH : 4k; +SCRATCH_Y_ORIGIN = DEFINED(SCRATCH_Y_ORIGIN) ? SCRATCH_Y_ORIGIN : 0x20081000; +SCRATCH_Y_LENGTH = DEFINED(SCRATCH_Y_LENGTH) ? SCRATCH_Y_LENGTH : 4k; +XIP_RAM_ORIGIN = DEFINED(XIP_RAM_ORIGIN) ? XIP_RAM_ORIGIN : 0x13FFC000; +XIP_RAM_LENGTH = DEFINED(XIP_RAM_LENGTH) ? XIP_RAM_LENGTH : 16k; diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld deleted file mode 100644 index 434cdab9..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld deleted file mode 100644 index 246bbf05..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_scratch.ld +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k - SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k -} diff --git a/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld b/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld deleted file mode 100644 index e94479b5..00000000 --- a/src/rp2_common/pico_crt0/rp2350/platform/memory_xip_ram.ld +++ /dev/null @@ -1,4 +0,0 @@ -MEMORY -{ - XIP_RAM(rwx) : ORIGIN = 0x13FFC000, LENGTH = 16k -} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld index 88127d89..12b7c85a 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_copy_to_ram.ld @@ -1,7 +1,10 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for storage memory regions */ INCLUDE "rp2_common/memory_aliases_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld index a8de400d..6b1ccf82 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_default.ld @@ -1,7 +1,10 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for storage memory regions */ INCLUDE "rp2_common/memory_aliases_default.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld index 61ae84dc..8fb49e6b 100644 --- a/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memmap_no_flash.ld @@ -1,6 +1,9 @@ +/* Include platform memory locations */ +INCLUDE "platform/default_locations.ld" + /* Include memory regions used */ -INCLUDE "platform/memory_ram.ld" -INCLUDE "platform/memory_scratch.ld" +INCLUDE "rp2_common/memory_ram.ld" +INCLUDE "rp2_common/memory_scratch.ld" /* Include aliases for no_flash storage memory regions (alias to themselves) */ INCLUDE "rp2_common/memory_aliases_no_flash.ld" diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld new file mode 100644 index 00000000..2b8a88a0 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + RAM(rwx) : ORIGIN = RAM_ORIGIN, LENGTH = RAM_LENGTH +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld new file mode 100644 index 00000000..7ba5d217 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_scratch.ld @@ -0,0 +1,5 @@ +MEMORY +{ + SCRATCH_X(rwx) : ORIGIN = SCRATCH_X_ORIGIN, LENGTH = SCRATCH_X_LENGTH + SCRATCH_Y(rwx) : ORIGIN = SCRATCH_Y_ORIGIN, LENGTH = SCRATCH_Y_LENGTH +} diff --git a/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld new file mode 100644 index 00000000..636e9013 --- /dev/null +++ b/src/rp2_common/pico_standard_link/scripts/rp2_common/memory_xip_ram.ld @@ -0,0 +1,4 @@ +MEMORY +{ + XIP_RAM(rwx) : ORIGIN = XIP_RAM_ORIGIN, LENGTH = XIP_RAM_LENGTH +} diff --git a/test/kitchen_sink/CMakeLists.txt b/test/kitchen_sink/CMakeLists.txt index 71b8a58b..33e5fbc2 100644 --- a/test/kitchen_sink/CMakeLists.txt +++ b/test/kitchen_sink/CMakeLists.txt @@ -215,13 +215,14 @@ if (NOT KITCHEN_SINK_NO_BINARY_TYPE_VARIANTS) target_compile_definitions(kitchen_sink_blocked_ram PRIVATE KITCHEN_SINK_ID="blocked-ram binary") endif() - add_executable(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) - # Have heap start from 0x20030000, and custom linker script - pico_set_linker_script(kitchen_sink_memmap_custom ${CMAKE_CURRENT_LIST_DIR}/memmap_custom.ld) - pico_set_linker_script_var(kitchen_sink_memmap_custom HEAP_LOC 0x20030000) - target_link_libraries(kitchen_sink_memmap_custom kitchen_sink_libs kitchen_sink_options) - pico_add_extra_outputs(kitchen_sink_memmap_custom) - target_compile_definitions(kitchen_sink_memmap_custom PRIVATE KITCHEN_SINK_ID="custom memmap binary") + add_executable(kitchen_sink_ram_custom ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink.c) + # Have ram start from 0x20020000 length 128k, and heap start from 0x20030000 + pico_set_linker_script_var(kitchen_sink_ram_custom RAM_ORIGIN 0x20020000) + pico_set_linker_script_var(kitchen_sink_ram_custom RAM_LENGTH 128k) + pico_set_linker_script_var(kitchen_sink_ram_custom HEAP_LOC 0x20030000) + target_link_libraries(kitchen_sink_ram_custom kitchen_sink_libs kitchen_sink_options) + pico_add_extra_outputs(kitchen_sink_ram_custom) + target_compile_definitions(kitchen_sink_ram_custom PRIVATE KITCHEN_SINK_ID="custom ram binary") endif() add_executable(kitchen_sink_cpp ${CMAKE_CURRENT_LIST_DIR}/kitchen_sink_cpp.cpp) diff --git a/test/kitchen_sink/memmap_custom.ld b/test/kitchen_sink/memmap_custom.ld deleted file mode 100644 index 7fe2098f..00000000 --- a/test/kitchen_sink/memmap_custom.ld +++ /dev/null @@ -1,18 +0,0 @@ -/* Include memory regions used */ -INCLUDE "rp2_common/memory_flash.ld" -INCLUDE "platform/memory_scratch.ld" - -/* Only use 128k of SRAM, starting at 0x20020000 */ -MEMORY -{ - RAM(rwx) : ORIGIN = 0x20020000, LENGTH = 128k -} - -/* Include aliases for storage memory regions */ -INCLUDE "rp2_common/memory_aliases_default.ld" - -/* Define entry point symbol */ -ENTRY(_entry_point) - -/* Include default sections */ -INCLUDE "rp2_common/sections_default.ld"