boot: nuttx: Support application specific

wdg initialization.

Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
This commit is contained in:
Andrés Sánchez Pascual 2022-11-07 18:09:25 +01:00 committed by Gustavo Henrique Nihei
parent 246aca368e
commit 6ea3e9bd17
4 changed files with 93 additions and 0 deletions

View File

@ -181,6 +181,15 @@
*/
#ifdef CONFIG_MCUBOOT_WATCHDOG
#ifndef CONFIG_MCUBOOT_WATCHDOG_DEVPATH
# define CONFIG_MCUBOOT_WATCHDOG_DEVPATH "/dev/watchdog0"
#endif
#ifndef CONFIG_MCUBOOT_WATCHDOG_TIMEOUT
# define CONFIG_MCUBOOT_WATCHDOG_TIMEOUT 10000 /* Watchdog timeout in ms */
#endif
# define MCUBOOT_WATCHDOG_FEED() do \
{ \
mcuboot_watchdog_feed(); \

View File

@ -41,4 +41,25 @@
void mcuboot_watchdog_feed(void);
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: mcuboot_watchdog_init
*
* Description:
* Initialize the watchdog timer by setting the trigger timeout and
* starting it.
*
* Input Parameters:
* None.
*
* Returned Value:
* OK on success, ERROR if not.
*
****************************************************************************/
int mcuboot_watchdog_init(void);
#endif /* __BOOT_NUTTX_INCLUDE_WATCHDOG_WATCHDOG_H */

View File

@ -114,6 +114,15 @@ int main(int argc, FAR char *argv[])
syslog(LOG_INFO, "*** Booting MCUboot build %s ***\n", CONFIG_MCUBOOT_VERSION);
#ifdef CONFIG_MCUBOOT_WATCHDOG
int ret = mcuboot_watchdog_init();
if (ret < 0)
{
syslog(LOG_ERR, "Unable to initialize the watchdog timer\n");
FIH_PANIC;
}
#endif
FIH_CALL(boot_go, fih_rc, &rsp);
if (fih_not_eq(fih_rc, FIH_SUCCESS))

View File

@ -74,3 +74,57 @@ void mcuboot_watchdog_feed(void)
close(fd);
}
/****************************************************************************
* Name: mcuboot_watchdog_init
*
* Description:
* Initialize the watchdog timer by setting the trigger timeout and
* starting it.
*
* Input Parameters:
* None.
*
* Returned Value:
* OK on success, ERROR if not.
*
****************************************************************************/
int mcuboot_watchdog_init(void)
{
int fd;
int ret;
fd = open(CONFIG_MCUBOOT_WATCHDOG_DEVPATH, O_RDONLY);
if (fd < 0)
{
BOOT_LOG_ERR("Failed to open %s", CONFIG_MCUBOOT_WATCHDOG_DEVPATH);
goto errout;
}
ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_MCUBOOT_WATCHDOG_TIMEOUT);
if (ret < 0)
{
int errcode = errno;
BOOT_LOG_ERR("Failed to set timeout in watchdog device: %d", errcode);
goto errout_with_dev;
}
ret = ioctl(fd, WDIOC_START, 0);
if (ret < 0)
{
int errcode = errno;
BOOT_LOG_ERR("Failed to start watchdog device: %d", errcode);
goto errout_with_dev;
}
close(fd);
return OK;
errout_with_dev:
close(fd);
errout:
return ERROR;
}