From ba69ec277baa992833c312d571bab4fdc746dbaf Mon Sep 17 00:00:00 2001 From: mikee47 Date: Sun, 2 Jun 2024 09:02:18 +0100 Subject: [PATCH] Use arm toolchain and gdb multiarch from repo for rp2040 Added `libc_replacements` which stubs-out various unused newlib functions. Without this, linker generates warnings like `_close is not implemented and will always fail`. These functions aren't actually used anyway and are discarded during garbage collection. Windows install unchanged; best solution is not to use Windows. --- .../Components/libc/src/libc_replacements.c | 126 ++++++++++++++++++ Sming/Arch/Rp2040/Tools/install.sh | 29 ++-- Sming/Arch/Rp2040/build.mk | 9 +- Tools/export.sh | 3 - docs/source/upgrading/5.1-5.2.rst | 16 ++- 5 files changed, 159 insertions(+), 24 deletions(-) create mode 100644 Sming/Arch/Rp2040/Components/libc/src/libc_replacements.c diff --git a/Sming/Arch/Rp2040/Components/libc/src/libc_replacements.c b/Sming/Arch/Rp2040/Components/libc/src/libc_replacements.c new file mode 100644 index 0000000000..7f5f87da0a --- /dev/null +++ b/Sming/Arch/Rp2040/Components/libc/src/libc_replacements.c @@ -0,0 +1,126 @@ +/* + libc_replacements.c - replaces libc functions with functions + from Espressif SDK + + Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 03 April 2015 by Markus Sattler + + */ + +#include +#include +#include +#include +#include +#include + +int _open_r(struct _reent* unused, const char* ptr, int mode) +{ + (void)unused; + (void)ptr; + (void)mode; + return 0; +} + +int _close_r(struct _reent* unused, int file) +{ + (void)unused; + (void)file; + return 0; +} + +int _fstat_r(struct _reent* unused, int file, struct stat* st) +{ + (void)unused; + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _lseek_r(struct _reent* unused, int file, int ptr, int dir) +{ + (void)unused; + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +int _read_r(struct _reent* unused, int file, char* ptr, int len) +{ + (void)unused; + (void)file; + (void)ptr; + (void)len; + return 0; +} + +int _write_r(struct _reent* r, int file, char* ptr, int len) +{ + (void)r; + if(file == STDOUT_FILENO) { + return m_nputs(ptr, len); + } + return 0; +} + +int _putc_r(struct _reent* r, int c, FILE* file) __attribute__((weak)); + +int _putc_r(struct _reent* r, int c, FILE* file) +{ + (void)r; + if(file->_file == STDOUT_FILENO) { + m_putc(c); + return c; + } + return EOF; +} + +int puts(const char* str) +{ + m_puts(str); + m_putc('\n'); + return 1; +} + +#undef putchar +int putchar(int c) +{ + m_putc(c); + return c; +} + +void _exit(int status) +{ + (void)status; + abort(); +} + +int atexit(void (*func)()) +{ + (void)func; + return 0; +} + +void abort() __attribute((weak)); +void abort() +{ + for(;;) { + } +} diff --git a/Sming/Arch/Rp2040/Tools/install.sh b/Sming/Arch/Rp2040/Tools/install.sh index 03451153e5..542a502b33 100755 --- a/Sming/Arch/Rp2040/Tools/install.sh +++ b/Sming/Arch/Rp2040/Tools/install.sh @@ -2,18 +2,19 @@ # # Rp2040 install.sh -$PKG_INSTALL ninja-build +case $DIST in + debian) + $PKG_INSTALL \ + ninja-build \ + libstdc++-arm-none-eabi-newlib \ + gdb-multiarch + ;; -if [ -d "$PICO_TOOLCHAIN_PATH/arm-none-eabi" ]; then - printf "\n\n** Skipping Rp2040 tools installation: '$PICO_TOOLCHAIN_PATH' exists\n\n" -else - TOOLCHAIN_VERSION="10.3-2021.10" - TOOLCHAIN_BASE_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm" - TOOLCHAIN_NAME="gcc-arm-none-eabi-$TOOLCHAIN_VERSION" - TOOLCHAIN_FILE="$TOOLCHAIN_NAME-$(uname -m)-linux.tar.bz2" - TOOLCHAIN_URL="$TOOLCHAIN_BASE_URL/$TOOLCHAIN_VERSION/$TOOLCHAIN_FILE" - $WGET "$TOOLCHAIN_URL" -O "$DOWNLOADS/$TOOLCHAIN_FILE" - mkdir -p "$PICO_TOOLCHAIN_PATH" - tar -jxf "$DOWNLOADS/$TOOLCHAIN_FILE" -C "$PICO_TOOLCHAIN_PATH" --totals --transform='s|^/*||' - mv "$PICO_TOOLCHAIN_PATH/$TOOLCHAIN_NAME/"* "$PICO_TOOLCHAIN_PATH" -fi + fedora) + $PKG_INSTALL \ + ninja-build \ + arm-none-eabi-gcc-cs-c++ \ + arm-none-eabi-newlib + ;; + +esac diff --git a/Sming/Arch/Rp2040/build.mk b/Sming/Arch/Rp2040/build.mk index 77cb67856f..eed70da219 100644 --- a/Sming/Arch/Rp2040/build.mk +++ b/Sming/Arch/Rp2040/build.mk @@ -22,15 +22,16 @@ DEBUG_VARS += PICO_TOOLCHAIN_PATH ifdef PICO_TOOLCHAIN_PATH export PICO_TOOLCHAIN_PATH := $(call FixPath,$(PICO_TOOLCHAIN_PATH)) TOOLSPEC := $(PICO_TOOLCHAIN_PATH)/bin/$(CONFIG_TOOLPREFIX)- +GDB_TOOLSPEC := $(TOOLSPEC) ifeq (,$(wildcard $(PICO_TOOLCHAIN_PATH)/$(CONFIG_TOOLPREFIX))) $(error PICO_TOOLCHAIN_PATH not set correctly: $(PICO_TOOLCHAIN_PATH)) endif else -PICO_TOOLCHAIN_PATH := $(shell which $(CONFIG_TOOLPREFIX)-gcc) -ifeq (,$(PICO_TOOLCHAIN_PATH)) +ifeq (,$(shell which $(CONFIG_TOOLPREFIX)-gcc)) $(error Toolchain not found, maybe set PICO_TOOLCHAIN_PATH) endif -TOOLSPEC := $(dir $(PICO_TOOLCHAIN_PATH))$(CONFIG_TOOLPREFIX)- +TOOLSPEC := $(CONFIG_TOOLPREFIX)- +GDB_TOOLSPEC := endif # select which tools to use as assembler, compiler, librarian and linker @@ -42,7 +43,7 @@ LD := $(TOOLSPEC)gcc NM := $(TOOLSPEC)nm OBJCOPY := $(TOOLSPEC)objcopy OBJDUMP := $(TOOLSPEC)objdump -GDB := $(TOOLSPEC)gdb +GDB := $(GDB_TOOLSPEC)gdb CPPFLAGS += \ -nostdlib diff --git a/Tools/export.sh b/Tools/export.sh index 763f395023..ca2d26dd33 100755 --- a/Tools/export.sh +++ b/Tools/export.sh @@ -36,6 +36,3 @@ export ESP_HOME=${ESP_HOME:=/opt/esp-quick-toolchain} # Esp32 export IDF_PATH=${IDF_PATH:=/opt/esp-idf} export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=/opt/esp32} - -# Rp2040 -export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=/opt/rp2040} diff --git a/docs/source/upgrading/5.1-5.2.rst b/docs/source/upgrading/5.1-5.2.rst index b7c034a8ac..ae59e4ffa9 100644 --- a/docs/source/upgrading/5.1-5.2.rst +++ b/docs/source/upgrading/5.1-5.2.rst @@ -43,7 +43,17 @@ esp8266: https://github.com/earlephilhower/newlib-xtensa/blob/xtensa-4_0_0-lock- esp32: https://github.com/espressif/newlib-esp32/blob/esp-4.3.0/newlib/libc/ -**Esp32 IDF** +**Toolchain versions updated** -The installation scripts now install IDF version 5.2 by default. -See :ref:`idf_versions` for further details. +Esp8266 + The installer has been updated to use the latest toolchain (Feb 23), gcc 10.3. + +Esp32 IDF + The installation scripts now install IDF version 5.2 by default. + See :ref:`idf_versions` for further details. + +RP2040 + The installation scripts install the ARM toolchain available in your Linux distribution. + + Previously it installed a version from ARMs developer website to /opt/rp2040 and set ``PICO_TOOLCHAIN_PATH`` accordingly. + With the new version there is no longer any need to set this environment variable.