cmd: add conitrace command
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 7 Sep 2018 17:43:11 +0000 (19:43 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 26 Sep 2018 01:49:18 +0000 (21:49 -0400)
The 'conitrace' command prints the codes received from the console input as
hexadecimal numbers.

This developer utility is useful for testing the handling of special keys
by keyboard drivers.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
cmd/Kconfig
cmd/Makefile
cmd/conitrace.c [new file with mode: 0644]

index 13d4c991bf8bf7fc82b601ebc81f23a9dbcee1b6..cf97a0f2be31f5ffb7d1d59c1d52d2127c44bb37 100644 (file)
@@ -1338,6 +1338,12 @@ config CMD_CACHE
        help
          Enable the "icache" and "dcache" commands
 
+config CMD_CONITRACE
+       bool "conitrace - trace console input codes"
+       help
+         Enable the 'conitrace' command which displays the codes received
+         from the console input as hexadecimal numbers.
+
 config CMD_DISPLAY
        bool "Enable the 'display' command, for character displays"
        help
index a61fab6583df4f4a5e0658d46eb6a00df74e42be..d3815abf26736665f55849b59ad9ea9425b05480 100644 (file)
@@ -34,6 +34,7 @@ obj-$(CONFIG_CMD_CACHE) += cache.o
 obj-$(CONFIG_CMD_CBFS) += cbfs.o
 obj-$(CONFIG_CMD_CLK) += clk.o
 obj-$(CONFIG_CMD_CONFIG) += config.o
+obj-$(CONFIG_CMD_CONITRACE) += conitrace.o
 obj-$(CONFIG_CMD_CONSOLE) += console.o
 obj-$(CONFIG_CMD_CPU) += cpu.o
 obj-$(CONFIG_DATAFLASH_MMC_SELECT) += dataflash_mmc_mux.o
diff --git a/cmd/conitrace.c b/cmd/conitrace.c
new file mode 100644 (file)
index 0000000..85c5422
--- /dev/null
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * The 'conitrace' command prints the codes received from the console input as
+ * hexadecimal numbers.
+ *
+ * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ */
+#include <common.h>
+#include <command.h>
+
+static int do_conitrace(cmd_tbl_t *cmdtp, int flag, int argc,
+                       char * const argv[])
+{
+       bool first = true;
+
+       printf("Waiting for your input\n");
+       printf("To terminate type 'x'\n");
+
+       /* Empty input buffer */
+       while (tstc())
+               getc();
+
+       for (;;) {
+               int c = getc();
+
+               if (first && (c == 'x' || c == 'X'))
+                       break;
+
+               printf("%02x ", c);
+               first = false;
+
+               /* 1 ms delay - serves to detect separate keystrokes */
+               udelay(1000);
+               if (!tstc()) {
+                       printf("\n");
+                       first = true;
+               }
+       }
+
+       return CMD_RET_SUCCESS;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char conitrace_help_text[] = "";
+#endif
+
+U_BOOT_CMD_COMPLETE(
+       conitrace, 2, 0, do_conitrace,
+       "trace console input",
+       conitrace_help_text, NULL
+);