Skip to content

Conversation

@mathieuchopstm
Copy link
Contributor

Fixes #86223 (hopefully).

The WDT_DISABLE_AT_BOOT Kconfig option has been interpreted as "enable the WDT if disabled" by some driver implementers, even though this is at best a hack. Document its true purpose explicitly and update all drivers to follow the now-documented semantics.

I took a conservative approach and only updated drivers which were explicitly playing the if (!IS_ENABLED(WDT_DISABLE_AT_BOOT)) { enable_myself(); } game, but maybe other drivers need to be updated too.

WDT_DISABLE_AT_BOOT should only be used to forcefully disable watchdog
timers that are enabled by default after system reset. Update the Kconfig
help text of WDT_DISABLE_AT_BOOT and its dependency HAS_WDT_DISABLE_AT_BOOT
to make this clear.

Signed-off-by: Mathieu Choplain <[email protected]>
@mathieuchopstm
Copy link
Contributor Author

Gentle poke at NXP folks (@decsny) because there's something that seems weird in your SoCs' CMakeLists:

zephyr_compile_definitions_ifndef(CONFIG_WDT_DISABLE_AT_BOOT DISABLE_WDOG=1)

zephyr_compile_definitions_ifndef(CONFIG_WDT_DISABLE_AT_BOOT DISABLE_WDOG=0)

select HAS_WDT_DISABLE_AT_BOOT may need to be added in SoC Kconfig for these targets too, I'd like review on that point.


I'm also wondering if WDT_DISABLE_AT_BOOT shouldn't be changed to default y since that is kinda what seems to be the expected behavior (i.e., watchdog would be opt-in rather than opt-out).

Finally, this probably needs an entry in migration guide/release notes since this will most likely break people's apps (for those who were using WDT_DISABLE_AT_BOOT=n as a de facto WDT_ENABLE_AT_BOOT=y).

@henrikbrixandersen
Copy link
Member

I like the idea of revisiting this and unifying behaviour across drivers.

I do see a need for having the counterpart in as well (enable watchdog at boot with a given timeout), as this is a common way of ensuring that failure to fully initialise your firmware will be caught somehow (I really prefer MCUs where the watchdog is enabled at boot by hardware for this reason).

There are many drivers which control a disabled-by-default watchdog timer
but take the liberty of selecting HAS_WDT_DISABLE_AT_BOOT and interpreting
WDT_DISABLE_AT_BOOT=n as "enable the timer", which does not correspond to
the semantics of this option.

Update all such drivers to no longer select HAS_WDT_DISABLE_AT_BOOT and
ignore the WDT_DISABLE_AT_BOOT option.

Signed-off-by: Mathieu Choplain <[email protected]>
@mathieuchopstm mathieuchopstm force-pushed the topic/cfg_wdt_disable_at_boot_rework branch from 572e53e to f2217b0 Compare October 23, 2025 14:59
@sonarqubecloud
Copy link

@mathieuchopstm
Copy link
Contributor Author

I like the idea of revisiting this and unifying behaviour across drivers.

I do see a need for having the counterpart in as well (enable watchdog at boot with a given timeout), as this is a common way of ensuring that failure to fully initialise your firmware will be caught somehow (I really prefer MCUs where the watchdog is enabled at boot by hardware for this reason).

I did consider this (i.e., WDT_ENABLED_AT_BOOT alternative solution in the issue linked) but it's actually much less trivial than I hoped - at least, if one wants the implementation to not be hacky (as in, relying on implementation details). For example, you are supposed to wdt_feed() using the pseudo-handle returned by wdt_install_timeout()... but how can you do that if someone else calls wdt_install_timeout()?

Today, everyone just sets WDT_DISABLED_AT_BOOT=n, gets the watchdog enabled at boot by the driver, calls wdt_feed() with whatever channel_id and everything works out anyways because most drivers ignore channel_id (e.g., because there's only one channel), but it still is a hack regardless of whether it works or not.

So we'd need something else, like maybe a /chosen/zephyr,system-watchdog and a tiny module which does the wdt_install_timeout(), wdt_setup(), wdt_feed() and exposes it through a """new""" API.

There is definitely a need for "set some Kconfig and get a watchdog setup during boot" - that's what WDT_DISABLED_AT_BOOT=n was abused for 🙂 - but I'm not super inspired about how to implement that, which is kinda why I'm trying to get attention / feedback on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Watchdog Watchdog platform: Andes Technology platform: ESP32 Espressif ESP32 platform: GD32 GigaDevice platform: LiteX platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico) platform: STM32 ST Micro STM32 platform: TI SimpleLink Texas Instruments SimpleLink MCU RFC Request For Comments: want input from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify expected behavior when CONFIG_WDT_DISABLE_AT_BOOT=n

4 participants