From patchwork Tue Apr 21 22:02:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 463525 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 72C451402E8 for ; Wed, 22 Apr 2015 08:06:05 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF9A439B3; Wed, 22 Apr 2015 00:05:41 +0200 (CEST) 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 jPWXWUsFWo-w; Wed, 22 Apr 2015 00:05:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1402039D9; Wed, 22 Apr 2015 00:05:18 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 445B9B37C8 for ; Wed, 22 Apr 2015 00:05:02 +0200 (CEST) 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 oyY2jPrLeTkb for ; Wed, 22 Apr 2015 00:05:02 +0200 (CEST) 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 ni.com (skprod3.natinst.com [130.164.80.24]) by theia.denx.de (Postfix) with ESMTPS id BB3D0B37B5 for ; Wed, 22 Apr 2015 00:05:01 +0200 (CEST) Received: from us-aus-mgwout2.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod3.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t3LM4s09002259; Tue, 21 Apr 2015 17:04:54 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout2.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015042117045481-104434 ; Tue, 21 Apr 2015 17:04:54 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Tue, 21 Apr 2015 17:02:50 -0500 Message-Id: <1429653771-11676-11-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1429653771-11676-1-git-send-email-joe.hershberger@ni.com> References: <1429653771-11676-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/21/2015 05:04:54 PM, Serialize by Router on US-AUS-MGWOut2/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/21/2015 05:04:54 PM, Serialize complete at 04/21/2015 05:04:54 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-04-21_07:, , signatures=0 Cc: Tom Rini , Jeroen Hofstee , Joe Hershberger Subject: [U-Boot] [PATCH 10/11] net: Use env callbacks for net variables X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Instead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-) diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -37,6 +37,26 @@ #define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif + /* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. @@ -44,7 +64,7 @@ #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \ diff --git a/net/net.c b/net/net.c index a365df0..57111ad 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile); +static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void) static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);