Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pico_set_modified_binary_type function #2137

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/rp2_common/pico_standard_link/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,51 @@ if (NOT TARGET pico_standard_link)
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BINARY_TYPE ${TYPE})
endfunction()

function(pico_set_modified_binary_type TARGET TYPE)
set(multiValueArgs RAM SCRATCH_X SCRATCH_Y)
cmake_parse_arguments(PARSE_ARGV 0 args
"" "" "${multiValueArgs}"
)

pico_set_binary_type(${TARGET} ${TYPE})

# Scripts that will be created by this function
set(LINKER_CMAKE_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/memmap_${TARGET}.cmake")
set(LINKER_LD_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/memmap_${TARGET}.ld")

# Configure memmap_${TARGET}.cmake script file to create memmap_${TARGET}.ld
if (args_RAM)
list(POP_FRONT args_RAM ORIGIN LENGTH)
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")
endif()
if (args_SCRATCH_X)
list(POP_FRONT args_SCRATCH_X ORIGIN LENGTH)
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")
endif()
if (args_SCRATCH_Y)
list(POP_FRONT args_SCRATCH_Y ORIGIN LENGTH)
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")
endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
# CMAKE_CURRENT_FUNCTION_LIST_DIR added in 3.17.0
configure_file(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/memmap_script.template.cmake ${LINKER_CMAKE_SCRIPT} @ONLY)
else()
configure_file(${PICO_SDK_PATH}src/rp2_common/pico_standard_link/memmap_script.template.cmake ${LINKER_CMAKE_SCRIPT} @ONLY)
endif()

# Add command to run this script whenever it or memmap_${TYPE}.ld changes
add_custom_command(OUTPUT ${LINKER_LD_SCRIPT}
COMMAND ${CMAKE_COMMAND}
-DPICO_LINKER_SCRIPT_PATH:PATH=${PICO_LINKER_SCRIPT_PATH}
-Doutput_file:FILEPATH=${LINKER_LD_SCRIPT}
-P "${LINKER_CMAKE_SCRIPT}"
DEPENDS ${PICO_LINKER_SCRIPT_PATH}/memmap_${TYPE}.ld ${LINKER_CMAKE_SCRIPT})
add_custom_target(memmap_${TARGET}_ld DEPENDS ${LINKER_LD_SCRIPT})
add_dependencies(${TARGET} memmap_${TARGET}_ld)

pico_set_linker_script(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/memmap_${TARGET}.ld)
endfunction()

if (NOT PICO_DEFAULT_BINARY_TYPE)
if (PICO_NO_FLASH)
set(PICO_DEFAULT_BINARY_TYPE no_flash)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file(READ ${PICO_LINKER_SCRIPT_PATH}/memmap_@[email protected] LINKER_SCRIPT)
@RAM@
@SCRATCH_X@
@SCRATCH_Y@
file(WRITE ${output_file} "${LINKER_SCRIPT}")
Loading