summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-11-07 14:26:42 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-11-07 14:26:42 +0100
commit047d617c6449da6b17a3b844802bb5e127fef7c3 (patch)
tree6d28caf8a4f7c155b3406d71a0b5f7c38f844eac /commands
parentcd8a909bb3e7af6d905e4b554b10a3bf9718f5c5 (diff)
parentcbfdbf38c190bc9197f85c9633f103cdc15de571 (diff)
downloadbarebox-047d617c6449da6b17a3b844802bb5e127fef7c3.tar.gz
Merge branch 'for-next/watchdog'
Diffstat (limited to 'commands')
-rw-r--r--commands/wd.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/commands/wd.c b/commands/wd.c
index 26823f8..8029bab 100644
--- a/commands/wd.c
+++ b/commands/wd.c
@@ -16,6 +16,8 @@
#include <command.h>
#include <errno.h>
#include <linux/ctype.h>
+#include <getopt.h>
+#include <complete.h>
#include <watchdog.h>
/* default timeout in [sec] */
@@ -23,18 +25,30 @@ static unsigned timeout = CONFIG_CMD_WD_DEFAULT_TIMOUT;
static int do_wd(int argc, char *argv[])
{
+ struct watchdog *wd = watchdog_get_default();
+ int opt;
int rc;
- if (argc > 1) {
- if (isdigit(*argv[1])) {
- timeout = simple_strtoul(argv[1], NULL, 0);
+ while ((opt = getopt(argc, argv, "d:")) > 0) {
+ switch (opt) {
+ case 'd':
+ wd = watchdog_get_by_name(optarg);
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind < argc) {
+ if (isdigit(*argv[optind])) {
+ timeout = simple_strtoul(argv[optind], NULL, 0);
} else {
printf("numerical parameter expected\n");
- return 1;
+ return COMMAND_ERROR_USAGE;
}
}
- rc = watchdog_set_timeout(timeout);
+ rc = watchdog_set_timeout(wd, timeout);
if (rc < 0) {
switch (rc) {
case -EINVAL:
@@ -43,12 +57,15 @@ static int do_wd(int argc, char *argv[])
case -ENOSYS:
printf("Watchdog cannot be disabled\n");
break;
+ case -ENODEV:
+ printf("Watchdog device doesn't exist.\n");
+ break;
default:
printf("Watchdog fails: '%s'\n", strerror(-rc));
break;
}
- return 1;
+ return COMMAND_ERROR;
}
return 0;
@@ -58,12 +75,15 @@ BAREBOX_CMD_HELP_START(wd)
BAREBOX_CMD_HELP_TEXT("Enable the watchdog to bark in TIME seconds.")
BAREBOX_CMD_HELP_TEXT("When TIME is 0, the watchdog gets disabled,")
BAREBOX_CMD_HELP_TEXT("Without a parameter the watchdog will be re-triggered.")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-d DEVICE\t", "watchdog name (default is highest priority watchdog)")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(wd)
.cmd = do_wd,
BAREBOX_CMD_DESC("enable/disable/trigger the watchdog")
- BAREBOX_CMD_OPTS("[TIME]")
+ BAREBOX_CMD_OPTS("[-d DEVICE] [TIME]")
BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
BAREBOX_CMD_HELP(cmd_wd_help)
+ BAREBOX_CMD_COMPLETE(device_complete)
BAREBOX_CMD_END