blob: d803bc6c896d460d027a35d05ee24cae2252a232 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Harald Weltea311ef32007-12-19 14:14:47 +01002/*
3 * (C) Copyright 2007 OpenMoko, Inc.
4 * Written by Harald Welte <laforge@openmoko.org>
Harald Weltea311ef32007-12-19 14:14:47 +01005 */
6
7/*
8 * Boot support
9 */
Harald Weltea311ef32007-12-19 14:14:47 +010010#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020011#include <stdio_dev.h>
Jean-Christophe PLAGNIOL-VILLARD8a4a7842008-08-31 04:24:55 +020012#include <serial.h>
Harald Weltea311ef32007-12-19 14:14:47 +010013
Simon Glassed38aef2020-05-10 11:40:03 -060014int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[])
Harald Weltea311ef32007-12-19 14:14:47 +010015{
Harald Weltea311ef32007-12-19 14:14:47 +010016 int last_tilde = 0;
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020017 struct stdio_dev *dev = NULL;
Harald Weltea311ef32007-12-19 14:14:47 +010018
19 if (argc < 1)
20 return -1;
21
22 /* Scan for selected output/input device */
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020023 dev = stdio_get_by_name(argv[1]);
Harald Weltea311ef32007-12-19 14:14:47 +010024 if (!dev)
25 return -1;
26
Asherah Connor311880f2021-03-10 22:39:24 +110027 if (IS_ENABLED(CONFIG_SERIAL))
28 serial_reinit_all();
29
Harald Weltea311ef32007-12-19 14:14:47 +010030 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 /* read from console and display on serial port */
Asherah Connor10ec1312021-03-10 22:39:23 +110037 if (stdio_devices[0]->tstc(stdio_devices[0])) {
38 c = stdio_devices[0]->getc(stdio_devices[0]);
Harald Weltea311ef32007-12-19 14:14:47 +010039 if (last_tilde == 1) {
40 if (c == '.') {
41 putc(c);
42 putc('\n');
43 break;
44 } else {
45 last_tilde = 0;
46 /* write the delayed tilde */
Asherah Connor10ec1312021-03-10 22:39:23 +110047 dev->putc(dev, '~');
Harald Weltea311ef32007-12-19 14:14:47 +010048 /* fall-through to print current
49 * character */
50 }
51 }
52 if (c == '~') {
53 last_tilde = 1;
54 puts("[u-boot]");
55 putc(c);
56 }
Asherah Connor10ec1312021-03-10 22:39:23 +110057 dev->putc(dev, c);
Harald Weltea311ef32007-12-19 14:14:47 +010058 }
59
60 /* read from serial port and display on console */
Asherah Connor10ec1312021-03-10 22:39:23 +110061 if (dev->tstc(dev)) {
62 c = dev->getc(dev);
Harald Weltea311ef32007-12-19 14:14:47 +010063 putc(c);
64 }
65 }
66 return 0;
67}
68
Harald Weltea311ef32007-12-19 14:14:47 +010069/***************************************************/
70
71U_BOOT_CMD(
72 terminal, 3, 1, do_terminal,
Peter Tyserdfb72b82009-01-27 18:03:12 -060073 "start terminal emulator",
Harald Weltea311ef32007-12-19 14:14:47 +010074 ""
75);