Blame view
common/console.c
19.9 KB
47d1a6e1e
|
1 2 3 4 |
/* * (C) Copyright 2000 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it * |
1a4596601
|
5 |
* SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1e
|
6 7 8 |
*/ #include <common.h> |
24b852a7a
|
9 |
#include <console.h> |
d6ea5307d
|
10 |
#include <debug_uart.h> |
7b3c4c3a5
|
11 |
#include <dm.h> |
47d1a6e1e
|
12 |
#include <stdarg.h> |
482f4691a
|
13 |
#include <iomux.h> |
47d1a6e1e
|
14 |
#include <malloc.h> |
4e6bafa56
|
15 |
#include <mapmem.h> |
91b136c79
|
16 |
#include <os.h> |
849d5d9cd
|
17 |
#include <serial.h> |
52cb4d4fb
|
18 |
#include <stdio_dev.h> |
27b207fd0
|
19 |
#include <exports.h> |
849d5d9cd
|
20 |
#include <environment.h> |
644074671
|
21 |
#include <watchdog.h> |
47d1a6e1e
|
22 |
|
d87080b72
|
23 |
DECLARE_GLOBAL_DATA_PTR; |
849d5d9cd
|
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
static int on_console(const char *name, const char *value, enum env_op op, int flags) { int console = -1; /* Check for console redirection */ if (strcmp(name, "stdin") == 0) console = stdin; else if (strcmp(name, "stdout") == 0) console = stdout; else if (strcmp(name, "stderr") == 0) console = stderr; /* if not actually setting a console variable, we don't care */ if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0) return 0; switch (op) { case env_op_create: case env_op_overwrite: |
b02654294
|
44 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
849d5d9cd
|
45 46 47 48 49 50 |
if (iomux_doenv(console, value)) return 1; #else /* Try assigning specified device */ if (console_assign(console, value) < 0) return 1; |
b02654294
|
51 |
#endif |
849d5d9cd
|
52 53 54 55 56 57 58 59 60 61 62 63 64 |
return 0; case env_op_delete: if ((flags & H_FORCE) == 0) printf("Can't delete \"%s\" ", name); return 1; default: return 0; } } U_BOOT_ENV_CALLBACK(console, on_console); |
e080d545f
|
65 66 67 68 |
#ifdef CONFIG_SILENT_CONSOLE static int on_silent(const char *name, const char *value, enum env_op op, int flags) { |
5daf6e56d
|
69 |
#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET) |
e080d545f
|
70 71 72 |
if (flags & H_INTERACTIVE) return 0; #endif |
5daf6e56d
|
73 |
#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC) |
e080d545f
|
74 75 76 77 78 79 80 81 82 83 84 85 86 |
if ((flags & H_INTERACTIVE) == 0) return 0; #endif if (value != NULL) gd->flags |= GD_FLG_SILENT; else gd->flags &= ~GD_FLG_SILENT; return 0; } U_BOOT_ENV_CALLBACK(silent, on_silent); #endif |
b02654294
|
87 |
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) |
47d1a6e1e
|
88 89 90 91 92 |
/* * if overwrite_console returns 1, the stdin, stderr and stdout * are switched to the serial port, else the settings in the * environment are used */ |
6d0f6bcf3
|
93 |
#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
ec6f14994
|
94 95 |
extern int overwrite_console(void); #define OVERWRITE_CONSOLE overwrite_console() |
47d1a6e1e
|
96 |
#else |
83e40ba75
|
97 |
#define OVERWRITE_CONSOLE 0 |
6d0f6bcf3
|
98 |
#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ |
47d1a6e1e
|
99 |
|
b02654294
|
100 |
#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |
47d1a6e1e
|
101 |
|
52cb4d4fb
|
102 |
static int console_setfile(int file, struct stdio_dev * dev) |
47d1a6e1e
|
103 104 105 106 107 108 109 110 111 112 113 114 |
{ int error = 0; if (dev == NULL) return -1; switch (file) { case stdin: case stdout: case stderr: /* Start new device */ if (dev->start) { |
709ea543b
|
115 |
error = dev->start(dev); |
47d1a6e1e
|
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
/* If it's not started dont use it */ if (error < 0) break; } /* Assign the new device (leaving the existing one started) */ stdio_devices[file] = dev; /* * Update monitor functions * (to use the console stuff by other applications) */ switch (file) { case stdin: |
49cad5478
|
130 131 |
gd->jt->getc = getc; gd->jt->tstc = tstc; |
47d1a6e1e
|
132 133 |
break; case stdout: |
49cad5478
|
134 135 136 |
gd->jt->putc = putc; gd->jt->puts = puts; gd->jt->printf = printf; |
47d1a6e1e
|
137 138 139 140 141 142 143 144 145 |
break; } break; default: /* Invalid file ID */ error = -1; } return error; } |
42f9f915c
|
146 147 148 149 |
/** * console_dev_is_serial() - Check if a stdio device is a serial device * * @sdev: Device to check |
7b3c4c3a5
|
150 151 |
* @return true if this device is in the serial uclass (or for pre-driver-model, * whether it is called "serial". |
42f9f915c
|
152 153 154 155 |
*/ static bool console_dev_is_serial(struct stdio_dev *sdev) { bool is_serial; |
7b3c4c3a5
|
156 157 158 159 160 161 162 |
#ifdef CONFIG_DM_SERIAL if (sdev->flags & DEV_FLAGS_DM) { struct udevice *dev = sdev->priv; is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL; } else #endif |
42f9f915c
|
163 164 165 166 |
is_serial = !strcmp(sdev->name, "serial"); return is_serial; } |
b02654294
|
167 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
168 |
/** Console I/O multiplexing *******************************************/ |
52cb4d4fb
|
169 170 |
static struct stdio_dev *tstcdev; struct stdio_dev **console_devices[MAX_FILES]; |
16a28ef21
|
171 172 173 174 175 176 177 178 |
int cd_count[MAX_FILES]; /* * This depends on tstc() always being called before getc(). * This is guaranteed to be true because this routine is called * only from fgetc() which assures it. * No attempt is made to demultiplex multiple input sources. */ |
5f0320108
|
179 |
static int console_getc(int file) |
16a28ef21
|
180 181 182 183 |
{ unsigned char ret; /* This is never called with testcdev == NULL */ |
709ea543b
|
184 |
ret = tstcdev->getc(tstcdev); |
16a28ef21
|
185 186 187 |
tstcdev = NULL; return ret; } |
5f0320108
|
188 |
static int console_tstc(int file) |
16a28ef21
|
189 190 |
{ int i, ret; |
52cb4d4fb
|
191 |
struct stdio_dev *dev; |
16a28ef21
|
192 193 194 195 196 |
disable_ctrlc(1); for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; if (dev->tstc != NULL) { |
709ea543b
|
197 |
ret = dev->tstc(dev); |
16a28ef21
|
198 199 200 201 202 203 204 205 206 207 208 |
if (ret > 0) { tstcdev = dev; disable_ctrlc(0); return ret; } } } disable_ctrlc(0); return 0; } |
5f0320108
|
209 |
static void console_putc(int file, const char c) |
16a28ef21
|
210 211 |
{ int i; |
52cb4d4fb
|
212 |
struct stdio_dev *dev; |
16a28ef21
|
213 214 215 216 |
for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; if (dev->putc != NULL) |
709ea543b
|
217 |
dev->putc(dev, c); |
16a28ef21
|
218 219 |
} } |
a8552c7c9
|
220 |
static void console_puts_noserial(int file, const char *s) |
276696675
|
221 222 223 224 225 226 |
{ int i; struct stdio_dev *dev; for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; |
42f9f915c
|
227 |
if (dev->puts != NULL && !console_dev_is_serial(dev)) |
a8552c7c9
|
228 |
dev->puts(dev, s); |
276696675
|
229 230 |
} } |
276696675
|
231 |
|
5f0320108
|
232 |
static void console_puts(int file, const char *s) |
16a28ef21
|
233 234 |
{ int i; |
52cb4d4fb
|
235 |
struct stdio_dev *dev; |
16a28ef21
|
236 237 238 239 |
for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; if (dev->puts != NULL) |
709ea543b
|
240 |
dev->puts(dev, s); |
16a28ef21
|
241 242 |
} } |
5f0320108
|
243 |
|
52cb4d4fb
|
244 |
static inline void console_doenv(int file, struct stdio_dev *dev) |
5f0320108
|
245 246 247 248 249 250 |
{ iomux_doenv(file, dev->name); } #else static inline int console_getc(int file) { |
709ea543b
|
251 |
return stdio_devices[file]->getc(stdio_devices[file]); |
5f0320108
|
252 253 254 255 |
} static inline int console_tstc(int file) { |
709ea543b
|
256 |
return stdio_devices[file]->tstc(stdio_devices[file]); |
5f0320108
|
257 258 259 260 |
} static inline void console_putc(int file, const char c) { |
709ea543b
|
261 |
stdio_devices[file]->putc(stdio_devices[file], c); |
5f0320108
|
262 |
} |
a8552c7c9
|
263 |
static inline void console_puts_noserial(int file, const char *s) |
276696675
|
264 |
{ |
42f9f915c
|
265 |
if (!console_dev_is_serial(stdio_devices[file])) |
a8552c7c9
|
266 |
stdio_devices[file]->puts(stdio_devices[file], s); |
276696675
|
267 |
} |
276696675
|
268 |
|
5f0320108
|
269 270 |
static inline void console_puts(int file, const char *s) { |
709ea543b
|
271 |
stdio_devices[file]->puts(stdio_devices[file], s); |
5f0320108
|
272 |
} |
52cb4d4fb
|
273 |
static inline void console_doenv(int file, struct stdio_dev *dev) |
5f0320108
|
274 275 276 |
{ console_setfile(file, dev); } |
b02654294
|
277 |
#endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */ |
16a28ef21
|
278 |
|
47d1a6e1e
|
279 |
/** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
d9c27253c
|
280 |
int serial_printf(const char *fmt, ...) |
47d1a6e1e
|
281 282 283 |
{ va_list args; uint i; |
6d0f6bcf3
|
284 |
char printbuffer[CONFIG_SYS_PBSIZE]; |
47d1a6e1e
|
285 |
|
ec6f14994
|
286 |
va_start(args, fmt); |
47d1a6e1e
|
287 288 289 290 |
/* For this to work, printbuffer must be larger than * anything we ever want to print. */ |
068af6f84
|
291 |
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
ec6f14994
|
292 |
va_end(args); |
47d1a6e1e
|
293 |
|
ec6f14994
|
294 |
serial_puts(printbuffer); |
d9c27253c
|
295 |
return i; |
47d1a6e1e
|
296 |
} |
ec6f14994
|
297 |
int fgetc(int file) |
47d1a6e1e
|
298 |
{ |
16a28ef21
|
299 |
if (file < MAX_FILES) { |
b02654294
|
300 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
301 302 303 304 |
/* * Effectively poll for input wherever it may be available. */ for (;;) { |
644074671
|
305 |
WATCHDOG_RESET(); |
16a28ef21
|
306 307 308 309 310 |
/* * Upper layer may have already called tstc() so * check for that first. */ if (tstcdev != NULL) |
5f0320108
|
311 312 |
return console_getc(file); console_tstc(file); |
16a28ef21
|
313 314 315 316 317 318 319 320 321 |
#ifdef CONFIG_WATCHDOG /* * If the watchdog must be rate-limited then it should * already be handled in board-specific code. */ udelay(1); #endif } #else |
5f0320108
|
322 |
return console_getc(file); |
16a28ef21
|
323 324 |
#endif } |
47d1a6e1e
|
325 326 327 |
return -1; } |
ec6f14994
|
328 |
int ftstc(int file) |
47d1a6e1e
|
329 330 |
{ if (file < MAX_FILES) |
5f0320108
|
331 |
return console_tstc(file); |
47d1a6e1e
|
332 333 334 |
return -1; } |
ec6f14994
|
335 |
void fputc(int file, const char c) |
47d1a6e1e
|
336 337 |
{ if (file < MAX_FILES) |
5f0320108
|
338 |
console_putc(file, c); |
47d1a6e1e
|
339 |
} |
ec6f14994
|
340 |
void fputs(int file, const char *s) |
47d1a6e1e
|
341 342 |
{ if (file < MAX_FILES) |
5f0320108
|
343 |
console_puts(file, s); |
47d1a6e1e
|
344 |
} |
d9c27253c
|
345 |
int fprintf(int file, const char *fmt, ...) |
47d1a6e1e
|
346 347 348 |
{ va_list args; uint i; |
6d0f6bcf3
|
349 |
char printbuffer[CONFIG_SYS_PBSIZE]; |
47d1a6e1e
|
350 |
|
ec6f14994
|
351 |
va_start(args, fmt); |
47d1a6e1e
|
352 353 354 355 |
/* For this to work, printbuffer must be larger than * anything we ever want to print. */ |
068af6f84
|
356 |
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
ec6f14994
|
357 |
va_end(args); |
47d1a6e1e
|
358 359 |
/* Send to desired file */ |
ec6f14994
|
360 |
fputs(file, printbuffer); |
d9c27253c
|
361 |
return i; |
47d1a6e1e
|
362 363 364 |
} /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
ec6f14994
|
365 |
int getc(void) |
47d1a6e1e
|
366 |
{ |
f5c3ba797
|
367 368 369 370 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return 0; #endif |
e3e454cd7
|
371 372 |
if (!gd->have_console) return 0; |
9854a8748
|
373 374 375 376 377 378 379 380 381 |
#ifdef CONFIG_CONSOLE_RECORD if (gd->console_in.start) { int ch; ch = membuff_getbyte(&gd->console_in); if (ch != -1) return 1; } #endif |
47d1a6e1e
|
382 383 |
if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ |
ec6f14994
|
384 |
return fgetc(stdin); |
47d1a6e1e
|
385 386 387 |
} /* Send directly to the handler */ |
ec6f14994
|
388 |
return serial_getc(); |
47d1a6e1e
|
389 |
} |
ec6f14994
|
390 |
int tstc(void) |
47d1a6e1e
|
391 |
{ |
f5c3ba797
|
392 393 394 395 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return 0; #endif |
e3e454cd7
|
396 397 |
if (!gd->have_console) return 0; |
9854a8748
|
398 399 400 401 402 403 |
#ifdef CONFIG_CONSOLE_RECORD if (gd->console_in.start) { if (membuff_peekbyte(&gd->console_in) != -1) return 1; } #endif |
47d1a6e1e
|
404 405 |
if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ |
ec6f14994
|
406 |
return ftstc(stdin); |
47d1a6e1e
|
407 408 409 |
} /* Send directly to the handler */ |
ec6f14994
|
410 |
return serial_tstc(); |
47d1a6e1e
|
411 |
} |
276696675
|
412 413 |
#define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 |
8f9255841
|
414 |
#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) |
9558b48af
|
415 416 417 418 |
#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ) static void pre_console_putc(const char c) { |
4e6bafa56
|
419 420 421 |
char *buffer; buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); |
9558b48af
|
422 423 |
buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c; |
4e6bafa56
|
424 425 |
unmap_sysmem(buffer); |
9558b48af
|
426 |
} |
be135cc5e
|
427 428 429 430 431 |
static void pre_console_puts(const char *s) { while (*s) pre_console_putc(*s++); } |
276696675
|
432 |
static void print_pre_console_buffer(int flushpoint) |
9558b48af
|
433 |
{ |
a8552c7c9
|
434 |
unsigned long in = 0, out = 0; |
a8552c7c9
|
435 |
char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; |
4e6bafa56
|
436 |
char *buf_in; |
9558b48af
|
437 |
|
4e6bafa56
|
438 |
buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); |
9558b48af
|
439 |
if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) |
a8552c7c9
|
440 |
in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; |
9558b48af
|
441 |
|
a8552c7c9
|
442 443 |
while (in < gd->precon_buf_idx) buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)]; |
4e6bafa56
|
444 |
unmap_sysmem(buf_in); |
a8552c7c9
|
445 446 447 448 449 450 451 452 453 454 455 |
buf_out[out] = 0; switch (flushpoint) { case PRE_CONSOLE_FLUSHPOINT1_SERIAL: puts(buf_out); break; case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: console_puts_noserial(stdout, buf_out); break; } |
9558b48af
|
456 457 458 |
} #else static inline void pre_console_putc(const char c) {} |
be135cc5e
|
459 |
static inline void pre_console_puts(const char *s) {} |
276696675
|
460 |
static inline void print_pre_console_buffer(int flushpoint) {} |
9558b48af
|
461 |
#endif |
ec6f14994
|
462 |
void putc(const char c) |
47d1a6e1e
|
463 |
{ |
64e9b4f34
|
464 465 466 467 468 469 470 |
#ifdef CONFIG_SANDBOX /* sandbox can send characters to stdout before it has a console */ if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { os_putc(c); return; } #endif |
d6ea5307d
|
471 472 473 474 475 476 477 |
#ifdef CONFIG_DEBUG_UART /* if we don't have a console yet, use the debug UART */ if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { printch(c); return; } #endif |
9854a8748
|
478 479 480 481 |
#ifdef CONFIG_CONSOLE_RECORD if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) membuff_putbyte(&gd->console_out, c); #endif |
a6cccaea5
|
482 483 |
#ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) |
f6e20fc6c
|
484 |
return; |
a6cccaea5
|
485 |
#endif |
f5c3ba797
|
486 487 488 489 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return; #endif |
e3e454cd7
|
490 |
if (!gd->have_console) |
9558b48af
|
491 |
return pre_console_putc(c); |
e3e454cd7
|
492 |
|
47d1a6e1e
|
493 494 |
if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ |
ec6f14994
|
495 |
fputc(stdout, c); |
47d1a6e1e
|
496 497 |
} else { /* Send directly to the handler */ |
276696675
|
498 |
pre_console_putc(c); |
ec6f14994
|
499 |
serial_putc(c); |
47d1a6e1e
|
500 501 |
} } |
ec6f14994
|
502 |
void puts(const char *s) |
47d1a6e1e
|
503 |
{ |
be135cc5e
|
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
#ifdef CONFIG_DEBUG_UART if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { while (*s) { int ch = *s++; printch(ch); } return; } #endif #ifdef CONFIG_CONSOLE_RECORD if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) membuff_put(&gd->console_out, s, strlen(s)); #endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) return; #endif #ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return; #endif if (!gd->have_console) return pre_console_puts(s); if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ fputs(stdout, s); } else { /* Send directly to the handler */ pre_console_puts(s); serial_puts(s); } |
47d1a6e1e
|
539 |
} |
9854a8748
|
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
#ifdef CONFIG_CONSOLE_RECORD int console_record_init(void) { int ret; ret = membuff_new(&gd->console_out, CONFIG_CONSOLE_RECORD_OUT_SIZE); if (ret) return ret; ret = membuff_new(&gd->console_in, CONFIG_CONSOLE_RECORD_IN_SIZE); return ret; } void console_record_reset(void) { membuff_purge(&gd->console_out); membuff_purge(&gd->console_in); } void console_record_reset_enable(void) { console_record_reset(); gd->flags |= GD_FLG_RECORD; } #endif |
47d1a6e1e
|
565 566 567 |
/* test if ctrl-c was pressed */ static int ctrlc_disabled = 0; /* see disable_ctrl() */ static int ctrlc_was_pressed = 0; |
ec6f14994
|
568 |
int ctrlc(void) |
47d1a6e1e
|
569 |
{ |
8969ea3e9
|
570 |
#ifndef CONFIG_SANDBOX |
47d1a6e1e
|
571 |
if (!ctrlc_disabled && gd->have_console) { |
ec6f14994
|
572 573 |
if (tstc()) { switch (getc()) { |
47d1a6e1e
|
574 575 576 577 578 579 580 581 |
case 0x03: /* ^C - Control C */ ctrlc_was_pressed = 1; return 1; default: break; } } } |
8969ea3e9
|
582 |
#endif |
47d1a6e1e
|
583 584 |
return 0; } |
a5dffa4b6
|
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
/* Reads user's confirmation. Returns 1 if user's input is "y", "Y", "yes" or "YES" */ int confirm_yesno(void) { int i; char str_input[5]; /* Flush input */ while (tstc()) getc(); i = 0; while (i < sizeof(str_input)) { str_input[i] = getc(); putc(str_input[i]); if (str_input[i] == '\r') break; i++; } putc(' '); if (strncmp(str_input, "y\r", 2) == 0 || strncmp(str_input, "Y\r", 2) == 0 || strncmp(str_input, "yes\r", 4) == 0 || strncmp(str_input, "YES\r", 4) == 0) return 1; return 0; } |
47d1a6e1e
|
613 614 615 |
/* pass 1 to disable ctrlc() checking, 0 to enable. * returns previous state */ |
ec6f14994
|
616 |
int disable_ctrlc(int disable) |
47d1a6e1e
|
617 618 619 620 621 622 623 624 625 626 627 |
{ int prev = ctrlc_disabled; /* save previous state */ ctrlc_disabled = disable; return prev; } int had_ctrlc (void) { return ctrlc_was_pressed; } |
ec6f14994
|
628 |
void clear_ctrlc(void) |
47d1a6e1e
|
629 630 631 |
{ ctrlc_was_pressed = 0; } |
47d1a6e1e
|
632 |
/** U-Boot INIT FUNCTIONS *************************************************/ |
d7be3056d
|
633 |
struct stdio_dev *search_device(int flags, const char *name) |
c1de7a6da
|
634 |
{ |
52cb4d4fb
|
635 |
struct stdio_dev *dev; |
c1de7a6da
|
636 |
|
52cb4d4fb
|
637 |
dev = stdio_get_by_name(name); |
a2931b30d
|
638 639 640 641 |
#ifdef CONFIG_VIDCONSOLE_AS_LCD if (!dev && !strcmp(name, "lcd")) dev = stdio_get_by_name("vidconsole"); #endif |
c1de7a6da
|
642 |
|
ec6f14994
|
643 |
if (dev && (dev->flags & flags)) |
c1de7a6da
|
644 645 646 647 |
return dev; return NULL; } |
d7be3056d
|
648 |
int console_assign(int file, const char *devname) |
47d1a6e1e
|
649 |
{ |
c1de7a6da
|
650 |
int flag; |
52cb4d4fb
|
651 |
struct stdio_dev *dev; |
47d1a6e1e
|
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
/* Check for valid file */ switch (file) { case stdin: flag = DEV_FLAGS_INPUT; break; case stdout: case stderr: flag = DEV_FLAGS_OUTPUT; break; default: return -1; } /* Check for valid device name */ |
c1de7a6da
|
667 |
dev = search_device(flag, devname); |
47d1a6e1e
|
668 |
|
ec6f14994
|
669 670 |
if (dev) return console_setfile(file, dev); |
47d1a6e1e
|
671 672 673 |
return -1; } |
43e0a3dec
|
674 |
static void console_update_silent(void) |
47d1a6e1e
|
675 |
{ |
f72da3406
|
676 |
#ifdef CONFIG_SILENT_CONSOLE |
00caae6d4
|
677 |
if (env_get("silent") != NULL) |
f72da3406
|
678 |
gd->flags |= GD_FLG_SILENT; |
43e0a3dec
|
679 680 |
else gd->flags &= ~GD_FLG_SILENT; |
f72da3406
|
681 |
#endif |
43e0a3dec
|
682 |
} |
b0895384b
|
683 684 685 686 687 688 689 690 691 692 693 694 |
int console_announce_r(void) { #if !CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) char buf[DISPLAY_OPTIONS_BANNER_LENGTH]; display_options_get_banner(false, buf, sizeof(buf)); console_puts_noserial(stdout, buf); #endif return 0; } |
43e0a3dec
|
695 696 697 698 699 700 |
/* Called before relocation - use serial functions */ int console_init_f(void) { gd->have_console = 1; console_update_silent(); |
f72da3406
|
701 |
|
276696675
|
702 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL); |
9558b48af
|
703 |
|
ec6f14994
|
704 |
return 0; |
47d1a6e1e
|
705 |
} |
7e3be7cf3
|
706 707 |
void stdio_print_current_devices(void) { |
7e3be7cf3
|
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
/* Print information */ puts("In: "); if (stdio_devices[stdin] == NULL) { puts("No input devices available! "); } else { printf ("%s ", stdio_devices[stdin]->name); } puts("Out: "); if (stdio_devices[stdout] == NULL) { puts("No output devices available! "); } else { printf ("%s ", stdio_devices[stdout]->name); } puts("Err: "); if (stdio_devices[stderr] == NULL) { puts("No error devices available! "); } else { printf ("%s ", stdio_devices[stderr]->name); } |
7e3be7cf3
|
735 |
} |
b02654294
|
736 |
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) |
47d1a6e1e
|
737 |
/* Called after the relocation - use desired console functions */ |
ec6f14994
|
738 |
int console_init_r(void) |
47d1a6e1e
|
739 740 |
{ char *stdinname, *stdoutname, *stderrname; |
52cb4d4fb
|
741 |
struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
6d0f6bcf3
|
742 |
#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
6e5923851
|
743 |
int i; |
6d0f6bcf3
|
744 |
#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
b02654294
|
745 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
746 747 |
int iomux_err = 0; #endif |
47d1a6e1e
|
748 749 |
/* set default handlers at first */ |
49cad5478
|
750 751 752 753 754 |
gd->jt->getc = serial_getc; gd->jt->tstc = serial_tstc; gd->jt->putc = serial_putc; gd->jt->puts = serial_puts; gd->jt->printf = serial_printf; |
47d1a6e1e
|
755 756 757 |
/* stdin stdout and stderr are in environment */ /* scan for it */ |
00caae6d4
|
758 759 760 |
stdinname = env_get("stdin"); stdoutname = env_get("stdout"); stderrname = env_get("stderr"); |
47d1a6e1e
|
761 |
|
53677ef18
|
762 |
if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
ec6f14994
|
763 764 765 |
inputdev = search_device(DEV_FLAGS_INPUT, stdinname); outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); |
b02654294
|
766 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
767 768 769 770 771 772 773 |
iomux_err = iomux_doenv(stdin, stdinname); iomux_err += iomux_doenv(stdout, stdoutname); iomux_err += iomux_doenv(stderr, stderrname); if (!iomux_err) /* Successful, so skip all the code below. */ goto done; #endif |
47d1a6e1e
|
774 775 776 |
} /* if the devices are overwritten or not found, use default device */ if (inputdev == NULL) { |
ec6f14994
|
777 |
inputdev = search_device(DEV_FLAGS_INPUT, "serial"); |
47d1a6e1e
|
778 779 |
} if (outputdev == NULL) { |
ec6f14994
|
780 |
outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
47d1a6e1e
|
781 782 |
} if (errdev == NULL) { |
ec6f14994
|
783 |
errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
47d1a6e1e
|
784 785 786 |
} /* Initializes output console first */ if (outputdev != NULL) { |
16a28ef21
|
787 |
/* need to set a console if not done above. */ |
5f0320108
|
788 |
console_doenv(stdout, outputdev); |
47d1a6e1e
|
789 790 |
} if (errdev != NULL) { |
16a28ef21
|
791 |
/* need to set a console if not done above. */ |
5f0320108
|
792 |
console_doenv(stderr, errdev); |
47d1a6e1e
|
793 794 |
} if (inputdev != NULL) { |
16a28ef21
|
795 |
/* need to set a console if not done above. */ |
5f0320108
|
796 |
console_doenv(stdin, inputdev); |
47d1a6e1e
|
797 |
} |
b02654294
|
798 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
799 800 |
done: #endif |
78c112c9f
|
801 |
#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
7e3be7cf3
|
802 |
stdio_print_current_devices(); |
78c112c9f
|
803 |
#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
a2931b30d
|
804 805 806 807 808 |
#ifdef CONFIG_VIDCONSOLE_AS_LCD if (strstr(stdoutname, "lcd")) printf("Warning: Please change 'lcd' to 'vidconsole' in stdout/stderr environment vars "); #endif |
47d1a6e1e
|
809 |
|
6d0f6bcf3
|
810 |
#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
47d1a6e1e
|
811 812 |
/* set the environment variables (will overwrite previous env settings) */ for (i = 0; i < 3; i++) { |
382bee57f
|
813 |
env_set(stdio_names[i], stdio_devices[i]->name); |
47d1a6e1e
|
814 |
} |
6d0f6bcf3
|
815 |
#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
47d1a6e1e
|
816 |
|
c4e0057fa
|
817 |
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
47d1a6e1e
|
818 819 820 |
#if 0 /* If nothing usable installed, use only the initial console */ if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
ec6f14994
|
821 |
return 0; |
47d1a6e1e
|
822 |
#endif |
276696675
|
823 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
ec6f14994
|
824 |
return 0; |
47d1a6e1e
|
825 |
} |
b02654294
|
826 |
#else /* !CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |
47d1a6e1e
|
827 828 |
/* Called after the relocation - use desired console functions */ |
ec6f14994
|
829 |
int console_init_r(void) |
47d1a6e1e
|
830 |
{ |
52cb4d4fb
|
831 |
struct stdio_dev *inputdev = NULL, *outputdev = NULL; |
c1de7a6da
|
832 |
int i; |
52cb4d4fb
|
833 |
struct list_head *list = stdio_get_list(); |
c1de7a6da
|
834 |
struct list_head *pos; |
52cb4d4fb
|
835 |
struct stdio_dev *dev; |
47d1a6e1e
|
836 |
|
43e0a3dec
|
837 |
console_update_silent(); |
d791b1dc3
|
838 |
#ifdef CONFIG_SPLASH_SCREEN |
ec6f14994
|
839 840 |
/* * suppress all output if splash screen is enabled and we have |
a74908161
|
841 842 843 |
* a bmp to display. We redirect the output from frame buffer * console to serial console in this case or suppress it if * "silent" mode was requested. |
ec6f14994
|
844 |
*/ |
00caae6d4
|
845 |
if (env_get("splashimage") != NULL) { |
a74908161
|
846 847 848 |
if (!(gd->flags & GD_FLG_SILENT)) outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); } |
f72da3406
|
849 |
#endif |
47d1a6e1e
|
850 |
/* Scan devices looking for input and output devices */ |
c1de7a6da
|
851 |
list_for_each(pos, list) { |
52cb4d4fb
|
852 |
dev = list_entry(pos, struct stdio_dev, list); |
47d1a6e1e
|
853 854 855 856 857 858 859 |
if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; } if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } |
c1de7a6da
|
860 861 |
if(inputdev && outputdev) break; |
47d1a6e1e
|
862 863 864 865 |
} /* Initializes output console first */ if (outputdev != NULL) { |
ec6f14994
|
866 867 |
console_setfile(stdout, outputdev); console_setfile(stderr, outputdev); |
b02654294
|
868 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
869 870 871 |
console_devices[stdout][0] = outputdev; console_devices[stderr][0] = outputdev; #endif |
47d1a6e1e
|
872 873 874 875 |
} /* Initializes input console */ if (inputdev != NULL) { |
ec6f14994
|
876 |
console_setfile(stdin, inputdev); |
b02654294
|
877 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21
|
878 879 |
console_devices[stdin][0] = inputdev; #endif |
47d1a6e1e
|
880 |
} |
78c112c9f
|
881 |
#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
7e3be7cf3
|
882 |
stdio_print_current_devices(); |
78c112c9f
|
883 |
#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
47d1a6e1e
|
884 885 886 |
/* Setting environment variables */ for (i = 0; i < 3; i++) { |
382bee57f
|
887 |
env_set(stdio_names[i], stdio_devices[i]->name); |
47d1a6e1e
|
888 |
} |
c4e0057fa
|
889 |
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
47d1a6e1e
|
890 891 892 |
#if 0 /* If nothing usable installed, use only the initial console */ if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
ec6f14994
|
893 |
return 0; |
47d1a6e1e
|
894 |
#endif |
276696675
|
895 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
ec6f14994
|
896 |
return 0; |
47d1a6e1e
|
897 |
} |
b02654294
|
898 |
#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |