env: Move env_set() to env.h
[oweals/u-boot.git] / common / console.c
index 0b0dd76256c7c865668add13a2ae89eb1530cb3f..0f7e0916cd2f5416a5921da85e2c8db4c39e9d82 100644 (file)
@@ -8,6 +8,7 @@
 #include <console.h>
 #include <debug_uart.h>
 #include <dm.h>
+#include <env.h>
 #include <stdarg.h>
 #include <iomux.h>
 #include <malloc.h>
@@ -463,6 +464,11 @@ static void print_pre_console_buffer(int flushpoint)
        char buf_out[CONFIG_PRE_CON_BUF_SZ + 1];
        char *buf_in;
 
+#ifdef CONFIG_SILENT_CONSOLE
+       if (gd->flags & GD_FLG_SILENT)
+               return;
+#endif
+
        buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ);
        if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
                in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
@@ -511,8 +517,11 @@ void putc(const char c)
                membuff_putbyte(&gd->console_out, c);
 #endif
 #ifdef CONFIG_SILENT_CONSOLE
-       if (gd->flags & GD_FLG_SILENT)
+       if (gd->flags & GD_FLG_SILENT) {
+               if (!(gd->flags & GD_FLG_DEVINIT))
+                       pre_console_putc(c);
                return;
+       }
 #endif
 
 #ifdef CONFIG_DISABLE_CONSOLE
@@ -559,8 +568,11 @@ void puts(const char *s)
                membuff_put(&gd->console_out, s, strlen(s));
 #endif
 #ifdef CONFIG_SILENT_CONSOLE
-       if (gd->flags & GD_FLG_SILENT)
+       if (gd->flags & GD_FLG_SILENT) {
+               if (!(gd->flags & GD_FLG_DEVINIT))
+                       pre_console_puts(s);
                return;
+       }
 #endif
 
 #ifdef CONFIG_DISABLE_CONSOLE
@@ -720,14 +732,22 @@ int console_assign(int file, const char *devname)
        return -1;
 }
 
-static void console_update_silent(void)
+/* return true if the 'silent' flag is removed */
+static bool console_update_silent(void)
 {
 #ifdef CONFIG_SILENT_CONSOLE
-       if (env_get("silent") != NULL)
+       if (env_get("silent")) {
                gd->flags |= GD_FLG_SILENT;
-       else
+       } else {
+               unsigned long flags = gd->flags;
+
                gd->flags &= ~GD_FLG_SILENT;
+
+               return !!(flags & GD_FLG_SILENT);
+       }
 #endif
+
+       return false;
 }
 
 int console_announce_r(void)
@@ -792,6 +812,13 @@ int console_init_r(void)
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
        int iomux_err = 0;
 #endif
+       int flushpoint;
+
+       /* update silent for env loaded from flash (initr_env) */
+       if (console_update_silent())
+               flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL;
+       else
+               flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL;
 
        /* set default handlers at first */
        gd->jt->getc  = serial_getc;
@@ -869,7 +896,7 @@ done:
        if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
                return 0;
 #endif
-       print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
+       print_pre_console_buffer(flushpoint);
        return 0;
 }
 
@@ -883,8 +910,13 @@ int console_init_r(void)
        struct list_head *list = stdio_get_list();
        struct list_head *pos;
        struct stdio_dev *dev;
+       int flushpoint;
 
-       console_update_silent();
+       /* update silent for env loaded from flash (initr_env) */
+       if (console_update_silent())
+               flushpoint = PRE_CONSOLE_FLUSHPOINT1_SERIAL;
+       else
+               flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL;
 
 #ifdef CONFIG_SPLASH_SCREEN
        /*
@@ -947,7 +979,7 @@ int console_init_r(void)
        if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
                return 0;
 #endif
-       print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL);
+       print_pre_console_buffer(flushpoint);
        return 0;
 }