powerpc: fix 8xx and 82xx type-punning warnings with GCC 4.7
[oweals/u-boot.git] / common / console.c
index 25b141a325a51d6b749d6cd4456cebda2054d3a5..bf7317869097a8bf84bf9929bacdf90ff8f693a3 100644 (file)
 #include <common.h>
 #include <stdarg.h>
 #include <malloc.h>
+#include <serial.h>
 #include <stdio_dev.h>
 #include <exports.h>
+#include <environment.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static int on_console(const char *name, const char *value, enum env_op op,
+       int flags)
+{
+       int console = -1;
+
+       /* Check for console redirection */
+       if (strcmp(name, "stdin") == 0)
+               console = stdin;
+       else if (strcmp(name, "stdout") == 0)
+               console = stdout;
+       else if (strcmp(name, "stderr") == 0)
+               console = stderr;
+
+       /* if not actually setting a console variable, we don't care */
+       if (console == -1 || (gd->flags & GD_FLG_DEVINIT) == 0)
+               return 0;
+
+       switch (op) {
+       case env_op_create:
+       case env_op_overwrite:
+
+#ifdef CONFIG_CONSOLE_MUX
+               if (iomux_doenv(console, value))
+                       return 1;
+#else
+               /* Try assigning specified device */
+               if (console_assign(console, value) < 0)
+                       return 1;
+#endif /* CONFIG_CONSOLE_MUX */
+               return 0;
+
+       case env_op_delete:
+               if ((flags & H_FORCE) == 0)
+                       printf("Can't delete \"%s\"\n", name);
+               return 1;
+
+       default:
+               return 0;
+       }
+}
+U_BOOT_ENV_CALLBACK(console, on_console);
+
+#ifdef CONFIG_SILENT_CONSOLE
+static int on_silent(const char *name, const char *value, enum env_op op,
+       int flags)
+{
+#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_SET
+       if (flags & H_INTERACTIVE)
+               return 0;
+#endif
+#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC
+       if ((flags & H_INTERACTIVE) == 0)
+               return 0;
+#endif
+
+       if (value != NULL)
+               gd->flags |= GD_FLG_SILENT;
+       else
+               gd->flags &= ~GD_FLG_SILENT;
+
+       return 0;
+}
+U_BOOT_ENV_CALLBACK(silent, on_silent);
+#endif
+
 #ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
 /*
  * if overwrite_console returns 1, the stdin, stderr and stdout
@@ -681,8 +748,6 @@ int console_init_r(void)
 done:
 #endif
 
-       gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
-
 #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
        stdio_print_current_devices();
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
@@ -694,6 +759,8 @@ done:
        }
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
+       gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
+
 #if 0
        /* If nothing usable installed, use only the initial console */
        if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
@@ -758,8 +825,6 @@ int console_init_r(void)
 #endif
        }
 
-       gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
-
 #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
        stdio_print_current_devices();
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
@@ -769,6 +834,8 @@ int console_init_r(void)
                setenv(stdio_names[i], stdio_devices[i]->name);
        }
 
+       gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
+
 #if 0
        /* If nothing usable installed, use only the initial console */
        if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))