[U-Boot] [RFC PATCH v2 5/5] env: Add a console env handler
Joe Hershberger
joe.hershberger at ni.com
Fri Sep 28 00:47:40 CEST 2012
Remove the hard-coded console handler and use a callback instead
Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---
common/cmd_nvedit.c | 31 -------------------------------
common/console.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
include/env_callback.h | 1 +
3 files changed, 47 insertions(+), 31 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 652e8ce..6a6421a 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -190,7 +190,6 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
int _do_env_set(int flag, int argc, char * const argv[])
{
int i, len;
- int console = -1;
char *name, *value, *s;
ENTRY e, *ep;
@@ -210,36 +209,6 @@ int _do_env_set(int flag, int argc, char * const argv[])
e.data = NULL;
hsearch_r(e, FIND, &ep, &env_htab);
- /* 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) {
- if (argc < 3) { /* Cannot delete it! */
- printf("Can't delete \"%s\"\n", name);
- return 1;
- }
-
-#ifdef CONFIG_CONSOLE_MUX
- i = iomux_doenv(console, argv[2]);
- if (i)
- return i;
-#else
- /* Try assigning specified device */
- if (console_assign(console, argv[2]) < 0)
- return 1;
-
-#ifdef CONFIG_SERIAL_MULTI
- if (serial_assign(argv[2]) < 0)
- return 1;
-#endif
-#endif /* CONFIG_CONSOLE_MUX */
- }
-
/*
* Some variables like "ethaddr" and "serial#" can be set only
* once and cannot be deleted; also, "ver" is readonly.
diff --git a/common/console.c b/common/console.c
index 1177f7d..18b4fcc 100644
--- a/common/console.c
+++ b/common/console.c
@@ -26,9 +26,55 @@
#include <malloc.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 console = -1;
+#ifdef CONFIG_CONSOLE_MUX
+ int retval;
+#endif
+
+ /* 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;
+
+ switch (op) {
+ case env_op_create:
+ case env_op_overwrite:
+
+#ifdef CONFIG_CONSOLE_MUX
+ retval = iomux_doenv(console, value);
+ if (retval)
+ return retval;
+#else
+ /* Try assigning specified device */
+ if (console_assign(console, value) < 0)
+ return 1;
+
+#ifdef CONFIG_SERIAL_MULTI
+ if (serial_assign(value) < 0)
+ return 1;
+#endif
+#endif /* CONFIG_CONSOLE_MUX */
+ return 0;
+
+ case env_op_delete:
+ 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
diff --git a/include/env_callback.h b/include/env_callback.h
index d399b39..0a50268 100644
--- a/include/env_callback.h
+++ b/include/env_callback.h
@@ -37,6 +37,7 @@
*/
#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
"loadaddr:loadaddr,bootfile:bootfile,baudrate:baudrate," \
+ "stdin:console,stdout:console,stderr:console," \
CONFIG_ENV_CALLBACK_LIST_STATIC
enum env_op {
--
1.7.11.5
More information about the U-Boot
mailing list