mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1 1/2] usb: gadget: start usbgadget automatically
@ 2017-03-24 10:21 Oleksij Rempel
  2017-03-24 10:21 ` [PATCH v1 2/2] commands: usbgadget: provide fallback to global variables Oleksij Rempel
  2017-03-29  7:29 ` [PATCH v1 1/2] usb: gadget: start usbgadget automatically Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2017-03-24 10:21 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

... if global variable configured to do it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/usb/gadget/Kconfig     |  6 ++++
 drivers/usb/gadget/Makefile    |  1 +
 drivers/usb/gadget/autostart.c | 67 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 drivers/usb/gadget/autostart.c

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index eb279ae8d..dd5d4a75a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -30,6 +30,12 @@ config USB_GADGET_DRIVER_PXA27X
 	default y
 	select USB_GADGET_DUALSPEED
 
+config USB_GADGET_AUTOSTART
+	bool
+	default y
+	select ENVIRONMENT_VARIABLES
+	prompt "Automatically start usbgadget on boot"
+
 comment "USB Gadget drivers"
 
 config USB_GADGET_DFU
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 9ef594575..e74cf0266 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -1,5 +1,6 @@
 
 obj-$(CONFIG_USB_GADGET) += composite.o config.o usbstring.o epautoconf.o udc-core.o functions.o config.o multi.o
+obj-$(CONFIG_USB_GADGET_AUTOSTART) += autostart.o
 obj-$(CONFIG_USB_GADGET_SERIAL) += u_serial.o serial.o f_serial.o f_acm.o
 obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
 obj-$(CONFIG_USB_GADGET_FASTBOOT) += f_fastboot.o
diff --git a/drivers/usb/gadget/autostart.c b/drivers/usb/gadget/autostart.c
new file mode 100644
index 000000000..43c2ba23d
--- /dev/null
+++ b/drivers/usb/gadget/autostart.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 Oleksij Rempel <o.rempel@pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <fs.h>
+#include <xfuncs.h>
+#include <usb/usbserial.h>
+#include <usb/dfu.h>
+#include <usb/gadget-multi.h>
+#include <globalvar.h>
+#include <magicvar.h>
+
+static int autostart;
+static int acm;
+static char *fastboot_function;
+
+static int usbgadget_autostart(void)
+{
+	struct f_multi_opts opts = {};
+
+	if (!autostart)
+		return 0;
+
+	if (fastboot_function)
+		opts.fastboot_opts.files = file_list_parse(fastboot_function);
+
+	opts.create_acm = acm;
+
+	return usb_multi_register(&opts);
+}
+postenvironment_initcall(usbgadget_autostart);
+
+static int usbgadget_globalvars_init(void)
+{
+
+	globalvar_add_simple_bool("usbgadget.autostart", &autostart);
+	globalvar_add_simple_bool("usbgadget.acm", &acm);
+	globalvar_add_simple_string("usbgadget.fastboot_function",
+				    &fastboot_function);
+
+	return 0;
+}
+device_initcall(usbgadget_globalvars_init);
+
+BAREBOX_MAGICVAR_NAMED(global_usbgadget_autostart,
+		       global.usbgadget.autostart,
+		       "usbgadget: Automatically start usbgadget on boot");
+BAREBOX_MAGICVAR_NAMED(global_usbgadget_acm,
+		       global.usbgadget.acm,
+		       "usbgadget: Create CDC ACM function");
+BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_function,
+		       global.usbgadget.fastboot_function,
+		       "usbgadget: Create Android Fastboot function");
-- 
2.11.0


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

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

* [PATCH v1 2/2] commands: usbgadget: provide fallback to global variables
  2017-03-24 10:21 [PATCH v1 1/2] usb: gadget: start usbgadget automatically Oleksij Rempel
@ 2017-03-24 10:21 ` Oleksij Rempel
  2017-03-29  7:29 ` [PATCH v1 1/2] usb: gadget: start usbgadget automatically Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2017-03-24 10:21 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

usbgadget autostarter is providing now a global variable to configure fastboot.
We can use is as fallback for the cmd_usbgadget as well.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 commands/usbgadget.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index a7e8d6c0c..9f250633d 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -20,6 +20,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <environment.h>
 #include <errno.h>
 #include <malloc.h>
 #include <getopt.h>
