Commit 6ea3e9bd authored by Andrés Sánchez Pascual's avatar Andrés Sánchez Pascual Committed by Gustavo Henrique Nihei
Browse files

boot: nuttx: Support application specific


wdg initialization.

Signed-off-by: default avatarAndrés Sánchez Pascual <tito97_sp@hotmail.com>
parent 246aca36
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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(); \
+21 −0
Original line number Diff line number Diff line
@@ -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 */
+9 −0
Original line number Diff line number Diff line
@@ -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))
+54 −0
Original line number Diff line number Diff line
@@ -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;
}