From 442f5a48c5f4a5ab8eb506ff88d2f64062574196 Mon Sep 17 00:00:00 2001 From: Karl Kristian Dyrholm Torp Date: Tue, 26 Nov 2024 15:47:57 +0100 Subject: [PATCH 1/2] boot: Allow watchdog timeout to be configured This change adds a new Kconfig option MCUBOOT_WATCHDOG_TIMEOUT to specify the watchdog timeout value. Several devices (NXP among others) require a timeout to be installed in order to enable the watchdog. Signed-off-by: Karl Kristian Dyrholm Torp --- boot/zephyr/Kconfig | 8 ++++++++ .../include/mcuboot_config/mcuboot_config.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig index 197f44918..7fb291ff0 100644 --- a/boot/zephyr/Kconfig +++ b/boot/zephyr/Kconfig @@ -750,6 +750,14 @@ config BOOT_WATCHDOG_FEED_NRFX_WDT imply NRFX_WDT30 imply NRFX_WDT31 +config MCUBOOT_WATCHDOG_TIMEOUT + int "Watchdog timeout in milliseconds" + default 0 + depends on BOOT_WATCHDOG_FEED + help + Specify the watchdog timeout for devices that require a timeout + installed to setup the watchdog. + config BOOT_IMAGE_ACCESS_HOOKS bool "Enable hooks for overriding MCUboot's native routines" help diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h index 8d479ced7..94c6d3644 100644 --- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h +++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h @@ -371,6 +371,22 @@ #include #include +#if CONFIG_MCUBOOT_WATCHDOG_TIMEOUT +#define MCUBOOT_WATCHDOG_INSTALL_TIMEOUT() \ + do { \ + struct wdt_timeout_cfg wdtConfig = { \ + .flags = WDT_FLAG_RESET_SOC, \ + .window.min = 0, \ + .window.max = CONFIG_MCUBOOT_WATCHDOG_TIMEOUT \ + }; \ + wdt_install_timeout(wdt, &wdtConfig); \ + } while (0) +#else +#define MCUBOOT_WATCHDOG_INSTALL_TIMEOUT() \ + do { \ + } while (0) +#endif /* CONFIG_MCUBOOT_WATCHDOG_TIMEOUT */ + #define MCUBOOT_WATCHDOG_SETUP() \ do { \ const struct device* wdt = \ @@ -385,6 +401,7 @@ const struct device* wdt = \ DEVICE_DT_GET(DT_ALIAS(watchdog0)); \ if (device_is_ready(wdt)) { \ + MCUBOOT_WATCHDOG_INSTALL_TIMEOUT(); \ wdt_feed(wdt, 0); \ } \ } while (0) From c1af91c363009b175aaf0e7bc4fe494f6c44a656 Mon Sep 17 00:00:00 2001 From: Karl Kristian Dyrholm Torp Date: Tue, 26 Nov 2024 19:33:21 +0100 Subject: [PATCH 2/2] Install timeout when during setup of watchdog Signed-off-by: Karl Kristian Dyrholm Torp --- boot/zephyr/include/mcuboot_config/mcuboot_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h index 94c6d3644..83ae2305c 100644 --- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h +++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h @@ -392,6 +392,7 @@ const struct device* wdt = \ DEVICE_DT_GET(DT_ALIAS(watchdog0)); \ if (device_is_ready(wdt)) { \ + MCUBOOT_WATCHDOG_INSTALL_TIMEOUT(); \ wdt_setup(wdt, 0); \ } \ } while (0) @@ -401,7 +402,6 @@ const struct device* wdt = \ DEVICE_DT_GET(DT_ALIAS(watchdog0)); \ if (device_is_ready(wdt)) { \ - MCUBOOT_WATCHDOG_INSTALL_TIMEOUT(); \ wdt_feed(wdt, 0); \ } \ } while (0)