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