Skip to content

Commit 6ea3e9b

Browse files
tito97spgustavonihei
authored andcommitted
boot: nuttx: Support application specific
wdg initialization. Signed-off-by: Andrés Sánchez Pascual <[email protected]>
1 parent 246aca3 commit 6ea3e9b

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

boot/nuttx/include/mcuboot_config/mcuboot_config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@
181181
*/
182182

183183
#ifdef CONFIG_MCUBOOT_WATCHDOG
184+
185+
#ifndef CONFIG_MCUBOOT_WATCHDOG_DEVPATH
186+
# define CONFIG_MCUBOOT_WATCHDOG_DEVPATH "/dev/watchdog0"
187+
#endif
188+
189+
#ifndef CONFIG_MCUBOOT_WATCHDOG_TIMEOUT
190+
# define CONFIG_MCUBOOT_WATCHDOG_TIMEOUT 10000 /* Watchdog timeout in ms */
191+
#endif
192+
184193
# define MCUBOOT_WATCHDOG_FEED() do \
185194
{ \
186195
mcuboot_watchdog_feed(); \

boot/nuttx/include/watchdog/watchdog.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,25 @@
4141

4242
void mcuboot_watchdog_feed(void);
4343

44+
/****************************************************************************
45+
* Public Function Prototypes
46+
****************************************************************************/
47+
48+
/****************************************************************************
49+
* Name: mcuboot_watchdog_init
50+
*
51+
* Description:
52+
* Initialize the watchdog timer by setting the trigger timeout and
53+
* starting it.
54+
*
55+
* Input Parameters:
56+
* None.
57+
*
58+
* Returned Value:
59+
* OK on success, ERROR if not.
60+
*
61+
****************************************************************************/
62+
63+
int mcuboot_watchdog_init(void);
64+
4465
#endif /* __BOOT_NUTTX_INCLUDE_WATCHDOG_WATCHDOG_H */

boot/nuttx/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ int main(int argc, FAR char *argv[])
114114

115115
syslog(LOG_INFO, "*** Booting MCUboot build %s ***\n", CONFIG_MCUBOOT_VERSION);
116116

117+
#ifdef CONFIG_MCUBOOT_WATCHDOG
118+
int ret = mcuboot_watchdog_init();
119+
if (ret < 0)
120+
{
121+
syslog(LOG_ERR, "Unable to initialize the watchdog timer\n");
122+
FIH_PANIC;
123+
}
124+
#endif
125+
117126
FIH_CALL(boot_go, fih_rc, &rsp);
118127

119128
if (fih_not_eq(fih_rc, FIH_SUCCESS))

boot/nuttx/src/watchdog/watchdog.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,57 @@ void mcuboot_watchdog_feed(void)
7474

7575
close(fd);
7676
}
77+
78+
/****************************************************************************
79+
* Name: mcuboot_watchdog_init
80+
*
81+
* Description:
82+
* Initialize the watchdog timer by setting the trigger timeout and
83+
* starting it.
84+
*
85+
* Input Parameters:
86+
* None.
87+
*
88+
* Returned Value:
89+
* OK on success, ERROR if not.
90+
*
91+
****************************************************************************/
92+
93+
int mcuboot_watchdog_init(void)
94+
{
95+
int fd;
96+
int ret;
97+
98+
fd = open(CONFIG_MCUBOOT_WATCHDOG_DEVPATH, O_RDONLY);
99+
if (fd < 0)
100+
{
101+
BOOT_LOG_ERR("Failed to open %s", CONFIG_MCUBOOT_WATCHDOG_DEVPATH);
102+
goto errout;
103+
}
104+
105+
ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_MCUBOOT_WATCHDOG_TIMEOUT);
106+
if (ret < 0)
107+
{
108+
int errcode = errno;
109+
110+
BOOT_LOG_ERR("Failed to set timeout in watchdog device: %d", errcode);
111+
goto errout_with_dev;
112+
}
113+
114+
ret = ioctl(fd, WDIOC_START, 0);
115+
if (ret < 0)
116+
{
117+
int errcode = errno;
118+
119+
BOOT_LOG_ERR("Failed to start watchdog device: %d", errcode);
120+
goto errout_with_dev;
121+
}
122+
123+
close(fd);
124+
return OK;
125+
126+
errout_with_dev:
127+
close(fd);
128+
errout:
129+
return ERROR;
130+
}

0 commit comments

Comments
 (0)