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 0475219
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 25 deletions.
12 changes: 11 additions & 1 deletion Sming/Arch/Rp2040/Components/libc/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ LIBC_DEFSYMS := \
__wrap_vprintf=m_vprintf \
__wrap_printf=m_printf

EXTRA_LDFLAGS := $(call DefSym,$(LIBC_DEFSYMS))
LIBC_UNDEFSYMS := \
_close_r \
_lseek_r \
_read_r \
_write_r \
_isatty_r


EXTRA_LDFLAGS := \
$(call DefSym,$(LIBC_DEFSYMS)) \
$(call Undef,$(LIBC_UNDEFSYMS))
86 changes: 86 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,86 @@
/*
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 _isatty_r(struct _reent* r, int fd)
{
return 0;
}
17 changes: 13 additions & 4 deletions Sming/Arch/Rp2040/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,30 @@ The following instructions should help.

Compiler/linker
The RP2040 contains two ARM Cortex-M0+ cores. Tools for all platforms can be downloaded from the
`ARM developer website <https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads>`__.
`ARM developer website <https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads>`__.

Unzip the archive to a suitable location (e.g. ``/opt/rp2040`` or ``c:\tools\rp2040``) and set :envvar:`PICO_TOOLCHAIN_PATH` accordingly.

.. note::

At time of writing the Ubuntu repositories contain an older version of this toolchain.
It also does not contain GDB, but can be installed separately:
The Sming installer script can do this for you ``Tools/install.sh rp2040``

You can alternatively use the toolchains provided in your GNU/Linux distribution.

Ubuntu
::
sudo apt install gcc-arm-none-eabi gdb-multiarch

To use gdb-multiarch you'll need to do this:
To use gdb-multiarch you'll need to do this::

make gdb GDB=gdb-multiarch

Fedora
::
sudo dnf install arm-none-eabi-gcc-cs-c++ arm-none-eabi-newlib

The standard GDB appears to work OK.

Ninja
This is used to build the RP2040 SDK code:

Expand Down
10 changes: 5 additions & 5 deletions Sming/Arch/Rp2040/Tools/install.cmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
REM Rp2040 install.cmd

if exist "%PICO_TOOLCHAIN_PATH%/arm-none-eabi" goto :already_got
set TOOLCHAIN_VERSION=10.3-2021.07
set TOOLCHAIN_BASE_URL=https://developer.arm.com/-/media/Files/downloads/gnu-rm
set TOOLCHAIN_NAME=gcc-arm-none-eabi-%TOOLCHAIN_VERSION%
set TOOLCHAIN_FILE=%TOOLCHAIN_NAME%-win32.zip
curl -Lo tmp.zip %TOOLCHAIN_BASE_URL%/%TOOLCHAIN_VERSION%/%TOOLCHAIN_FILE% || goto :EOF
set TOOLCHAIN_VERSION=13.2.rel1
set TOOLCHAIN_BASE_URL=https://developer.arm.com/-/media/Files/downloads/gnu
set TOOLCHAIN_NAME=arm-gnu-toolchain-%TOOLCHAIN_VERSION%-mingw-w64-i686-arm-none-eabi
set TOOLCHAIN_FILE=%TOOLCHAIN_NAME%.zip
curl -Lo tmp.zip %TOOLCHAIN_BASE_URL%/%TOOLCHAIN_VERSION%/binrel/%TOOLCHAIN_FILE% || goto :EOF
7z -o"%PICO_TOOLCHAIN_PATH%-tmp" x tmp.zip || goto :EOF
del tmp.zip
move "%PICO_TOOLCHAIN_PATH%-tmp/%TOOLCHAIN_NAME%" "%PICO_TOOLCHAIN_PATH%"
Expand Down
15 changes: 7 additions & 8 deletions Sming/Arch/Rp2040/Tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ $PKG_INSTALL ninja-build

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"
elif [ -n "$PICO_TOOLCHAIN_PATH" ]; then
TOOLCHAIN_VERSION="13.2.rel1"
TOOLCHAIN_BASE_URL="https://developer.arm.com/-/media/Files/downloads/gnu"
TOOLCHAIN_FILE="arm-gnu-toolchain-$TOOLCHAIN_VERSION-$(uname -m)-arm-none-eabi.tar.xz"
TOOLCHAIN_URL="$TOOLCHAIN_BASE_URL/$TOOLCHAIN_VERSION/binrel/$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"
tar -xf "$DOWNLOADS/$TOOLCHAIN_FILE" -C "$PICO_TOOLCHAIN_PATH" --totals --transform='s|^/*||'
mv "$PICO_TOOLCHAIN_PATH/"*/* "$PICO_TOOLCHAIN_PATH"
fi
1 change: 1 addition & 0 deletions Sming/Arch/Rp2040/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# linker flags used to generate the main object file
LDFLAGS += \
-Wl,--no-warn-rwx-segments \
-Wl,--build-id=none \
--specs=nosys.specs \
-mcpu=cortex-m0plus \
Expand Down
7 changes: 3 additions & 4 deletions Sming/Arch/Rp2040/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ 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)-
endif

# select which tools to use as assembler, compiler, librarian and linker
Expand All @@ -42,7 +41,7 @@ LD := $(TOOLSPEC)gcc
NM := $(TOOLSPEC)nm
OBJCOPY := $(TOOLSPEC)objcopy
OBJDUMP := $(TOOLSPEC)objdump
GDB := $(TOOLSPEC)gdb
GDB := gdb

CPPFLAGS += \
-nostdlib
Expand Down
13 changes: 10 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,14 @@ 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 installer has been updated to use the latest toolchain (Oct 23), gcc 13.2.

0 comments on commit 0475219

Please sign in to comment.