From 5b712cd8cb9dd8b571efa120d3c6384a1aec3352 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 2 Jun 2025 14:13:07 -0700 Subject: [PATCH] pico-sdk: Switch to picolibc This selects picolibc by using --specs=picolibc.specs for compiling and linking. The linker scripts are adjusted to add KEEP to ensure that --gc-sections doesn't remove the contents of the files. Signed-off-by: Keith Packard --- ChangeLog.zephyr.md | 7 +++++++ src/rp2040/boot_stage2/CMakeLists.txt | 5 +++-- src/rp2040/boot_stage2/boot_stage2.ld | 4 ++-- src/rp2350/boot_stage2/CMakeLists.txt | 4 ++-- src/rp2350/boot_stage2/boot_stage2.ld | 4 ++-- src/rp2_common/pico_runtime/CMakeLists.txt | 5 +++-- src/rp2_common/pico_standard_link/CMakeLists.txt | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ChangeLog.zephyr.md b/ChangeLog.zephyr.md index e15cfbe51..779420215 100644 --- a/ChangeLog.zephyr.md +++ b/ChangeLog.zephyr.md @@ -3,6 +3,13 @@ Need to take care to not break these changes when updating pico-sdk. ## Patch List: + - [#10] pico-sdk: Switch to picolibc + - src/rp2040/boot_stage2/CMakeLists.txt + - src/rp2040/boot_stage2/boot_stage2.ld + - src/rp2350/boot_stage2/CMakeLists.txt + - src/rp2350/boot_stage2/boot_stage2.ld + - src/rp2_common/pico_runtime/CMakeLists.txt + - src/rp2_common/pico_standard_link/CMakeLists.txt - [#9] pico-sdk: Disabling sanity check the IRQ status - src/rp2_common/hardware_gpio/gpio.c - [#8] pico-sdk: pico_platform_compiler: Do not redefine `__weak` diff --git a/src/rp2040/boot_stage2/CMakeLists.txt b/src/rp2040/boot_stage2/CMakeLists.txt index ba42256b7..ef7e07b35 100644 --- a/src/rp2040/boot_stage2/CMakeLists.txt +++ b/src/rp2040/boot_stage2/CMakeLists.txt @@ -43,7 +43,8 @@ function(pico_define_boot_stage2 NAME SOURCES) if (PICO_C_COMPILER_IS_CLANG) target_link_options(${NAME} PRIVATE "-nostdlib") elseif (PICO_C_COMPILER_IS_GNU) - target_link_options(${NAME} PRIVATE "--specs=nosys.specs") + target_compile_options(${NAME} PRIVATE "--specs=picolibc.specs") + target_link_options(${NAME} PRIVATE "--specs=picolibc.specs") target_link_options(${NAME} PRIVATE "-nostartfiles") endif () @@ -51,7 +52,7 @@ function(pico_define_boot_stage2 NAME SOURCES) target_include_directories(${NAME} PRIVATE ${PICO_BOOT_STAGE2_DIR}/asminclude) target_link_libraries(${NAME} hardware_regs boot_stage2_headers) - target_link_options(${NAME} PRIVATE "LINKER:--script=${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld") + target_link_options(${NAME} PRIVATE "-T${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld") set_target_properties(${NAME} PROPERTIES LINK_DEPENDS ${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld) pico_add_dis_output(${NAME}) diff --git a/src/rp2040/boot_stage2/boot_stage2.ld b/src/rp2040/boot_stage2/boot_stage2.ld index 32978a16e..040dc81e1 100644 --- a/src/rp2040/boot_stage2/boot_stage2.ld +++ b/src/rp2040/boot_stage2/boot_stage2.ld @@ -8,7 +8,7 @@ SECTIONS { . = ORIGIN(SRAM); .text : { _start = .; /* make LLVM happy */ - *(.entry) - *(.text) + KEEP(*(.entry)) + KEEP(*(.text .text.*)) } >SRAM } diff --git a/src/rp2350/boot_stage2/CMakeLists.txt b/src/rp2350/boot_stage2/CMakeLists.txt index e878ccc5b..e0f7cc609 100644 --- a/src/rp2350/boot_stage2/CMakeLists.txt +++ b/src/rp2350/boot_stage2/CMakeLists.txt @@ -43,7 +43,7 @@ function(pico_define_boot_stage2 NAME SOURCES) if (PICO_C_COMPILER_IS_CLANG) target_link_options(${NAME} PRIVATE "-nostdlib") elseif (PICO_C_COMPILER_IS_GNU) - target_link_options(${NAME} PRIVATE "--specs=nosys.specs") + target_link_options(${NAME} PRIVATE "--specs=picolibc.specs") target_link_options(${NAME} PRIVATE "-nostartfiles") endif () @@ -51,7 +51,7 @@ function(pico_define_boot_stage2 NAME SOURCES) target_include_directories(${NAME} PRIVATE ${PICO_BOOT_STAGE2_DIR}/asminclude) target_link_libraries(${NAME} hardware_regs boot_stage2_headers) - target_link_options(${NAME} PRIVATE "LINKER:--script=${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld") + target_link_options(${NAME} PRIVATE "-T${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld") set_target_properties(${NAME} PROPERTIES LINK_DEPENDS ${PICO_BOOT_STAGE2_DIR}/boot_stage2.ld) pico_add_dis_output(${NAME}) diff --git a/src/rp2350/boot_stage2/boot_stage2.ld b/src/rp2350/boot_stage2/boot_stage2.ld index ee1bce466..67e454a15 100644 --- a/src/rp2350/boot_stage2/boot_stage2.ld +++ b/src/rp2350/boot_stage2/boot_stage2.ld @@ -8,7 +8,7 @@ SECTIONS { . = ORIGIN(SRAM); .text : { _start = .; /* make LLVM happy */ - *(.entry) - *(.text) + KEEP(*(.entry .entry.*)) + KEEP(*(.text .text.*)) } >SRAM } diff --git a/src/rp2_common/pico_runtime/CMakeLists.txt b/src/rp2_common/pico_runtime/CMakeLists.txt index da329e695..e86ae096c 100644 --- a/src/rp2_common/pico_runtime/CMakeLists.txt +++ b/src/rp2_common/pico_runtime/CMakeLists.txt @@ -46,7 +46,8 @@ endforeach() # todo is this correct/needed? if (PICO_C_COMPILER_IS_GNU) - target_link_options(pico_runtime INTERFACE "--specs=nosys.specs") + target_compile_options(pico_runtime INTERFACE "--specs=picolibc.specs") + target_link_options(pico_runtime INTERFACE "--specs=picolibc.specs") elseif (PICO_C_COMPILER_IS_CLANG) # target_link_options(pico_runtime INTERFACE "-nostdlib") endif() @@ -144,4 +145,4 @@ function(pico_minimize_runtime TARGET) if (NOT RUNTIME_INCLUDE_FPGA_CHECK) target_compile_definitions(${TARGET} PRIVATE PICO_NO_FPGA_CHECK=1) endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/src/rp2_common/pico_standard_link/CMakeLists.txt b/src/rp2_common/pico_standard_link/CMakeLists.txt index a428eb69d..3f378f153 100644 --- a/src/rp2_common/pico_standard_link/CMakeLists.txt +++ b/src/rp2_common/pico_standard_link/CMakeLists.txt @@ -65,7 +65,7 @@ if (NOT TARGET pico_standard_link) # 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 "$>,$,${PICO_LINKER_SCRIPT_PATH}/memmap_$,>,${PICO_DEFAULT_BINARY_TYPE},$>.ld>") target_link_options(pico_standard_link INTERFACE - "LINKER:--script=${_LINKER_SCRIPT_EXPRESSION}" + "-T${_LINKER_SCRIPT_EXPRESSION}" ) pico_add_link_depend(pico_standard_link ${_LINKER_SCRIPT_EXPRESSION}) unset(_LINKER_SCRIPT_EXPRESSION)