[U-Boot] [PATCH 23/30] boards: move board_get_enetaddr() into board-specific init

Mike Frysinger vapier at gentoo.org
Tue Feb 17 06:10:44 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.

Rather than have the common ppc code have board-specific hooks, move the
board_get_enetaddr() function into the board-specific init functions.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
CC: Ben Warren <biggerbadderben at gmail.com>
---
 board/RPXClassic/RPXClassic.c       |   16 +++++++++--
 board/mbx8xx/mbx8xx.c               |   14 +++++++++-
 board/sandburst/common/sb_common.c  |    4 +--
 board/sandburst/common/sb_common.h  |    1 +
 board/sandburst/karef/karef.c       |   29 ++++++++++++++++++++
 board/sandburst/metrobox/metrobox.c |   29 ++++++++++++++++++++
 board/siemens/IAD210/IAD210.c       |   14 +++++++++-
 board/v38b/v38b.c                   |   12 ++++++++
 board/xpedite1k/xpedite1k.c         |   51 +++++++++++++++++++++++++++-------
 include/common.h                    |    7 -----
 include/configs/IAD210.h            |    1 +
 include/configs/MBX860T.h           |    2 +
 include/configs/RPXClassic.h        |    1 +
 include/configs/XPEDITE1K.h         |    1 +
 include/configs/v38b.h              |    1 +
 lib_ppc/board.c                     |   28 -------------------
 16 files changed, 157 insertions(+), 54 deletions(-)

diff --git a/board/RPXClassic/RPXClassic.c b/board/RPXClassic/RPXClassic.c
index 9fdf700..5aa713f 100644
--- a/board/RPXClassic/RPXClassic.c
+++ b/board/RPXClassic/RPXClassic.c
@@ -105,7 +105,7 @@ int checkboard (void)
  * board_get_enetaddr -- Read the MAC Address in the I2C EEPROM
  *-----------------------------------------------------------------------------
  */
-void board_get_enetaddr (uchar * enet)
+static void board_get_enetaddr(uchar *enet)
 {
 	int i;
 	char buff[256], *cp;
@@ -142,9 +142,19 @@ void board_get_enetaddr (uchar * enet)
 	enet[3] |= 0x80;
 #endif
 
-	printf ("MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n",
-		enet[0], enet[1], enet[2], enet[3], enet[4], enet[5]);
+	printf("MAC address = %pM\n", enet);
+}
+
+int misc_init_r(void)
+{
+	uchar enetaddr[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
 
+	return 0;
 }
 
 void rpxclassic_init (void)
diff --git a/board/mbx8xx/mbx8xx.c b/board/mbx8xx/mbx8xx.c
index af4f57d..a3bf1f7 100644
--- a/board/mbx8xx/mbx8xx.c
+++ b/board/mbx8xx/mbx8xx.c
@@ -241,7 +241,7 @@ static unsigned int get_reffreq (void)
 	return *((ulong *) packet->data);
 }
 
-void board_get_enetaddr (uchar * addr)
+static void board_get_enetaddr(uchar *addr)
 {
 	int i;
 	vpd_packet_t *packet;
@@ -251,6 +251,18 @@ void board_get_enetaddr (uchar * addr)
 		addr[i] = packet->data[i];
 }
 
