terminal.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007 OpenMoko, Inc.
  4. * Written by Harald Welte <laforge@openmoko.org>
  5. */
  6. /*
  7. * Boot support
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <stdio_dev.h>
  12. #include <serial.h>
  13. int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[])
  14. {
  15. int last_tilde = 0;
  16. struct stdio_dev *dev = NULL;
  17. if (argc < 1)
  18. return -1;
  19. /* Scan for selected output/input device */
  20. dev = stdio_get_by_name(argv[1]);
  21. if (!dev)
  22. return -1;
  23. serial_reinit_all();
  24. printf("Entering terminal mode for port %s\n", dev->name);
  25. puts("Use '~.' to leave the terminal and get back to u-boot\n");
  26. while (1) {
  27. int c;
  28. /* read from console and display on serial port */
  29. if (stdio_devices[0]->tstc()) {
  30. c = stdio_devices[0]->getc();
  31. if (last_tilde == 1) {
  32. if (c == '.') {
  33. putc(c);
  34. putc('\n');
  35. break;
  36. } else {
  37. last_tilde = 0;
  38. /* write the delayed tilde */
  39. dev->putc('~');
  40. /* fall-through to print current
  41. * character */
  42. }
  43. }
  44. if (c == '~') {
  45. last_tilde = 1;
  46. puts("[u-boot]");
  47. putc(c);
  48. }
  49. dev->putc(c);
  50. }
  51. /* read from serial port and display on console */
  52. if (dev->tstc()) {
  53. c = dev->getc();
  54. putc(c);
  55. }
  56. }
  57. return 0;
  58. }
  59. /***************************************************/
  60. U_BOOT_CMD(
  61. terminal, 3, 1, do_terminal,
  62. "start terminal emulator",
  63. ""
  64. );