mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] usbgadget: autostart: add usbgadget_autostart helper for board code
@ 2022-08-15  9:17 Ahmad Fatoum
  2022-08-16  7:57 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2022-08-15  9:17 UTC (permalink / raw)
  To: barebox; +Cc: mfe, Ahmad Fatoum

barebox will rerun a setter if a nv variable changes its global variable's
default. If setter is accessing other nv variables though, the setter
will not rerun when they change. For this reason, usbgadget_autostart_init()
must be registered at postenvironment_initcall() level, but this makes
the variable only reliably usable from the shell as there's no later
initcall level than postenvironment_initcall() for board code to run at.

Add a new usbgadget_autostart(boot enable) function that board code can
use instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/usbgadget.c         | 15 ++++++++++++++-
 include/usb/gadget-multi.h |  3 +++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/common/usbgadget.c b/common/usbgadget.c
index 2ec6d9226cca..161fd16fedb7 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -121,6 +121,12 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx)
 	return err;
 }
 
+void usbgadget_autostart(bool enable)
+{
+	globalvar_set("usbgadget.autostart", enable ? "1" : "0");
+	autostart = enable;
+}
+
 static int usbgadget_globalvars_init(void)
 {
 	globalvar_add_simple_bool("usbgadget.acm", &acm);
@@ -132,8 +138,15 @@ device_initcall(usbgadget_globalvars_init);
 
 static int usbgadget_autostart_init(void)
 {
-	if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART))
+	if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART)) {
 		globalvar_add_bool("usbgadget.autostart", usbgadget_autostart_set, &autostart, NULL);
+		/* We are already at latest initcall level, yet board code
+		 * may want to set this variable without resorting to scripts.
+		 * Check autostart manually here, so we don't miss it.
+		 */
+		if (autostart)
+			globalvar_set("usbgadget.autostart", "1");
+	}
 	return 0;
 }
 postenvironment_initcall(usbgadget_autostart_init);
diff --git a/include/usb/gadget-multi.h b/include/usb/gadget-multi.h
index 2d8d7533a816..e67ca165c18b 100644
--- a/include/usb/gadget-multi.h
+++ b/include/usb/gadget-multi.h
@@ -3,6 +3,7 @@
 #ifndef __USB_GADGET_MULTI_H
 #define __USB_GADGET_MULTI_H
 
+#include <linux/types.h>
 #include <usb/fastboot.h>
 #include <usb/dfu.h>
 #include <usb/usbserial.h>
@@ -36,4 +37,6 @@ struct usbgadget_funcs {
 
 int usbgadget_register(const struct usbgadget_funcs *funcs);
 
+void usbgadget_autostart(bool enable);
+
 #endif /* __USB_GADGET_MULTI_H */
-- 
2.30.2




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

end of thread, other threads:[~2022-08-17  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15  9:17 [PATCH] usbgadget: autostart: add usbgadget_autostart helper for board code Ahmad Fatoum
2022-08-16  7:57 ` Sascha Hauer
2022-08-17  6:30   ` Ahmad Fatoum
2022-08-17  7:10     ` Sascha Hauer

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