[PATCH v2 3/4] serial gadget: enable/disable on request

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Jan 4 03:00:43 EST 2012


On 21:52 Tue 03 Jan     , Eric Bénard wrote:
> - add a usbserial command to enable/disable the serial gadget
> - allow dfu and usbserial to cohexist in the same barebox
> - add a timeout in u_serial so that we don't get locked if the user
> enable usbserial from a UART console but doesn't consume the data
> on the usbserial port created on the PC
> - remove debug or verbose printf
> - tested on i.MX25 & i.MX35
> 
> Signed-off-by: Eric Bénard <eric at eukrea.com>
> ---
> v2 : always recompile after fixing checkpatch notes ...
> 
>  commands/Makefile             |    1 +
>  commands/usbserial.c          |  102 +++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/gadget/Kconfig    |    5 +--
>  drivers/usb/gadget/f_acm.c    |    4 +-
>  drivers/usb/gadget/serial.c   |   40 +++++++++++++---
>  drivers/usb/gadget/u_serial.c |   22 ++++++---
>  6 files changed, 152 insertions(+), 22 deletions(-)
>  create mode 100644 commands/usbserial.c
> 
> diff --git a/commands/Makefile b/commands/Makefile
> index 24753be..43630e1 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -47,6 +47,7 @@ obj-$(CONFIG_CMD_LSMOD)		+= lsmod.o
>  obj-$(CONFIG_CMD_INSMOD)	+= insmod.o
>  obj-$(CONFIG_CMD_BMP)		+= bmp.o
>  obj-$(CONFIG_USB_GADGET_DFU)	+= dfu.o
> +obj-$(CONFIG_USB_GADGET_SERIAL)	+= usbserial.o
>  obj-$(CONFIG_CMD_GPIO)		+= gpio.o
>  obj-$(CONFIG_CMD_UNCOMPRESS)	+= uncompress.o
>  obj-$(CONFIG_CMD_I2C)		+= i2c.o
> diff --git a/commands/usbserial.c b/commands/usbserial.c
> new file mode 100644
> index 0000000..7dfc102
> --- /dev/null
> +++ b/commands/usbserial.c
> @@ -0,0 +1,102 @@
> +/*
> + * dfu.c - device firmware update command
please fix
> + *
> + * Copyright (c) 2009 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> + */
> +#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>
> +
> +static int do_usbserial(struct command *cmdtp, int argc, char *argv[])
> +{
> +	int opt;
> +	struct usb_serial_pdata pdata;
> +	char *argstr;
> +	char *manufacturer = "barebox";
> +	char *productname = CONFIG_BOARDINFO;
> +	u16 idVendor = 0, idProduct = 0;
> +	int mode = 0;
> +
> +	while ((opt = getopt(argc, argv, "m:p:V:P:asd")) > 0) {
> +		switch (opt) {
> +		case 'm':
> +			manufacturer = optarg;
> +			break;
> +		case 'p':
> +			productname = optarg;
> +			break;
> +		case 'V':
> +			idVendor = simple_strtoul(optarg, NULL, 0);
> +			break;
> +		case 'P':
> +			idProduct = simple_strtoul(optarg, NULL, 0);
> +			break;
> +		case 'a':
> +			mode = 0;
> +			break;
> +/*		case 'o':
> +			mode = 1;
> +			break;*/
ditto
> +		case 's':
> +			mode = 2;
> +			break;
> +		case 'd':
> +			usb_serial_unregister();
> +			return 0;
> +		}
> +	}
> +
> +	argstr = argv[optind];
> +
> +	pdata.manufacturer = manufacturer;
> +	pdata.productname = productname;
> +	pdata.idVendor = idVendor;
> +	pdata.idProduct = idProduct;
> +	pdata.mode = mode;
> +
> +	return usb_serial_register(&pdata);
> +}
> +
> +BAREBOX_CMD_HELP_START(usbserial)
> +BAREBOX_CMD_HELP_USAGE("usbserial [OPTIONS] <description>\n")
> +BAREBOX_CMD_HELP_SHORT("Enable/disable a serial gadget on the USB device interface.\n")
> +BAREBOX_CMD_HELP_OPT  ("-m <str>",  "Manufacturer string (barebox)\n")
> +BAREBOX_CMD_HELP_OPT  ("-p <str>",  "product string (" CONFIG_BOARDINFO ")\n")
> +BAREBOX_CMD_HELP_OPT  ("-V <id>",   "vendor id\n")
> +BAREBOX_CMD_HELP_OPT  ("-P <id>",   "product id\n")
> +BAREBOX_CMD_HELP_OPT  ("-a",   "CDC ACM (default)\n")
> +/*BAREBOX_CMD_HELP_OPT  ("-o",   "CDC OBEX\n")*/
ditto
> +BAREBOX_CMD_HELP_OPT  ("-s",   "Generic Serial\n")
> +BAREBOX_CMD_HELP_OPT  ("-d",   "Disable the serial gadget\n")
> +BAREBOX_CMD_HELP_END
> +
> +/**
> + * @page usbserial_command
> + */
> +
> +BAREBOX_CMD_START(usbserial)
> +	.cmd		= do_usbserial,
> +	.usage		= "Serial gadget enable/disable",
> +	BAREBOX_CMD_HELP(cmd_usbserial_help)
> +BAREBOX_CMD_END
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index fd471c0..797d19f 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -30,8 +30,7 @@ config USB_GADGET_DRIVER_PXA27X
>  	select POLLER
>  endchoice
>  
> -choice
> -	prompt "USB Gadget drivers"
> +comment "USB Gadget drivers"
>  
>  config USB_GADGET_DFU
>  	bool
> @@ -42,7 +41,5 @@ config USB_GADGET_SERIAL
>  	depends on EXPERIMENTAL
>  	prompt "Serial Gadget"
>  
> -endchoice
> -
>  endif
Best Regards,
J.



More information about the barebox mailing list