Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Harald Welte | d16471e | 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 | d16471e | 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 | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 12 | #include <stdio_dev.h> |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 13 | #include <serial.h> |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 14 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[]) |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 16 | { |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 17 | int last_tilde = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 18 | struct stdio_dev *dev = NULL; |
Harald Welte | d16471e | 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 | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 24 | dev = stdio_get_by_name(argv[1]); |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 25 | if (!dev) |
| 26 | return -1; |
| 27 | |
Asherah Connor | ac38214 | 2021-03-10 22:39:24 +1100 | [diff] [blame] | 28 | if (IS_ENABLED(CONFIG_SERIAL)) |
| 29 | serial_reinit_all(); |
| 30 | |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 31 | printf("Entering terminal mode for port %s\n", dev->name); |
| 32 | puts("Use '~.' to leave the terminal and get back to u-boot\n"); |
| 33 | |
| 34 | while (1) { |
| 35 | int c; |
| 36 | |
| 37 | /* read from console and display on serial port */ |
Asherah Connor | 5c935eb | 2021-03-10 22:39:23 +1100 | [diff] [blame] | 38 | if (stdio_devices[0]->tstc(stdio_devices[0])) { |
| 39 | c = stdio_devices[0]->getc(stdio_devices[0]); |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 40 | if (last_tilde == 1) { |
| 41 | if (c == '.') { |
| 42 | putc(c); |
| 43 | putc('\n'); |
| 44 | break; |
| 45 | } else { |
| 46 | last_tilde = 0; |
| 47 | /* write the delayed tilde */ |
Asherah Connor | 5c935eb | 2021-03-10 22:39:23 +1100 | [diff] [blame] | 48 | dev->putc(dev, '~'); |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 49 | /* fall-through to print current |
| 50 | * character */ |
| 51 | } |
| 52 | } |
| 53 | if (c == '~') { |
| 54 | last_tilde = 1; |
| 55 | puts("[u-boot]"); |
| 56 | putc(c); |
| 57 | } |
Asherah Connor | 5c935eb | 2021-03-10 22:39:23 +1100 | [diff] [blame] | 58 | dev->putc(dev, c); |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* read from serial port and display on console */ |
Asherah Connor | 5c935eb | 2021-03-10 22:39:23 +1100 | [diff] [blame] | 62 | if (dev->tstc(dev)) { |
| 63 | c = dev->getc(dev); |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 64 | putc(c); |
| 65 | } |
| 66 | } |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /***************************************************/ |
| 72 | |
| 73 | U_BOOT_CMD( |
| 74 | terminal, 3, 1, do_terminal, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 75 | "start terminal emulator", |
Harald Welte | d16471e | 2007-12-19 14:14:47 +0100 | [diff] [blame] | 76 | "" |
| 77 | ); |