From 63a2a6ce1b077f1ee2f29af71fb8181e2fd0546f Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 26 Jan 2021 14:55:40 +0100 Subject: [PATCH] treewide: model newlib as a FEATURE --- Makefile.features | 4 ++++ boards/nucleo-l011k4/Makefile.dep | 1 - boards/samd10-xmini/Makefile.dep | 1 - boards/stm32f030f4-demo/Makefile.dep | 1 - cpu/arm7_common/Kconfig | 1 + cpu/arm7_common/Makefile.dep | 8 ++------ cpu/arm7_common/Makefile.features | 1 + cpu/cortexm_common/Kconfig | 1 + cpu/cortexm_common/Makefile.dep | 13 ++----------- cpu/cortexm_common/Makefile.features | 1 + cpu/esp32/Makefile.dep | 5 ++++- cpu/esp8266/Makefile.dep | 1 - cpu/esp_common/Kconfig | 1 + cpu/esp_common/Makefile.dep | 2 +- cpu/esp_common/Makefile.features | 1 + cpu/fe310/Kconfig | 1 + cpu/fe310/Makefile.dep | 6 +++--- cpu/fe310/Makefile.features | 1 + cpu/mips32r2_common/Kconfig | 1 + cpu/mips32r2_common/Makefile.dep | 2 +- cpu/mips32r2_common/Makefile.features | 1 + cpu/msp430_common/Kconfig | 1 + cpu/msp430_common/Makefile.features | 1 + kconfigs/Kconfig.features | 5 +++++ makefiles/features_modules.inc.mk | 10 ++++++++++ sys/Makefile.dep | 4 ++-- 26 files changed, 46 insertions(+), 29 deletions(-) diff --git a/Makefile.features b/Makefile.features index 2af98b39b1..62074595a3 100644 --- a/Makefile.features +++ b/Makefile.features @@ -20,3 +20,7 @@ include $(RIOTCPU)/$(CPU)/Makefile.features # Provide CPU as a feature to allow listing all boards with a CPU FEATURES_PROVIDED += cpu_$(CPU) + +# Features that are conflicting for all architectures +FEATURES_CONFLICT += picolibc:newlib +FEATURES_CONFLICT_MSG += "Only one standard C library can be used" diff --git a/boards/nucleo-l011k4/Makefile.dep b/boards/nucleo-l011k4/Makefile.dep index ef8cfa7e73..cb66ca7c2b 100644 --- a/boards/nucleo-l011k4/Makefile.dep +++ b/boards/nucleo-l011k4/Makefile.dep @@ -1,5 +1,4 @@ # Use Picolibc to reduce ROM usage -USEMODULE += picolibc FEATURES_REQUIRED += picolibc include $(RIOTBOARD)/common/nucleo/Makefile.dep diff --git a/boards/samd10-xmini/Makefile.dep b/boards/samd10-xmini/Makefile.dep index 264d8c7a0c..1bf6b87905 100644 --- a/boards/samd10-xmini/Makefile.dep +++ b/boards/samd10-xmini/Makefile.dep @@ -4,4 +4,3 @@ endif # Use Picolibc to reduce ROM usage FEATURES_REQUIRED += picolibc -USEMODULE += picolibc diff --git a/boards/stm32f030f4-demo/Makefile.dep b/boards/stm32f030f4-demo/Makefile.dep index b71192dbac..5ff120ed4c 100644 --- a/boards/stm32f030f4-demo/Makefile.dep +++ b/boards/stm32f030f4-demo/Makefile.dep @@ -1,3 +1,2 @@ # Use Picolibc to reduce ROM usage FEATURES_REQUIRED += picolibc -USEMODULE += picolibc diff --git a/cpu/arm7_common/Kconfig b/cpu/arm7_common/Kconfig index f8fbd5a2dc..68a82004a2 100644 --- a/cpu/arm7_common/Kconfig +++ b/cpu/arm7_common/Kconfig @@ -24,6 +24,7 @@ config CPU_CORE_ARM7TDMI_S ## Declaration of specific features config HAS_ARCH_ARM7 bool + select HAS_NEWLIB 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 48998943d9..93fe31908b 100644 --- a/cpu/arm7_common/Makefile.dep +++ b/cpu/arm7_common/Makefile.dep @@ -1,12 +1,8 @@ # use common ARM7 periph code USEMODULE += arm7_common_periph -ifneq (,$(filter picolibc,$(FEATURES_USED))) - # Use Picolibc when explicitly selected - USEMODULE += picolibc -else - # all cortex MCU's use newlib as libc - USEMODULE += newlib +FEATURES_REQUIRED_ANY += newlib|picolibc +ifneq (,$(filter newlib,$(USEMODULE))) # use the nano-specs of Newlib when available USEMODULE += newlib_nano endif diff --git a/cpu/arm7_common/Makefile.features b/cpu/arm7_common/Makefile.features index b4681a50cd..bb88c29bc8 100644 --- a/cpu/arm7_common/Makefile.features +++ b/cpu/arm7_common/Makefile.features @@ -6,6 +6,7 @@ FEATURES_PROVIDED += arch_arm FEATURES_PROVIDED += arch_arm7 FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += picolibc FEATURES_PROVIDED += puf_sram diff --git a/cpu/cortexm_common/Kconfig b/cpu/cortexm_common/Kconfig index 472281e362..51267c16a9 100644 --- a/cpu/cortexm_common/Kconfig +++ b/cpu/cortexm_common/Kconfig @@ -47,6 +47,7 @@ config CPU_CORE_CORTEX_M select HAS_CPU_CHECK_ADDRESS select HAS_SSP select HAS_CORTEXM_SVC + select HAS_NEWLIB ## Common CPU symbols config CPU_CORE diff --git a/cpu/cortexm_common/Makefile.dep b/cpu/cortexm_common/Makefile.dep index c07e776efa..856befb6c1 100644 --- a/cpu/cortexm_common/Makefile.dep +++ b/cpu/cortexm_common/Makefile.dep @@ -4,17 +4,8 @@ USEMODULE += cortexm_common # include common periph code USEMODULE += cortexm_common_periph -# Ensure newlib is not added if picolibc is already in FEATURES_USED or USEMODULE. -# nucleo-l011k4 doesn't use features to forces picolibc but directly set it in -# USEMODULE. This is because during the first pass of the dependency resolution, -# with the feature mechanism, the picolib feature is not present in FEATURES_USED -# at this staged and as a result newlib modules are wrongly added. -ifneq (,$(filter picolibc,$(FEATURES_USED) $(USEMODULE))) - # Use Picolibc when explicitly selected - USEMODULE += picolibc -else - # all cortex MCU's use newlib as libc - USEMODULE += newlib +FEATURES_REQUIRED_ANY += newlib|picolibc +ifneq (,$(filter newlib,$(USEMODULE))) # use the nano-specs of Newlib when available USEMODULE += newlib_nano endif diff --git a/cpu/cortexm_common/Makefile.features b/cpu/cortexm_common/Makefile.features index bc2895d380..869d8988e7 100644 --- a/cpu/cortexm_common/Makefile.features +++ b/cpu/cortexm_common/Makefile.features @@ -5,6 +5,7 @@ FEATURES_PROVIDED += cpp FEATURES_PROVIDED += cpu_check_address FEATURES_PROVIDED += cpu_core_cortexm FEATURES_PROVIDED += libstdcpp +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_pm FEATURES_PROVIDED += puf_sram FEATURES_PROVIDED += picolibc diff --git a/cpu/esp32/Makefile.dep b/cpu/esp32/Makefile.dep index e94e666b7f..73630031f8 100644 --- a/cpu/esp32/Makefile.dep +++ b/cpu/esp32/Makefile.dep @@ -5,9 +5,12 @@ include $(RIOTCPU)/esp_common/Makefile.dep USEMODULE += esp_idf_driver USEMODULE += esp_idf_esp32 USEMODULE += esp_idf_soc -USEMODULE += newlib_nano USEMODULE += pm_layered +ifneq (,$(filter newlib,$(USEMODULE))) + USEMODULE += newlib_nano +endif + ifneq (,$(filter esp_eth,$(USEMODULE))) USEMODULE += esp_freertos USEMODULE += esp_idf_eth diff --git a/cpu/esp8266/Makefile.dep b/cpu/esp8266/Makefile.dep index c6028b4235..906343cc94 100644 --- a/cpu/esp8266/Makefile.dep +++ b/cpu/esp8266/Makefile.dep @@ -9,7 +9,6 @@ USEMODULE += esp_idf_util USEMODULE += esp_idf_wpa_supplicant_crypto USEMODULE += esp_sdk USEMODULE += mtd -USEMODULE += newlib USEMODULE += periph_common USEMODULE += ps diff --git a/cpu/esp_common/Kconfig b/cpu/esp_common/Kconfig index 80f023239b..b0dc7df141 100644 --- a/cpu/esp_common/Kconfig +++ b/cpu/esp_common/Kconfig @@ -16,6 +16,7 @@ config CPU_COMMON_ESP select HAS_ESP_SPIFFS select HAS_ESP_WIFI select HAS_ESP_WIFI_AP + select HAS_NEWLIB select HAS_LIBSTDCPP select HAS_PERIPH_CPUID select HAS_PERIPH_HWRNG diff --git a/cpu/esp_common/Makefile.dep b/cpu/esp_common/Makefile.dep index 500f071308..03b82fead0 100644 --- a/cpu/esp_common/Makefile.dep +++ b/cpu/esp_common/Makefile.dep @@ -7,7 +7,6 @@ USEMODULE += esp_common_periph USEMODULE += esp_freertos USEMODULE += esp_idf USEMODULE += log -USEMODULE += newlib USEMODULE += periph USEMODULE += periph_hwrng USEMODULE += periph_flash @@ -22,6 +21,7 @@ USEMODULE += xtensa # Features used by ESP* +FEATURES_REQUIRED += newlib FEATURES_REQUIRED += cpp # Vendor code uses C++ ifneq (,$(filter esp_wifi_ap,$(USEMODULE))) diff --git a/cpu/esp_common/Makefile.features b/cpu/esp_common/Makefile.features index af36311915..efb55a6e10 100644 --- a/cpu/esp_common/Makefile.features +++ b/cpu/esp_common/Makefile.features @@ -10,6 +10,7 @@ FEATURES_PROVIDED += esp_spiffs FEATURES_PROVIDED += esp_wifi_ap FEATURES_PROVIDED += esp_wifi FEATURES_PROVIDED += libstdcpp +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_hwrng FEATURES_PROVIDED += periph_pm diff --git a/cpu/fe310/Kconfig b/cpu/fe310/Kconfig index f280f4ada5..c86563c86d 100644 --- a/cpu/fe310/Kconfig +++ b/cpu/fe310/Kconfig @@ -8,6 +8,7 @@ config CPU_ARCH_RISCV bool select HAS_ARCH_RISCV + select HAS_NEWLIB select HAS_PICOLIBC if '$(RIOT_CI_BUILD)' != '1' select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG diff --git a/cpu/fe310/Makefile.dep b/cpu/fe310/Makefile.dep index d5de24f900..96958b072d 100644 --- a/cpu/fe310/Makefile.dep +++ b/cpu/fe310/Makefile.dep @@ -1,6 +1,6 @@ -ifneq (,$(filter picolibc,$(FEATURES_USED))) - USEMODULE += picolibc -else + +FEATURES_REQUIRED_ANY += picolibc|newlib +ifneq (,$(filter newlib,$(USEMODULE))) USEMODULE += newlib_nano USEMODULE += newlib_syscalls_fe310 endif diff --git a/cpu/fe310/Makefile.features b/cpu/fe310/Makefile.features index 5830696231..3691c9e139 100644 --- a/cpu/fe310/Makefile.features +++ b/cpu/fe310/Makefile.features @@ -2,6 +2,7 @@ FEATURES_PROVIDED += arch_32bit FEATURES_PROVIDED += arch_riscv FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_plic diff --git a/cpu/mips32r2_common/Kconfig b/cpu/mips32r2_common/Kconfig index 94e1b715e3..4f45b6fc6c 100644 --- a/cpu/mips32r2_common/Kconfig +++ b/cpu/mips32r2_common/Kconfig @@ -9,6 +9,7 @@ config CPU_ARCH_MIPS32R2 bool select HAS_ARCH_32BIT select HAS_ARCH_MIPS32R2 + select HAS_NEWLIB select HAS_CPP select HAS_LIBSTDCPP select HAS_PERIPH_PM diff --git a/cpu/mips32r2_common/Makefile.dep b/cpu/mips32r2_common/Makefile.dep index bf981e4daf..3ba06ade82 100644 --- a/cpu/mips32r2_common/Makefile.dep +++ b/cpu/mips32r2_common/Makefile.dep @@ -1,7 +1,7 @@ USEMODULE += mips32r2_common USEMODULE += mips32r2_common_periph -USEMODULE += newlib +FEATURES_REQUIRED += newlib # mips32 needs periph_timer for its gettimeofday() implementation FEATURES_REQUIRED += periph_timer diff --git a/cpu/mips32r2_common/Makefile.features b/cpu/mips32r2_common/Makefile.features index 13c8e6f760..8c33bbbbff 100644 --- a/cpu/mips32r2_common/Makefile.features +++ b/cpu/mips32r2_common/Makefile.features @@ -2,6 +2,7 @@ CPU_ARCH = mips32r2 FEATURES_PROVIDED += arch_32bit FEATURES_PROVIDED += arch_mips32r2 +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += periph_pm diff --git a/cpu/msp430_common/Kconfig b/cpu/msp430_common/Kconfig index 4a598fdb21..0b0e21d8cb 100644 --- a/cpu/msp430_common/Kconfig +++ b/cpu/msp430_common/Kconfig @@ -12,6 +12,7 @@ config CPU_ARCH_MSP430 select HAS_ARCH_MSP430 select HAS_PERIPH_FLASHPAGE select HAS_PERIPH_FLASHPAGE_PAGEWISE + select HAS_NEWLIB select HAS_PERIPH_PM select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG diff --git a/cpu/msp430_common/Makefile.features b/cpu/msp430_common/Makefile.features index 96151a8936..a987418df6 100644 --- a/cpu/msp430_common/Makefile.features +++ b/cpu/msp430_common/Makefile.features @@ -3,6 +3,7 @@ CPU_CORE = msp430 FEATURES_PROVIDED += arch_16bit FEATURES_PROVIDED += arch_msp430 +FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_flashpage FEATURES_PROVIDED += periph_flashpage_pagewise FEATURES_PROVIDED += periph_pm diff --git a/kconfigs/Kconfig.features b/kconfigs/Kconfig.features index 2bcc8288ff..9a318e5840 100644 --- a/kconfigs/Kconfig.features +++ b/kconfigs/Kconfig.features @@ -321,6 +321,11 @@ config HAS_PICOLIBC help Indicates that the picolibc C library is available for the platform. +config HAS_NEWLIB + bool + help + Indicates that the newlib C library is available for the platform. + config HAS_PUF_SRAM bool help diff --git a/makefiles/features_modules.inc.mk b/makefiles/features_modules.inc.mk index 1469df279d..5b1c9eda9a 100644 --- a/makefiles/features_modules.inc.mk +++ b/makefiles/features_modules.inc.mk @@ -45,5 +45,15 @@ ifneq (,$(filter cortexm_mpu,$(FEATURES_USED))) USEMODULE += mpu_stack_guard endif +# use picolibc if the feature is used +ifneq (,$(filter picolibc,$(FEATURES_USED))) + USEMODULE += picolibc +endif + +# use newlib if the feature is used +ifneq (,$(filter newlib,$(FEATURES_USED))) + USEMODULE += newlib +endif + # use efm32_coretemp if the feature is used USEMODULE += $(filter efm32_coretemp, $(FEATURES_USED)) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 8a343cd8a4..18c7cce2de 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -530,11 +530,11 @@ ifneq (,$(filter od_string,$(USEMODULE))) endif ifneq (,$(filter newlib_gnu_source,$(USEMODULE))) - USEMODULE += newlib + FEATURES_REQUIRED += newlib endif ifneq (,$(filter newlib_nano,$(USEMODULE))) - USEMODULE += newlib + FEATURES_REQUIRED += newlib endif ifneq (,$(filter newlib,$(USEMODULE)))