[U-Boot] [PATCH 25/30] pcs440ep: get mac address from environment and move load_sernum_ethaddr() to board init

Mike Frysinger vapier at gentoo.org
Tue Feb 17 06:10:46 CET 2009


The environment is the canonical storage location of the mac address, so
we're killing off the global data location and moving everything to
querying the env directly.

Move all the work of load_sernum_ethaddr() into a local load_ethaddr()
func and call that from misc_init_r().  We leave load_sernum_ethaddr()
as a stub so that it can be removed from all places in a later commit.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
CC: Stefan Roese <sr at denx.de>
CC: Ben Warren <biggerbadderben at gmail.com>
---
 board/pcs440ep/pcs440ep.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c
index 5fd3291..067d959 100644
--- a/board/pcs440ep/pcs440ep.c
+++ b/board/pcs440ep/pcs440ep.c
@@ -182,14 +182,21 @@ int board_early_init_f(void)
 }
 
 #define EEPROM_LEN	256
-void load_sernum_ethaddr (void)
+static void load_ethaddr(void)
 {
+	int	ok_ethaddr, ok_eth1addr;
 	int	ret;
 	char	buf[EEPROM_LEN];
 	char	mac[32];
 	char	*use_eeprom;
 	u16	checksumcrc16 = 0;
 
+	/* If the env is sane, then nothing for us to do */
+	ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
+	ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
+	if (ok_ethaddr && ok_eth1addr)
+		return;
+
 	/* read the MACs from EEprom */
 	status_led_set (0, STATUS_LED_ON);
 	status_led_set (1, STATUS_LED_ON);
@@ -207,22 +214,10 @@ void load_sernum_ethaddr (void)
 			printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
 		} else {
 			/* get the MACs */
-			sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
-				buf[3],
-				buf[4],
-				buf[5],
-				buf[6],
-				buf[7],
-				buf[8]);
-			setenv ("ethaddr", (char *) mac);
-			sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
-				buf[9],
-				buf[10],
-				buf[11],
-				buf[12],
-				buf[13],
-				buf[14]);
-			setenv ("eth1addr", (char *) mac);
+			if (!ok_ethaddr)
+				eth_setenv_enetaddr("ethaddr", &buf[3]);
+			if (!ok_eth1addr)
+				eth_setenv_enetaddr("eth1addr", &buf[9]);
 			return;
 		}
 	}
@@ -249,6 +244,10 @@ void load_sernum_ethaddr (void)
 	return;
 }
 
+void load_sernum_ethaddr (void)
+{
+}
+
 #ifdef CONFIG_PREBOOT
 
 static uchar kbd_magic_prefix[]		= "key_magic";
@@ -446,6 +445,8 @@ int misc_init_r (void)
 	uint pbcr;
 	int size_val = 0;
 
+	load_ethaddr();
+
 	/* Re-do sizing to get full correct info */
 	mtdcr(ebccfga, pb0cr);
 	pbcr = mfdcr(ebccfgd);
-- 
1.6.1.3



More information about the U-Boot mailing list