[PATCH] usbgadget: autostart: add usbgadget_autostart helper for board code
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Aug 15 02:17:33 PDT 2022
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 at 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
More information about the barebox
mailing list