cmd_terminal.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * (C) Copyright 2007 OpenMoko, Inc.
  3. * Written by Harald Welte <laforge@openmoko.org>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Boot support
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <stdio_dev.h>
  29. #include <serial.h>
  30. int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
  31. {
  32. int last_tilde = 0;
  33. struct stdio_dev *dev = NULL;
  34. if (argc < 1)
  35. return -1;
  36. /* Scan for selected output/input device */
  37. dev = stdio_get_by_name(argv[1]);
  38. if (!dev)
  39. return -1;
  40. serial_reinit_all();
  41. printf("Entering terminal mode for port %s\n", dev->name);
  42. puts("Use '~.' to leave the terminal and get back to u-boot\n");
  43. while (1) {
  44. int c;
  45. /* read from console and display on serial port */
  46. if (stdio_devices[0]->tstc()) {
  47. c = stdio_devices[0]->getc();
  48. if (last_tilde == 1) {
  49. if (c == '.') {
  50. putc(c);
  51. putc('\n');
  52. break;
  53. } else {
  54. last_tilde = 0;
  55. /* write the delayed tilde */
  56. dev->putc('~');
  57. /* fall-through to print current
  58. * character */
  59. }
  60. }
  61. if (c == '~') {
  62. last_tilde = 1;
  63. puts("[u-boot]");
  64. putc(c);
  65. }
  66. dev->putc(c);
  67. }
  68. /* read from serial port and display on console */
  69. if (dev->tstc()) {
  70. c = dev->getc();
  71. putc(c);
  72. }
  73. }
  74. return 0;
  75. }
  76. /***************************************************/
  77. U_BOOT_CMD(
  78. terminal, 3, 1, do_terminal,
  79. "start terminal emulator",
  80. ""
  81. );