deadbat-alternate.patch
[u-boot-openmoko/mini2440.git] / common / cmd_terminal.c
blob762c3ea7296121714d92ae45d58a014634d907f4
1 /*
2 * (C) Copyright 2007 OpenMoko, Inc.
3 * Written by Harald Welte <laforge@openmoko.org>
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
25 * Boot support
27 #include <common.h>
28 #include <command.h>
29 #include <devices.h>
31 #if defined(CONFIG_CMD_TERMINAL)
33 int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
35 int i, l;
36 int last_tilde = 0;
37 device_t *dev = NULL;
39 if (argc < 1)
40 return -1;
42 /* Scan for selected output/input device */
43 for (i = 1; i <= ListNumItems (devlist); i++) {
44 device_t *tmp = ListGetPtrToItem (devlist, i);
45 if (!strcmp(tmp->name, argv[1])) {
46 dev = tmp;
47 break;
50 if (!dev)
51 return -1;
53 #if defined(CONFIG_ARCH_GTA01_v3) || defined(CONFIG_ARCH_GTA01_v4) || \
54 defined(CONFIG_ARCH_GTA01B_v2) || defined(CONFIG_ARCH_GTA01B_v3) || \
55 defined(CONFIG_ARCH_GTA01B_v4)
56 if (!strcmp(dev->name, "serial") ||
57 !strcmp(dev->name, "s3ser0"))
58 neo1973_gta01_serial0_gsm(1);
59 #endif
61 //serial_reinit_all();
62 printf("Entering terminal mode for port %s\n", dev->name);
63 puts("Use '~.' to leave the terminal and get back to u-boot\n");
65 while (1) {
66 int c;
68 /* read from console and display on serial port */
69 if (stdio_devices[0]->tstc()) {
70 c = stdio_devices[0]->getc();
71 if (last_tilde == 1) {
72 if (c == '.') {
73 putc(c);
74 putc('\n');
75 break;
76 } else {
77 last_tilde = 0;
78 /* write the delayed tilde */
79 dev->putc('~');
80 /* fall-through to print current
81 * character */
84 if (c == '~') {
85 last_tilde = 1;
86 puts("[u-boot]");
87 putc(c);
89 dev->putc(c);
92 /* read from serial port and display on console */
93 if (dev->tstc()) {
94 c = dev->getc();
95 putc(c);
98 #if defined(CONFIG_ARCH_GTA01_v3) || defined(CONFIG_ARCH_GTA01_v4) || \
99 defined(CONFIG_ARCH_GTA01B_v2) || defined(CONFIG_ARCH_GTA01B_v3) || \
100 defined(CONFIG_ARCH_GTA01B_v4)
101 if (!strcmp(dev->name, "serial") ||
102 !strcmp(dev->name, "s3ser0"))
103 neo1973_gta01_serial0_gsm(0);
104 #endif
106 return 0;
110 /***************************************************/
112 U_BOOT_CMD(
113 terminal, 3, 1, do_terminal,
114 "terminal - start terminal emulator\n",
118 #endif /* CONFIG_CMD_TERMINAL */