[PATCH 3/3] cmd: add acmconsole command

Loic Poulain loic.poulain at linaro.org
Thu Aug 19 13:13:06 CEST 2021


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 at 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 at 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



More information about the U-Boot mailing list