@@ -32,11 +33,11 @@
 static int do_usbgadget(int argc, char *argv[])
 {
 	int opt;
-	int acm = 1, create_serial = 0;
+	int acm = 1, create_serial = 0, fastboot_set = 0;
 	char *fastboot_opts = NULL, *dfu_opts = NULL;
 	struct f_multi_opts opts = {};
 
-	while ((opt = getopt(argc, argv, "asdA:D:")) > 0) {
+	while ((opt = getopt(argc, argv, "asdA::D:")) > 0) {
 		switch (opt) {
 		case 'a':
 			acm = 1;
@@ -51,6 +52,7 @@ static int do_usbgadget(int argc, char *argv[])
 			break;
 		case 'A':
 			fastboot_opts = optarg;
+			fastboot_set = 1;
 			break;
 		case 'd':
 			usb_multi_unregister();
@@ -60,6 +62,9 @@ static int do_usbgadget(int argc, char *argv[])
 		}
 	}
 
+	if (fastboot_set && !fastboot_opts)
+		fastboot_opts = getenv("global.usbgadget.fastboot_function");
+
 	if (!dfu_opts && !fastboot_opts && !create_serial)
 		return COMMAND_ERROR_USAGE;
 
-- 
2.11.0


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

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

* Re: [PATCH v1 1/2] usb: gadget: start usbgadget automatically
  2017-03-24 10:21 [PATCH v1 1/2] usb: gadget: start usbgadget automatically Oleksij Rempel
  2017-03-24 10:21 ` [PATCH v1 2/2] commands: usbgadget: provide fallback to global variables Oleksij Rempel
@ 2017-03-29  7:29 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-03-29  7:29 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Fri, Mar 24, 2017 at 11:21:22AM +0100, Oleksij Rempel wrote:
> ... if global variable configured to do it.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/usb/gadget/Kconfig     |  6 ++++
>  drivers/usb/gadget/Makefile    |  1 +
>  drivers/usb/gadget/autostart.c | 67 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 74 insertions(+)
>  create mode 100644 drivers/usb/gadget/autostart.c

Applied, thanks

Sascha

> 
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index eb279ae8d..dd5d4a75a 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -30,6 +30,12 @@ config USB_GADGET_DRIVER_PXA27X
>  	default y
>  	select USB_GADGET_DUALSPEED
>  
> +config USB_GADGET_AUTOSTART
> +	bool
> +	default y
> +	select ENVIRONMENT_VARIABLES
> +	prompt "Automatically start usbgadget on boot"
> +
>  comment "USB Gadget drivers"
>  
>  config USB_GADGET_DFU
> diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
> index 9ef594575..e74cf0266 100644
> --- a/drivers/usb/gadget/Makefile
> +++ b/drivers/usb/gadget/Makefile
> @@ -1,5 +1,6 @@
>  
>  obj-$(CONFIG_USB_GADGET) += composite.o config.o usbstring.o epautoconf.o udc-core.o functions.o config.o multi.o
> +obj-$(CONFIG_USB_GADGET_AUTOSTART) += autostart.o
>  obj-$(CONFIG_USB_GADGET_SERIAL) += u_serial.o serial.o f_serial.o f_acm.o
>  obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
>  obj-$(CONFIG_USB_GADGET_FASTBOOT) += f_fastboot.o
> diff --git a/drivers/usb/gadget/autostart.c b/drivers/usb/gadget/autostart.c
> new file mode 100644
> index 000000000..43c2ba23d
> --- /dev/null
> +++ b/drivers/usb/gadget/autostart.c
> @@ -0,0 +1,67 @@
> +/*
> + * Copyright (c) 2017 Oleksij Rempel <o.rempel@pengutronix.de>, Pengutronix
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +#include <common.h>
> +#include <command.h>
> +#include <errno.h>
> +#include <malloc.h>
> +#include <getopt.h>
> +#include <fs.h>
> +#include <xfuncs.h>
> +#include <usb/usbserial.h>
> +#include <usb/dfu.h>
> +#include <usb/gadget-multi.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
> +
> +static int autostart;
> +static int acm;
> +static char *fastboot_function;
> +
> +static int usbgadget_autostart(void)
> +{
> +	struct f_multi_opts opts = {};
> +
> +	if (!autostart)
> +		return 0;
> +
> +	if (fastboot_function)
> +		opts.fastboot_opts.files = file_list_parse(fastboot_function);
> +
> +	opts.create_acm = acm;
> +
> +	return usb_multi_register(&opts);
> +}
> +postenvironment_initcall(usbgadget_autostart);
> +
> +static int usbgadget_globalvars_init(void)
> +{
> +
> +	globalvar_add_simple_bool("usbgadget.autostart", &autostart);
> +	globalvar_add_simple_bool("usbgadget.acm", &acm);
> +	globalvar_add_simple_string("usbgadget.fastboot_function",
> +				    &fastboot_function);
> +
> +	return 0;
> +}
> +device_initcall(usbgadget_globalvars_init);
> +
> +BAREBOX_MAGICVAR_NAMED(global_usbgadget_autostart,
> +		       global.usbgadget.autostart,
> +		       "usbgadget: Automatically start usbgadget on boot");
> +BAREBOX_MAGICVAR_NAMED(global_usbgadget_acm,
> +		       global.usbgadget.acm,
> +		       "usbgadget: Create CDC ACM function");
> +BAREBOX_MAGICVAR_NAMED(global_usbgadget_fastboot_function,
> +		       global.usbgadget.fastboot_function,
> +		       "usbgadget: Create Android Fastboot function");
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 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] 3+ messages in thread

end of thread, other threads:[~2017-03-29  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24 10:21 [PATCH v1 1/2] usb: gadget: start usbgadget automatically Oleksij Rempel
2017-03-24 10:21 ` [PATCH v1 2/2] commands: usbgadget: provide fallback to global variables Oleksij Rempel
2017-03-29  7:29 ` [PATCH v1 1/2] usb: gadget: start usbgadget automatically Sascha Hauer

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