Skip to content

Buildsystem: Introduce Global Makefiles for boards Directory #21327

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

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

crasbe
Copy link
Contributor

@crasbe crasbe commented Mar 26, 2025

Contribution description

Many boards in RIOT (such as the feather-nrf52840, feather-m0, ...) use common board definitions for things like the bootloader. Back when this was implemented in #8058, the approach was to include the directory by adding the path to the DIRS variable and setting the USEMODULE in one of the common folders.

This is not really elegant and the Makefile in the boards/common/... subfolder didn't even get executed.
You can find more information about this in #21298.

The original approach from #21299 was to automatically add the directories based on the USEMODULE name, for example add the directory boards/common/adafruit-nrf52-bootloader when using USEMODULE += boards_common_adafruit-nrf52-bootloader.
This might have unintended side effects since this was not originally intended, so the proposal from @mguetschow from #21299 (comment) was chosen.

This PR therefore introduces the new Makefiles boards/Makefile, boards/Makefile.include, boards/Makefile.dep and boards/Makefile.features to automatically include the right Makefiles when using certain modules.

For example in the current master when using the boards/common/adafruit-nrf52-bootloader common folder, you have to explicitly add the directory in your board/myboard/Makefile, add the common Makefile.include in your board/myboard/Makefile.include and add the common Makefile.dep in your board/myboard/Makefile.dep.

With this PR, this is not necessary anymore because these includes are done in the boards/Makefile{,.features,.include,.dep} files now.
This approach would also work for the cpu/ subfolder, but for the time being I'd like to do this step by step (not looking at you #21299 👀).

TODO: I would like to extend the Porting Boards documentation to include information about common board modules and how to use (and possibly even how to create) them.

Testing procedure

Make sure the boards still compile and the common folder is still included.

Compilation of tests/sys/shell for the seeedstudio-xiao-nrf52840 on master:
cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ BOARD=seeedstudio-xiao-nrf52840 make -C tests/sys/shell
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/sys/shell'
Building application "tests_shell" for "seeedstudio-xiao-nrf52840" with CPU "nrf52".

"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/boards/common/init
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/boards/seeedstudio-xiao-nrf52840
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/boards/common/adafruit-nrf52-bootloader
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/core
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/core/lib
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/nrf52
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/cortexm_common
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/cortexm_common/periph
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/nrf52/periph
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/nrf52/vectors
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/nrf5x_common
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/nrf5x_common/periph
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/drivers
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/drivers/periph_common
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/app_metadata
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/auto_init
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/auto_init/usb
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/div
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/event
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/fmt
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/frac
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/isrpipe
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/libc
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/luid
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/malloc_thread_safe
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/newlib_syscalls_default
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/preprocessor
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/ps
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/shell
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/shell/cmds
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/stdio
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/test_utils/interactive_sync
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/test_utils/print_stack_usage
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/tsrb
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/usb/usbus
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/usb/usbus/cdc/acm
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/usb_board_reset
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/sys/ztimer
   text    data     bss     dec     hex filename
  23652     128    4696   28476    6f3c /home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/sys/shell/bin/seeedstudio-xiao-nrf52840/tests_shell.elf
make: Leaving directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/tests/sys/shell'
Compilation of tests/sys/shell for the seeedstudio-xiao-nrf52840 with this PR:
cbuec@W11nMate:~/RIOTstuff/riot-boards-common/RIOT$ BOARD=seeedstudio-xiao-nrf52840 make -C tests/sys/shell
make: Entering directory '/home/cbuec/RIOTstuff/riot-boards-common/RIOT/tests/sys/shell'
Building application "tests_shell" for "seeedstudio-xiao-nrf52840" with CPU "nrf52".

