All of lore.kernel.org
 help / color / mirror / Atom feed
From: Loic Poulain <loic.poulain@linaro.org>
To: marex@denx.de
Cc: u-boot@lists.denx.de, lukma@denx.de,
	Loic Poulain <loic.poulain@linaro.org>
Subject: [PATCH 3/3] cmd: add acmconsole command
Date: Thu, 19 Aug 2021 13:13:06 +0200	[thread overview]
Message-ID: <1629371586-9349-3-git-send-email-loic.poulain@linaro.org> (raw)
In-Reply-To: <1629371586-9349-1-git-send-email-loic.poulain@linaro.org>

This command allows to start CDC ACM function and redirect console
(stdin, stdout, stderr) to USB (acmconsole start). The console can
then be accessed through the USB host for debugging purpose. The
host can stop the session (acmconsole stop) to revert back console
to serial and unregister CDC ACM USB function.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
---
 cmd/Kconfig      |  8 ++++++++
 cmd/Makefile     |  2 ++
 cmd/acmconsole.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 cmd/acmconsole.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index ffef3cc..7cc9b1c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1382,6 +1382,14 @@ config CMD_AXI
 	  Interface) busses, a on-chip interconnect specification for managing
 	  functional blocks in SoC designs, which is also often used in designs
 	  involving FPGAs (e.g.  communication with IP cores in Xilinx FPGAs).
+
+config CMD_USB_ACM_CONSOLE
+	bool "ACM USB console"
+	select USB_FUNCTION_ACM
+	help
+	  Enable the command "acmconsole" for accessing u-boot console from a
+	  USB host through CDC ACM protocol.
+
 endmenu
 
 
diff --git a/cmd/Makefile b/cmd/Makefile
index ed36694..c116091 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_CMD_BOOTMENU) += bootmenu.o
 obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o
 obj-$(CONFIG_CMD_BOOTZ) += bootz.o
 obj-$(CONFIG_CMD_BOOTI) += booti.o
+ob-y += acmconsole.o
 obj-$(CONFIG_CMD_BTRFS) += btrfs.o
 obj-$(CONFIG_CMD_BUTTON) += button.o
 obj-$(CONFIG_CMD_CACHE) += cache.o
@@ -174,6 +175,7 @@ obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o
 obj-$(CONFIG_CMD_USB_MASS_STORAGE) += usb_mass_storage.o
 obj-$(CONFIG_CMD_USB_SDP) += usb_gadget_sdp.o
 obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o
+obj-$(CONFIG_CMD_USB_ACM_CONSOLE) += acmconsole.o
 obj-$(CONFIG_CMD_XIMG) += ximg.o
 obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o
 obj-$(CONFIG_CMD_SPL) += spl.o
diff --git a/cmd/acmconsole.c b/cmd/acmconsole.c
new file mode 100644
index 0000000..dac8136
--- /dev/null
+++ b/cmd/acmconsole.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * acmconsole.c -- Console over USB CDC serial (ACM) function gadget function
+ *
+ * Copyright (c) 2021, Linaro Ltd <loic.poulain@linaro.org>
+ */
+
+#include <common.h>
+#include <console.h>
+#include <dfu.h>
+#include <g_dnl.h>
+#include <stdio_dev.h>
+#include <usb.h>
+#include <watchdog.h>
+
+int do_usb_acmconsole(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	int ret;
+
+	if (argc != 2)
+		return CMD_RET_USAGE;
+
+	if (!strcmp(argv[1], "start")) {
+		ret = g_dnl_register("usb_serial_acm");
+		if (ret)
+			return ret;
+
+		/* ACM function creates a stdio device name 'stdio_acm' */
+		console_assign(stdin, "stdio_acm");
+		console_assign(stdout, "stdio_acm");
+		console_assign(stderr, "stdio_acm");
+	} else if (!strcmp(argv[1], "stop")) {
+		/* default to serial (TODO: restore initial devices) */
+		console_assign(stdin, "serial");
+		console_assign(stdout, "serial");
+		console_assign(stderr, "serial");
+
+		g_dnl_unregister();
+		g_dnl_clear_detach();
+	} else {
+		return CMD_RET_USAGE;
+	}
+
+	return 0;
+}
+
+U_BOOT_CMD(acmconsole, CONFIG_SYS_MAXARGS, 1, do_usb_acmconsole,
+	   "Console over USB CDC ACM",
+	   "start - start console over USB CDC ACM gadget function\n" \
+	   "acmconsole stop - stop USB console");
-- 
2.7.4


  parent reply	other threads:[~2021-08-19 11:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 11:13 [PATCH 1/3] lib/circbuf: Make circbuf selectable symbol Loic Poulain
2021-08-19 11:13 ` [PATCH 2/3] usb: gadget: Add CDC ACM function Loic Poulain
2021-09-07 10:21   ` Loic Poulain
2021-09-27 19:55   ` Pali Rohár
2021-08-19 11:13 ` Loic Poulain [this message]
2021-09-27 20:04   ` [PATCH 3/3] cmd: add acmconsole command Pali Rohár
2021-11-16 19:05     ` Loic Poulain
2021-11-16 19:36       ` Pali Rohár
2021-11-22 10:33         ` Loic Poulain
2021-11-22 11:54           ` Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1629371586-9349-3-git-send-email-loic.poulain@linaro.org \
    --to=loic.poulain@linaro.org \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.