Patchwork [U-Boot,u-boot] net/net.c: Update ipaddr if the environment has changed

login
register
mail settings
Submitter Enric Balletbo i Serra
Date June 1, 2011, 7:01 a.m.
Message ID <1306911707-10564-1-git-send-email-eballetbo@iseebcn.com>
Download mbox | patch
Permalink /patch/98131/
State Accepted
Commit 23a70bf9c352ec5b6ac52d5be8087b963c2073dd
Delegated to: Wolfgang Denk
Headers show

Comments

Enric Balletbo i Serra - June 1, 2011, 7:01 a.m.
At least on ARM the ipaddr is only set in board_init_r function. The
problem is if ipaddr is not defined in environment importing another
environment defined don't update the ipaddr value.

For example, suppose we've a default environment without net variables
defined and we want to import an uEnv.txt environment from SD-card like
this:

  ipaddr=192.168.2.240
  netmask=255.255.255.0
  gatewayip=192.168.2.1
  serverip=192.168.2.114

Then if you try boot from NFS results in:

  Importing environment from mmc ...
  Running uenvcmd ...
  smc911x: detected LAN9221 controller
  smc911x: phy initialized
  smc911x: MAC ac:de:48:00:00:00
  *** ERROR: `ipaddr' not set

The ipaddr at this point is NULL beacause is only set at board_init_r
function. This patch updates the ipaddr value if the environment has
changed.

Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
---
 net/net.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Mike Frysinger - June 1, 2011, 3:21 p.m.
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
Wolfgang Denk - June 1, 2011, 8:18 p.m.
Dear Enric Balletbo i Serra,

In message <1306911707-10564-1-git-send-email-eballetbo@iseebcn.com> you wrote:
> At least on ARM the ipaddr is only set in board_init_r function. The
> problem is if ipaddr is not defined in environment importing another
> environment defined don't update the ipaddr value.
> 
> For example, suppose we've a default environment without net variables
> defined and we want to import an uEnv.txt environment from SD-card like
> this:
> 
>   ipaddr=192.168.2.240
>   netmask=255.255.255.0
>   gatewayip=192.168.2.1
>   serverip=192.168.2.114
> 
> Then if you try boot from NFS results in:
> 
>   Importing environment from mmc ...
>   Running uenvcmd ...
>   smc911x: detected LAN9221 controller
>   smc911x: phy initialized
>   smc911x: MAC ac:de:48:00:00:00
>   *** ERROR: `ipaddr' not set
> 
> The ipaddr at this point is NULL beacause is only set at board_init_r
> function. This patch updates the ipaddr value if the environment has
> changed.
> 
> Signed-off-by: Enric Balletbo i Serra <eballetbo@iseebcn.com>
> ---
>  net/net.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Patch

diff --git a/net/net.c b/net/net.c
index 7a93542..7a60583 100644
--- a/net/net.c
+++ b/net/net.c
@@ -321,7 +321,8 @@  NetInitLoop(proto_t protocol)
 
 	/* update only when the environment has changed */
 	if (env_changed_id != env_id) {
-		NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
+		NetOurIP = getenv_IPaddr("ipaddr");
+		NetCopyIP(&bd->bi_ip_addr, &NetOurIP);
 		NetOurGatewayIP = getenv_IPaddr("gatewayip");
 		NetOurSubnetMask = getenv_IPaddr("netmask");
 		NetServerIP = getenv_IPaddr("serverip");