summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-03 13:48:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-12 08:00:00 +0200
commit25e04a10438440cb9ca71da5b3c1edcdfc704757 (patch)
treecbdfd7a16f052a1c38cf0aa2e16ead07d6fb4a10 /common
parentf84f3df85c4c305d460d4a249872e7f34fc20f0c (diff)
downloadbarebox-25e04a10438440cb9ca71da5b3c1edcdfc704757.tar.gz
barebox-25e04a10438440cb9ca71da5b3c1edcdfc704757.tar.xz
usbgadget: autostart: fix indeterminism around usbgadget.autostart
The setter for usbgadget.autostart evaluates other device paramaters, so it must happen postenvironment, otherwise it could run too early and not see the device parameters it depends on. This was observed with usbgadget.dfu_function, which wasn't loaded from the environment early enough, but it now does. While at it, remove some more wonkyness: - usbgadget_autostart_set is only ever called when the IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART), so drop the check - There is no need to make usbgadget.acm specific to autostart. It's behavior now is counter intuitive (enable Kconfig symbol, but don't set global variable and it will have an effect. Disable CONFIG_USB_GADGET_AUTOSTART, which looks completely unrelated and it no longer works. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-10-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/usbgadget.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/common/usbgadget.c b/common/usbgadget.c
index feec0b6634..0b2d9a2120 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -97,7 +97,7 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx)
bool fastboot_bbu = get_fastboot_bbu();
int err;
- if (!IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART) || !autostart || started)
+ if (!autostart || started)
return 0;
err = usbgadget_register(true, NULL, true, NULL, acm, fastboot_bbu);
@@ -109,17 +109,21 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx)
static int usbgadget_globalvars_init(void)
{
- if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART)) {
- globalvar_add_bool("usbgadget.autostart", usbgadget_autostart_set,
- &autostart, NULL);
- globalvar_add_simple_bool("usbgadget.acm", &acm);
- }
+ globalvar_add_simple_bool("usbgadget.acm", &acm);
globalvar_add_simple_string("usbgadget.dfu_function", &dfu_function);
return 0;
}
device_initcall(usbgadget_globalvars_init);
+static int usbgadget_autostart_init(void)
+{
+ if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART))
+ globalvar_add_bool("usbgadget.autostart", usbgadget_autostart_set, &autostart, NULL);
+ return 0;
+}
+postenvironment_initcall(usbgadget_autostart_init);
+
BAREBOX_MAGICVAR(global.usbgadget.autostart,
"usbgadget: Automatically start usbgadget on boot");
BAREBOX_MAGICVAR(global.usbgadget.acm,