cmd_terminal.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <devices.h>
  29. #if defined(CONFIG_CMD_TERMINAL)
  30. int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
  31. {
  32. int i, l;
  33. int last_tilde = 0;
  34. device_t *dev = NULL;
  35. if (argc < 1)
  36. return -1;
  37. /* Scan for selected output/input device */
  38. for (i = 1; i <= ListNumItems (devlist); i++) {
  39. device_t *tmp = ListGetPtrToItem (devlist, i);
  40. if (!strcmp(tmp->name, argv[1])) {
  41. dev = tmp;
  42. break;
  43. }
  44. }
  45. if (!dev)
  46. return -1;
  47. serial_reinit_all();
  48. printf("Entering terminal mode for port %s\n", dev->name);
  49. puts("Use '~.' to leave the terminal and get back to u-boot\n");
  50. while (1) {
  51. int c;
  52. /* read from console and display on serial port */
  53. if (stdio_devices[0]->tstc()) {
  54. c = stdio_devices[0]->getc();
  55. if (last_tilde == 1) {
  56. if (c == '.') {
  57. putc(c);
  58. putc('\n');
  59. break;
  60. } else {
  61. last_tilde = 0;
  62. /* write the delayed tilde */
  63. dev->putc('~');
  64. /* fall-through to print current
  65. * character */
  66. }
  67. }
  68. if (c == '~') {
  69. last_tilde = 1;
  70. puts("[u-boot]");
  71. putc(c);
  72. }
  73. dev->putc(c);
  74. }
  75. /* read from serial port and display on console */
  76. if (dev->tstc()) {
  77. c = dev->getc();
  78. putc(c);
  79. }
  80. }
  81. return 0;
  82. }
  83. /***************************************************/
  84. U_BOOT_CMD(
  85. terminal, 3, 1, do_terminal,
  86. "terminal - start terminal emulator\n",
  87. ""
  88. );
  89. #endif /* CONFIG_CMD_TERMINAL */