Fixed tools/env utilities
[u-boot-openmoko/mini2440.git] / common / cmd_terminal.c
blob882cefa59219e44c2d1c789c7a6beb0fbba213d9
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>
30 #include <serial.h>
32 #if defined(CONFIG_CMD_TERMINAL)
34 static void init_serial_by_name(char *name)
36 struct serial_device *ser;
37 for (ser = serial_devices; ser; ser = ser->next) {
38 if (!strcmp(ser->name, name)) {
39 ser->init();
40 return;
45 int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[])
47 int i, l;
48 int last_tilde = 0;
49 device_t *dev = NULL;
51 if (argc < 1)
52 return -1;
54 /* Scan for selected output/input device */
55 for (i = 1; i <= ListNumItems (devlist); i++) {
56 device_t *tmp = ListGetPtrToItem (devlist, i);
57 if (!strcmp(tmp->name, argv[1])) {
58 dev = tmp;
59 break;
62 if (!dev)
63 return -1;
65 #if defined(CONFIG_ARCH_GTA01_v3) || defined(CONFIG_ARCH_GTA01_v4) || \
66 defined(CONFIG_ARCH_GTA01B_v2) || defined(CONFIG_ARCH_GTA01B_v3) || \
67 defined(CONFIG_ARCH_GTA01B_v4)
68 if (!strcmp(dev->name, "serial") ||
69 !strcmp(dev->name, "s3ser0"))
70 neo1973_gta01_serial0_gsm(1);
71 #endif
73 init_serial_by_name(dev->name);
74 //serial_reinit_all();
75 printf("Entering terminal mode for port %s\n", dev->name);
76 puts("Use '~.' to leave the terminal and get back to u-boot\n");
78 while (1) {
79 int c;
81 /* read from console and display on serial port */
82 if (stdio_devices[0]->tstc()) {
83 c = stdio_devices[0]->getc();
84 if (last_tilde == 1) {
85 if (c == '.') {
86 putc(c);
87 putc('\n');
88 break;
89 } else {
90 last_tilde = 0;
91 /* write the delayed tilde */
92 dev->putc('~');
93 /* fall-through to print current
94 * character */
97 if (c == '~') {
98 last_tilde = 1;
99 puts("[u-boot]");
100 putc(c);
102 dev->putc(c);
105 /* read from serial port and display on console */
106 if (dev->tstc()) {
107 c = dev->getc();
108 putc(c);
111 #if defined(CONFIG_ARCH_GTA01_v3) || defined(CONFIG_ARCH_GTA01_v4) || \
112 defined(CONFIG_ARCH_GTA01B_v2) || defined(CONFIG_ARCH_GTA01B_v3) || \
113 defined(CONFIG_ARCH_GTA01B_v4)
114 if (!strcmp(dev->name, "serial") ||
115 !strcmp(dev->name, "s3ser0"))
116 neo1973_gta01_serial0_gsm(0);
117 #endif
119 return 0;
123 /***************************************************/
125 U_BOOT_CMD(
126 terminal, 3, 1, do_terminal,
127 "terminal - start terminal emulator\n",
131 #endif /* CONFIG_CMD_TERMINAL */