boot: nuttx: Support application specific
wdg initialization. Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
This commit is contained in:
parent
246aca368e
commit
6ea3e9bd17
|
@ -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(); \
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue