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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Boot support |
| 10 | */ |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 13 | #include <stdio_dev.h> |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 14 | #include <serial.h> |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 15 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 16 | 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] | 17 | { |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 18 | int last_tilde = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 19 | struct stdio_dev *dev = NULL; |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 20 | |
| 21 | if (argc < 1) |
| 22 | return -1; |
| 23 | |
| 24 | /* Scan for selected output/input device */ |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 25 | dev = stdio_get_by_name(argv[1]); |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 26 | if (!dev) |
| 27 | return -1; |
| 28 | |
| 29 | serial_reinit_all(); |
| 30 | printf("Entering terminal mode for port %s\n", dev->name); |
| 31 | puts("Use '~.' to leave the terminal and get back to u-boot\n"); |
| 32 | |
| 33 | while (1) { |
| 34 | int c; |
| 35 | |
| 36 | /* read from console and display on serial port */ |
| 37 | if (stdio_devices[0]->tstc()) { |
| 38 | c = stdio_devices[0]->getc(); |
| 39 | if (last_tilde == 1) { |
| 40 | if (c == '.') { |
| 41 | putc(c); |
| 42 | putc('\n'); |
| 43 | break; |
| 44 | } else { |
| 45 | last_tilde = 0; |
| 46 | /* write the delayed tilde */ |
| 47 | dev->putc('~'); |
| 48 | /* fall-through to print current |
| 49 | * character */ |
| 50 | } |
| 51 | } |
| 52 | if (c == '~') { |
| 53 | last_tilde = 1; |
| 54 | puts("[u-boot]"); |
| 55 | putc(c); |
| 56 | } |
| 57 | dev->putc(c); |
| 58 | } |
| 59 | |
| 60 | /* read from serial port and display on console */ |
| 61 | if (dev->tstc()) { |
| 62 | c = dev->getc(); |
| 63 | putc(c); |
| 64 | } |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /***************************************************/ |
| 71 | |
| 72 | U_BOOT_CMD( |
| 73 | terminal, 3, 1, do_terminal, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 74 | "start terminal emulator", |
Harald Welte | a311ef3 | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 75 | "" |
| 76 | ); |