+int misc_init_r(void)
+{
+	uchar enetaddr[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
+
+	return 0;
+}
+
 /*
  * Check Board Identity:
  */
diff --git a/board/sandburst/common/sb_common.c b/board/sandburst/common/sb_common.c
index f6ea16f..b8160c8 100644
--- a/board/sandburst/common/sb_common.c
+++ b/board/sandburst/common/sb_common.c
@@ -394,9 +394,8 @@ int is_pci_host(struct pci_controller *hose)
  *  mgmt mac address.
  *
  ************************************************************************/
-static int macaddr_idx = 0;
 
-void board_get_enetaddr (uchar * enet)
+void board_get_enetaddr(int macaddr_idx, uchar *enet)
 {
 	int i;
 	unsigned short tmp;
@@ -419,7 +418,6 @@ void board_get_enetaddr (uchar * enet)
 		tmp += 31;
 		memcpy(&enet[4], &tmp, 2);
 
-		macaddr_idx++;
 	} else {
 		enet[0] = 0x02;
 		enet[1] = 0x00;
diff --git a/board/sandburst/common/sb_common.h b/board/sandburst/common/sb_common.h
index 888e4f0..e652ba8 100644
--- a/board/sandburst/common/sb_common.h
+++ b/board/sandburst/common/sb_common.h
@@ -72,5 +72,6 @@ int sbcommon_get_master(void);
 int sbcommon_secondary_present(void);
 unsigned short sbcommon_get_serial_number(void);
 void sbcommon_fans(void);
+void board_get_enetaddr(int macaddr_idx, uchar *enet);
 
 #endif /* __SBCOMMON_H__ */
diff --git a/board/sandburst/karef/karef.c b/board/sandburst/karef/karef.c
index 9b94af5..55310d7 100644
--- a/board/sandburst/karef/karef.c
+++ b/board/sandburst/karef/karef.c
@@ -354,6 +354,7 @@ int misc_init_r (void)
 {
 	unsigned short sernum;
 	char envstr[255];
+	uchar enetaddr[6];
 	KAREF_FPGA_REGS_ST *karef_ps;
 	OFEM_FPGA_REGS_ST *ofem_ps;
 
@@ -408,6 +409,34 @@ int misc_init_r (void)
 		printf("fakeled is set. use 'setenv fakeled ; setenv bootdelay 5 ; saveenv' to recover\n");
 	}
 
+#ifdef CONFIG_HAS_ETH0
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(0, enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH1
+	if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
+		board_get_enetaddr(1, enetaddr);
+		eth_putenv_enetaddr("eth1addr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH2
+	if (!eth_getenv_enetaddr("eth2addr", enetaddr)) {
+		board_get_enetaddr(2, enetaddr);
+		eth_putenv_enetaddr("eth2addr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH3
+	if (!eth_getenv_enetaddr("eth3addr", enetaddr)) {
+		board_get_enetaddr(3, enetaddr);
+		eth_putenv_enetaddr("eth3addr", enetaddr);
+	}
+#endif
+
 	return (0);
 }
 
diff --git a/board/sandburst/metrobox/metrobox.c b/board/sandburst/metrobox/metrobox.c
index ec4c451..8bb8c02 100644
--- a/board/sandburst/metrobox/metrobox.c
+++ b/board/sandburst/metrobox/metrobox.c
@@ -321,6 +321,7 @@ int misc_init_r (void)
 {
 	unsigned short sernum;
 	char envstr[255];
+	uchar enetaddr[6];
 	unsigned char opto_rev;
 	OPTO_FPGA_REGS_ST *opto_ps;
 
@@ -379,6 +380,34 @@ int misc_init_r (void)
 		}
 	}
 
+#ifdef CONFIG_HAS_ETH0
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(0, enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH1
+	if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
+		board_get_enetaddr(1, enetaddr);
+		eth_putenv_enetaddr("eth1addr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH2
+	if (!eth_getenv_enetaddr("eth2addr", enetaddr)) {
+		board_get_enetaddr(2, enetaddr);
+		eth_putenv_enetaddr("eth2addr", enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH3
+	if (!eth_getenv_enetaddr("eth3addr", enetaddr)) {
+		board_get_enetaddr(3, enetaddr);
+		eth_putenv_enetaddr("eth3addr", enetaddr);
+	}
+#endif
+
 	return (0);
 }
 
diff --git a/board/siemens/IAD210/IAD210.c b/board/siemens/IAD210/IAD210.c
index e21bb24..67e5c8f 100644
--- a/board/siemens/IAD210/IAD210.c
+++ b/board/siemens/IAD210/IAD210.c
@@ -258,7 +258,7 @@ int board_early_init_f (void)
 	return 0;
 }
 
-void board_get_enetaddr (uchar * addr)
+static void board_get_enetaddr(uchar *addr)
 {
 	int i;
 	volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
@@ -284,3 +284,15 @@ void board_get_enetaddr (uchar * addr)
 
 	cpm->cp_rccr = rccrtmp;
 }
+
+int misc_init_r(void)
+{
+	uchar enetaddr[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
+
+	return 0;
+}
diff --git a/board/v38b/v38b.c b/board/v38b/v38b.c
index d774295..9e7c1d7 100644
--- a/board/v38b/v38b.c
+++ b/board/v38b/v38b.c
@@ -223,6 +223,18 @@ int board_early_init_r(void)
 	return 0;
 }
 
+extern void board_get_enetaddr(uchar *enetaddr);
+int misc_init_r(void)
+{
+	uchar enetaddr[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(enetaddr);
+		eth_putenv_enetaddr("ethaddr", enetaddr);
+	}
+
+	return 0;
+}
 
 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
 void init_ide_reset(void)
diff --git a/board/xpedite1k/xpedite1k.c b/board/xpedite1k/xpedite1k.c
index 58bcfaf..cd1a368 100644
--- a/board/xpedite1k/xpedite1k.c
+++ b/board/xpedite1k/xpedite1k.c
@@ -335,29 +335,58 @@ ulong post_word_load (void)
  * board_get_enetaddr -- Read the MAC Addresses in the I2C EEPROM
  *-----------------------------------------------------------------------------
  */
-static int enetaddr_num = 0;
-void board_get_enetaddr (uchar * enet)
+static int read_i2c;
+static void board_get_enetaddr(uchar *enet)
 {
 	int i;
 	unsigned char buff[0x100], *cp;
 
+	if (read_i2c)
+		return;
+
 	/* Initialize I2C					*/
 	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 
 	/* Read 256 bytes in EEPROM				*/
 	i2c_read (0x50, 0, 1, buff, 0x100);
 
-	if (enetaddr_num == 0) {
-		cp = &buff[0xF4];
-		enetaddr_num = 1;
-	}
-	else
-		cp = &buff[0xFA];
-
+	cp = &buff[0xF4];
 	for (i = 0; i < 6; i++,cp++)
 		enet[i] = *cp;
 
-	printf ("MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n",
-		enet[0], enet[1], enet[2], enet[3], enet[4], enet[5]);
+	printf("MAC address = %pM\n", enet);
+	read_i2c = 1;
+}
+
+int misc_init_r(void)
+{
+	uchar enetaddr[6], i2c_enetaddr[6];
+
+	if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+		board_get_enetaddr(i2c_enetaddr);
+		eth_putenv_enetaddr("ethaddr", i2c_enetaddr);
+	}
+
+#ifdef CONFIG_HAS_ETH1
+	if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
+		board_get_enetaddr(i2c_enetaddr);
+		eth_putenv_enetaddr("eth1addr", i2c_enetaddr);
+	}
+#endif
+
+#ifdef CONFIG_HAS_ETH2
+	if (!eth_getenv_enetaddr("eth2addr", enetaddr)) {
+		board_get_enetaddr(i2c_enetaddr);
+		eth_putenv_enetaddr("eth2addr", i2c_enetaddr);
+	}
+#endif
 
+#ifdef CONFIG_HAS_ETH3
+	if (!eth_getenv_enetaddr("eth3addr", enetaddr)) {
+		board_get_enetaddr(i2c_enetaddr);
+		eth_putenv_enetaddr("eth3addr", i2c_enetaddr);
+	}
+#endif
+
+	return 0;
 }
diff --git a/include/common.h b/include/common.h
index afee188..1b76f9e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -351,13 +351,6 @@ void	board_serial_init (void);
 void	board_ether_init (void);
 #endif
 
-#if defined(CONFIG_RPXCLASSIC)	|| defined(CONFIG_MBX) || \
-    defined(CONFIG_IAD210)	|| defined(CONFIG_XPEDITE1K) || \
-    defined(CONFIG_METROBOX)    || defined(CONFIG_KAREF) || \
-    defined(CONFIG_V38B)
-void	board_get_enetaddr (uchar *addr);
-#endif
-
 #ifdef CONFIG_HERMES
 /* $(BOARD)/hermes.c */
 void hermes_start_lxt980 (int speed);
diff --git a/include/configs/IAD210.h b/include/configs/IAD210.h
index ca488c6..ea1e706 100644
--- a/include/configs/IAD210.h
+++ b/include/configs/IAD210.h
@@ -67,6 +67,7 @@
 
 /* using this define saves us updating another source file */
 #define CONFIG_BOARD_EARLY_INIT_F 1
+#define CONFIG_MISC_INIT_R
 
 #undef	CONFIG_BOOTARGS
 /* #define CONFIG_BOOTCOMMAND							\
diff --git a/include/configs/MBX860T.h b/include/configs/MBX860T.h
index 4cb3a69..0c28710 100644
--- a/include/configs/MBX860T.h
+++ b/include/configs/MBX860T.h
@@ -50,6 +50,8 @@
 #undef	CONFIG_8xx_TFTP_MODE
 #endif
 
+#define CONFIG_MISC_INIT_R
+
 #define CONFIG_DRAM_SPEED	(CONFIG_8xx_BUSCLOCK)	/* MHz		*/
 #define CONFIG_BOOTCOMMAND	"bootm FE020000"	/* autoboot command */
 #define CONFIG_BOOTARGS		" "
diff --git a/include/configs/RPXClassic.h b/include/configs/RPXClassic.h
index 162ef09..bec5278 100644
--- a/include/configs/RPXClassic.h
+++ b/include/configs/RPXClassic.h
@@ -53,6 +53,7 @@
 #define CONFIG_SYS_DISCOVER_PHY        1
 #define CONFIG_MII              1
 #endif /* CONFIG_FEC_ENET */
+#define CONFIG_MISC_INIT_R
 
 /* Video console (graphic: Epson SED13806 on ECCX board, no keyboard         */
 #if 1
diff --git a/include/configs/XPEDITE1K.h b/include/configs/XPEDITE1K.h
index 8d44ec6..74e55c9 100644
--- a/include/configs/XPEDITE1K.h
+++ b/include/configs/XPEDITE1K.h
@@ -38,6 +38,7 @@
 #define CONFIG_440		1
 #define CONFIG_440GX		1		/* 440 GX */
 #define CONFIG_BOARD_EARLY_INIT_F 1		/* Call board_pre_init	*/
+#define CONFIG_MISC_INIT_R
 #undef	CONFIG_SYS_DRAM_TEST				/* Disable-takes long time! */
 #define CONFIG_SYS_CLK_FREQ	33333333	/* external freq to pll */
 
diff --git a/include/configs/v38b.h b/include/configs/v38b.h
index fc7128e..92bcdb3 100644
--- a/include/configs/v38b.h
+++ b/include/configs/v38b.h
@@ -40,6 +40,7 @@
 
 #define CONFIG_BOARD_EARLY_INIT_R	1	/* do board-specific init */
 #define CONFIG_BOARD_EARLY_INIT_F	1	/* do board-specific init */
+#define CONFIG_MISC_INIT_R
 
 #define CONFIG_SYS_XLB_PIPELINING		1	/* gives better performance */
 
diff --git a/lib_ppc/board.c b/lib_ppc/board.c
index 50d7ad2..1160d2e 100644
--- a/lib_ppc/board.c
+++ b/lib_ppc/board.c
@@ -883,14 +883,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #endif
 
 	s = getenv ("ethaddr");
-#if defined (CONFIG_MBX) || \
-    defined (CONFIG_RPXCLASSIC) || \
-    defined(CONFIG_IAD210) || \
-    defined(CONFIG_V38B)
-	if (s == NULL)
-		board_get_enetaddr (bd->bi_enetaddr);
-	else
-#endif
 		for (i = 0; i < 6; ++i) {
 			bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 			if (s)
@@ -918,11 +910,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	/* handle the 3rd ethernet address */
 
 	s = getenv ("eth2addr");
-#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
-	if (s == NULL)
-		board_get_enetaddr(bd->bi_enet2addr);
-	else
-#endif
 	for (i = 0; i < 6; ++i) {
 		bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 		if (s)
@@ -933,11 +920,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #ifdef CONFIG_HAS_ETH3
 	/* handle 4th ethernet address */
 	s = getenv("eth3addr");
-#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
-	if (s == NULL)
-		board_get_enetaddr(bd->bi_enet3addr);
-	else
-#endif
 	for (i = 0; i < 6; ++i) {
 		bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 		if (s)
@@ -948,11 +930,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #ifdef CONFIG_HAS_ETH4
 	/* handle 5th ethernet address */
 	s = getenv("eth4addr");
-#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
-	if (s == NULL)
-		board_get_enetaddr(bd->bi_enet4addr);
-	else
-#endif
 	for (i = 0; i < 6; ++i) {
 		bd->bi_enet4addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 		if (s)
@@ -963,11 +940,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #ifdef CONFIG_HAS_ETH5
 	/* handle 6th ethernet address */
 	s = getenv("eth5addr");
-#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF)
-	if (s == NULL)
-		board_get_enetaddr(bd->bi_enet5addr);
-	else
-#endif
 	for (i = 0; i < 6; ++i) {
 		bd->bi_enet5addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 		if (s)
-- 
1.6.1.3



More information about the U-Boot mailing list