cmd_terminal.c 2.2 KB

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