conitrace.c 956 B

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