From patchwork Thu Jul 28 16:25:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot] da850: add support to read mac address from spi flash Date: Thu, 28 Jul 2011 06:25:29 -0000 From: nagabhushana.netagunte@ti.com X-Patchwork-Id: 107279 Message-Id: <1311870338-18950-5-git-send-email-nagabhushana.netagunte@ti.com> To: Cc: Nagabhushana Netagunte , Prakash PM , sudhakar.raj@ti.com, manjunath.hadli@ti.com From: Nagabhushana Netagunte 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 Signed-off-by: Nagabhushana Netagunte --- 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 #include #include +#include +#include #include #include #include #include +#include #include 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 */