]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
env: Add a console env handler
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 12 Dec 2012 04:16:29 +0000 (22:16 -0600)
committerTom Rini <trini@ti.com>
Thu, 13 Dec 2012 18:46:56 +0000 (11:46 -0700)
Remove the hard-coded console handler and use a callback instead

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
common/cmd_nvedit.c
common/console.c
include/env_callback.h

index 9ff8b36d3eac36737c7a021e334ea4d61b0db18a..cb191cd0637c14332b609b8e8519d38afec388e1 100644 (file)
@@ -47,7 +47,6 @@
 #include <errno.h>
 #include <malloc.h>
 #include <watchdog.h>
-#include <serial.h>
 #include <linux/stddef.h>
 #include <asm/byteorder.h>
 
@@ -206,10 +205,9 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
 int env_change_ok(const ENTRY *item, const char *newval, enum env_op op,
        int flag)
 {
-       int   console = -1;
+#ifndef CONFIG_ENV_OVERWRITE
        const char *name;
-#if !defined(CONFIG_ENV_OVERWRITE) && defined(CONFIG_OVERWRITE_ETHADDR_ONCE) \
-&& defined(CONFIG_ETHADDR)
+#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
        const char *oldval = NULL;
 
        if (op != env_op_create)
@@ -217,35 +215,7 @@ int env_change_ok(const ENTRY *item, const char *newval, enum env_op op,
 #endif
 
        name = item->key;
-
-       /* Default value for NULL to protect string-manipulating functions */
-       newval = newval ? : "";
-
-       /* 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 (console != -1 && (gd->flags & GD_FLG_DEVINIT) != 0) {
-               if ((newval == NULL) || (*newval == '\0')) {
-                       /* We cannot delete stdin/stdout/stderr */
-                       if ((flag & H_FORCE) == 0)
-                               printf("Can't delete \"%s\"\n", name);
-                       return 1;
-               }
-
-#ifdef CONFIG_CONSOLE_MUX
-               if (iomux_doenv(console, newval))
-                       return 1;
-#else
-               /* Try assigning specified device */
-               if (console_assign(console, newval) < 0)
-                       return 1;
-#endif /* CONFIG_CONSOLE_MUX */
-       }
+#endif
 
 #ifndef CONFIG_ENV_OVERWRITE
        /*
index c21934d1b8aa9160734f2e73d4078e63ed6d7fb7..270170b3ddff6e3f57ef8903d657cbce39dc0ed9 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_SYS_CONSOLE_IS_IN_ENV
 /*
  * if overwrite_console returns 1, the stdin, stderr and stdout
index bb398ec57458620e1cd006d30960d249241259cb..9d2d2c9bf6c0d7cbc507d835ff04215440bda14a 100644 (file)
@@ -42,6 +42,7 @@
        "baudrate:baudrate," \
        "bootfile:bootfile," \
        "loadaddr:loadaddr," \
+       "stdin:console,stdout:console,stderr:console," \
        CONFIG_ENV_CALLBACK_LIST_STATIC
 
 struct env_clbk_tbl {