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