Skip to content

Commit

Permalink
Support builds with picolibc
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed Oct 16, 2021
1 parent 5dfcd6b commit 6634822
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
23 changes: 23 additions & 0 deletions platforms/chibios/boards/SIPEED_LONGAN_NANO/configs/chconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2021 QMK
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* To compile the ChibiOS syscall stubs with picolibc
* the _reent struct has to be defined. */
#if !defined(_FROM_ASM_) && defined(USE_PICOLIBC)
struct _reent;
#endif

#include_next <chconf.h>
19 changes: 16 additions & 3 deletions tmk_core/chibios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,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)
LDSYMBOLS =--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 \
Expand All @@ -311,7 +311,8 @@ SHARED_CFLAGS = -fomit-frame-pointer \
-fshort-wchar

# Shared Linker flags for all toolchains
SHARED_LDFLAGS = -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS) \
SHARED_LDFLAGS = -T $(LDSCRIPT) \
-Wl,$(LDSYMBOLS) \
-Wl,--gc-sections \
-nostartfiles

Expand All @@ -329,7 +330,19 @@ ifeq ($(strip $(MCU)), risc-v)
endif
endif
endif


# Default to compiling with picolibc for RISC-V targets if available,
# which is available by default on current (bullseye) debian based systems.
ifeq ($(shell $(TOOLCHAIN)gcc --specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
# Toolchain specific Compiler flags
# Note that we still link with our own linker script
# by providing it via the -T flag above.
TOOLCHAIN_CFLAGS = --specs=picolibc.specs

# Tell QMK that we are compiling with picolibc.
OPT_DEFS += -DUSE_PICOLIBC
endif

# MCU architecture flags
MCUFLAGS = -march=$(MCU_ARCH) \
-mabi=$(MCU_ABI) \
Expand Down
6 changes: 6 additions & 0 deletions tmk_core/common/chibios/syscall-fallbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include <sys/stat.h>
#include <sys/types.h>

/* To compile the ChibiOS syscall stubs with picolibc
* the _reent struct has to be defined. */
#if defined(USE_PICOLIBC)
struct _reent;
#endif

#pragma GCC diagnostic ignored "-Wmissing-prototypes"

__attribute__((weak, used)) int _open_r(struct _reent *r, const char *path, int flag, int m) {
Expand Down

0 comments on commit 6634822

Please sign in to comment.