From: Simon Kagstrom <simon.kagstrom@netinsight.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/2]: common: Add a watchdog CLI command
Date: Thu, 29 Oct 2009 09:09:23 +0100 [thread overview]
Message-ID: <20091029090923.32a58e07@marrow.netinsight.se> (raw)
In-Reply-To: <20091029090749.2a2c91d7@marrow.netinsight.se>
A watchdog command to enable the watchdog with a timeout from the CLI
can sometimes be useful. Add that. This also adds a common API for
enabling watchdogs. The API is simple:
int watchdog_enable(unsigned int timeout);
the timeout range vary depending on hardware, and the driver should
return a negative value if the call failed.
Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
ChangeLog:
v2:
* Passing zero as timeout is invalid (Prafulla)
* Add return value from watchdog_enable(), negative means failure (Prafulla, Wolfgang)
* Remove watchdog_disable() (Wolfgang)
* Use weak default function for watchdog_enable() (Wolfgang)
* Provide friendly and helpful printouts when invalid parameters are
passed to the CLI command
common/Makefile | 1 +
common/cmd_watchdog.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
common/main.c | 7 +++++
include/watchdog.h | 2 +
4 files changed, 72 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..ca1a8fd
--- /dev/null
+++ b/common/cmd_watchdog.c
@@ -0,0 +1,62 @@
+/*
+ * (C) Copyright 2009
+ * Net Insight <www.netinsight.net>
+ * Written-by: Simon Kagstrom <simon.kagstrom@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;
+ unsigned long timeout;
+
+ /* need one argument */
+ if (argc != 2)
+ goto usage;
+
+ cmd = argv[1];
+ timeout = simple_strtoul(cmd, &endp, 0);
+ if (endp == cmd) {
+ printf("Error: Could not convert `%s' to a number\n\n", cmd);
+ goto usage;
+ }
+ if (timeout < 1) {
+ printf("Error: zero timeouts are invalid\n\n");
+ goto usage;
+ }
+
+ /* Everything fine, enable the watchdog */
+ if (watchdog_enable(timeout) < 0) {
+ printf("Error: Could not enable watchdog, check timeout parameter\n\n");
+ goto usage;
+ }
+
+ 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"
+);
diff --git a/common/main.c b/common/main.c
index 10d8904..47e867b 100644
--- a/common/main.c
+++ b/common/main.c
@@ -1446,3 +1446,10 @@ int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
return 0;
}
#endif
+
+
+inline int __watchdog_enable(unsigned int timeout_secs)
+{
+ return -1;
+}
+int watchdog_enable(unsigned int timeout_secs) __attribute__((weak, alias("__watchdog_enable")));
diff --git a/include/watchdog.h b/include/watchdog.h
index 9265be9..74c2bda 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -70,6 +70,8 @@
#endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
#endif /* CONFIG_HW_WATCHDOG */
+extern int watchdog_enable(unsigned int timeout_secs);
+
/*
* Prototypes from $(CPU)/cpu.c.
*/
--
1.6.0.4
next prev parent reply other threads:[~2009-10-29 8:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 14:11 [U-Boot] [PATCH 0/2]: Watchdog support from the command line Simon Kagstrom
2009-10-28 14:14 ` [U-Boot] [PATCH 1/2]: common: Add a watchdog CLI command Simon Kagstrom
2009-10-28 14:29 ` Prafulla Wadaskar
2009-10-28 14:49 ` Simon Kagstrom
2009-10-28 15:56 ` Wolfgang Denk
2009-10-28 14:15 ` [U-Boot] [PATCH 2/2]: arm:kirkwood: Add hardware watchdog support for Marvell Kirkwood boards Simon Kagstrom
2009-10-28 15:41 ` Prafulla Wadaskar
2009-10-29 8:07 ` [U-Boot] [PATCH v2 0/2]: Watchdog support from the command line Simon Kagstrom
2009-10-29 8:09 ` Simon Kagstrom [this message]
2009-10-29 8:29 ` [U-Boot] [PATCH v2 1/2]: common: Add a watchdog CLI command Prafulla Wadaskar
2009-11-06 9:28 ` Simon Kagstrom
2009-11-06 9:34 ` Prafulla Wadaskar
2009-11-06 11:18 ` Mike Frysinger
2009-10-29 8:11 ` [U-Boot] [PATCH v2 2/2]: arm:kirkwood: Add hardware watchdog support for Marvell Kirkwood boards Simon Kagstrom
2009-10-29 8:32 ` Prafulla Wadaskar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091029090923.32a58e07@marrow.netinsight.se \
--to=simon.kagstrom@netinsight.net \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox