terminal.c 1.4 KB

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