mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/6] commands: wd: support configuring watchdog by name
Date: Wed, 23 Oct 2019 18:56:01 +0200	[thread overview]
Message-ID: <20191023165601.16441-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20191023165601.16441-1-a.fatoum@pengutronix.de>

So far, wd has always configured the highest-priority watchdog when
multiple are available. Add an optional -d parameter to support
configuring the other watchdogs as well. The name passed can be either
the watchdog device name (e.g. wdog0) or the hardware device name (e.g.
efi-wdt).

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/wd.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/commands/wd.c b/commands/wd.c
index f857291f0362..8029bab1ce19 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(watchdog_get_default(), 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
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-10-23 16:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23 16:55 [PATCH 1/6] Documentation: efi: emphasize watchdog deactivation on ExitBootServices Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 2/6] efi: efi-image: don't mask x86 interrupts on boot Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 3/6] watchdog: efi: bump down priority below default Ahmad Fatoum
2019-10-23 16:55 ` [PATCH 4/6] watchdog: export priority as device parameter Ahmad Fatoum
2019-10-23 16:56 ` [PATCH 5/6] watchdog: export API to configure watchdogs by name Ahmad Fatoum
2019-10-23 16:56 ` Ahmad Fatoum [this message]
2019-10-24  6:34 ` [PATCH 1/6] Documentation: efi: emphasize watchdog deactivation on ExitBootServices Oleksij Rempel
2019-10-24  7:59 ` Sascha Hauer

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=20191023165601.16441-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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