[U-Boot] [PATCH 1/2] da850evm: add support to read mac address from spi flash

Manjunath Hadli manjunath.hadli at ti.com
Thu Feb 2 14:42:17 CET 2012


add support to read mac address for da850/L138 evm manufactued by
Logic PD which store mac address in SPI flash manufactued by ST
Microelectronics. This patch adds support to read mac address from
spi flash and set the mac address if it hasen't been set in environmet.
Introduced a config option CONFIG_MAC_ADDR_IN_SPIFLASH indicating
where to look mac address for.

Signed-off-by: Manjunath Hadli <manjunath.hadli at ti.com>
Cc: Tom Rini <trini at ti.com>
---
 board/davinci/da8xxevm/da850evm.c |   58 +++++++++++++++++++++++++++++++++++++
 boards.cfg                        |    2 +-
 2 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index 9bd3e71..dcb22cb 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -25,12 +25,15 @@
 #include <i2c.h>
 #include <net.h>
 #include <netdev.h>
+#include <spi.h>
+#include <spi_flash.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/emif_defs.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/arch/pinmux_defs.h>
 #include <asm/io.h>
 #include <asm/arch/davinci_misc.h>
+#include <asm/errno.h>
 #include <hwconfig.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -43,6 +46,43 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
+#define CFG_MAC_ADDR_SPI_BUS	0
+#define CFG_MAC_ADDR_SPI_CS	0
+#define CFG_MAC_ADDR_SPI_MAX_HZ	CONFIG_SF_DEFAULT_SPEED
+#define CFG_MAC_ADDR_SPI_MODE	SPI_MODE_3
+
+#define CFG_MAC_ADDR_OFFSET	(flash->size - SZ_64K)
+
+#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
+static int get_mac_addr(u8 *addr)
+{
+	struct spi_flash *flash;
+	int ret;
+
+	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
+			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
+	if (!flash) {
+		printf(" Error - unable to probe SPI flash.\n");
+		ret = -1;
+		goto err_probe;
+	}
+
+	ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr);
+	if (ret) {
+		printf("Error - unable to read MAC address from SPI flash.\n");
+		goto err_read;
+	}
+
+err_read:
+	/* cannot call free currently since the free function calls free() for
+	 * spi_flash structure though it is not directly allocated through
+	 * malloc()
+	 */
+err_probe:
+	return ret;
+}
+#endif
+
 void dsp_lpsc_on(unsigned domain, unsigned int id)
 {
 	dv_reg_p mdstat, mdctl, ptstat, ptcmd;
@@ -98,6 +138,24 @@ static void dspwake(void)
 int misc_init_r(void)
 {
 	dspwake();
+
+#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
+	uchar buff[8];
+	int ret;
+
+	if (!eth_getenv_enetaddr("ethaddr", buff)) {
+		ret = get_mac_addr(buff);
+		if (ret != 0)
+			return -EINVAL;
+
+		if (!is_valid_ether_addr(buff)) {
+			printf("Invalid MAC address read.\n");
+			return -EINVAL;
+		}
+
+		eth_setenv_enetaddr("ethaddr", buff);
+	}
+#endif
 	return 0;
 }
 
diff --git a/boards.cfg b/boards.cfg
index 2f90dbf..ad6c5b8 100644
--- a/boards.cfg
+++ b/boards.cfg
@@ -121,7 +121,7 @@ pm9g45                       arm         arm926ejs   pm9g45              ronetix
 cam_enc_4xx                  arm         arm926ejs   cam_enc_4xx         ait            davinci     cam_enc_4xx
 da830evm                     arm         arm926ejs   da8xxevm            davinci        davinci
 da850_am18xxevm              arm         arm926ejs   da8xxevm            davinci        davinci     da850evm:DA850_AM18X_EVM
-da850evm                     arm         arm926ejs   da8xxevm            davinci        davinci
+da850evm                     arm         arm926ejs   da8xxevm            davinci        davinci     da850evm:MAC_ADDR_IN_SPIFLASH
 davinci_dm355evm             arm         arm926ejs   dm355evm            davinci        davinci
 davinci_dm355leopard         arm         arm926ejs   dm355leopard        davinci        davinci
 davinci_dm365evm             arm         arm926ejs   dm365evm            davinci        davinci
-- 
1.6.2.4



More information about the U-Boot mailing list