1 // SPDX-License-Identifier: GPL-2.0+
4 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
9 #include <debug_uart.h>
10 #include <display_options.h>
19 #include <stdio_dev.h>
21 #include <env_internal.h>
23 #include <asm/global_data.h>
24 #include <linux/delay.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 static int on_console(const char *name, const char *value, enum env_op op,
33 /* Check for console redirection */
34 if (strcmp(name, "stdin") == 0)
36 else if (strcmp(name, "stdout") == 0)
38 else if (strcmp(name, "stderr") == 0)
41 /* if not actually setting a console variable, we don't care */
42 if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0)
47 case env_op_overwrite:
49 if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
50 if (iomux_doenv(console, value))
53 /* Try assigning specified device */
54 if (console_assign(console, value) < 0)
61 if ((flags & H_FORCE) == 0)
62 printf("Can't delete \"%s\"\n", name);
69 U_BOOT_ENV_CALLBACK(console, on_console);
71 #ifdef CONFIG_SILENT_CONSOLE
72 static int on_silent(const char *name, const char *value, enum env_op op,
75 if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET))
76 if (flags & H_INTERACTIVE)
79 if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC))
80 if ((flags & H_INTERACTIVE) == 0)
84 gd->flags |= GD_FLG_SILENT;
86 gd->flags &= ~GD_FLG_SILENT;
90 U_BOOT_ENV_CALLBACK(silent, on_silent);
93 #ifdef CONFIG_CONSOLE_RECORD
94 /* helper function: access to gd->console_out and gd->console_in */
95 static void console_record_putc(const char c)
97 if (!(gd->flags & GD_FLG_RECORD))
99 if (gd->console_out.start &&
100 !membuff_putbyte((struct membuff *)&gd->console_out, c))
101 gd->flags |= GD_FLG_RECORD_OVF;
104 static void console_record_puts(const char *s)
106 if (!(gd->flags & GD_FLG_RECORD))
108 if (gd->console_out.start) {
111 if (membuff_put((struct membuff *)&gd->console_out, s, len) !=
113 gd->flags |= GD_FLG_RECORD_OVF;
117 static int console_record_getc(void)
119 if (!(gd->flags & GD_FLG_RECORD))
121 if (!gd->console_in.start)
124 return membuff_getbyte((struct membuff *)&gd->console_in);
127 static int console_record_tstc(void)
129 if (!(gd->flags & GD_FLG_RECORD))
131 if (gd->console_in.start) {
132 if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1)
138 static void console_record_putc(char c)
142 static void console_record_puts(const char *s)
146 static int console_record_getc(void)
151 static int console_record_tstc(void)
157 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
159 * if overwrite_console returns 1, the stdin, stderr and stdout
160 * are switched to the serial port, else the settings in the
161 * environment are used
163 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
164 extern int overwrite_console(void);
165 #define OVERWRITE_CONSOLE overwrite_console()
167 #define OVERWRITE_CONSOLE 0
168 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
170 #endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */
172 static int console_setfile(int file, struct stdio_dev * dev)
183 error = console_start(file, dev);
187 /* Assign the new device (leaving the existing one started) */
188 stdio_devices[file] = dev;
191 * Update monitor functions
192 * (to use the console stuff by other applications)
196 gd->jt->getc = getchar;
202 gd->jt->printf = printf;
207 default: /* Invalid file ID */
214 * console_dev_is_serial() - Check if a stdio device is a serial device
216 * @sdev: Device to check
217 * Return: true if this device is in the serial uclass (or for pre-driver-model,
218 * whether it is called "serial".
220 static bool console_dev_is_serial(struct stdio_dev *sdev)
224 if (IS_ENABLED(CONFIG_DM_SERIAL) && (sdev->flags & DEV_FLAGS_DM)) {
225 struct udevice *dev = sdev->priv;
227 is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL;
229 is_serial = !strcmp(sdev->name, "serial");
235 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
236 /** Console I/O multiplexing *******************************************/
238 /* tstcdev: save the last stdio device with pending characters, with tstc != 0 */
239 static struct stdio_dev *tstcdev;
240 struct stdio_dev **console_devices[MAX_FILES];
241 int cd_count[MAX_FILES];
243 static void console_devices_set(int file, struct stdio_dev *dev)
245 console_devices[file][0] = dev;
250 * console_needs_start_stop() - check if we need to start or stop the STDIO device
252 * @sdev: STDIO device in question
254 * This function checks if we need to start or stop the stdio device used for
255 * a console. For IOMUX case it simply enforces one time start and one time
256 * stop of the device independently of how many STDIO files are using it. In
257 * other words, we start console once before first STDIO device wants it and
258 * stop after the last is gone.
260 static bool console_needs_start_stop(int file, struct stdio_dev *sdev)
264 for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
268 if (iomux_match_device(console_devices[i], cd_count[i], sdev) >= 0)
275 * This depends on tstc() always being called before getchar().
276 * This is guaranteed to be true because this routine is called
277 * only from fgetc() which assures it.
278 * No attempt is made to demultiplex multiple input sources.
280 static int console_getc(int file)
284 /* This is never called with testcdev == NULL */
285 ret = tstcdev->getc(tstcdev);
290 /* Upper layer may have already called tstc(): check the saved result */
291 static bool console_has_tstc(void)
296 static int console_tstc(int file)
299 struct stdio_dev *dev;
302 prev = disable_ctrlc(1);
303 for_each_console_dev(i, file, dev) {
304 if (dev->tstc != NULL) {
305 ret = dev->tstc(dev);
318 static void console_putc(int file, const char c)
321 struct stdio_dev *dev;
323 for_each_console_dev(i, file, dev) {
324 if (dev->putc != NULL)
330 * console_puts_select() - Output a string to all console devices
332 * @file: File number to output to (e,g, stdout, see stdio.h)
333 * @serial_only: true to output only to serial, false to output to everything
335 * @s: String to output
337 static void console_puts_select(int file, bool serial_only, const char *s)
340 struct stdio_dev *dev;
342 for_each_console_dev(i, file, dev) {
343 bool is_serial = console_dev_is_serial(dev);
345 if (dev->puts && serial_only == is_serial)
350 void console_puts_select_stderr(bool serial_only, const char *s)
352 if (gd->flags & GD_FLG_DEVINIT)
353 console_puts_select(stderr, serial_only, s);
356 static void console_puts(int file, const char *s)
359 struct stdio_dev *dev;
361 for_each_console_dev(i, file, dev) {
362 if (dev->puts != NULL)
367 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
368 static inline void console_doenv(int file, struct stdio_dev *dev)
370 iomux_doenv(file, dev->name);
375 static void console_devices_set(int file, struct stdio_dev *dev)
379 static inline bool console_needs_start_stop(int file, struct stdio_dev *sdev)
384 static inline int console_getc(int file)
386 return stdio_devices[file]->getc(stdio_devices[file]);
389 static bool console_has_tstc(void)
394 static inline int console_tstc(int file)
396 return stdio_devices[file]->tstc(stdio_devices[file]);
399 static inline void console_putc(int file, const char c)
401 stdio_devices[file]->putc(stdio_devices[file], c);
404 void console_puts_select(int file, bool serial_only, const char *s)
406 if ((gd->flags & GD_FLG_DEVINIT) &&
407 serial_only == console_dev_is_serial(stdio_devices[file]))
408 stdio_devices[file]->puts(stdio_devices[file], s);
411 static inline void console_puts(int file, const char *s)
413 stdio_devices[file]->puts(stdio_devices[file], s);
416 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
417 static inline void console_doenv(int file, struct stdio_dev *dev)
419 console_setfile(file, dev);
422 #endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */
424 static void __maybe_unused console_setfile_and_devices(int file, struct stdio_dev *dev)
426 console_setfile(file, dev);
427 console_devices_set(file, dev);
430 int console_start(int file, struct stdio_dev *sdev)
434 if (!console_needs_start_stop(file, sdev))
437 /* Start new device */
439 error = sdev->start(sdev);
440 /* If it's not started don't use it */
447 void console_stop(int file, struct stdio_dev *sdev)
449 if (!console_needs_start_stop(file, sdev))
456 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
458 int serial_printf(const char *fmt, ...)
462 char printbuffer[CONFIG_SYS_PBSIZE];
466 /* For this to work, printbuffer must be larger than
467 * anything we ever want to print.
469 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
472 serial_puts(printbuffer);
478 if (file < MAX_FILES) {
480 * Effectively poll for input wherever it may be available.
484 if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
486 * Upper layer may have already called tstc() so
487 * check for that first.
489 if (console_has_tstc())
490 return console_getc(file);
493 if (console_tstc(file))
494 return console_getc(file);
498 * If the watchdog must be rate-limited then it should
499 * already be handled in board-specific code.
501 if (IS_ENABLED(CONFIG_WATCHDOG))
511 if (file < MAX_FILES)
512 return console_tstc(file);
517 void fputc(int file, const char c)
519 if (file < MAX_FILES)
520 console_putc(file, c);
523 void fputs(int file, const char *s)
525 if (file < MAX_FILES)
526 console_puts(file, s);
529 int fprintf(int file, const char *fmt, ...)
533 char printbuffer[CONFIG_SYS_PBSIZE];
537 /* For this to work, printbuffer must be larger than
538 * anything we ever want to print.
540 i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
543 /* Send to desired file */
544 fputs(file, printbuffer);
548 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
554 if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
557 if (!gd->have_console)
560 ch = console_record_getc();
564 if (gd->flags & GD_FLG_DEVINIT) {
565 /* Get from the standard input */
569 /* Send directly to the handler */
570 return serial_getc();
575 if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
578 if (!gd->have_console)
581 if (console_record_tstc())
584 if (gd->flags & GD_FLG_DEVINIT) {
585 /* Test the standard input */
589 /* Send directly to the handler */
590 return serial_tstc();
593 #define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0
594 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1
596 #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
597 #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_VAL(PRE_CON_BUF_SZ))
599 static void pre_console_putc(const char c)
603 buffer = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), CONFIG_VAL(PRE_CON_BUF_SZ));
605 buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
607 unmap_sysmem(buffer);
610 static void pre_console_puts(const char *s)
613 pre_console_putc(*s++);
616 static void print_pre_console_buffer(int flushpoint)
618 unsigned long in = 0, out = 0;
619 char buf_out[CONFIG_VAL(PRE_CON_BUF_SZ) + 1];
622 if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT))
625 buf_in = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), CONFIG_VAL(PRE_CON_BUF_SZ));
626 if (gd->precon_buf_idx > CONFIG_VAL(PRE_CON_BUF_SZ))
627 in = gd->precon_buf_idx - CONFIG_VAL(PRE_CON_BUF_SZ);
629 while (in < gd->precon_buf_idx)
630 buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)];
631 unmap_sysmem(buf_in);
635 switch (flushpoint) {
636 case PRE_CONSOLE_FLUSHPOINT1_SERIAL:
639 case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL:
640 console_puts_select(stdout, false, buf_out);
645 static inline void pre_console_putc(const char c) {}
646 static inline void pre_console_puts(const char *s) {}
647 static inline void print_pre_console_buffer(int flushpoint) {}
650 void putc(const char c)
655 console_record_putc(c);
657 /* sandbox can send characters to stdout before it has a console */
658 if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
663 /* if we don't have a console yet, use the debug UART */
664 if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) {
669 if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) {
670 if (!(gd->flags & GD_FLG_DEVINIT))
675 if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
678 if (!gd->have_console)
679 return pre_console_putc(c);
681 if (gd->flags & GD_FLG_DEVINIT) {
682 /* Send to the standard output */
685 /* Send directly to the handler */
691 void puts(const char *s)
696 console_record_puts(s);
698 /* sandbox can send characters to stdout before it has a console */
699 if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
704 if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) {
713 if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) {
714 if (!(gd->flags & GD_FLG_DEVINIT))
719 if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
722 if (!gd->have_console)
723 return pre_console_puts(s);
725 if (gd->flags & GD_FLG_DEVINIT) {
726 /* Send to the standard output */
729 /* Send directly to the handler */
735 #ifdef CONFIG_CONSOLE_RECORD
736 int console_record_init(void)
740 ret = membuff_new((struct membuff *)&gd->console_out,
741 gd->flags & GD_FLG_RELOC ?
742 CONFIG_CONSOLE_RECORD_OUT_SIZE :
743 CONFIG_CONSOLE_RECORD_OUT_SIZE_F);
746 ret = membuff_new((struct membuff *)&gd->console_in,
747 CONFIG_CONSOLE_RECORD_IN_SIZE);
752 void console_record_reset(void)
754 membuff_purge((struct membuff *)&gd->console_out);
755 membuff_purge((struct membuff *)&gd->console_in);
756 gd->flags &= ~GD_FLG_RECORD_OVF;
759 int console_record_reset_enable(void)
761 console_record_reset();
762 gd->flags |= GD_FLG_RECORD;
767 int console_record_readline(char *str, int maxlen)
769 if (gd->flags & GD_FLG_RECORD_OVF)
772 return membuff_readline((struct membuff *)&gd->console_out, str,
776 int console_record_avail(void)
778 return membuff_avail((struct membuff *)&gd->console_out);
781 int console_in_puts(const char *str)
783 return membuff_put((struct membuff *)&gd->console_in, str, strlen(str));
788 /* test if ctrl-c was pressed */
789 static int ctrlc_disabled = 0; /* see disable_ctrl() */
790 static int ctrlc_was_pressed = 0;
793 if (!ctrlc_disabled && gd->have_console) {
796 case 0x03: /* ^C - Control C */
797 ctrlc_was_pressed = 1;
807 /* Reads user's confirmation.
808 Returns 1 if user's input is "y", "Y", "yes" or "YES"
810 int confirm_yesno(void)
819 while (i < sizeof(str_input)) {
820 str_input[i] = getchar();
822 if (str_input[i] == '\r')
827 if (strncmp(str_input, "y\r", 2) == 0 ||
828 strncmp(str_input, "Y\r", 2) == 0 ||
829 strncmp(str_input, "yes\r", 4) == 0 ||
830 strncmp(str_input, "YES\r", 4) == 0)
834 /* pass 1 to disable ctrlc() checking, 0 to enable.
835 * returns previous state
837 int disable_ctrlc(int disable)
839 int prev = ctrlc_disabled; /* save previous state */
841 ctrlc_disabled = disable;
847 return ctrlc_was_pressed;
850 void clear_ctrlc(void)
852 ctrlc_was_pressed = 0;
855 /** U-Boot INIT FUNCTIONS *************************************************/
857 struct stdio_dev *console_search_dev(int flags, const char *name)
859 struct stdio_dev *dev;
861 dev = stdio_get_by_name(name);
862 #ifdef CONFIG_VIDCONSOLE_AS_LCD
863 if (!dev && !strcmp(name, CONFIG_VIDCONSOLE_AS_NAME))
864 dev = stdio_get_by_name("vidconsole");
867 if (dev && (dev->flags & flags))
873 int console_assign(int file, const char *devname)
876 struct stdio_dev *dev;
878 /* Check for valid file */
879 flag = stdio_file_to_flags(file);
883 /* Check for valid device name */
885 dev = console_search_dev(flag, devname);
888 return console_setfile(file, dev);
893 /* return true if the 'silent' flag is removed */
894 static bool console_update_silent(void)
896 unsigned long flags = gd->flags;
898 if (!IS_ENABLED(CONFIG_SILENT_CONSOLE))
901 if (env_get("silent")) {
902 gd->flags |= GD_FLG_SILENT;
906 gd->flags &= ~GD_FLG_SILENT;
908 return !!(flags & GD_FLG_SILENT);
911 int console_announce_r(void)
913 #if !CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
914 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
916 display_options_get_banner(false, buf, sizeof(buf));
918 console_puts_select(stdout, false, buf);
924 /* Called before relocation - use serial functions */
925 int console_init_f(void)
927 gd->have_console = 1;
929 console_update_silent();
931 print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL);
936 void stdio_print_current_devices(void)
938 /* Print information */
940 if (stdio_devices[stdin] == NULL) {
941 puts("No input devices available!\n");
943 printf ("%s\n", stdio_devices[stdin]->name);
947 if (stdio_devices[stdout] == NULL) {
948 puts("No output devices available!\n");
950 printf ("%s\n", stdio_devices[stdout]->name);
954 if (stdio_devices[stderr] == NULL) {
955 puts("No error devices available!\n");
957 printf ("%s\n", stdio_devices[stderr]->name);
961 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
962 /* Called after the relocation - use desired console functions */
963 int console_init_r(void)
965 char *stdinname, *stdoutname, *stderrname;
966 struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
971 /* update silent for env loaded from flash (initr_env) */
972 if (console_update_silent())
973 flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL;
975 flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL;
977 /* set default handlers at first */
978 gd->jt->getc = serial_getc;
979 gd->jt->tstc = serial_tstc;
980 gd->jt->putc = serial_putc;
981 gd->jt->puts = serial_puts;
982 gd->jt->printf = serial_printf;
984 /* stdin stdout and stderr are in environment */
986 stdinname = env_get("stdin");
987 stdoutname = env_get("stdout");
988 stderrname = env_get("stderr");
990 if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
991 inputdev = console_search_dev(DEV_FLAGS_INPUT, stdinname);
992 outputdev = console_search_dev(DEV_FLAGS_OUTPUT, stdoutname);
993 errdev = console_search_dev(DEV_FLAGS_OUTPUT, stderrname);
994 if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
995 iomux_err = iomux_doenv(stdin, stdinname);
996 iomux_err += iomux_doenv(stdout, stdoutname);
997 iomux_err += iomux_doenv(stderr, stderrname);
999 /* Successful, so skip all the code below. */
1003 /* if the devices are overwritten or not found, use default device */
1004 if (inputdev == NULL) {
1005 inputdev = console_search_dev(DEV_FLAGS_INPUT, "serial");
1007 if (outputdev == NULL) {
1008 outputdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial");
1010 if (errdev == NULL) {
1011 errdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial");
1013 /* Initializes output console first */
1014 if (outputdev != NULL) {
1015 /* need to set a console if not done above. */
1016 console_doenv(stdout, outputdev);
1018 if (errdev != NULL) {
1019 /* need to set a console if not done above. */
1020 console_doenv(stderr, errdev);
1022 if (inputdev != NULL) {
1023 /* need to set a console if not done above. */
1024 console_doenv(stdin, inputdev);
1029 if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
1030 stdio_print_current_devices();
1032 #ifdef CONFIG_VIDCONSOLE_AS_LCD
1033 if (strstr(stdoutname, CONFIG_VIDCONSOLE_AS_NAME))
1034 printf("Warning: Please change '%s' to 'vidconsole' in stdout/stderr environment vars\n",
1035 CONFIG_VIDCONSOLE_AS_NAME);
1038 if (IS_ENABLED(CONFIG_SYS_CONSOLE_ENV_OVERWRITE)) {
1039 /* set the environment variables (will overwrite previous env settings) */
1040 for (i = 0; i < MAX_FILES; i++)
1041 env_set(stdio_names[i], stdio_devices[i]->name);
1044 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
1046 print_pre_console_buffer(flushpoint);
1050 #else /* !CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */
1052 /* Called after the relocation - use desired console functions */
1053 int console_init_r(void)
1055 struct stdio_dev *inputdev = NULL, *outputdev = NULL;
1057 struct list_head *list = stdio_get_list();
1058 struct list_head *pos;
1059 struct stdio_dev *dev;
1062 /* update silent for env loaded from flash (initr_env) */
1063 if (console_update_silent())
1064 flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL;
1066 flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL;
1069 * suppress all output if splash screen is enabled and we have
1070 * a bmp to display. We redirect the output from frame buffer
1071 * console to serial console in this case or suppress it if
1072 * "silent" mode was requested.
1074 if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && env_get("splashimage")) {
1075 if (!(gd->flags & GD_FLG_SILENT))
1076 outputdev = console_search_dev (DEV_FLAGS_OUTPUT, "serial");
1079 /* Scan devices looking for input and output devices */
1080 list_for_each(pos, list) {
1081 dev = list_entry(pos, struct stdio_dev, list);
1083 if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
1086 if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
1089 if(inputdev && outputdev)
1093 /* Initializes output console first */
1094 if (outputdev != NULL) {
1095 console_setfile_and_devices(stdout, outputdev);
1096 console_setfile_and_devices(stderr, outputdev);
1099 /* Initializes input console */
1100 if (inputdev != NULL)
1101 console_setfile_and_devices(stdin, inputdev);
1103 if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
1104 stdio_print_current_devices();
1106 /* Setting environment variables */
1107 for (i = 0; i < MAX_FILES; i++) {
1108 env_set(stdio_names[i], stdio_devices[i]->name);
1111 gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
1113 print_pre_console_buffer(flushpoint);
1117 #endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */