terminal.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if (IS_ENABLED(CONFIG_SERIAL))
  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(stdio_devices[0])) {
  31. c = stdio_devices[0]->getc(stdio_devices[0]);
  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(dev, '~');
  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(dev, c);
  51. }
  52. /* read from serial port and display on console */
  53. if (dev->tstc(dev)) {
  54. c = dev->getc(dev);
  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. );