"Das U-Boot" Source Tree
at master 75 lines 1.5 kB view raw
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * (C) Copyright 2007 OpenMoko, Inc. 4 * Written by Harald Welte <laforge@openmoko.org> 5 */ 6 7/* 8 * Boot support 9 */ 10#include <command.h> 11#include <stdio_dev.h> 12#include <serial.h> 13 14int do_terminal(struct cmd_tbl *cmd, int flag, int argc, char *const argv[]) 15{ 16 int last_tilde = 0; 17 struct stdio_dev *dev = NULL; 18 19 if (argc < 1) 20 return -1; 21 22 /* Scan for selected output/input device */ 23 dev = stdio_get_by_name(argv[1]); 24 if (!dev) 25 return -1; 26 27 if (IS_ENABLED(CONFIG_SERIAL)) 28 serial_reinit_all(); 29 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 /* read from console and display on serial port */ 37 if (stdio_devices[0]->tstc(stdio_devices[0])) { 38 c = stdio_devices[0]->getc(stdio_devices[0]); 39 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 */ 47 dev->putc(dev, '~'); 48 /* fall-through to print current 49 * character */ 50 } 51 } 52 if (c == '~') { 53 last_tilde = 1; 54 puts("[u-boot]"); 55 putc(c); 56 } 57 dev->putc(dev, c); 58 } 59 60 /* read from serial port and display on console */ 61 if (dev->tstc(dev)) { 62 c = dev->getc(dev); 63 putc(c); 64 } 65 } 66 return 0; 67} 68 69/***************************************************/ 70 71U_BOOT_CMD( 72 terminal, 3, 1, do_terminal, 73 "start terminal emulator", 74 "" 75);