Skip to content

Conversation

@mathieuchopstm
Copy link
Contributor

In addition to the DT_HAS_<compat>_ENABLED options, the autogenerated Kconfig.dts file also provides the DT_COMPAT_<compat> macros which avoid manually declaring them when working around the no comma limitation. Unlike options which can be referenced before their declaration, macros MUST be defined before their usage (otherwise, they expand to nothing ("")):

Because the defconfig files were sourced before dts/Kconfig, it was not possible to use the DT_COMPAT macros from shields/boards/SoC defconfig; this is not only confusing but also suboptimal because the macros must be defined manually.

Include dts/Kconfig earlier to allow usage of the DT_COMPAT macros from shields, boards and SoC defconfig. This should have no adverse effect since there is no reason to override the options provided by the autogenerated Kconfig.dts anyways.

This issue was encountered in #100215.

In addition to the DT_HAS_<compat>_ENABLED options, the autogenerated
Kconfig.dts file also provides the DT_COMPAT_<compat> *macros* which avoid
manually declaring them when working around the no comma limitation. Unlike
options which can be referenced before their declaration, macros MUST
be defined before their usage (otherwise, they expand to nothing ("")).

Because the defconfig files were sourced before "dts/Kconfig", it was not
possible to use the DT_COMPAT macros from shields/boards/SoC defconfig;
this is not only confusing but also suboptimal because the macros must be
defined manually.

Include "dts/Kconfig" earlier to allow usage of the DT_COMPAT macros from
shields, boards and SoC defconfig. This should have no adverse effect
since there is no reason to override the options provided by the
autogenerated Kconfig.dts anyways.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>

# This should be sourced early since the autogen Kconfig.dts options
# and macros may get used by shields/boards/SoC defconfig or modules.
source "dts/Kconfig"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why you wouldn't even source it before $(APPLICATION_SOURCE_DIR)/VERSION?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the VERSION Kconfig file is not a """true""" Kconfig file (i.e., it's only supposed to provide constants), it doesn't seem necessary to provide the definitions to it:

VERSION_MAJOR = 5
VERSION_MINOR = 6
PATCHLEVEL = 7
VERSION_TWEAK = 89
EXTRAVERSION = development

Copy link
Contributor

@pdgendt pdgendt Dec 8, 2025

Choose a reason for hiding this comment

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

I agree this is true for most cases, but maybe someone wants to do

EXTRAVERSION = $(shell,getextraversion,$(dt_has_compat,$(DT_COMPAT_MY_SPECIAL_IC))

Far-fetched, I know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we stick to what the documentation says, I don't think such a pattern is valid (notice how Kconfig is not mentioned at all).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but it doesn't harm too, I guess? 🤷‍♂️
We know the contents of Kconfig.dts does not depend on the application version.

Anyway, needs an approval from assignee, I'm fine either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this is true for most cases, but maybe someone wants to do

EXTRAVERSION = $(shell,getextraversion,$(dt_has_compat,$(DT_COMPAT_MY_SPECIAL_IC))

The VERSION file is not only used by Kconfig but in several other places, so that would be an extremely bad idea.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

@fabiobaltieri fabiobaltieri merged commit 22a163f into zephyrproject-rtos:main Dec 10, 2025
29 checks passed
@mathieuchopstm mathieuchopstm deleted the topic/kconfig_dts_sourced_early branch December 11, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants