summaryrefslogtreecommitdiff
path: root/cmd/conitrace.c
blob: d50f3bf3ccbfdb4609a7f37806a77f85ea8dd559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 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>
#include <linux/delay.h>

static int do_conitrace(struct cmd_tbl *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())
		getchar();

	for (;;) {
		int c = getchar();

		if (first && (c == 'x' || c == 'X'))
			break;

		printf("%02x ", c);
		first = false;

		/* 10 ms delay - serves to detect separate keystrokes */
		udelay(10000);
		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
);