From: Nagabhushana Netagunte <nagabhushana.netagu...@ti.com>

add misc_int_r function to read the mac address from SPI flash
if env variable ethaddr is not set.

Signed-off-by: Prakash PM <prakash...@ti.com>
Signed-off-by: Nagabhushana Netagunte <nagabhushana.netagu...@ti.com>
---
 board/davinci/da8xxevm/da850evm.c |   65 +++++++++++++++++++++++++++++++++++++
 include/configs/da850evm.h        |    1 +
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/board/davinci/da8xxevm/da850evm.c 
b/board/davinci/da8xxevm/da850evm.c
index a77e438..8d09bb9 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>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -383,4 +386,66 @@ int board_eth_init(bd_t *bis)
 
        return 0;
 }
+
 #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)
+
+static int get_mac_addr(u8 *addr)
+{
+       int ret;
+       struct spi_flash *flash;
+
+       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;
+}
+
+int misc_init_r(void)
+{
+       uint8_t tmp[20], addr[10];
+       int ret;
+
+       printf("ARM Clock : %d Hz\n", clk_get(DAVINCI_ARM_CLKID));
+
+       if (getenv("ethaddr") == NULL) {
+               /* Set Ethernet MAC address from EEPROM */
+               ret = get_mac_addr(addr);
+               if (ret != 0)
+                       return -EINVAL;
+
+               if (is_multicast_ether_addr(addr) || is_zero_ether_addr(addr)) {
+                       printf("Invalid MAC address read.\n");
+                       return -EINVAL;
+               }
+               sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x", addr[0],
+                               addr[1], addr[2], addr[3], addr[4], addr[5]);
+
+               setenv("ethaddr", (char *)tmp);
+       }
+
+       return 0;
+}
diff --git a/include/configs/da850evm.h b/include/configs/da850evm.h
index 21d8fe3..f7bf6be 100644
--- a/include/configs/da850evm.h
+++ b/include/configs/da850evm.h
@@ -161,6 +161,7 @@
 /*
  * U-Boot general configuration
  */
+#define CONFIG_MISC_INIT_R
 #define CONFIG_BOOTFILE                "uImage" /* Boot file name */
 #define CONFIG_SYS_PROMPT      "U-Boot > " /* Command Prompt */
 #define CONFIG_SYS_CBSIZE      1024 /* Console I/O Buffer Size */
-- 
1.6.2.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to