From 853657c23d385fd105b72833c8c0cfb2a82a45a2 Mon Sep 17 00:00:00 2001 From: Fabio Utzig Date: Tue, 7 May 2019 08:06:07 -0300 Subject: [PATCH] Add watchdog feeding macro When HW / OS provides an always enabled watchdog, this macro can optionally be implemented to avoid resets which are expected to occur under normal conditions when swapping very large images or running on slower devices. Signed-off-by: Fabio Utzig --- boot/bootutil/src/loader.c | 2 ++ .../include/mcuboot_config/mcuboot_config.h | 10 ++++++++++ boot/zephyr/include/mcuboot_config/mcuboot_config.h | 5 +++++ samples/mcuboot_config/mcuboot_config.template.h | 13 +++++++++++++ 4 files changed, 30 insertions(+) diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c index d7484398..c6ec34f5 100644 --- a/boot/bootutil/src/loader.c +++ b/boot/bootutil/src/loader.c @@ -954,6 +954,8 @@ boot_copy_sector(const struct flash_area *fap_src, } bytes_copied += chunk_sz; + + MCUBOOT_WATCHDOG_FEED(); } return 0; diff --git a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h index b539e48f..f04eebc6 100644 --- a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h +++ b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h @@ -73,4 +73,14 @@ #define MCUBOOT_MAX_IMG_SECTORS MYNEWT_VAL(BOOTUTIL_MAX_IMG_SECTORS) +#if MYNEWT_VAL(WATCHDOG_INTERVAL) +#include +#define MCUBOOT_WATCHDOG_FEED() \ + do { \ + hal_watchdog_tickle(); \ + } while (0) +#else +#define MCUBOOT_WATCHDOG_FEED() do {} while (0) +#endif + #endif /* __MCUBOOT_CONFIG_H__ */ diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h index 4365ed2d..d79d5563 100644 --- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h +++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h @@ -78,4 +78,9 @@ #endif /* !__BOOTSIM__ */ +#define MCUBOOT_WATCHDOG_FEED() \ + do { \ + /* TODO: to be implemented */ \ + } while (0) + #endif /* __MCUBOOT_CONFIG_H__ */ diff --git a/samples/mcuboot_config/mcuboot_config.template.h b/samples/mcuboot_config/mcuboot_config.template.h index d29f4f6f..14ad2187 100644 --- a/samples/mcuboot_config/mcuboot_config.template.h +++ b/samples/mcuboot_config/mcuboot_config.template.h @@ -116,4 +116,17 @@ * "assert" is used. */ /* #define MCUBOOT_HAVE_ASSERT_H */ +/* + * Watchdog feeding + */ + +/* This macro might be implemented if the OS / HW watchdog is enabled while + * doing a swap upgrade and the time it takes for a swapping is long enough + * to cause an unwanted reset. If implementing this, the OS main.c must also + * enable the watchdog (if required)! + * + * #define MCUBOOT_WATCHDOG_FEED() + * do { do watchdog feeding here! } while (0) + */ + #endif /* __MCUBOOT_CONFIG_H__ */