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