conitrace.c 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // 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>
  10. #include <linux/delay.h>
  11. static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc,
  12. char *const argv[])
  13. {
  14. bool first = true;
  15. printf("Waiting for your input\n");
  16. printf("To terminate type 'x'\n");
  17. /* Empty input buffer */
  18. while (tstc())
  19. getchar();
  20. for (;;) {
  21. int c = getchar();
  22. if (first && (c == 'x' || c == 'X'))
  23. break;
  24. printf("%02x ", c);
  25. first = false;
  26. /* 10 ms delay - serves to detect separate keystrokes */
  27. udelay(10000);
  28. if (!tstc()) {
  29. printf("\n");
  30. first = true;
  31. }
  32. }
  33. return CMD_RET_SUCCESS;
  34. }
  35. #ifdef CONFIG_SYS_LONGHELP
  36. static char conitrace_help_text[] = "";
  37. #endif
  38. U_BOOT_CMD_COMPLETE(
  39. conitrace, 2, 0, do_conitrace,
  40. "trace console input",
  41. conitrace_help_text, NULL
  42. );