[Core] RISC-V toolchain and picolibc fixes (#15109)

* [Core] Fix RISC-V toolchain installation

The risc-v toolchain is only available on distributions based on Debian 11+
so we check for their availability before installing them.

* [Core] Fix heap symbols and syscalls for picolibc

picolibc internally uses __heap_start and __heap_end instead of the
defacto chibios linker script standard __heap_base__ and __heap_end__
therefore we introduce these symbols as an alias. Usually all memory
used within QMK is statically allocated, but some algorithms make usage
of malloc and friends.

Also the timeval struct is not defined by picolibc for syscalls, therefore it
is declared as stub.
This commit is contained in:
Stefan Kerkmann 2021-11-20 21:04:16 +01:00 committed by GitHub
parent 32215d5bff
commit 5c2052fd47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 12 deletions

View file

@ -316,7 +316,7 @@ endif
# #
# Use defined stack sizes of the main thread in linker scripts # Use defined stack sizes of the main thread in linker scripts
LDSYMBOLS =--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE) SHARED_LDSYMBOLS = -Wl,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
# Shared Compiler flags for all toolchains # Shared Compiler flags for all toolchains
SHARED_CFLAGS = -fomit-frame-pointer \ SHARED_CFLAGS = -fomit-frame-pointer \
@ -327,7 +327,6 @@ SHARED_CFLAGS = -fomit-frame-pointer \
# Shared Linker flags for all toolchains # Shared Linker flags for all toolchains
SHARED_LDFLAGS = -T $(LDSCRIPT) \ SHARED_LDFLAGS = -T $(LDSCRIPT) \
-Wl,$(LDSYMBOLS) \
-Wl,--gc-sections \ -Wl,--gc-sections \
-nostartfiles -nostartfiles
@ -346,14 +345,18 @@ ifeq ($(strip $(MCU)), risc-v)
endif endif
endif endif
# Default to compiling with picolibc for RISC-V targets if available, # Default to compiling with picolibc for RISC-V targets if available, which
# which is available by default on current (bullseye) debian based systems. # is available by default on distributions based on Debian 11+.
ifeq ($(shell $(TOOLCHAIN)gcc --specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) ifeq ($(shell $(TOOLCHAIN)gcc --specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
# Toolchain specific Compiler flags # Toolchain specific Compiler flags Note that we still link with our own
# Note that we still link with our own linker script # linker script by providing it via the -T flag in SHARED_LDFLAGS.
# by providing it via the -T flag above.
TOOLCHAIN_CFLAGS = --specs=picolibc.specs TOOLCHAIN_CFLAGS = --specs=picolibc.specs
# picolibc internally uses __heap_start and __heap_end instead of the
# defacto chibios linker script standard __heap_base__ and __heap_end__
# therefore we introduce these symbols as an alias.
TOOLCHAIN_LDSYMBOLS = -Wl,--defsym=__heap_start=__heap_base__,--defsym=__heap_end=__heap_end__
# Tell QMK that we are compiling with picolibc. # Tell QMK that we are compiling with picolibc.
OPT_DEFS += -DUSE_PICOLIBC OPT_DEFS += -DUSE_PICOLIBC
endif endif
@ -404,7 +407,7 @@ CFLAGS += $(SHARED_CFLAGS) $(TOOLCHAIN_CFLAGS)
CXXFLAGS += $(CFLAGS) $(SHARED_CXXFLAGS) $(TOOLCHAIN_CXXFLAGS) -fno-rtti CXXFLAGS += $(CFLAGS) $(SHARED_CXXFLAGS) $(TOOLCHAIN_CXXFLAGS) -fno-rtti
# Linker flags # Linker flags
LDFLAGS += $(SHARED_LDFLAGS) $(TOOLCHAIN_LDFLAGS) $(MCUFLAGS) LDFLAGS += $(SHARED_LDFLAGS) $(SHARED_LDSYMBOLS) $(TOOLCHAIN_LDFLAGS) $(TOOLCHAIN_LDSYMBOLS) $(MCUFLAGS)
# Tell QMK that we are hosting it on ChibiOS. # Tell QMK that we are hosting it on ChibiOS.
OPT_DEFS += -DPROTOCOL_CHIBIOS OPT_DEFS += -DPROTOCOL_CHIBIOS

View file

@ -22,6 +22,7 @@
* the _reent struct has to be defined. */ * the _reent struct has to be defined. */
#if defined(USE_PICOLIBC) #if defined(USE_PICOLIBC)
struct _reent; struct _reent;
struct timeval;
#endif #endif
#pragma GCC diagnostic ignored "-Wmissing-prototypes" #pragma GCC diagnostic ignored "-Wmissing-prototypes"

View file

@ -11,12 +11,18 @@ _qmk_install_prepare() {
_qmk_install() { _qmk_install() {
echo "Installing dependencies" echo "Installing dependencies"
sudo apt-get -yq install \ sudo apt-get --quiet --yes install \
build-essential clang-format diffutils gcc git unzip wget zip \ build-essential clang-format diffutils gcc git unzip wget zip \
python3-pip binutils-avr gcc-avr avr-libc binutils-arm-none-eabi \ python3-pip binutils-avr gcc-avr avr-libc binutils-arm-none-eabi \
gcc-arm-none-eabi libnewlib-arm-none-eabi avrdude dfu-programmer \ gcc-arm-none-eabi libnewlib-arm-none-eabi avrdude dfu-programmer \
dfu-util teensy-loader-cli libhidapi-hidraw0 libusb-dev \ dfu-util teensy-loader-cli libhidapi-hidraw0 libusb-dev
picolibc-riscv64-unknown-elf gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf
python3 -m pip install --user -r $QMK_FIRMWARE_DIR/requirements.txt # RISC-V toolchains with picolibc support are only available for distributions based on Debian 11+.
if sudo apt-get install --simulate --quiet --yes picolibc-riscv64-unknown-elf gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf > /dev/null 2>&1; then
sudo apt-get --quiet --yes install picolibc-riscv64-unknown-elf \
gcc-riscv64-unknown-elf \
binutils-riscv64-unknown-elf
fi
python3 -m pip install --user -r "$QMK_FIRMWARE_DIR"/requirements.txt
} }