Patchwork [U-Boot,5/6] da850: add support to read mac address from spi flash

login
register
mail settings
Submitter nagabhushana.netagunte@ti.com
Date Sept. 30, 2011, 11:24 a.m.
Message ID <1317381867-18981-6-git-send-email-nagabhushana.netagunte@ti.com>
Download mbox | patch
Permalink /patch/117102/
State Superseded
Headers show

Comments

nagabhushana.netagunte@ti.com - Sept. 30, 2011, 11:24 a.m.
From: Nagabhushana Netagunte <nagabhushana.netagunte@ti.com>

add support to read mac address from spi flash if env variable
is not set. This is supported only on L138 boards based on da850
SOC. Introduced a macro CONFIG_MAC_ADDR_IN_SPIFLASH indicating
where to look mac address for.

Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
Signed-off-by: Nagabhushana Netagunte <nagabhushana.netagunte@ti.com>
---
 board/davinci/da8xxevm/da850evm.c |   63 +++++++++++++++++++++++++++++++++++++
 include/configs/da850_l138evm.h   |    1 +
 2 files changed, 64 insertions(+), 0 deletions(-)
Mike Frysinger - Sept. 30, 2011, 3:51 p.m.
On Friday, September 30, 2011 07:24:26 nagabhushana.netagunte@ti.com wrote:
> +		if (is_multicast_ether_addr(buff) ||
> +				is_zero_ether_addr(buff)) {

NAK: use is_valid_ether_addr()

> +		sprintf((char *)enetaddr, "%pM", buff);
> +
> +		eth_setenv_enetaddr("ethaddr", enetaddr);

NAK: eth_setenv_enetaddr() does the sprintf for you
-mike
Hadli, Manjunath - Oct. 8, 2011, 9:08 a.m.
Mike,
 
On Fri, Sep 30, 2011 at 21:21:34, Mike Frysinger wrote:
> On Friday, September 30, 2011 07:24:26 nagabhushana.netagunte@ti.com wrote:
> > +		if (is_multicast_ether_addr(buff) ||
> > +				is_zero_ether_addr(buff)) {
> 
> NAK: use is_valid_ether_addr()
Thanks. Changed this.
> 
> > +		sprintf((char *)enetaddr, "%pM", buff);
> > +
> > +		eth_setenv_enetaddr("ethaddr", enetaddr);
> 
> NAK: eth_setenv_enetaddr() does the sprintf for you -mike
Thanks Mike. I have removed the sprintf.
> 

Also, 
I will be taking care of the patch set from now. I will resubmit the patches with the changes.

Thx,
-Manju

Patch

diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
index 29cee37..31ab0d6 100644
--- a/board/davinci/da8xxevm/da850evm.c
+++ b/board/davinci/da8xxevm/da850evm.c
@@ -25,10 +25,13 @@ 
 #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/io.h>
+#include <asm/errno.h>
 #include <asm/arch/davinci_misc.h>
 #include <hwconfig.h>
 
@@ -166,6 +169,44 @@  const struct pinmux_config nor_pins[] = {
 #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;
@@ -220,7 +261,29 @@  static void dspwake(void)
 
 int misc_init_r(void)
 {
+	uint8_t enetaddr[8];
+	uchar buff[8];
+	int ret;
+
 	dspwake();
+
+#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
+	if (!eth_getenv_enetaddr("ethaddr", buff)) {
+		ret = get_mac_addr(buff);
+		if (ret != 0)
+			return -EINVAL;
+
+		if (is_multicast_ether_addr(buff) ||
+				is_zero_ether_addr(buff)) {
+			printf("Invalid MAC address read.\n");
+			return -EINVAL;
+		}
+
+		sprintf((char *)enetaddr, "%pM", buff);
+
+		eth_setenv_enetaddr("ethaddr", enetaddr);
+	}
+#endif
 	return 0;
 }
 
diff --git a/include/configs/da850_l138evm.h b/include/configs/da850_l138evm.h
index 0bd630f..9e4a652 100644
--- a/include/configs/da850_l138evm.h
+++ b/include/configs/da850_l138evm.h
@@ -172,6 +172,7 @@ 
 #define CONFIG_SYS_LONGHELP
 #define CONFIG_CRC32_VERIFY
 #define CONFIG_MX_CYCLIC
+#define CONFIG_MAC_ADDR_IN_SPIFLASH
 
 /*
  * Linux Information