Skip to content

Buildsystem: Migrate Boards and CPU using Common Code to USEMODULE #21331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
crasbe opened this issue Mar 27, 2025 · 1 comment
Open

Buildsystem: Migrate Boards and CPU using Common Code to USEMODULE #21331

crasbe opened this issue Mar 27, 2025 · 1 comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Community: help wanted The contributors require help from other members of the community Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: tracking The issue tracks and organizes the sub-tasks of a larger effort

Comments

@crasbe
Copy link
Contributor

crasbe commented Mar 27, 2025

As discussed in #21298 and #21299, boards and cpus use a rather convoluted way of using common code in the boards/common and cpu/xxx_common folders:

The Makefile usually includes a statement to include the directories:

ifneq (,$(filter boards_common_adafruit-nrf52-bootloader,$(USEMODULE)))
# add the adafruit-nrf52-bootloader directory to the build
DIRS += $(RIOTBOARD)/common/adafruit-nrf52-bootloader
endif

The Makefile.{include, dep, features} has to have dedicated include commands:

# Include the common definitions for the Adafruit nRF52 Bootloader
include $(RIOTBOARD)/common/adafruit-nrf52-bootloader/Makefile.include

The USEMODULE for the common board is not defined in the boards/xxx/Makefile.dep as you would expect but in the boards/common/yyy/Makefile.dep:

# make sure the bootloader module is used for reset to work
USEMODULE += boards_common_adafruit-nrf52-bootloader




Since this is rather ugly, PR #21327 introduced Makefiles in the boards/ folder that work similar to the way the sys/Makefile*s work: It checks if the common code USEMODULE is set and automagically includes the necessary folders and directories.

Instead of setting all the things discussed previously, a board now only has to set the USEMODULE in the boards/xxx/Makefile.dep and no additional incldues or DIR += commands.

USEMODULE += boards_common_adafruit-nrf52-bootloader

The first common code that got adapted to the new style was the adafruit-nrf52-bootloader in #21327, but there is still a lot of potential:

RIOT$ grep -Rwh . -e "DIRS =" | grep -i common | sort -u
DIRS = $(ATMEGA_COMMON)
DIRS = $(RIOTBOARD)/common/arduino-atmega
DIRS = $(RIOTBOARD)/common/arduino-due
DIRS = $(RIOTBOARD)/common/arduino-mkr
DIRS = $(RIOTBOARD)/common/arduino-zero
DIRS = $(RIOTBOARD)/common/atmega
DIRS = $(RIOTBOARD)/common/atxmega
DIRS = $(RIOTBOARD)/common/blxxxpill
DIRS = $(RIOTBOARD)/common/e104-bt50xxa-tb
DIRS = $(RIOTBOARD)/common/esp32
DIRS = $(RIOTBOARD)/common/esp32c3
DIRS = $(RIOTBOARD)/common/esp32s2
DIRS = $(RIOTBOARD)/common/esp32s3
DIRS = $(RIOTBOARD)/common/esp32x
DIRS = $(RIOTBOARD)/common/esp8266
DIRS = $(RIOTBOARD)/common/iotlab
DIRS = $(RIOTBOARD)/common/kw41z
DIRS = $(RIOTBOARD)/common/msb-430
DIRS = $(RIOTBOARD)/common/nrf51
DIRS = $(RIOTBOARD)/common/nrf52xxxdk
DIRS = $(RIOTBOARD)/common/nucleo
DIRS = $(RIOTBOARD)/common/particle-mesh
DIRS = $(RIOTBOARD)/common/remote
DIRS = $(RIOTBOARD)/common/samdx1-arduino-bootloader
DIRS = $(RIOTBOARD)/common/saml1x
DIRS = $(RIOTBOARD)/common/silabs
DIRS = $(RIOTBOARD)/common/weact-f4x1cx
DIRS = $(RIOTCPU)/arm7_common
DIRS = $(RIOTCPU)/arm7_common periph
DIRS = $(RIOTCPU)/atmega_common/
DIRS = $(RIOTCPU)/cortexm_common periph
DIRS = $(RIOTCPU)/cortexm_common periph stmclk vectors
DIRS = $(RIOTCPU)/riscv_common periph vendor
DIRS = periph $(RIOTCPU)/avr8_common/
DIRS = periph $(RIOTCPU)/cortexm_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/cc26xx_cc13xx
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/nrf5x_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/nrf5x_common vectors
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam0_common
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam0_common vectors
DIRS = periph $(RIOTCPU)/cortexm_common $(RIOTCPU)/sam_common
DIRS = periph $(RIOTCPU)/cortexm_common vendor
RIOT$ grep -Rwh . -e "DIRS +=" | grep -i common | sort -u
  DIRS += $(RIOTBOARD)/common/adafruit-nrf52-bootloader
  DIRS += $(RIOTBOARD)/common/microbit
  DIRS += $(RIOTBOARD)/common/samdx1-arduino-bootloader
  DIRS += common
  DIRS += net/application_layer/cord/common
<div class="line">DIRS += $(RIOTBOARD)/common/myCommonFolder</div>
DIRS += $(RIOTBOARD)/common/arduino-zero
DIRS += $(RIOTBOARD)/common/init
DIRS += $(RIOTBOARD)/common/myCommonFolder
DIRS += $(RIOTBOARD)/common/qn908x
DIRS += $(RIOTBOARD)/common/remote
DIRS += $(RIOTBOARD)/common/samdx1-arduino-bootloader
DIRS += $(RIOTBOARD)/common/slwstk6000b
DIRS += $(RIOTBOARD)/common/sodaq
DIRS += $(RIOTCPU)/cortexm_common
DIRS += $(RIOTCPU)/esp_common
DIRS += periph $(RIOTCPU)/riscv_common
DIRS += src/common
@crasbe crasbe added Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Community: help wanted The contributors require help from other members of the community Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: tracking The issue tracks and organizes the sub-tasks of a larger effort labels Mar 27, 2025
@crasbe
Copy link
Contributor Author

crasbe commented Apr 5, 2025

This issue is similar to what was started and documented in #8713 and #9913 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system Area: cpu Area: CPU/MCU ports Community: help wanted The contributors require help from other members of the community Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: tracking The issue tracks and organizes the sub-tasks of a larger effort
Projects
None yet
Development

No branches or pull requests

1 participant