da850evm: add board specific functions
v2 cover da850evm: add board specific functions
There are two da850 SOC based EVMs, one from Spectrum digital and other from Logic PD. Boards from Spectrum digital have mac address stored in I2C EEPROM and they have spi flash manufactured by WINBOND. Boards from Logic PD store mac address in ST Microelectronics SPI flash. This patch series adds support to read mac address from the appropriate device.
Changes for v2:
1: Fixed a comment from Wolfgang, comparing MAC address if present in
different locations and raising a warning on mismatch.
2: Fixed a comment from Mike, removed return -EINVAL statement,
just issuing a warning in case of error in misc_init_r() function while reading MAC address.
Manjunath Hadli (2):
da850evm: add support to read mac address from SPI flash
da850evm: read mac address from I2C EEPROM on AM18x EVM
board/davinci/da8xxevm/da850evm.c | 103 +++++++++++++++++++++++++++++++++++++ boards.cfg | 4 +- 2 files changed, 105 insertions(+), 2 deletions(-)
PATCH v2 1/2 da850evm: add support to read mac address from SPI flash
add support to read mac address for da850/L138 evm manufactured by Logic PD which store mac address in SPI flash manufactured by ST Microelectronics. This patch adds support to read mac address from SPI flash and set the mac address if it hasn't been set in environment, If it has been set in the environment it compares the value one with SPI flash and warns on mismatch. Introduced a config option CONFIG_MAC_ADDR_IN_SPIFLASH indicating where to look mac address for.
--- board/davinci/da8xxevm/da850evm.c | 72 +++++++++++++++++++++++++++++++++++++ boards.cfg | 2 +- 2 files changed, 73 insertions(+), 1 deletions(-)
board/davinci/da8xxevm/da850evm.c +72 -0
@@ -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,36 @@ 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" ); +return -1 ; + } + + ret =spi_flash_read (flash,CFG_MAC_ADDR_OFFSET ,6 , addr); +if (ret) { +printf ("Error - unable to read MAC address from SPI flash.\n" ); +return -1 ; + } + +return ret; +} +#endif +void dsp_lpsc_on (unsigned domain,unsigned int id) {dv_reg_p mdstat, mdctl, ptstat, ptcmd;
@@ -98,6 +131,45 @@ static void dspwake(void)int misc_init_r (void ) {dspwake (); + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH +uchar env_enetaddr[6 ]; +int enetaddr_found; +int spi_mac_read; +uchar buff[6 ]; + + enetaddr_found =eth_getenv_enetaddr ("ethaddr" , env_enetaddr); + spi_mac_read =get_mac_addr (buff); + +/* +* MAC address not present in the environment +* try and read the MAC address from SPI flash +* and set it. +*/ +if (!enetaddr_found) { +if (!spi_mac_read) { +if (is_valid_ether_addr (buff)) { +if (eth_setenv_enetaddr ("ethaddr" , buff)) { +printf ("Warning: Failed to " +"set MAC address from SPI flash\n" ); + } + }else { +printf ("Warning: Invalid " +"MAC address read from SPI flash\n" ); + } + } + }else { +/* +* MAC address present in environment compare it with +* the MAC address in SPI flash and warn on mismatch +*/ +if (!spi_mac_read &&is_valid_ether_addr (buff) && +memcmp (env_enetaddr, buff,6 )) +printf ("Warning: MAC address in SPI flash don't match " +"with the MAC address in the environment\n" ); +printf ("Default using MAC address from environment\n" ); + } +#endif return 0 ; }
boards.cfg +1 -1
@@ -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
Signature · 1 line
1.6.2.4
PATCH v2 1/2 da850evm: add support to read mac address from SPI flash
board/davinci/da8xxevm/da850evm.c DECLARE_GLOBAL_DATA_PTR; · line 52
Quoted 7 lines · On Friday 10 February 2012 01:22:24 Manjunath Hadli wrote:
board/davinci/da8xxevm/da850evm.c +4
-0+#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
these defines get used only once below, so doesn't seem terribly useful to have as defines. up to you.
board/davinci/da8xxevm/da850evm.c static void dspwake(void) · line 142
Quoted 12 lines
int
misc_init_r(void)
{board/davinci/da8xxevm/da850evm.c +9
-0dspwake (); + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH +uchar env_enetaddr[6 ]; +int enetaddr_found; +int spi_mac_read; +uchar buff[6 ]; + + enetaddr_found =eth_getenv_enetaddr ("ethaddr" , env_enetaddr); + spi_mac_read =get_mac_addr (buff);
you always read the SPI flash even if the env is available. that sounds like a waste of time to me. i'd expect the logic to simply be:
if (!eth_getenv_enetaddr("ethaddr", env_enetaddr)) {
if (get_mac_addr(buff) == 0)
eth_setenv_enetaddr("ethaddr", buff);
}no need to warn in misc_init_r() since your get_mac_addr() already issues a warning
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120210/729ea09a/attachment.pgp>
Hadli
PATCH v2 1/2 da850evm: add support to read mac address from SPI flash
Mike,
Quoted 10 lines · Mike Frysinger
board/davinci/da8xxevm/da850evm.c DECLARE_GLOBAL_DATA_PTR; · line 52
Quoted 7 lines · On Friday 10 February 2012 01:22:24 Manjunath Hadli wrote:
board/davinci/da8xxevm/da850evm.c +4
-0+#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_3these defines get used only once below, so doesn't seem terribly useful to have as defines. up to you.
I would like to have these :), If you still insist I'll get rid of these.
Quoted 16 lines
board/davinci/da8xxevm/da850evm.c static void dspwake(void) · line 142
Quoted 13 lines
int
misc_init_r(void)
{board/davinci/da8xxevm/da850evm.c +9
-0dspwake (); + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH +uchar env_enetaddr[6 ]; +int enetaddr_found; +int spi_mac_read; +uchar buff[6 ]; + + enetaddr_found =eth_getenv_enetaddr ("ethaddr" , env_enetaddr); + spi_mac_read =get_mac_addr (buff);you always read the SPI flash even if the env is available. that sounds like a waste of time to me. i'd expect the logic to simply be:
Quoted 7 lines
if (!eth_getenv_enetaddr("ethaddr", env_enetaddr)) { if (get_mac_addr(buff) == 0) eth_setenv_enetaddr("ethaddr", buff); }no need to warn in
misc_init_r()since yourget_mac_addr()already issues a warning -mike
My earlier patch series did the same thing, but Wolfgang suggested, "If we have multiple storage for the MAC address, we should always raise a warning if these contain different information."
http://www.mail-archive.com/u-boot at lists.denx.de/msg76666.html the above link should sort out things clearer.
Regards,
--Manju
PATCH v2 2/2 da850evm: read mac address from I2C EEPROM on AM18x EVM
In reply to Manjunath Hadliadd support to read mac address for AM18x EVM manufactured from Spectrum digital which have mac address stored in I2C EEPROM manufactured by WINBOND. This patch reads mac address from I2C EEPROM and sets the environment variable if not set, If mac address is already present in environment compare it with the mac address in EEPROM and warn on mismatch.Introduced a config option CONFIG_MAC_ADDR_IN_EEPROM to where to look for the mac address.
--- board/davinci/da8xxevm/da850evm.c | 35 +++++++++++++++++++++++++++++++++-- boards.cfg | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-)
board/davinci/da8xxevm/da850evm.c +33 -2
@@ -132,13 +132,17 @@ int misc_init_r(void) {dspwake (); -#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH +#if defined(CONFIG_MAC_ADDR_IN_SPIFLASH ) || defined(CONFIG_MAC_ADDR_IN_EEPROM ) +uchar env_enetaddr[6 ];int enetaddr_found; + + enetaddr_found =eth_getenv_enetaddr ("ethaddr" , env_enetaddr); + +#ifdef CONFIG_MAC_ADDR_IN_SPIFLASH int spi_mac_read;uchar buff[6 ]; - enetaddr_found =eth_getenv_enetaddr ("ethaddr" , env_enetaddr); spi_mac_read =get_mac_addr (buff);/*
@@ -170,6 +174,33 @@ int misc_init_r(void)printf ("Default using MAC address from environment\n" ); }#endif +uint8_t enetaddr[8 ]; +int eeprom_mac_read; + +/* Read Ethernet MAC address from EEPROM */ + eeprom_mac_read =dvevm_read_mac_address (enetaddr); + +/* +* MAC address not present in the environment +* try and read the MAC address from EEPROM flash +* and set it. +*/ +if (!enetaddr_found) { +if (eeprom_mac_read) +/* Set Ethernet MAC address from EEPROM */ +davinci_sync_env_enetaddr (enetaddr); + }else { +/* +* MAC address present in environment compare it with +* the MAC address in EEPROM and warn on mismatch +*/ +if (eeprom_mac_read &&memcmp (enetaddr, env_enetaddr,6 )) +printf ("Warning: MAC address in EEPROM don't match " +"with the MAC address in the environment\n" ); +printf ("Default using MAC address from environment\n" ); + } + +#endif return 0 ; }
boards.cfg +1 -1
@@ -120,7 +120,7 @@ pm9263 arm arm926ejs pm9263 ronetix pm9g45 arm arm926ejs pm9g45 ronetix at91 pm9g45:AT91SAM9G45 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 +da850_am18xxevm arm arm926ejs da8xxevm davinci davinci da850evm:DA850_AM18X_EVM,MAC_ADDR_IN_EEPROM,SYS_I2C_EEPROM_ADDR_LEN=2,SYS_I2C_EEPROM_ADDR=0x50 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
Signature · 1 line
1.6.2.4