[U-Boot] [PATCH 1/2]: common: Add a watchdog CLI command
Prafulla Wadaskar
prafulla at marvell.com
Wed Oct 28 15:29:35 CET 2009
> -----Original Message-----
> From: Simon Kagstrom [mailto:simon.kagstrom at netinsight.net]
> Sent: Wednesday, October 28, 2009 7:44 PM
> To: U-Boot ML; Prafulla Wadaskar
> Subject: [PATCH 1/2]: common: Add a watchdog CLI command
>
> A watchdog command to enable the watchdog with a timeout or disable it
> can sometimes be useful. Add that. This also adds a common API for
> enabling or disabling watchdogs. The API is simple:
>
> void watchdog_enable(unsigned int timeout);
> void watchdog_disable(void);
>
> disabling the watchdog might or might not be possible depending on the
> hardware, and the timeout range can also vary in the same way.
>
> Signed-off-by: Simon Kagstrom <simon.kagstrom at netinsight.net>
> ---
> common/Makefile | 1 +
> common/cmd_watchdog.c | 61
> +++++++++++++++++++++++++++++++++++++++++++++++++
> include/watchdog.h | 9 +++++++
> 3 files changed, 71 insertions(+), 0 deletions(-)
> create mode 100644 common/cmd_watchdog.c
>
> diff --git a/common/Makefile b/common/Makefile
> index 3781738..f14ba0e 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -160,6 +160,7 @@ COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
> COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
> COBJS-$(CONFIG_UPDATE_TFTP) += update.o
> COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
> +COBJS-$(CONFIG_CMD_WATCHDOG) += cmd_watchdog.o
>
>
> COBJS := $(sort $(COBJS-y))
> diff --git a/common/cmd_watchdog.c b/common/cmd_watchdog.c
> new file mode 100644
> index 0000000..d26be4f
> --- /dev/null
> +++ b/common/cmd_watchdog.c
> @@ -0,0 +1,61 @@
> +/*
> + * (C) Copyright 2009
> + * Net Insight <www.netinsight.net>
> + * Written-by: Simon Kagstrom <simon.kagstrom at netinsight.net>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> + * MA 02110-1301 USA
> + */
> +
> +#include <common.h>
> +#include <watchdog.h>
> +
> +static int do_watchdog(cmd_tbl_t *cmdtp, int flag, int argc,
> char *argv[])
> +{
> + const char *cmd;
> + char *endp;
> + int timeout;
> +
> + /* need one argument */
> + if (argc != 2)
> + goto usage;
> +
> + cmd = argv[1];
> +
> + if (strcmp(cmd, "off") == 0) {
> + watchdog_disable();
> + return 0;
> + }
> + timeout = simple_strtoul(cmd, &endp, 0);
> + if (endp == cmd)
> + goto usage;
> + if (timeout < 0)
> + goto usage;
How about passing zero value here, will it be a correct input for watchdog_enable?
> +
> + /* Everything fine, enable the watchdog */
> + watchdog_enable(timeout);
Can we check for some error code here from lower layer and dump some error message?
For ex. Specified timeout value may be invalid for specific h/w
> +
> + return 0;
> +usage:
> + cmd_usage(cmdtp);
> + return 1;
> +}
> +
> +U_BOOT_CMD(
> + watchdog, 2, 0, do_watchdog,
> + "Watchdog commands",
> + "<timeout> - start the watchdog with `timeout'
> seconds timeout\n"
> + "watchdog off - stop the watchdog (can't be
> done on all boards)\n"
> +);
> diff --git a/include/watchdog.h b/include/watchdog.h
> index 9265be9..953cf61 100644
> --- a/include/watchdog.h
> +++ b/include/watchdog.h
> @@ -70,6 +70,15 @@
> #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
> #endif /* CONFIG_HW_WATCHDOG */
>
> +#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
> +extern void watchdog_enable(unsigned int timeout_secs);
> +
> +extern void watchdog_disable(void);
> +#else
> +static inline void watchdog_enable(unsigned int timeout_secs) { }
> +static inline void watchdog_disable(void) { }
> +#endif
> +
> /*
> * Prototypes from $(CPU)/cpu.c.
> */
What does this means?
Regards..
Prafulla . .
> --
> 1.6.0.4
>
>
More information about the U-Boot
mailing list