Skip to content

Commit 853657c

Browse files
committed
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 <[email protected]>
1 parent af1e02e commit 853657c

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

boot/bootutil/src/loader.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ boot_copy_sector(const struct flash_area *fap_src,
954954
}
955955

956956
bytes_copied += chunk_sz;
957+
958+
MCUBOOT_WATCHDOG_FEED();
957959
}
958960

959961
return 0;

boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@
7373

7474
#define MCUBOOT_MAX_IMG_SECTORS MYNEWT_VAL(BOOTUTIL_MAX_IMG_SECTORS)
7575

76+
#if MYNEWT_VAL(WATCHDOG_INTERVAL)
77+
#include <hal/hal_watchdog.h>
78+
#define MCUBOOT_WATCHDOG_FEED() \
79+
do { \
80+
hal_watchdog_tickle(); \
81+
} while (0)
82+
#else
83+
#define MCUBOOT_WATCHDOG_FEED() do {} while (0)
84+
#endif
85+
7686
#endif /* __MCUBOOT_CONFIG_H__ */

boot/zephyr/include/mcuboot_config/mcuboot_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@
7878

7979
#endif /* !__BOOTSIM__ */
8080

81+
#define MCUBOOT_WATCHDOG_FEED() \
82+
do { \
83+
/* TODO: to be implemented */ \
84+
} while (0)
85+
8186
#endif /* __MCUBOOT_CONFIG_H__ */

samples/mcuboot_config/mcuboot_config.template.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,17 @@
116116
* "assert" is used. */
117117
/* #define MCUBOOT_HAVE_ASSERT_H */
118118

119+
/*
120+
* Watchdog feeding
121+
*/
122+
123+
/* This macro might be implemented if the OS / HW watchdog is enabled while
124+
* doing a swap upgrade and the time it takes for a swapping is long enough
125+
* to cause an unwanted reset. If implementing this, the OS main.c must also
126+
* enable the watchdog (if required)!
127+
*
128+
* #define MCUBOOT_WATCHDOG_FEED()
129+
* do { do watchdog feeding here! } while (0)
130+
*/
131+
119132
#endif /* __MCUBOOT_CONFIG_H__ */

0 commit comments

Comments
 (0)