mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort
@ 2020-06-22 15:15 Ahmad Fatoum
  2020-06-23  8:23 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2020-06-22 15:15 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

nv.autoboot=abort has been added as development aid to have barebox stop
at the shell prompt automatically. It makes sense to inhibit all watchdogs
in this mode, so the user can later use the shell in peace.

This also applies to fastboot aborting the shell prompt. If this
happens, watchdog will be automatically inhibited as well.
Behavior on user aborting the shell prompt via keypad or uart input
remains unchanged for backwards-compatibility.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
 - use watchdog_hw_running helper
---
 common/startup.c           |  4 ++++
 drivers/watchdog/wd_core.c | 27 +++++++++++++++++++++++++++
 include/watchdog.h         |  6 ++++++
 3 files changed, 37 insertions(+)

diff --git a/common/startup.c b/common/startup.c
index 511675ed55d4..fa66fe086edb 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -43,6 +43,7 @@
 #include <console_countdown.h>
 #include <environment.h>
 #include <linux/ctype.h>
+#include <watchdog.h>
 
 extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
 		  __barebox_initcalls_end[];
@@ -351,6 +352,9 @@ static int run_init(void)
 	if (autoboot == AUTOBOOT_MENU)
 		run_command(MENUFILE);
 
+	if (autoboot == AUTOBOOT_ABORT && autoboot == global_autoboot_state)
+		watchdog_inhibit_all();
+
 	run_shell();
 	run_command(MENUFILE);
 
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index a17234f4b6c1..7835ab6d1ff6 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -273,3 +273,30 @@ struct watchdog *watchdog_get_by_name(const char *name)
 	return NULL;
 }
 EXPORT_SYMBOL(watchdog_get_by_name);
+
+int watchdog_inhibit_all(void)
+{
+	struct watchdog *wd;
+	int ret = 0;
+
+	list_for_each_entry(wd, &watchdog_list, list) {
+		int err;
+		if (!wd->priority || watchdog_hw_running(wd) == false)
+			continue;
+
+		err = watchdog_set_timeout(wd, 0);
+		if (!err)
+			continue;
+
+		if (err != -ENOSYS || !IS_ENABLED(CONFIG_WATCHDOG_POLLER)) {
+			ret = err;
+			continue;
+		}
+
+		wd->poller_enable = true;
+		watchdog_poller_start(wd);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(watchdog_inhibit_all);
diff --git a/include/watchdog.h b/include/watchdog.h
index 419c1cdf469e..81414ef8ecaa 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -45,6 +45,7 @@ int watchdog_deregister(struct watchdog *);
 struct watchdog *watchdog_get_default(void);
 struct watchdog *watchdog_get_by_name(const char *name);
 int watchdog_set_timeout(struct watchdog*, unsigned);
+int watchdog_inhibit_all(void);
 #else
 static inline int watchdog_register(struct watchdog *w)
 {
@@ -70,6 +71,11 @@ static inline int watchdog_set_timeout(struct watchdog*w, unsigned t)
 {
 	return 0;
 }
+
+static inline int watchdog_inhibit_all(void)
+{
+	return -ENOSYS;
+}
 #endif
 
 #define WATCHDOG_DEFAULT_PRIORITY 100
-- 
2.27.0


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort
  2020-06-22 15:15 [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort Ahmad Fatoum
@ 2020-06-23  8:23 ` Sascha Hauer
  2020-06-23  8:34   ` Ahmad Fatoum
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2020-06-23  8:23 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jun 22, 2020 at 05:15:25PM +0200, Ahmad Fatoum wrote:
> nv.autoboot=abort has been added as development aid to have barebox stop
> at the shell prompt automatically. It makes sense to inhibit all watchdogs
> in this mode, so the user can later use the shell in peace.

As a person who is frequently annoyed by watchdogs I really like this
change.

We could add a new option to the wd command to call
watchdog_inhibit_all() for the case when the autoboot timeout has been
interrupted by the user.

Anyway, this could be done as a separate patch.

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort
  2020-06-23  8:23 ` Sascha Hauer
@ 2020-06-23  8:34   ` Ahmad Fatoum
  2020-06-23  9:39     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2020-06-23  8:34 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hello Sascha,

On 6/23/20 10:23 AM, Sascha Hauer wrote:
> On Mon, Jun 22, 2020 at 05:15:25PM +0200, Ahmad Fatoum wrote:
>> nv.autoboot=abort has been added as development aid to have barebox stop
>> at the shell prompt automatically. It makes sense to inhibit all watchdogs
>> in this mode, so the user can later use the shell in peace.
> 
> As a person who is frequently annoyed by watchdogs I really like this
> change.

:]

> We could add a new option to the wd command to call
> watchdog_inhibit_all() for the case when the autoboot timeout has been
> interrupted by the user.
> 
> Anyway, this could be done as a separate patch.

I thought about having $global.autoboot_watchdog_inhibit_abort={nv,all},
but didn't go through with it because I couldn't find a name I like.

Is this what you are suggesting, but with wd setting an internal parameter
instead?

Cheers,
Ahmad

> 
> Applied, thanks
> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort
  2020-06-23  8:34   ` Ahmad Fatoum
@ 2020-06-23  9:39     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2020-06-23  9:39 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Tue, Jun 23, 2020 at 10:34:26AM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 6/23/20 10:23 AM, Sascha Hauer wrote:
> > On Mon, Jun 22, 2020 at 05:15:25PM +0200, Ahmad Fatoum wrote:
> >> nv.autoboot=abort has been added as development aid to have barebox stop
> >> at the shell prompt automatically. It makes sense to inhibit all watchdogs
> >> in this mode, so the user can later use the shell in peace.
> > 
> > As a person who is frequently annoyed by watchdogs I really like this
> > change.
> 
> :]
> 
> > We could add a new option to the wd command to call
> > watchdog_inhibit_all() for the case when the autoboot timeout has been
> > interrupted by the user.
> > 
> > Anyway, this could be done as a separate patch.
> 
> I thought about having $global.autoboot_watchdog_inhibit_abort={nv,all},
> but didn't go through with it because I couldn't find a name I like.
> 
> Is this what you are suggesting, but with wd setting an internal parameter
> instead?

I thought about a "wd -i" command that disables watchdogs or
automatically pings them. I would use this in case I want to do
something with barebox, but don't want to change nv.autoboot to "abort"

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-23  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 15:15 [PATCH v2] startup: inhibit watchdogs on non-interactive autoboot abort Ahmad Fatoum
2020-06-23  8:23 ` Sascha Hauer
2020-06-23  8:34   ` Ahmad Fatoum
2020-06-23  9:39     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox