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