From 5c2052fd476cb1d15eab66c23016a1add93f6767 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Sat, 20 Nov 2021 21:04:16 +0100 Subject: [PATCH] [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. --- platforms/chibios/platform.mk | 19 +++++++++++-------- platforms/chibios/syscall-fallbacks.c | 1 + util/install/debian.sh | 14 ++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/platforms/chibios/platform.mk b/platforms/chibios/platform.mk index 6b298732c2..1c8d430074 100644 --- a/platforms/chibios/platform.mk +++ b/platforms/chibios/platform.mk @@ -316,7 +316,7 @@ endif # # 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_CFLAGS = -fomit-frame-pointer \ @@ -327,7 +327,6 @@ SHARED_CFLAGS = -fomit-frame-pointer \ # Shared Linker flags for all toolchains SHARED_LDFLAGS = -T $(LDSCRIPT) \ - -Wl,$(LDSYMBOLS) \ -Wl,--gc-sections \ -nostartfiles @@ -346,14 +345,18 @@ ifeq ($(strip $(MCU)), risc-v) endif endif - # Default to compiling with picolibc for RISC-V targets if available, - # which is available by default on current (bullseye) debian based systems. + # Default to compiling with picolibc for RISC-V targets if available, which + # 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 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 }