From cff8e862b8f6d1227451ea4dc3afb3277c2fd378 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 11 Sep 2020 14:23:25 +0200 Subject: [PATCH 1/4] picolibc: model as a feature --- cpu/arm7_common/Kconfig | 1 + cpu/arm7_common/Makefile.dep | 2 +- cpu/arm7_common/Makefile.features | 1 + cpu/cortexm_common/Kconfig | 1 + cpu/cortexm_common/Makefile.dep | 2 +- cpu/cortexm_common/Makefile.features | 1 + cpu/fe310/Kconfig | 1 + cpu/fe310/Makefile.dep | 2 +- cpu/fe310/Makefile.features | 1 + kconfigs/Kconfig.features | 5 +++++ 10 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cpu/arm7_common/Kconfig b/cpu/arm7_common/Kconfig index 8d2959b5bf..edc4337c63 100644 --- a/cpu/arm7_common/Kconfig +++ b/cpu/arm7_common/Kconfig @@ -23,6 +23,7 @@ config CPU_CORE_ARM7TDMI_S ## Declaration of specific features config HAS_ARCH_ARM7 bool + select HAS_PICOLIBC help Indicates that the core is part of the ARM7 group of cores. diff --git a/cpu/arm7_common/Makefile.dep b/cpu/arm7_common/Makefile.dep index 2d3962bb58..fabfff3190 100644 --- a/cpu/arm7_common/Makefile.dep +++ b/cpu/arm7_common/Makefile.dep @@ -1,7 +1,7 @@ # use common ARM7 periph code USEMODULE += arm7_common_periph -ifeq (1,$(PICOLIBC)) +ifneq (,$(filter picolibc,$(FEATURES_USED))) # Use Picolibc when explicitly selected USEMODULE += picolibc else diff --git a/cpu/arm7_common/Makefile.features b/cpu/arm7_common/Makefile.features index f382f9a5d8..b4681a50cd 100644 --- a/cpu/arm7_common/Makefile.features +++ b/cpu/arm7_common/Makefile.features @@ -7,5 +7,6 @@ FEATURES_PROVIDED += arch_arm7 FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += periph_pm +FEATURES_PROVIDED += picolibc FEATURES_PROVIDED += puf_sram FEATURES_PROVIDED += ssp diff --git a/cpu/cortexm_common/Kconfig b/cpu/cortexm_common/Kconfig index 13a67d2caa..ab3db98e04 100644 --- a/cpu/cortexm_common/Kconfig +++ b/cpu/cortexm_common/Kconfig @@ -39,6 +39,7 @@ config CPU_CORE_CORTEX_M select HAS_CPU_CORE_CORTEXM select HAS_PERIPH_PM select HAS_PUF_SRAM + select HAS_PICOLIBC select HAS_CPP select HAS_LIBSTDCPP select HAS_CPU_CHECK_ADDRESS diff --git a/cpu/cortexm_common/Makefile.dep b/cpu/cortexm_common/Makefile.dep index edc2835da9..d2b74c516f 100644 --- a/cpu/cortexm_common/Makefile.dep +++ b/cpu/cortexm_common/Makefile.dep @@ -4,7 +4,7 @@ USEMODULE += cortexm_common # include common periph code USEMODULE += cortexm_common_periph -ifeq (1,$(PICOLIBC)) +ifneq (,$(filter picolibc,$(FEATURES_USED))) # Use Picolibc when explicitly selected USEMODULE += picolibc else diff --git a/cpu/cortexm_common/Makefile.features b/cpu/cortexm_common/Makefile.features index 7527c079d0..4c5e44fb26 100644 --- a/cpu/cortexm_common/Makefile.features +++ b/cpu/cortexm_common/Makefile.features @@ -7,6 +7,7 @@ FEATURES_PROVIDED += cpu_core_cortexm FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += puf_sram +FEATURES_PROVIDED += picolibc FEATURES_PROVIDED += ssp # cortex-m4f and cortex-m7 provide FPU support diff --git a/cpu/fe310/Kconfig b/cpu/fe310/Kconfig index bdadfff1b5..1dc1554eac 100644 --- a/cpu/fe310/Kconfig +++ b/cpu/fe310/Kconfig @@ -8,6 +8,7 @@ config CPU_ARCH_RISCV bool select HAS_ARCH_RISCV + select HAS_PICOLIBC config CPU_CORE_RV32M bool diff --git a/cpu/fe310/Makefile.dep b/cpu/fe310/Makefile.dep index ff4abe1366..99efb3df64 100644 --- a/cpu/fe310/Makefile.dep +++ b/cpu/fe310/Makefile.dep @@ -1,4 +1,4 @@ -ifeq (1,$(PICOLIBC)) +ifneq (,$(filter picolibc,$(FEATURES_USED))) USEMODULE += picolibc else USEMODULE += newlib_nano diff --git a/cpu/fe310/Makefile.features b/cpu/fe310/Makefile.features index 9f46d6ce83..b60d9bd97e 100644 --- a/cpu/fe310/Makefile.features +++ b/cpu/fe310/Makefile.features @@ -7,4 +7,5 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_plic FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += periph_wdt +FEATURES_PROVIDED += picolibc FEATURES_PROVIDED += ssp diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index 057ee85e2d..120d0fe58c 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -288,6 +288,11 @@ config HAS_PERIPH_WDT_CB help Indicates that the WDT peripheral allows setting a callback. +config HAS_PICOLIBC + bool + help + Indicates that the picolibc C library is available for the platform. + config HAS_PUF_SRAM bool help From 69dd791cbdb8ff8af1833fdf566dfebae08b6c9a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 11 Sep 2020 14:25:44 +0200 Subject: [PATCH 2/4] examples/gnrc_minimal: use picolibc On `samr21-xpro` this saves 5624 bytes of ROM and 108 bytes of RAM. --- examples/gnrc_minimal/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/gnrc_minimal/Makefile b/examples/gnrc_minimal/Makefile index cb657e60b4..e6387276b2 100644 --- a/examples/gnrc_minimal/Makefile +++ b/examples/gnrc_minimal/Makefile @@ -26,6 +26,9 @@ USEMODULE += gnrc_icmpv6_echo # Use minimal standard PRNG USEMODULE += prng_minstd +# Use picolibc when available +FEATURES_OPTIONAL += picolibc + CFLAGS += -DLOG_LEVEL=LOG_NONE # disable log output # Set GNRC_PKTBUF_SIZE via CFLAGS if not being set via Kconfig. ifndef CONFIG_GNRC_PKTBUF_SIZE From ec6d8d04cc2875c199c8ef5f71c99a793c8f1dee Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 16 Sep 2020 11:13:13 +0200 Subject: [PATCH 3/4] examples/gnrc_minimal: don't use picolibc with LLVM --- examples/gnrc_minimal/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/gnrc_minimal/Makefile b/examples/gnrc_minimal/Makefile index e6387276b2..5f44b79cdb 100644 --- a/examples/gnrc_minimal/Makefile +++ b/examples/gnrc_minimal/Makefile @@ -26,8 +26,11 @@ USEMODULE += gnrc_icmpv6_echo # Use minimal standard PRNG USEMODULE += prng_minstd -# Use picolibc when available -FEATURES_OPTIONAL += picolibc +# llvm compatibility requires yet to be released picolibc 1.4.7 +ifneq (llvm, $(TOOLCHAIN)) + # Use picolibc when available + FEATURES_OPTIONAL += picolibc +endif CFLAGS += -DLOG_LEVEL=LOG_NONE # disable log output # Set GNRC_PKTBUF_SIZE via CFLAGS if not being set via Kconfig. From 45270dada0af1269f8499f04e4f82329230e6944 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 14 Oct 2020 11:08:36 +0200 Subject: [PATCH 4/4] cpu/fe310: blacklist picolibc on CI The RISC-V toolchain in riotdocker has issues with picolibc and will still include newlib headers. This leads to conflicts like ``` In file included from [01m[Knanostubs.c:22[m[K: [01m[K/usr/local/picolibc/riscv-none-embed/include/stdio.h:270:23:[m[K [01;31m[Kerror: [m[Kconflicting types for '[01m[K__FILE[m[K' typedef struct __file [01;31m[K__FILE[m[K; [01;31m[K^~~~~~[m[K In file included from [01m[K/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/riscv-none-embed/include/reent.h:93[m[K, from [01m[Knanostubs.c:20[m[K: [01m[K/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/riscv-none-embed/include/sys/reent.h:287:26:[m[K [01;36m[Knote: [m[Kprevious declaration of '[01m[K__FILE[m[K' was here typedef struct __sFILE [01;36m[K__FILE[m[K; [01;36m[K^~~~~~[m[K ``` The problem does not occur when installing both the toolchain and picolibc directly from the Debian / Ubuntu repositories, but CI uses an older Ubuntu version that does not have those packages yet, so it builds them manually. Blacklist RISC-V until CI has been updated. --- cpu/fe310/Kconfig | 2 +- cpu/fe310/Makefile.features | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu/fe310/Kconfig b/cpu/fe310/Kconfig index 1dc1554eac..d1be703e52 100644 --- a/cpu/fe310/Kconfig +++ b/cpu/fe310/Kconfig @@ -8,7 +8,7 @@ config CPU_ARCH_RISCV bool select HAS_ARCH_RISCV - select HAS_PICOLIBC + select HAS_PICOLIBC if '$(RIOT_CI_BUILD)' != '1' config CPU_CORE_RV32M bool diff --git a/cpu/fe310/Makefile.features b/cpu/fe310/Makefile.features index b60d9bd97e..5830696231 100644 --- a/cpu/fe310/Makefile.features +++ b/cpu/fe310/Makefile.features @@ -7,5 +7,9 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_plic FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += periph_wdt -FEATURES_PROVIDED += picolibc FEATURES_PROVIDED += ssp + +# RISC-V toolchain on CI does not work properly with picolibc yet +ifeq (,$(RIOT_CI_BUILD)) + FEATURES_PROVIDED += picolibc +endif