From patchwork Wed Dec 12 04:16:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 205364 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 75E9C2C008C for ; Wed, 12 Dec 2012 15:18:46 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 16F064A1C3; Wed, 12 Dec 2012 05:18:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Stru35Lz6A4X; Wed, 12 Dec 2012 05:18:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B464C4A1E5; Wed, 12 Dec 2012 05:18:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A46D84A1BA for ; Wed, 12 Dec 2012 05:17:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iWUwbGcFMccm for ; Wed, 12 Dec 2012 05:17:34 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller05.natinst.com (mailserver5.natinst.com [130.164.80.5]) by theia.denx.de (Postfix) with ESMTP id 10D644A1A7 for ; Wed, 12 Dec 2012 05:17:24 +0100 (CET) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller05.natinst.com (8.14.5/8.14.5) with ESMTP id qBC4HG0s022951; Tue, 11 Dec 2012 22:17:16 -0600 Received: from linux-xvxi.natinst.com ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.3FP2 HF169) with ESMTP id 2012121122171666-310427 ; Tue, 11 Dec 2012 22:17:16 -0600 From: Joe Hershberger To: u-boot@lists.denx.de Date: Tue, 11 Dec 2012 22:16:29 -0600 Message-Id: <1355285797-27051-13-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1355285797-27051-1-git-send-email-joe.hershberger@ni.com> References: <1354672367-23747-1-git-send-email-joe.hershberger@ni.com> <1355285797-27051-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 12/11/2012 10:17:16 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.3FP2 HF169|September 14, 2012) at 12/11/2012 10:17:16 PM, Serialize complete at 12/11/2012 10:17:16 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327, 1.0.431, 0.0.0000 definitions=2012-12-12_01:2012-12-12, 2012-12-12, 1970-01-01 signatures=0 Cc: Tom Rini , Joe Hershberger , Gerlando Falauto Subject: [U-Boot] [PATCH v5 12/20] env: Add a console env handler X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Remove the hard-coded console handler and use a callback instead Signed-off-by: Joe Hershberger --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None common/cmd_nvedit.c | 36 +++--------------------------------- common/console.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 1 + 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 9ff8b36..cb191cd 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -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 /* diff --git a/common/console.c b/common/console.c index 880acd9..549d379 100644 --- a/common/console.c +++ b/common/console.c @@ -24,11 +24,55 @@ #include #include #include +#include #include #include +#include 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 diff --git a/include/env_callback.h b/include/env_callback.h index bb398ec..9d2d2c9 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 {