Skip to content

Commit

Permalink
Use arm toolchain and gdb multiarch from repo for rp2040
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikee47 committed Jun 2, 2024
1 parent 7c2ff7c commit ba69ec2
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 24 deletions.
126 changes: 126 additions & 0 deletions Sming/Arch/Rp2040/Components/libc/src/libc_replacements.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/reent.h>
#include <esp_attr.h>
#include <m_printf.h>

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(;;) {
}
}
29 changes: 15 additions & 14 deletions Sming/Arch/Rp2040/Tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions Sming/Arch/Rp2040/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Tools/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
16 changes: 13 additions & 3 deletions docs/source/upgrading/5.1-5.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ba69ec2

Please sign in to comment.