[U-Boot] [PATCH 2/2] Davinci: Move config of MAC address to board setup

andreas.gaer at baslerweb.com andreas.gaer at baslerweb.com
Wed Apr 21 10:27:03 CEST 2010


From: Andreas Gaeer <Andreas.Gaer at baslerweb.com>

Without this change the MAC address only gets properly set when the
ethaddr is already set in u-boot environment.

Now the board setup should do the following:
1. Put a valid ethaddr into environment (eg. by I2C EEPROM)
2. Call dv_set_mac_address() to set the address in TI EMAC driver

Signed-off-by: Andreas Gaeer <Andreas.Gaer at baslerweb.com>
---
 arch/arm/lib/board.c              |   11 -----------
 board/davinci/common/misc.c       |   16 ++++++++++++++++
 board/davinci/common/misc.h       |    1 +
 board/davinci/da830evm/da830evm.c |    8 +++-----
 board/davinci/dm365evm/dm365evm.c |   10 +++++++++-
 board/davinci/dvevm/dvevm.c       |    5 +++++
 board/davinci/sffsdr/sffsdr.c     |    5 +++++
 board/davinci/sonata/sonata.c     |    5 +++++
 drivers/net/davinci_emac.c        |    3 +++
 9 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index f5660a9..384b9e1 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -385,17 +385,6 @@ void start_armboot (void)
 	/* enable exceptions */
 	enable_interrupts ();
 
-	/* Perform network card initialisation if necessary */
-#ifdef CONFIG_DRIVER_TI_EMAC
-	/* XXX: this needs to be moved to board init */
-extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
-	if (getenv ("ethaddr")) {
-		uchar enetaddr[6];
-		eth_getenv_enetaddr("ethaddr", enetaddr);
-		davinci_eth_set_mac_addr(enetaddr);
-	}
-#endif
-
 #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
 	/* XXX: this needs to be moved to board init */
 	if (getenv ("ethaddr")) {
diff --git a/board/davinci/common/misc.c b/board/davinci/common/misc.c
index 25ca326..01b1962 100644
--- a/board/davinci/common/misc.c
+++ b/board/davinci/common/misc.c
@@ -110,6 +110,22 @@ void dv_configure_mac_address(uint8_t *rom_enetaddr)
 	}
 }
 
+/* Get the MAC address from the environment and set it in the TI EMAC driver 
+ * Returns 1 when MAC could be set, 0 otherwise
+ */
+int dv_set_mac_address() {
+
+	uchar enetaddr[6];
+	if (getenv ("ethaddr")) {
+		if(eth_getenv_enetaddr("ethaddr", enetaddr)) {
+			davinci_eth_set_mac_addr(enetaddr);
+			return 1;
+		}
+	}
+	printf("Warning: Could not set MAC address!\n");
+	return 0;
+}
+
 #endif	/* DAVINCI_EMAC */
 
 /*
diff --git a/board/davinci/common/misc.h b/board/davinci/common/misc.h
index 329c369..664fca6 100644
--- a/board/davinci/common/misc.h
+++ b/board/davinci/common/misc.h
@@ -47,6 +47,7 @@ struct pinmux_resource {
 
 int dvevm_read_mac_address(uint8_t *buf);
 void dv_configure_mac_address(uint8_t *rom_enetaddr);
+int dv_set_mac_address();
 int davinci_configure_pin_mux(const struct pinmux_config *pins, int n_pins);
 int davinci_configure_pin_mux_items(const struct pinmux_resource *item,
 				    int n_items);
diff --git a/board/davinci/da830evm/da830evm.c b/board/davinci/da830evm/da830evm.c
index 6385443..aa5f6a2 100644
--- a/board/davinci/da830evm/da830evm.c
+++ b/board/davinci/da830evm/da830evm.c
@@ -207,12 +207,10 @@ int board_eth_init(bd_t *bis)
 		/* set address env if not already set */
 		dv_configure_mac_address(mac_addr);
 
