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