1
2
3
4
5
6
7
8
9
10#include <common.h>
11#include <command.h>
12#include <stdio_dev.h>
13#include <serial.h>
14
15int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[])
16{
17 int last_tilde = 0;
18 struct stdio_dev *dev = NULL;
19
20 if (argc < 1)
21 return -1;
22
23
24 dev = stdio_get_by_name(argv[1]);
25 if (!dev)
26 return -1;
27
28 if (IS_ENABLED(CONFIG_SERIAL))
29 serial_reinit_all();
30
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
38 if (stdio_devices[0]->tstc(stdio_devices[0])) {
39 c = stdio_devices[0]->getc(stdio_devices[0]);
40 if (last_tilde == 1) {
41 if (c == '.') {
42 putc(c);
43 putc('\n');
44 break;
45 } else {
46 last_tilde = 0;
47
48 dev->putc(dev, '~');
49
50
51 }
52 }
53 if (c == '~') {
54 last_tilde = 1;
55 puts("[u-boot]");
56 putc(c);
57 }
58 dev->putc(dev, c);
59 }
60
61
62 if (dev->tstc(dev)) {
63 c = dev->getc(dev);
64 putc(c);
65 }
66 }
67 return 0;
68}
69
70
71
72
73U_BOOT_CMD(
74 terminal, 3, 1, do_terminal,
75 "start terminal emulator",
76 ""
77);
78