]> git.sur5r.net Git - u-boot/blobdiff - common/console.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / common / console.c
index ec4af3bd90dfdca971b912ec65034d46754d024c..2688af56e1582ad2f2330477010c112533eeb279 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>
@@ -68,11 +67,11 @@ U_BOOT_ENV_CALLBACK(console, on_console);
 static int on_silent(const char *name, const char *value, enum env_op op,
        int flags)
 {
-#if !CONFIG_IS_ENABLED(CONFIG_SILENT_CONSOLE_UPDATE_ON_SET)
+#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)
        if (flags & H_INTERACTIVE)
                return 0;
 #endif
-#if !CONFIG_IS_ENABLED(CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC)
+#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)
        if ((flags & H_INTERACTIVE) == 0)
                return 0;
 #endif
@@ -450,6 +449,12 @@ static void pre_console_putc(const char c)
        unmap_sysmem(buffer);
 }
 
+static void pre_console_puts(const char *s)
+{
+       while (*s)
+               pre_console_putc(*s++);
+}
+
 static void print_pre_console_buffer(int flushpoint)
 {
        unsigned long in = 0, out = 0;
@@ -477,11 +482,19 @@ static void print_pre_console_buffer(int flushpoint)
 }
 #else
 static inline void pre_console_putc(const char c) {}
+static inline void pre_console_puts(const char *s) {}
 static inline void print_pre_console_buffer(int flushpoint) {}
 #endif
 
 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)) {
@@ -518,8 +531,41 @@ void putc(const char c)
 
 void puts(const char *s)
 {
-       while (*s)
-               putc(*s++);
+#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);
+       }
 }
 
 #ifdef CONFIG_CONSOLE_RECORD
@@ -666,7 +712,7 @@ int console_assign(int file, const char *devname)
 static void console_update_silent(void)
 {
 #ifdef CONFIG_SILENT_CONSOLE
-       if (getenv("silent") != NULL)
+       if (env_get("silent") != NULL)
                gd->flags |= GD_FLG_SILENT;
        else
                gd->flags &= ~GD_FLG_SILENT;
@@ -745,9 +791,9 @@ int console_init_r(void)
 
        /* stdin stdout and stderr are in environment */
        /* scan for it */
-       stdinname  = getenv("stdin");
-       stdoutname = getenv("stdout");
-       stderrname = getenv("stderr");
+       stdinname  = env_get("stdin");
+       stdoutname = env_get("stdout");
+       stderrname = env_get("stderr");
 
        if (OVERWRITE_CONSOLE == 0) {   /* if not overwritten by config switch */
                inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
@@ -800,8 +846,8 @@ done:
 
 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
        /* set the environment variables (will overwrite previous env settings) */
-       for (i = 0; i < 3; i++) {
-               setenv(stdio_names[i], stdio_devices[i]->name);
+       for (i = 0; i < MAX_FILES; i++) {
+               env_set(stdio_names[i], stdio_devices[i]->name);
        }
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
@@ -836,7 +882,7 @@ int console_init_r(void)
         * console to serial console in this case or suppress it if
         * "silent" mode was requested.
         */
-       if (getenv("splashimage") != NULL) {
+       if (env_get("splashimage") != NULL) {
                if (!(gd->flags & GD_FLG_SILENT))
                        outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
        }
@@ -879,8 +925,8 @@ int console_init_r(void)
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 
        /* Setting environment variables */
-       for (i = 0; i < 3; i++) {
-               setenv(stdio_names[i], stdio_devices[i]->name);
+       for (i = 0; i < MAX_FILES; i++) {
+               env_set(stdio_names[i], stdio_devices[i]->name);
        }
 
        gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */