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
This commit is contained in:
William Vinnicombe 2026-02-11 18:57:12 +00:00
parent 3811e671d5
commit a20f86a7e7
38 changed files with 99 additions and 41 deletions

View file

@ -1,4 +1,4 @@
/* Use blocked ram */
RAM_ORIGIN = 0x21000000;
INCLUDE "memmap_default.ld"
INCLUDE "rp2_common/memmap_default.ld"

View file

@ -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:$<JOIN:$<TARGET_PROPERTY:PICO_TARGET_LINKER_SCRIPT_VARS>,,>")

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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)

View file

@ -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");

View file

@ -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"