Blame view
common/console.c
19.9 KB
47d1a6e1e Initial revision |
1 2 3 4 |
/* * (C) Copyright 2000 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
47d1a6e1e Initial revision |
6 7 8 |
*/ #include <common.h> |
24b852a7a Move console defi... |
9 |
#include <console.h> |
d6ea5307d dm: Allow debug U... |
10 |
#include <debug_uart.h> |
7b3c4c3a5 dm: console: Chec... |
11 |
#include <dm.h> |
47d1a6e1e Initial revision |
12 |
#include <stdarg.h> |
482f4691a common:console: a... |
13 |
#include <iomux.h> |
47d1a6e1e Initial revision |
14 |
#include <malloc.h> |
4e6bafa56 console: Use map_... |
15 |
#include <mapmem.h> |
91b136c79 sandbox: Allow th... |
16 |
#include <os.h> |
849d5d9cd env: Add a consol... |
17 |
#include <serial.h> |
52cb4d4fb stdio/device: rew... |
18 |
#include <stdio_dev.h> |
27b207fd0 * Implement new m... |
19 |
#include <exports.h> |
849d5d9cd env: Add a consol... |
20 |
#include <environment.h> |
644074671 watchdog: Fix Wat... |
21 |
#include <watchdog.h> |
47d1a6e1e Initial revision |
22 |
|
d87080b72 GCC-4.x fixes: cl... |
23 |
DECLARE_GLOBAL_DATA_PTR; |
849d5d9cd env: Add a consol... |
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 console: Don't en... |
44 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
849d5d9cd env: Add a consol... |
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 console: Don't en... |
51 |
#endif |
849d5d9cd env: Add a consol... |
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 env: Add a silent... |
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 common: console: ... |
69 |
#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET) |
e080d545f env: Add a silent... |
70 71 72 |
if (flags & H_INTERACTIVE) return 0; #endif |
5daf6e56d common: console: ... |
73 |
#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC) |
e080d545f env: Add a silent... |
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 console: Don't en... |
87 |
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) |
47d1a6e1e Initial revision |
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 rename CFG_ macro... |
93 |
#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE |
ec6f14994 common/console: c... |
94 95 |
extern int overwrite_console(void); #define OVERWRITE_CONSOLE overwrite_console() |
47d1a6e1e Initial revision |
96 |
#else |
83e40ba75 * Patch by Detlev... |
97 |
#define OVERWRITE_CONSOLE 0 |
6d0f6bcf3 rename CFG_ macro... |
98 |
#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ |
47d1a6e1e Initial revision |
99 |
|
b02654294 console: Don't en... |
100 |
#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |
47d1a6e1e Initial revision |
101 |
|
52cb4d4fb stdio/device: rew... |
102 |
static int console_setfile(int file, struct stdio_dev * dev) |
47d1a6e1e Initial revision |
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 stdio: Pass devic... |
115 |
error = dev->start(dev); |
47d1a6e1e Initial revision |
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 Export redesign |
130 131 |
gd->jt->getc = getc; gd->jt->tstc = tstc; |
47d1a6e1e Initial revision |
132 133 |
break; case stdout: |
49cad5478 Export redesign |
134 135 136 |
gd->jt->putc = putc; gd->jt->puts = puts; gd->jt->printf = printf; |
47d1a6e1e Initial revision |
137 138 139 140 141 142 143 144 145 |
break; } break; default: /* Invalid file ID */ error = -1; } return error; } |
42f9f915c console: Unify th... |
146 147 148 149 |
/** * console_dev_is_serial() - Check if a stdio device is a serial device * * @sdev: Device to check |
7b3c4c3a5 dm: console: Chec... |
150 151 |
* @return true if this device is in the serial uclass (or for pre-driver-model, * whether it is called "serial". |
42f9f915c console: Unify th... |
152 153 154 155 |
*/ static bool console_dev_is_serial(struct stdio_dev *sdev) { bool is_serial; |
7b3c4c3a5 dm: console: Chec... |
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 console: Unify th... |
163 164 165 166 |
is_serial = !strcmp(sdev->name, "serial"); return is_serial; } |
b02654294 console: Don't en... |
167 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
168 |
/** Console I/O multiplexing *******************************************/ |
52cb4d4fb stdio/device: rew... |
169 170 |
static struct stdio_dev *tstcdev; struct stdio_dev **console_devices[MAX_FILES]; |
16a28ef21 IOMUX: Add consol... |
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 common/console: a... |
179 |
static int console_getc(int file) |
16a28ef21 IOMUX: Add consol... |
180 181 182 183 |
{ unsigned char ret; /* This is never called with testcdev == NULL */ |
709ea543b stdio: Pass devic... |
184 |
ret = tstcdev->getc(tstcdev); |
16a28ef21 IOMUX: Add consol... |
185 186 187 |
tstcdev = NULL; return ret; } |
5f0320108 common/console: a... |
188 |
static int console_tstc(int file) |
16a28ef21 IOMUX: Add consol... |
189 190 |
{ int i, ret; |
52cb4d4fb stdio/device: rew... |
191 |
struct stdio_dev *dev; |
16a28ef21 IOMUX: Add consol... |
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 stdio: Pass devic... |
197 |
ret = dev->tstc(dev); |
16a28ef21 IOMUX: Add consol... |
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 common/console: a... |
209 |
static void console_putc(int file, const char c) |
16a28ef21 IOMUX: Add consol... |
210 211 |
{ int i; |
52cb4d4fb stdio/device: rew... |
212 |
struct stdio_dev *dev; |
16a28ef21 IOMUX: Add consol... |
213 214 215 216 |
for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; if (dev->putc != NULL) |
709ea543b stdio: Pass devic... |
217 |
dev->putc(dev, c); |
16a28ef21 IOMUX: Add consol... |
218 219 |
} } |
a8552c7c9 console: Fix pre-... |
220 |
static void console_puts_noserial(int file, const char *s) |
276696675 console: Use pre-... |
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 console: Unify th... |
227 |
if (dev->puts != NULL && !console_dev_is_serial(dev)) |
a8552c7c9 console: Fix pre-... |
228 |
dev->puts(dev, s); |
276696675 console: Use pre-... |
229 230 |
} } |
276696675 console: Use pre-... |
231 |
|
5f0320108 common/console: a... |
232 |
static void console_puts(int file, const char *s) |
16a28ef21 IOMUX: Add consol... |
233 234 |
{ int i; |
52cb4d4fb stdio/device: rew... |
235 |
struct stdio_dev *dev; |
16a28ef21 IOMUX: Add consol... |
236 237 238 239 |
for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; if (dev->puts != NULL) |
709ea543b stdio: Pass devic... |
240 |
dev->puts(dev, s); |
16a28ef21 IOMUX: Add consol... |
241 242 |
} } |
5f0320108 common/console: a... |
243 |
|
52cb4d4fb stdio/device: rew... |
244 |
static inline void console_doenv(int file, struct stdio_dev *dev) |
5f0320108 common/console: a... |
245 246 247 248 249 250 |
{ iomux_doenv(file, dev->name); } #else static inline int console_getc(int file) { |
709ea543b stdio: Pass devic... |
251 |
return stdio_devices[file]->getc(stdio_devices[file]); |
5f0320108 common/console: a... |
252 253 254 255 |
} static inline int console_tstc(int file) { |
709ea543b stdio: Pass devic... |
256 |
return stdio_devices[file]->tstc(stdio_devices[file]); |
5f0320108 common/console: a... |
257 258 259 260 |
} static inline void console_putc(int file, const char c) { |
709ea543b stdio: Pass devic... |
261 |
stdio_devices[file]->putc(stdio_devices[file], c); |
5f0320108 common/console: a... |
262 |
} |
a8552c7c9 console: Fix pre-... |
263 |
static inline void console_puts_noserial(int file, const char *s) |
276696675 console: Use pre-... |
264 |
{ |
42f9f915c console: Unify th... |
265 |
if (!console_dev_is_serial(stdio_devices[file])) |
a8552c7c9 console: Fix pre-... |
266 |
stdio_devices[file]->puts(stdio_devices[file], s); |
276696675 console: Use pre-... |
267 |
} |
276696675 console: Use pre-... |
268 |
|
5f0320108 common/console: a... |
269 270 |
static inline void console_puts(int file, const char *s) { |
709ea543b stdio: Pass devic... |
271 |
stdio_devices[file]->puts(stdio_devices[file], s); |
5f0320108 common/console: a... |
272 |
} |
52cb4d4fb stdio/device: rew... |
273 |
static inline void console_doenv(int file, struct stdio_dev *dev) |
5f0320108 common/console: a... |
274 275 276 |
{ console_setfile(file, dev); } |
b02654294 console: Don't en... |
277 |
#endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */ |
16a28ef21 IOMUX: Add consol... |
278 |
|
47d1a6e1e Initial revision |
279 |
/** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ |
d9c27253c Make *printf() re... |
280 |
int serial_printf(const char *fmt, ...) |
47d1a6e1e Initial revision |
281 282 283 |
{ va_list args; uint i; |
6d0f6bcf3 rename CFG_ macro... |
284 |
char printbuffer[CONFIG_SYS_PBSIZE]; |
47d1a6e1e Initial revision |
285 |
|
ec6f14994 common/console: c... |
286 |
va_start(args, fmt); |
47d1a6e1e Initial revision |
287 288 289 290 |
/* For this to work, printbuffer must be larger than * anything we ever want to print. */ |
068af6f84 Make printf and v... |
291 |
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
ec6f14994 common/console: c... |
292 |
va_end(args); |
47d1a6e1e Initial revision |
293 |
|
ec6f14994 common/console: c... |
294 |
serial_puts(printbuffer); |
d9c27253c Make *printf() re... |
295 |
return i; |
47d1a6e1e Initial revision |
296 |
} |
ec6f14994 common/console: c... |
297 |
int fgetc(int file) |
47d1a6e1e Initial revision |
298 |
{ |
16a28ef21 IOMUX: Add consol... |
299 |
if (file < MAX_FILES) { |
b02654294 console: Don't en... |
300 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
301 302 303 304 |
/* * Effectively poll for input wherever it may be available. */ for (;;) { |
644074671 watchdog: Fix Wat... |
305 |
WATCHDOG_RESET(); |
16a28ef21 IOMUX: Add consol... |
306 307 308 309 310 |
/* * Upper layer may have already called tstc() so * check for that first. */ if (tstcdev != NULL) |
5f0320108 common/console: a... |
311 312 |
return console_getc(file); console_tstc(file); |
16a28ef21 IOMUX: Add consol... |
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 common/console: a... |
322 |
return console_getc(file); |
16a28ef21 IOMUX: Add consol... |
323 324 |
#endif } |
47d1a6e1e Initial revision |
325 326 327 |
return -1; } |
ec6f14994 common/console: c... |
328 |
int ftstc(int file) |
47d1a6e1e Initial revision |
329 330 |
{ if (file < MAX_FILES) |
5f0320108 common/console: a... |
331 |
return console_tstc(file); |
47d1a6e1e Initial revision |
332 333 334 |
return -1; } |
ec6f14994 common/console: c... |
335 |
void fputc(int file, const char c) |
47d1a6e1e Initial revision |
336 337 |
{ if (file < MAX_FILES) |
5f0320108 common/console: a... |
338 |
console_putc(file, c); |
47d1a6e1e Initial revision |
339 |
} |
ec6f14994 common/console: c... |
340 |
void fputs(int file, const char *s) |
47d1a6e1e Initial revision |
341 342 |
{ if (file < MAX_FILES) |
5f0320108 common/console: a... |
343 |
console_puts(file, s); |
47d1a6e1e Initial revision |
344 |
} |
d9c27253c Make *printf() re... |
345 |
int fprintf(int file, const char *fmt, ...) |
47d1a6e1e Initial revision |
346 347 348 |
{ va_list args; uint i; |
6d0f6bcf3 rename CFG_ macro... |
349 |
char printbuffer[CONFIG_SYS_PBSIZE]; |
47d1a6e1e Initial revision |
350 |
|
ec6f14994 common/console: c... |
351 |
va_start(args, fmt); |
47d1a6e1e Initial revision |
352 353 354 355 |
/* For this to work, printbuffer must be larger than * anything we ever want to print. */ |
068af6f84 Make printf and v... |
356 |
i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); |
ec6f14994 common/console: c... |
357 |
va_end(args); |
47d1a6e1e Initial revision |
358 359 |
/* Send to desired file */ |
ec6f14994 common/console: c... |
360 |
fputs(file, printbuffer); |
d9c27253c Make *printf() re... |
361 |
return i; |
47d1a6e1e Initial revision |
362 363 364 |
} /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/ |
ec6f14994 common/console: c... |
365 |
int getc(void) |
47d1a6e1e Initial revision |
366 |
{ |
f5c3ba797 Allow console inp... |
367 368 369 370 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return 0; #endif |
e3e454cd7 console: Squelch ... |
371 372 |
if (!gd->have_console) return 0; |
9854a8748 console: Add a co... |
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 Initial revision |
382 383 |
if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ |
ec6f14994 common/console: c... |
384 |
return fgetc(stdin); |
47d1a6e1e Initial revision |
385 386 387 |
} /* Send directly to the handler */ |
ec6f14994 common/console: c... |
388 |
return serial_getc(); |
47d1a6e1e Initial revision |
389 |
} |
ec6f14994 common/console: c... |
390 |
int tstc(void) |
47d1a6e1e Initial revision |
391 |
{ |
f5c3ba797 Allow console inp... |
392 393 394 395 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return 0; #endif |
e3e454cd7 console: Squelch ... |
396 397 |
if (!gd->have_console) return 0; |
9854a8748 console: Add a co... |
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 Initial revision |
404 405 |
if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ |
ec6f14994 common/console: c... |
406 |
return ftstc(stdin); |
47d1a6e1e Initial revision |
407 408 409 |
} /* Send directly to the handler */ |
ec6f14994 common/console: c... |
410 |
return serial_tstc(); |
47d1a6e1e Initial revision |
411 |
} |
276696675 console: Use pre-... |
412 413 |
#define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 |
8f9255841 Convert CONSOLE_P... |
414 |
#if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) |
9558b48af console: Implemen... |
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 console: Use map_... |
419 420 421 |
char *buffer; buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); |
9558b48af console: Implemen... |
422 423 |
buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c; |
4e6bafa56 console: Use map_... |
424 425 |
unmap_sysmem(buffer); |
9558b48af console: Implemen... |
426 |
} |
be135cc5e Revert "console: ... |
427 428 429 430 431 |
static void pre_console_puts(const char *s) { while (*s) pre_console_putc(*s++); } |
276696675 console: Use pre-... |
432 |
static void print_pre_console_buffer(int flushpoint) |
9558b48af console: Implemen... |
433 |
{ |
a8552c7c9 console: Fix pre-... |
434 |
unsigned long in = 0, out = 0; |
a8552c7c9 console: Fix pre-... |
435 |
char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; |
4e6bafa56 console: Use map_... |
436 |
char *buf_in; |
9558b48af console: Implemen... |
437 |
|
4e6bafa56 console: Use map_... |
438 |
buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); |
9558b48af console: Implemen... |
439 |
if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) |
a8552c7c9 console: Fix pre-... |
440 |
in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; |
9558b48af console: Implemen... |
441 |
|
a8552c7c9 console: Fix pre-... |
442 443 |
while (in < gd->precon_buf_idx) buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)]; |
4e6bafa56 console: Use map_... |
444 |
unmap_sysmem(buf_in); |
a8552c7c9 console: Fix pre-... |
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 console: Implemen... |
456 457 458 |
} #else static inline void pre_console_putc(const char c) {} |
be135cc5e Revert "console: ... |
459 |
static inline void pre_console_puts(const char *s) {} |
276696675 console: Use pre-... |
460 |
static inline void print_pre_console_buffer(int flushpoint) {} |
9558b48af console: Implemen... |
461 |
#endif |
ec6f14994 common/console: c... |
462 |
void putc(const char c) |
47d1a6e1e Initial revision |
463 |
{ |
64e9b4f34 Revert "sandbox: ... |
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 dm: Allow debug U... |
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 console: Add a co... |
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 * Patch by Wolter... |
482 483 |
#ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) |
f6e20fc6c Patch by Anders L... |
484 |
return; |
a6cccaea5 * Patch by Wolter... |
485 |
#endif |
f5c3ba797 Allow console inp... |
486 487 488 489 |
#ifdef CONFIG_DISABLE_CONSOLE if (gd->flags & GD_FLG_DISABLE_CONSOLE) return; #endif |
e3e454cd7 console: Squelch ... |
490 |
if (!gd->have_console) |
9558b48af console: Implemen... |
491 |
return pre_console_putc(c); |
e3e454cd7 console: Squelch ... |
492 |
|
47d1a6e1e Initial revision |
493 494 |
if (gd->flags & GD_FLG_DEVINIT) { /* Send to the standard output */ |
ec6f14994 common/console: c... |
495 |
fputc(stdout, c); |
47d1a6e1e Initial revision |
496 497 |
} else { /* Send directly to the handler */ |
276696675 console: Use pre-... |
498 |
pre_console_putc(c); |
ec6f14994 common/console: c... |
499 |
serial_putc(c); |
47d1a6e1e Initial revision |
500 501 |
} } |
ec6f14994 common/console: c... |
502 |
void puts(const char *s) |
47d1a6e1e Initial revision |
503 |
{ |
be135cc5e Revert "console: ... |
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 Initial revision |
539 |
} |
9854a8748 console: Add a co... |
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 Initial revision |
565 566 567 |
/* test if ctrl-c was pressed */ static int ctrlc_disabled = 0; /* see disable_ctrl() */ static int ctrlc_was_pressed = 0; |
ec6f14994 common/console: c... |
568 |
int ctrlc(void) |
47d1a6e1e Initial revision |
569 |
{ |
8969ea3e9 sandbox: Disable ... |
570 |
#ifndef CONFIG_SANDBOX |
47d1a6e1e Initial revision |
571 |
if (!ctrlc_disabled && gd->have_console) { |
ec6f14994 common/console: c... |
572 573 |
if (tstc()) { switch (getc()) { |
47d1a6e1e Initial revision |
574 575 576 577 578 579 580 581 |
case 0x03: /* ^C - Control C */ ctrlc_was_pressed = 1; return 1; default: break; } } } |
8969ea3e9 sandbox: Disable ... |
582 |
#endif |
47d1a6e1e Initial revision |
583 584 |
return 0; } |
a5dffa4b6 Add the function ... |
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 Initial revision |
613 614 615 |
/* pass 1 to disable ctrlc() checking, 0 to enable. * returns previous state */ |
ec6f14994 common/console: c... |
616 |
int disable_ctrlc(int disable) |
47d1a6e1e Initial revision |
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 common/console: c... |
628 |
void clear_ctrlc(void) |
47d1a6e1e Initial revision |
629 630 631 |
{ ctrlc_was_pressed = 0; } |
47d1a6e1e Initial revision |
632 |
/** U-Boot INIT FUNCTIONS *************************************************/ |
d7be3056d stdio: constify "... |
633 |
struct stdio_dev *search_device(int flags, const char *name) |
c1de7a6da devices: merge to... |
634 |
{ |
52cb4d4fb stdio/device: rew... |
635 |
struct stdio_dev *dev; |
c1de7a6da devices: merge to... |
636 |
|
52cb4d4fb stdio/device: rew... |
637 |
dev = stdio_get_by_name(name); |
a2931b30d dm: video: Add a ... |
638 639 640 641 |
#ifdef CONFIG_VIDCONSOLE_AS_LCD if (!dev && !strcmp(name, "lcd")) dev = stdio_get_by_name("vidconsole"); #endif |
c1de7a6da devices: merge to... |
642 |
|
ec6f14994 common/console: c... |
643 |
if (dev && (dev->flags & flags)) |
c1de7a6da devices: merge to... |
644 645 646 647 |
return dev; return NULL; } |
d7be3056d stdio: constify "... |
648 |
int console_assign(int file, const char *devname) |
47d1a6e1e Initial revision |
649 |
{ |
c1de7a6da devices: merge to... |
650 |
int flag; |
52cb4d4fb stdio/device: rew... |
651 |
struct stdio_dev *dev; |
47d1a6e1e Initial revision |
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 devices: merge to... |
667 |
dev = search_device(flag, devname); |
47d1a6e1e Initial revision |
668 |
|
ec6f14994 common/console: c... |
669 670 |
if (dev) return console_setfile(file, dev); |
47d1a6e1e Initial revision |
671 672 673 |
return -1; } |
43e0a3dec common/console.c:... |
674 |
static void console_update_silent(void) |
47d1a6e1e Initial revision |
675 |
{ |
f72da3406 Added config opti... |
676 |
#ifdef CONFIG_SILENT_CONSOLE |
00caae6d4 env: Rename geten... |
677 |
if (env_get("silent") != NULL) |
f72da3406 Added config opti... |
678 |
gd->flags |= GD_FLG_SILENT; |
43e0a3dec common/console.c:... |
679 680 |
else gd->flags &= ~GD_FLG_SILENT; |
f72da3406 Added config opti... |
681 |
#endif |
43e0a3dec common/console.c:... |
682 |
} |
b0895384b Allow displaying ... |
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 common/console.c:... |
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 Added config opti... |
701 |
|
276696675 console: Use pre-... |
702 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL); |
9558b48af console: Implemen... |
703 |
|
ec6f14994 common/console: c... |
704 |
return 0; |
47d1a6e1e Initial revision |
705 |
} |
7e3be7cf3 console: unify pr... |
706 707 |
void stdio_print_current_devices(void) { |
7e3be7cf3 console: unify pr... |
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 console: unify pr... |
735 |
} |
b02654294 console: Don't en... |
736 |
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) |
47d1a6e1e Initial revision |
737 |
/* Called after the relocation - use desired console functions */ |
ec6f14994 common/console: c... |
738 |
int console_init_r(void) |
47d1a6e1e Initial revision |
739 740 |
{ char *stdinname, *stdoutname, *stderrname; |
52cb4d4fb stdio/device: rew... |
741 |
struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; |
6d0f6bcf3 rename CFG_ macro... |
742 |
#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
6e5923851 * Cleanup, minor ... |
743 |
int i; |
6d0f6bcf3 rename CFG_ macro... |
744 |
#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
b02654294 console: Don't en... |
745 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
746 747 |
int iomux_err = 0; #endif |
47d1a6e1e Initial revision |
748 749 |
/* set default handlers at first */ |
49cad5478 Export redesign |
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 Initial revision |
755 756 757 |
/* stdin stdout and stderr are in environment */ /* scan for it */ |
00caae6d4 env: Rename geten... |
758 759 760 |
stdinname = env_get("stdin"); stdoutname = env_get("stdout"); stderrname = env_get("stderr"); |
47d1a6e1e Initial revision |
761 |
|
53677ef18 Big white-space c... |
762 |
if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ |
ec6f14994 common/console: c... |
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 console: Don't en... |
766 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
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 Initial revision |
774 775 776 |
} /* if the devices are overwritten or not found, use default device */ if (inputdev == NULL) { |
ec6f14994 common/console: c... |
777 |
inputdev = search_device(DEV_FLAGS_INPUT, "serial"); |
47d1a6e1e Initial revision |
778 779 |
} if (outputdev == NULL) { |
ec6f14994 common/console: c... |
780 |
outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
47d1a6e1e Initial revision |
781 782 |
} if (errdev == NULL) { |
ec6f14994 common/console: c... |
783 |
errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); |
47d1a6e1e Initial revision |
784 785 786 |
} /* Initializes output console first */ if (outputdev != NULL) { |
16a28ef21 IOMUX: Add consol... |
787 |
/* need to set a console if not done above. */ |
5f0320108 common/console: a... |
788 |
console_doenv(stdout, outputdev); |
47d1a6e1e Initial revision |
789 790 |
} if (errdev != NULL) { |
16a28ef21 IOMUX: Add consol... |
791 |
/* need to set a console if not done above. */ |
5f0320108 common/console: a... |
792 |
console_doenv(stderr, errdev); |
47d1a6e1e Initial revision |
793 794 |
} if (inputdev != NULL) { |
16a28ef21 IOMUX: Add consol... |
795 |
/* need to set a console if not done above. */ |
5f0320108 common/console: a... |
796 |
console_doenv(stdin, inputdev); |
47d1a6e1e Initial revision |
797 |
} |
b02654294 console: Don't en... |
798 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
799 800 |
done: #endif |
78c112c9f console: Enable f... |
801 |
#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
7e3be7cf3 console: unify pr... |
802 |
stdio_print_current_devices(); |
78c112c9f console: Enable f... |
803 |
#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
a2931b30d dm: video: Add a ... |
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 Initial revision |
809 |
|
6d0f6bcf3 rename CFG_ macro... |
810 |
#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE |
47d1a6e1e Initial revision |
811 812 |
/* set the environment variables (will overwrite previous env settings) */ for (i = 0; i < 3; i++) { |
382bee57f env: Rename seten... |
813 |
env_set(stdio_names[i], stdio_devices[i]->name); |
47d1a6e1e Initial revision |
814 |
} |
6d0f6bcf3 rename CFG_ macro... |
815 |
#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ |
47d1a6e1e Initial revision |
816 |
|
c4e0057fa env: Refactor do_... |
817 |
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
47d1a6e1e Initial revision |
818 819 820 |
#if 0 /* If nothing usable installed, use only the initial console */ if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
ec6f14994 common/console: c... |
821 |
return 0; |
47d1a6e1e Initial revision |
822 |
#endif |
276696675 console: Use pre-... |
823 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
ec6f14994 common/console: c... |
824 |
return 0; |
47d1a6e1e Initial revision |
825 |
} |
b02654294 console: Don't en... |
826 |
#else /* !CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |
47d1a6e1e Initial revision |
827 828 |
/* Called after the relocation - use desired console functions */ |
ec6f14994 common/console: c... |
829 |
int console_init_r(void) |
47d1a6e1e Initial revision |
830 |
{ |
52cb4d4fb stdio/device: rew... |
831 |
struct stdio_dev *inputdev = NULL, *outputdev = NULL; |
c1de7a6da devices: merge to... |
832 |
int i; |
52cb4d4fb stdio/device: rew... |
833 |
struct list_head *list = stdio_get_list(); |
c1de7a6da devices: merge to... |
834 |
struct list_head *pos; |
52cb4d4fb stdio/device: rew... |
835 |
struct stdio_dev *dev; |
47d1a6e1e Initial revision |
836 |
|
43e0a3dec common/console.c:... |
837 |
console_update_silent(); |
d791b1dc3 * Make sure Block... |
838 |
#ifdef CONFIG_SPLASH_SCREEN |
ec6f14994 common/console: c... |
839 840 |
/* * suppress all output if splash screen is enabled and we have |
a74908161 console.c: fix pr... |
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 common/console: c... |
844 |
*/ |
00caae6d4 env: Rename geten... |
845 |
if (env_get("splashimage") != NULL) { |
a74908161 console.c: fix pr... |
846 847 848 |
if (!(gd->flags & GD_FLG_SILENT)) outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); } |
f72da3406 Added config opti... |
849 |
#endif |
47d1a6e1e Initial revision |
850 |
/* Scan devices looking for input and output devices */ |
c1de7a6da devices: merge to... |
851 |
list_for_each(pos, list) { |
52cb4d4fb stdio/device: rew... |
852 |
dev = list_entry(pos, struct stdio_dev, list); |
47d1a6e1e Initial revision |
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 devices: merge to... |
860 861 |
if(inputdev && outputdev) break; |
47d1a6e1e Initial revision |
862 863 864 865 |
} /* Initializes output console first */ if (outputdev != NULL) { |
ec6f14994 common/console: c... |
866 867 |
console_setfile(stdout, outputdev); console_setfile(stderr, outputdev); |
b02654294 console: Don't en... |
868 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
869 870 871 |
console_devices[stdout][0] = outputdev; console_devices[stderr][0] = outputdev; #endif |
47d1a6e1e Initial revision |
872 873 874 875 |
} /* Initializes input console */ if (inputdev != NULL) { |
ec6f14994 common/console: c... |
876 |
console_setfile(stdin, inputdev); |
b02654294 console: Don't en... |
877 |
#if CONFIG_IS_ENABLED(CONSOLE_MUX) |
16a28ef21 IOMUX: Add consol... |
878 879 |
console_devices[stdin][0] = inputdev; #endif |
47d1a6e1e Initial revision |
880 |
} |
78c112c9f console: Enable f... |
881 |
#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET |
7e3be7cf3 console: unify pr... |
882 |
stdio_print_current_devices(); |
78c112c9f console: Enable f... |
883 |
#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ |
47d1a6e1e Initial revision |
884 885 886 |
/* Setting environment variables */ for (i = 0; i < 3; i++) { |
382bee57f env: Rename seten... |
887 |
env_set(stdio_names[i], stdio_devices[i]->name); |
47d1a6e1e Initial revision |
888 |
} |
c4e0057fa env: Refactor do_... |
889 |
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ |
47d1a6e1e Initial revision |
890 891 892 |
#if 0 /* If nothing usable installed, use only the initial console */ if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) |
ec6f14994 common/console: c... |
893 |
return 0; |
47d1a6e1e Initial revision |
894 |
#endif |
276696675 console: Use pre-... |
895 |
print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL); |
ec6f14994 common/console: c... |
896 |
return 0; |
47d1a6e1e Initial revision |
897 |
} |
b02654294 console: Don't en... |
898 |
#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ |