Conditional overlays in a module

Hello,

I'm trying to build a Zephyr module that manages some features for a specific board (an SDK for that board). In it, I would like to enable the IPC devices in the board's DT if a specific KConfig option is set. According to the you (Nordic) in a different ticket (private), these devices should remain "disabled" unless they are actually being used.

This is simple to achieve if the code is in the same project, as in CMakeLists.txt you can conditionally (based on KConfig) append an overlay file that enables the device to `DTC_OVERLAY_FILE` *before* the `find_package(Zephyr ...)` line.

You can't extract that to a module though, since even if you append the module path to `ZEPHYR_EXTRA_MODULES` before the `find_package(Zephyr ...)` line, CMake processes the module's CMakeLists.txt file *after* completing the application's, and therefore after `find_package(Zephyr ...)`, and you get this error:

> * WARNING
> *
> * CMake variable DTC_OVERLAY_FILE set to "C:/Users/MyName/Documents/Git/sdk/nRF54H20/ipc/overlays/cpuppr.overlay" in:
> * C:/Users/MyName/Documents/Git/sdk/nRF54H20/ipc/CMakeLists.txt
> *
> * This is too late to make changes! The change was ignored.
> *
> * Hint: DTC_OVERLAY_FILE must be set before calling find_package(Zephyr ...).

Snippets are another option, but these require the build command to include the snippet and snippets cannot be automatically included based on KConfig settings.

In the build command, I could also explicitly specify the overlay file, but just like the snippets option, that requires the user to specify multiple things (build command option, KConfig option).

So the question is: is there any way to, in a Module, conditionally modify the status of a device ("disabled" -> "okay") based on a KConfig option, without requiring the application/build to specify anything other than that KConfig option?

  • Hello,

    Unfortunately, it is not possible to make DeviceTree dependent on Kconfig, because when building, DeviceTree will always build it's configuration before Kconfig is even started. 

    So the options that you have is, as you already mentioned, either to use Snippets, or you can create different build configurations, where you include a different set of .conf files and .overlay files. 

    I do understand your desire to make it neat, e.g. setting a Kconfig, and then include all necessary stuff based on those, but when it comes to Devicetree and overlay files, this is not possible using Zephyr's build system, West.

    Best regards,

    Edvin

Related