Add customisable heap location, with pico_set_linker_script_var function

This commit is contained in:
William Vinnicombe 2025-12-01 20:40:45 +00:00
parent 18e65fad16
commit 1ae7e0b9c8
7 changed files with 24 additions and 12 deletions

View file

@ -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 : {

View file

@ -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 : {

View file

@ -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 : {

View file

@ -226,7 +226,7 @@ SECTIONS
}
PROVIDE(__persistent_data_end__ = .);
.heap (NOLOAD):
.heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD):
{
__end__ = .;
end = __end__;
@ -234,7 +234,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 : {

View file

@ -219,7 +219,7 @@ SECTIONS
}
PROVIDE(__persistent_data_end__ = .);
.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 : {

View file

@ -179,7 +179,7 @@ SECTIONS
}
PROVIDE(__persistent_data_end__ = .);
.heap (NOLOAD):
.heap DEFINED(HEAP_LOC) ? HEAP_LOC : . (NOLOAD):
{
__end__ = .;
end = __end__;
@ -187,7 +187,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 : {

View file

@ -105,6 +105,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
#
@ -165,6 +174,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:$<JOIN:$<TARGET_PROPERTY:PICO_TARGET_LINKER_SCRIPT_VARS>,,>")
# 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 "$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_LINKER_SCRIPT>>,$<TARGET_PROPERTY:PICO_TARGET_LINKER_SCRIPT>,${PICO_LINKER_SCRIPT_PATH}/memmap_$<IF:$<STREQUAL:$<TARGET_PROPERTY:PICO_TARGET_BINARY_TYPE>,>,${PICO_DEFAULT_BINARY_TYPE},$<TARGET_PROPERTY:PICO_TARGET_BINARY_TYPE>>.ld>")