]> git.sur5r.net Git - u-boot/blobdiff - common/console.c
Merge branch 'master' of git://git.denx.de/u-boot-socfpga
[u-boot] / common / console.c
index d763f2c68460df82aae6ce933823835b0e419200..2ba33dc5740240092e04883c5393f6b731ad51ad 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000
  * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -489,6 +488,13 @@ static inline void print_pre_console_buffer(int flushpoint) {}
 
 void putc(const char c)
 {
+#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
 #ifdef CONFIG_DEBUG_UART
        /* if we don't have a console yet, use the debug UART */
        if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
@@ -496,8 +502,10 @@ void putc(const char c)
                return;
        }
 #endif
+       if (!gd)
+               return;
 #ifdef CONFIG_CONSOLE_RECORD
-       if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start)
+       if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
                membuff_putbyte(&gd->console_out, c);
 #endif
 #ifdef CONFIG_SILENT_CONSOLE
@@ -535,8 +543,10 @@ void puts(const char *s)
                return;
        }
 #endif
+       if (!gd)
+               return;
 #ifdef CONFIG_CONSOLE_RECORD
-       if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start)
+       if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
                membuff_put(&gd->console_out, s, strlen(s));
 #endif
 #ifdef CONFIG_SILENT_CONSOLE
@@ -840,7 +850,7 @@ done:
 
 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
        /* set the environment variables (will overwrite previous env settings) */
-       for (i = 0; i < 3; i++) {
+       for (i = 0; i < MAX_FILES; i++) {
                env_set(stdio_names[i], stdio_devices[i]->name);
        }
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
@@ -919,7 +929,7 @@ int console_init_r(void)
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 
        /* Setting environment variables */
-       for (i = 0; i < 3; i++) {
+       for (i = 0; i < MAX_FILES; i++) {
                env_set(stdio_names[i], stdio_devices[i]->name);
        }