"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/pkg/cmsis/
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/boards
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/boards/common/adafruit-nrf52-bootloader
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/boards/common/init
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/boards/seeedstudio-xiao-nrf52840
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/core
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/core/lib
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/nrf52
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/cortexm_common
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/cortexm_common/periph
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/nrf52/periph
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/nrf52/vectors
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/nrf5x_common
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/cpu/nrf5x_common/periph
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/drivers
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/drivers/periph_common
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/app_metadata
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/auto_init
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/auto_init/usb
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/div
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/event
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/fmt
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/frac
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/isrpipe
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/libc
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/luid
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/malloc_thread_safe
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/newlib_syscalls_default
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/preprocessor
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/ps
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/shell
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/shell/cmds
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/stdio
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/stdio_uart
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/test_utils/interactive_sync
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/test_utils/print_stack_usage
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/tsrb
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/usb/usbus
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/usb/usbus/cdc/acm
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/usb_board_reset
"make" -C /home/cbuec/RIOTstuff/riot-boards-common/RIOT/sys/ztimer
   text    data     bss     dec     hex filename
  24484     128    4708   29320    7288 /home/cbuec/RIOTstuff/riot-boards-common/RIOT/tests/sys/shell/bin/seeedstudio-xiao-nrf52840/tests_shell.elf
make: Leaving directory '/home/cbuec/RIOTstuff/riot-boards-common/RIOT/tests/sys/shell'

Issues/PRs references

Fixes #21298.
Alternative approach for #21299.

@github-actions github-actions bot added Area: build system Area: Build system Area: boards Area: Board ports labels Mar 26, 2025
@crasbe crasbe added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 26, 2025
@crasbe crasbe force-pushed the pr/boards_common_new branch from 11cfaa5 to df30029 Compare March 26, 2025 10:50
@riot-ci
Copy link

riot-ci commented Mar 26, 2025

Murdock results

✔️ PASSED

76af091 doc: add doc about new common board style

Success Failures Total Runtime
149840 0 149840 01h:39m:28s

Artifacts

Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this clean-up! Thanks a lot!

Just two minor things below, and testing is still outstanding on my side.

@crasbe crasbe force-pushed the pr/boards_common_new branch from c646f8a to 3f2aa15 Compare March 26, 2025 14:13
@crasbe crasbe requested review from aabadie and jia200x as code owners March 26, 2025 16:04
@github-actions github-actions bot added the Area: doc Area: Documentation label Mar 26, 2025
@crasbe crasbe force-pushed the pr/boards_common_new branch from 071a53b to b7e42ed Compare March 26, 2025 16:13
@crasbe
Copy link
Contributor Author

crasbe commented Mar 26, 2025

Squashed and documentation added. Thank you for reviewing :)

@crasbe crasbe added CI: full build disable CI build filter CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 26, 2025
@@ -330,6 +351,20 @@ FEATURES_PROVIDED += periph_uart
include $(RIOTBOARD)/common/foo_common/Makefile.features
```

If the common code includes source files or headers, it might be necessary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If the common code includes source files or headers, it might be necessary
If the common code includes source files, it might be necessary

headers would have to go into Makefile.include, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. My thinking was that the make system won't even look at the directory at all without the DIRS +=, but in the old style, the Makefile.include was always added with an include statement, so the remark about the headers is redundant.

@mguetschow
Copy link
Contributor

Successfully tested on feather-nrf52840-sense and documentation looks good: https://ci.riot-os.org/results/0921ea0bb15c42708f5a42ccae923208/doc-preview/porting-boards.html#common-board-code

@crasbe crasbe force-pushed the pr/boards_common_new branch from b7e42ed to 76af091 Compare March 27, 2025 14:04
Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! 💙

@mguetschow mguetschow enabled auto-merge March 27, 2025 14:07
@mguetschow mguetschow added this pull request to the merge queue Mar 27, 2025
Merged via the queue into RIOT-OS:master with commit 3399b64 Mar 27, 2025
26 checks passed
@crasbe crasbe deleted the pr/boards_common_new branch March 27, 2025 20:18
@crasbe
Copy link
Contributor Author

crasbe commented Mar 27, 2025

@mguetschow thank you for working with me on this :)

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: doc Area: Documentation CI: full build disable CI build filter CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buildsystem: Makefile of Common Board Directories never called without adding DIRS
3 participants