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> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 29 | #include <stdio_dev.h> |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 30 | #include <serial.h> |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 31 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 32 | int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char * const argv[]) |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 33 | { |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 34 | int last_tilde = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 35 | struct stdio_dev *dev = NULL; |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 36 | |
| 37 | if (argc < 1) |
| 38 | return -1; |
| 39 | |
| 40 | /* Scan for selected output/input device */ |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 41 | dev = stdio_get_by_name(argv[1]); |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 42 | if (!dev) |
| 43 | return -1; |
| 44 | |
| 45 | serial_reinit_all(); |
| 46 | printf("Entering terminal mode for port %s\n", dev->name); |
| 47 | puts("Use '~.' to leave the terminal and get back to u-boot\n"); |
| 48 | |
| 49 | while (1) { |
| 50 | int c; |
| 51 | |
| 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 | |
| 76 | /* read from serial port and display on console */ |
| 77 | if (dev->tstc()) { |
| 78 | c = dev->getc(); |
| 79 | putc(c); |
| 80 | } |
| 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /***************************************************/ |
| 87 | |
| 88 | U_BOOT_CMD( |
| 89 | terminal, 3, 1, do_terminal, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 90 | "start terminal emulator", |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 91 | "" |
| 92 | ); |