@@ -78,6 +78,51 @@ if (NOT TARGET pico_standard_link)
78
78
set_target_properties (${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE} )
79
79
endfunction ()
80
80
81
+ function (pico_set_modified_binary_type TARGET TYPE )
82
+ set (multiValueArgs RAM SCRATCH_X SCRATCH_Y)
83
+ cmake_parse_arguments (PARSE_ARGV 0 args
84
+ "" "" "${multiValueArgs} "
85
+ )
86
+
87
+ pico_set_binary_type(${TARGET} ${TYPE} )
88
+
89
+ # Scripts that will be created by this function
90
+ set (LINKER_CMAKE_SCRIPT "${CMAKE_CURRENT_BINARY_DIR} /memmap_${TARGET} .cmake" )
91
+ set (LINKER_LD_SCRIPT "${CMAKE_CURRENT_BINARY_DIR} /memmap_${TARGET} .ld" )
92
+
93
+ # Configure memmap_${TARGET}.cmake script file to create memmap_${TARGET}.ld
94
+ if (args_RAM)
95
+ list (POP_FRONT args_RAM ORIGIN LENGTH )
96
+ set (RAM "string(REGEX REPLACE \" RAM\\\\ (rwx\\\\ ) *: *ORIGIN *= *[0-9xX]*, *LENGTH *= *[0-9kKmM]*\\ n\" \" RAM(rwx) : ORIGIN = ${ORIGIN} , LENGTH = ${LENGTH} \\ n\" LINKER_SCRIPT \"\$ {LINKER_SCRIPT}\" )\n " )
97
+ endif ()
98
+ if (args_SCRATCH_X)
99
+ list (POP_FRONT args_SCRATCH_X ORIGIN LENGTH )
100
+ set (SCRATCH_X "string(REGEX REPLACE \" SCRATCH_X\\\\ (rwx\\\\ ) *: *ORIGIN *= *[0-9xX]*, *LENGTH *= *[0-9kKmM]*\\ n\" \" SCRATCH_X(rwx) : ORIGIN = ${ORIGIN} , LENGTH = ${LENGTH} \\ n\" LINKER_SCRIPT \"\$ {LINKER_SCRIPT}\" )\n " )
101
+ endif ()
102
+ if (args_SCRATCH_Y)
103
+ list (POP_FRONT args_SCRATCH_Y ORIGIN LENGTH )
104
+ set (SCRATCH_Y "string(REGEX REPLACE \" SCRATCH_Y\\\\ (rwx\\\\ ) *: *ORIGIN *= *[0-9xX]*, *LENGTH *= *[0-9kKmM]*\\ n\" \" SCRATCH_Y(rwx) : ORIGIN = ${ORIGIN} , LENGTH = ${LENGTH} \\ n\" LINKER_SCRIPT \"\$ {LINKER_SCRIPT}\" )\n " )
105
+ endif ()
106
+ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0" )
107
+ # CMAKE_CURRENT_FUNCTION_LIST_DIR added in 3.17.0
108
+ configure_file (${CMAKE_CURRENT_FUNCTION_LIST_DIR} /memmap_script.template.cmake ${LINKER_CMAKE_SCRIPT} @ONLY)
109
+ else ()
110
+ configure_file (${PICO_SDK_PATH} src/rp2_common/pico_standard_link/memmap_script.template.cmake ${LINKER_CMAKE_SCRIPT} @ONLY)
111
+ endif ()
112
+
113
+ # Add command to run this script whenever it or memmap_${TYPE}.ld changes
114
+ add_custom_command (OUTPUT ${LINKER_LD_SCRIPT}
115
+ COMMAND ${CMAKE_COMMAND}
116
+ -DPICO_LINKER_SCRIPT_PATH:PATH =${PICO_LINKER_SCRIPT_PATH}
117
+ -Doutput_file:FILEPATH =${LINKER_LD_SCRIPT}
118
+ -P "${LINKER_CMAKE_SCRIPT} "
119
+ DEPENDS ${PICO_LINKER_SCRIPT_PATH} /memmap_${TYPE} .ld ${LINKER_CMAKE_SCRIPT} )
120
+ add_custom_target (memmap_${TARGET} _ld DEPENDS ${LINKER_LD_SCRIPT} )
121
+ add_dependencies (${TARGET} memmap_${TARGET} _ld)
122
+
123
+ pico_set_linker_script(${TARGET} ${CMAKE_CURRENT_BINARY_DIR} /memmap_${TARGET} .ld)
124
+ endfunction ()
125
+
81
126
# slightly messy as we support both the preferred PICO_DEFAULT_BINARY_TYPE and the individual variables
82
127
if (NOT PICO_DEFAULT_BINARY_TYPE)
83
128
if (PICO_NO_FLASH)
0 commit comments