Application Kconfig defaults are overwriting symbols in prj.conf

I was doing some developement for a custom board on NCS v2.9.1 when i noticed some of the changes i was making in my prj.conf weren't being set in the application. My impression was that symbols set in prj.conf have top level priority and overwrite any symbol defaults during merge. I was able to recreate this behavior in the zephyr minimal sample by making the following changes:

In zephyr/samples/basic/minimal/Kconfig:

# Copyright (c) 2023 Synopsys.
#
# SPDX-License-Identifier: Apache-2.0

config SAMPLE_DO_OUTPUT
	bool "Do print from the main thread which can be checked"

config PM
    default y

config PM_DEVICE
    default y

config PM_DEVICE_RUNTIME
    default y

source "Kconfig.zephyr"

In zephyr/samples/basic/minimal/prj.conf:

CONFIG_PM=n
CONFIG_PM_DEVICE=n
CONFIG_PM_DEVICE_RUNTIME=n

When building with: `west build -b nrf5340dk/nrf5340/cpuapp --pristine` I get some Kconfig warnings and the build fails:

warning: PM (defined at /Users/timothy.lee/echo3_ncs/zephyr/samples/basic/minimal/Kconfig:8,
soc/silabs/silabs_s2/efr32bg22/Kconfig.defconfig:12,
soc/silabs/silabs_s2/efr32bg27/Kconfig.defconfig:12,
soc/silabs/silabs_s2/efr32mg24/Kconfig.defconfig:12,
soc/renesas/smartbond/da1469x/Kconfig.defconfig:39, subsys/pm/Kconfig:13) was assigned the value 'n'
but got the value 'y'. See http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_PM and/or look
up PM in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.


warning: PM_DEVICE_RUNTIME (defined at
/Users/timothy.lee/echo3_ncs/zephyr/samples/basic/minimal/Kconfig:14, subsys/pm/Kconfig:96) was
assigned the value 'n' but got the value 'y'. See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_PM_DEVICE_RUNTIME and/or look up
PM_DEVICE_RUNTIME in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.

It seems like my prj.conf symbols are being overwritten by the Kconfig defaults. I also found it strange that the buildsys was referencing .defconfigs for silabs SOCs that I wasn't building for. If I turn the defaults in Kconfig to n the build passes as expected.

Related