blob: 9a1bc35184852e1a7c89e587d62ba722531432fa [file] [log] [blame]
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * The 'conitrace' command prints the codes received from the console input as
4 * hexadecimal numbers.
5 *
6 * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
7 */
8#include <common.h>
9#include <command.h>
Simon Glassc05ed002020-05-10 11:40:11 -060010#include <linux/delay.h>
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020011
Simon Glass09140112020-05-10 11:40:03 -060012static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020014{
15 bool first = true;
16
17 printf("Waiting for your input\n");
18 printf("To terminate type 'x'\n");
19
20 /* Empty input buffer */
21 while (tstc())
Heinrich Schuchardt2fb3ed22020-10-23 12:46:04 +020022 getchar();
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020023
24 for (;;) {
Heinrich Schuchardt2fb3ed22020-10-23 12:46:04 +020025 int c = getchar();
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020026
27 if (first && (c == 'x' || c == 'X'))
28 break;
29
30 printf("%02x ", c);
31 first = false;
32
Heinrich Schuchardt48618e92020-12-27 00:12:28 +010033 /* 10 ms delay - serves to detect separate keystrokes */
34 udelay(10000);
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020035 if (!tstc()) {
36 printf("\n");
37 first = true;
38 }
39 }
40
41 return CMD_RET_SUCCESS;
42}
43
Tom Rini36162182023-10-07 15:13:08 -040044U_BOOT_LONGHELP(conitrace, "");
Heinrich Schuchardt29cfc092018-09-07 19:43:11 +020045
46U_BOOT_CMD_COMPLETE(
47 conitrace, 2, 0, do_conitrace,
48 "trace console input",
49 conitrace_help_text, NULL
50);