boot: zephyr: setup watchdog
The Zephyr watchdog API defines a setup function. This function needs to
be executed before the watchdog is functional in some cases. This commit
adds MCUBOOT_WATCHDOG_SETUP when using the generic watchdog0 alias
otherwise it is an empty define.
Fixes https://github.com/mcu-tools/mcuboot/issues/1659
Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index e14bf4c..4af6f7d 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -308,6 +308,15 @@
#include <zephyr/device.h>
#include <zephyr/drivers/watchdog.h>
+#define MCUBOOT_WATCHDOG_SETUP() \
+ do { \
+ const struct device* wdt = \
+ DEVICE_DT_GET(DT_ALIAS(watchdog0)); \
+ if (device_is_ready(wdt)) { \
+ wdt_setup(wdt, 0); \
+ } \
+ } while (0)
+
#define MCUBOOT_WATCHDOG_FEED() \
do { \
const struct device* wdt = \
@@ -330,6 +339,10 @@
#endif /* CONFIG_BOOT_WATCHDOG_FEED */
+#ifndef MCUBOOT_WATCHDOG_SETUP
+#define MCUBOOT_WATCHDOG_SETUP()
+#endif
+
#define MCUBOOT_CPU_IDLE() \
if (!IS_ENABLED(CONFIG_MULTITHREADING)) { \
k_cpu_idle(); \
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index 2deef1e..50b9870 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -509,6 +509,7 @@
uint32_t reset_cause;
#endif
+ MCUBOOT_WATCHDOG_SETUP();
MCUBOOT_WATCHDOG_FEED();
#if !defined(MCUBOOT_DIRECT_XIP)