-	/* read the address back from env */
-	if (!eth_getenv_enetaddr("ethaddr", mac_addr))
+	/* Set the MAC address from environment */ 
+	if(!dv_set_mac_address()) {
 		return -1;
-
-	/* provide the resulting addr to the driver */
-	davinci_eth_set_mac_addr(mac_addr);
+	}
 
 	/* enable the Ethernet switch in the 3 port PHY */
 	if (i2c_write(PHY_SW_I2C_ADDR, 0, 0,
diff --git a/board/davinci/dm365evm/dm365evm.c b/board/davinci/dm365evm/dm365evm.c
index 290eb99..579684a 100644
--- a/board/davinci/dm365evm/dm365evm.c
+++ b/board/davinci/dm365evm/dm365evm.c
@@ -70,7 +70,15 @@ int board_eth_init(bd_t *bis)
 	if (dvevm_read_mac_address(eeprom_enetaddr))
 		dv_configure_mac_address(eeprom_enetaddr);
 
-	davinci_emac_initialize();
+	/* Set the MAC address from environment */ 
+	if(!dv_set_mac_address()) {
+		return -1;
+	}
+    
+	if(davinci_emac_initialize() <= 0) {
+		printf("davinci_emac_initialize failed!\n");
+		return -1;
+	}
 
 	return 0;
 }
diff --git a/board/davinci/dvevm/dvevm.c b/board/davinci/dvevm/dvevm.c
index 98937a9..4a6e736 100644
--- a/board/davinci/dvevm/dvevm.c
+++ b/board/davinci/dvevm/dvevm.c
@@ -73,6 +73,11 @@ int misc_init_r(void)
 	if (dvevm_read_mac_address(eeprom_enetaddr))
 		dv_configure_mac_address(eeprom_enetaddr);
 
+	/* Set the MAC address from environment */ 
+	if(!dv_set_mac_address()) {
+		return -1;
+	}
+
 	i2c_read(0x39, 0x00, 1, &video_mode, 1);
 
 	setenv("videostd", ((video_mode & 0x80) ? "pal" : "ntsc"));
diff --git a/board/davinci/sffsdr/sffsdr.c b/board/davinci/sffsdr/sffsdr.c
index c24b9e1..273a42a 100644
--- a/board/davinci/sffsdr/sffsdr.c
+++ b/board/davinci/sffsdr/sffsdr.c
@@ -143,5 +143,10 @@ int misc_init_r(void)
 	if (sffsdr_read_mac_address(eeprom_enetaddr))
 		dv_configure_mac_address(eeprom_enetaddr);
 
+	/* Set the MAC address from environment */ 
+	if(!dv_set_mac_address()) {
+		return -1;
+	}
+
 	return(0);
 }
diff --git a/board/davinci/sonata/sonata.c b/board/davinci/sonata/sonata.c
index 817970a..b287acc 100644
--- a/board/davinci/sonata/sonata.c
+++ b/board/davinci/sonata/sonata.c
@@ -72,6 +72,11 @@ int misc_init_r(void)
 	if (dvevm_read_mac_address(eeprom_enetaddr))
 		dv_configure_mac_address(eeprom_enetaddr);
 
+	/* Set the MAC address from environment */ 
+	if(!dv_set_mac_address()) {
+		return -1;
+	}
+
 	return(0);
 }
 
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 02bbb8c..21497d1 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -75,9 +75,12 @@ void davinci_eth_set_mac_addr(const u_int8_t *addr)
 {
 	int i;
 
+	debug_emac("davinci_eth_set_mac_addr(), MAC = ");
 	for (i = 0; i < sizeof (davinci_eth_mac_addr); i++) {
+		debug_emac(i ? ":%02x" : "%02x", addr[i]);
 		davinci_eth_mac_addr[i] = addr[i];
 	}
+	debug_emac("\n");
 }
 
 /* EMAC Addresses */
-- 
1.7.0.3



More information about the U-Boot mailing list