]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
d16471ee HW |
2 | /* |
3 | * (C) Copyright 2007 OpenMoko, Inc. | |
4 | * Written by Harald Welte <[email protected]> | |
d16471ee HW |
5 | */ |
6 | ||
7 | /* | |
8 | * Boot support | |
9 | */ | |
10 | #include <common.h> | |
11 | #include <command.h> | |
52cb4d4f | 12 | #include <stdio_dev.h> |
c1de7a6d | 13 | #include <serial.h> |
d16471ee | 14 | |
09140113 | 15 | int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[]) |
d16471ee | 16 | { |
d16471ee | 17 | int last_tilde = 0; |
52cb4d4f | 18 | struct stdio_dev *dev = NULL; |
d16471ee HW |
19 | |
20 | if (argc < 1) | |
21 | return -1; | |
22 | ||
23 | /* Scan for selected output/input device */ | |
52cb4d4f | 24 | dev = stdio_get_by_name(argv[1]); |
d16471ee HW |
25 | if (!dev) |
26 | return -1; | |
27 | ||
ac382143 AC |
28 | if (IS_ENABLED(CONFIG_SERIAL)) |
29 | serial_reinit_all(); | |
30 | ||
d16471ee HW |
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 */ | |
5c935eb6 AC |
38 | if (stdio_devices[0]->tstc(stdio_devices[0])) { |
39 | c = stdio_devices[0]->getc(stdio_devices[0]); | |
d16471ee HW |
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 */ | |
5c935eb6 | 48 | dev->putc(dev, '~'); |
d16471ee HW |
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 | } | |
5c935eb6 | 58 | dev->putc(dev, c); |
d16471ee HW |
59 | } |
60 | ||
61 | /* read from serial port and display on console */ | |
5c935eb6 AC |
62 | if (dev->tstc(dev)) { |
63 | c = dev->getc(dev); | |
d16471ee HW |
64 | putc(c); |
65 | } | |
66 | } | |
67 | return 0; | |
68 | } | |
69 | ||
70 | ||
71 | /***************************************************/ | |
72 | ||
73 | U_BOOT_CMD( | |
74 | terminal, 3, 1, do_terminal, | |
2fb2604d | 75 | "start terminal emulator", |
d16471ee HW |
76 | "" |
77 | ); |