summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2012-12-11 22:16:29 -0600
committerTom Rini <trini@ti.com>2012-12-13 11:46:56 -0700
commit849d5d9cda0e7c94797874d842e9b132ec45a565 (patch)
tree8de27e77e039a17b169a9fa080a09c9f5d0a8a06 /common/console.c
parent1cf0a8b2fbe38ed07b1babaaacfc22bd427f66f0 (diff)
downloadtalos-obmc-uboot-849d5d9cda0e7c94797874d842e9b132ec45a565.tar.gz
talos-obmc-uboot-849d5d9cda0e7c94797874d842e9b132ec45a565.zip
env: Add a console env handler
Remove the hard-coded console handler and use a callback instead Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index c21934d1b8..270170b3dd 100644
--- a/common/console.c
+++ b/common/console.c
@@ -24,11 +24,55 @@
#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
OpenPOWER on IntegriCloud