summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--3rd-party/pico-sdk.patch33
-rw-r--r--3rd-party/picolibc.patch90
-rw-r--r--CMakeLists.txt30
-rw-r--r--build-aux/picolibc/CMakeLists.txt23
-rw-r--r--build-aux/picolibc/cross-cortex-m0-none-eabi.txt66
5 files changed, 242 insertions, 0 deletions
diff --git a/3rd-party/pico-sdk.patch b/3rd-party/pico-sdk.patch
new file mode 100644
index 0000000..a74c9f0
--- /dev/null
+++ b/3rd-party/pico-sdk.patch
@@ -0,0 +1,33 @@
+diff --git a/src/rp2040/boot_stage2/CMakeLists.txt b/src/rp2040/boot_stage2/CMakeLists.txt
+index c576878..dd8d1e8 100644
+--- a/src/rp2040/boot_stage2/CMakeLists.txt
++++ b/src/rp2040/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=nosys.specs")
+ target_link_options(${NAME} PRIVATE "-nostartfiles")
+ endif ()
+
+diff --git a/src/rp2_common/pico_runtime/CMakeLists.txt b/src/rp2_common/pico_runtime/CMakeLists.txt
+index 3665cd8..bed4b47 100644
+--- a/src/rp2_common/pico_runtime/CMakeLists.txt
++++ b/src/rp2_common/pico_runtime/CMakeLists.txt
+@@ -46,7 +46,7 @@ endforeach()
+
+ # todo is this correct/needed?
+ if (PICO_C_COMPILER_IS_GNU)
+- target_link_options(pico_runtime INTERFACE "--specs=nosys.specs")
++ #target_link_options(pico_runtime INTERFACE "--specs=nosys.specs")
+ elseif (PICO_C_COMPILER_IS_CLANG)
+ # target_link_options(pico_runtime INTERFACE "-nostdlib")
+ endif()
+@@ -117,4 +117,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/3rd-party/picolibc.patch b/3rd-party/picolibc.patch
new file mode 100644
index 0000000..fdaf59f
--- /dev/null
+++ b/3rd-party/picolibc.patch
@@ -0,0 +1,90 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 391d2360c..a466455a8 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -59,7 +59,7 @@ endif()
+ set(CMAKE_SYSTEM_SUB_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
+
+ if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686" OR
+- ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
++ ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
+ set(CMAKE_SYSTEM_PROCESSOR "x86")
+ endif()
+
+@@ -512,6 +512,24 @@ CHECK_INCLUDE_FILE(xtensa/config/core-isa.h _XTENSA_HAVE_CONFIG_CORE_ISA_H)
+
+ configure_file(picolibc.h.in "${PICOLIBC_INCLUDE}/picolibc.h")
+
++set(DEFAULT_FLASH_ADDR 0x00000000)
++set(DEFAULT_FLASH_SIZE 0x00400000)
++set(DEFAULT_RAM_ADDR 0x20000000)
++set(DEFAULT_RAM_SIZE 0x00200000)
++set(DEFAULT_STACK_SIZE 0x00001000)
++set(DEFAULT_ALIGNMENT 8)
++
++set(BFD_START "")
++set(BFD_END "")
++set(LLD_START "/* For ld.lld: ")
++set(LLD_END "*/")
++set(TLS_PHDRS "tls_init PT_TLS;
++tls PT_TLS;")
++set(TLS_INIT_SEG "tls_init")
++
++configure_file(picolibc.ld.in "${PROJECT_BINARY_DIR}/picolibc.ld" @ONLY)
++set(PICOLIBC_LD "${PROJECT_BINARY_DIR}/picolibc.ld")
++
+ set(INCLUDEDIR include)
+ set(LIBDIR .)
+ if(PICOLIBC_TLS)
+@@ -524,7 +542,8 @@ set(ADDITIONAL_LIBS "")
+ set(SPECS_EXTRA "")
+ set(SPECS_ISYSTEM "-isystem ${PROJECT_BINARY_DIR}/${include}")
+ set(SPECS_LIBPATH "-L${PROJECT_BINARY_DIR}")
+-set(SPECS_STARTFILE "${PROJECT_BINARY_DIR}/crt0.o")
++set(SPECS_STARTFILE "@SPECS_STARTFILE@")
++
+ string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f_vfprintf}"
+ " %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfscanf=__f_vfscanf}"
+ " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfprintf=__d_vfprintf}"
+@@ -536,7 +555,13 @@ string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f
+ )
+ set(PREFIX "${PROJECT_BINARY_DIR}")
+
+-configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs" @ONLY)
++configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs.in2" @ONLY)
++
++add_custom_command(
++ OUTPUT "${PROJECT_BINARY_DIR}/picolibc.specs"
++ DEPENDS "${PROJECT_BINARY_DIR}/picolibc.specs.in2" picocrt
++ COMMAND sed "s,@SPECS_STARTFILE@,$<TARGET_OBJECTS:picocrt>,g" <"${PROJECT_BINARY_DIR}/picolibc.specs.in2" >"${PROJECT_BINARY_DIR}/picolibc.specs"
++)
+
+ set(PICOLIBC_COMPILE_OPTIONS
+ "-nostdlib"
+@@ -571,7 +596,8 @@ picolibc_supported_compile_options(
+ "-fsignaling-nans"
+ )
+
+-add_library(c STATIC)
++add_library(c STATIC
++ "${PROJECT_BINARY_DIR}/picolibc.specs")
+
+ target_compile_options(c PRIVATE ${PICOLIBC_COMPILE_OPTIONS})
+
+@@ -586,6 +612,8 @@ define_property(GLOBAL PROPERTY PICOLIBC_HEADERS
+
+ add_subdirectory(newlib)
+
++add_subdirectory(picocrt)
++
+ install(TARGETS c
+ LIBRARY DESTINATION lib
+ PUBLIC_HEADER DESTINATION include)
+@@ -597,7 +625,6 @@ if(TESTS)
+ # semihosting-based tests
+
+ add_subdirectory(semihost)
+- add_subdirectory(picocrt)
+
+ set(PICOCRT_OBJ $<TARGET_OBJECTS:picocrt>)
+ set(PICOCRT_SEMIHOST_OBJ $<TARGET_OBJECTS:picocrt-semihost>)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 100214c..76e31ef 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,11 @@ if (NOT PICO_PLATFORM)
endif()
set(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/3rd-party/pico-sdk")
+
+if (PICO_PLATFORM STREQUAL "rp2040")
+ set(PICO_CLIB "picolibc")
+ add_library(pico_cxx_options INTERFACE)
+endif()
include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake")
project(sbc_harness)
@@ -62,6 +67,31 @@ function(add_stack_analysis arg_outfile arg_objlib_target)
)
endfunction()
+if (PICO_PLATFORM STREQUAL "rp2040")
+ set(TESTS ON)
+ add_subdirectory(3rd-party/picolibc)
+
+ foreach(lib IN ITEMS pico_clib_interface)
+ # cpp
+ target_include_directories(${lib} INTERFACE ${CMAKE_BINARY_DIR}/3rd-party/picolibc/picolibc/include)
+ target_compile_definitions(${lib} INTERFACE
+ PICO_RUNTIME_NO_INIT_PER_CORE_TLS_SETUP=1
+ PICO_RUNTIME_SKIP_INIT_PER_CORE_TLS_SETUP=1
+ )
+
+ # cc
+ target_compile_options(${lib} INTERFACE --specs=${CMAKE_BINARY_DIR}/3rd-party/picolibc/picolibc.specs)
+ target_compile_options(${lib} INTERFACE -nolibc)
+
+ # ld
+ target_link_options( ${lib} INTERFACE --specs=${CMAKE_BINARY_DIR}/3rd-party/picolibc/picolibc.specs)
+ target_link_options( ${lib} INTERFACE -nolibc -lgcc)
+ target_link_libraries( ${lib} INTERFACE c)
+ endforeach()
+ target_link_options( bs2_default PRIVATE --specs=${CMAKE_BINARY_DIR}/3rd-party/picolibc/picolibc.specs -nolibc -lgcc)
+ target_link_libraries( bs2_default c)
+endif()
+
add_subdirectory(libcr)
add_subdirectory(libcr_ipc)
add_subdirectory(libmisc)
diff --git a/build-aux/picolibc/CMakeLists.txt b/build-aux/picolibc/CMakeLists.txt
new file mode 100644
index 0000000..e67347c
--- /dev/null
+++ b/build-aux/picolibc/CMakeLists.txt
@@ -0,0 +1,23 @@
+# https://github.com/picolibc/picolibc/issues/696
+
+include(ExternalProject)
+
+ExternalProject_Add(picolibc
+ PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
+ SOURCE_DIR "${CMAKE_SOURCE_DIR}/3rd-party/picolibc"
+ CONFIGURE_COMMAND meson setup \
+ --cross-file "${CMAKE_CURRENT_SOURCE_DIR}/cross-cortex-m0-none-eabi.txt" \
+ -Dc_args=-funwind-tables \
+ -Dc_args=-mpoke-function-name \
+ -Dmultilib=false \
+ -Dprefix="${CMAKE_CURRENT_BINARY_DIR}" \
+ -Dincludedir=arm-none-eabi/include \
+ -Dlibdir=arm-none-eabi/lib \
+ -Dspecsdir=arm-none-eabi/lib \
+ "${CMAKE_SOURCE_DIR}/3rd-party/picolibc"
+ BUILD_COMMAND ninja
+ INSTALL_COMMAND ninja install
+ LOG_CONFIGURE false
+ LOG_BUILD false
+ LOG_INSTALL false
+)
diff --git a/build-aux/picolibc/cross-cortex-m0-none-eabi.txt b/build-aux/picolibc/cross-cortex-m0-none-eabi.txt
new file mode 100644
index 0000000..38f4c05
--- /dev/null
+++ b/build-aux/picolibc/cross-cortex-m0-none-eabi.txt
@@ -0,0 +1,66 @@
+# https://github.com/picolibc/picolibc/issues/696#issuecomment-2015532132
+# https://github.com/picolibc/picolibc/files/14726061/cross-cortex-m0-none-eabi.txt
+# https://github.com/picolibc/picolibc/blob/1.8.8/scripts/cross-cortex-a9-none-eabi.txt
+# https://github.com/picolibc/picolibc/blob/1.8.8/COPYING.picolibc#L2868-L2916
+# https://github.com/picolibc/picolibc/blob/1.8.8/COPYING.picolibc#L5908-L5936
+#
+# Copyright (C) 2020 The Newlib Project
+# Copyright (C) 2021-2024 Keith Packard
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+[binaries]
+# Meson 0.53.2 doesn't use any cflags when doing basic compiler tests,
+# so we have to add -nostdlib to the compiler configuration itself or
+# early compiler tests will fail. This can be removed when picolibc
+# requires at least version 0.54.2 of meson.
+c = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-nostdlib']
+cpp = ['arm-none-eabi-g++', '-mcpu=cortex-m0', '-nostdlib']
+ar = 'arm-none-eabi-ar'
+as = 'arm-none-eabi-as'
+nm = 'arm-none-eabi-nm'
+strip = 'arm-none-eabi-strip'
+# only needed to run tests
+exe_wrapper = ['sh', '-c', 'test -z "$PICOLIBC_TEST" || run-arm "$@"', 'run-arm']
+
+[host_machine]
+system = 'none'
+cpu_family = 'arm'
+cpu = 'cortex-m0'
+endian = 'little'
+
+[properties]
+skip_sanity_check = true
+default_flash_addr = '0x00000000'
+default_flash_size = '0x00400000'
+default_ram_addr = '0x20000000'
+default_ram_size = '0x00200000'