diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-02-11 19:09:54 -0500 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2009-03-20 22:39:11 +0100 |
commit | 03f3d8d3b39cf85c0ce7ca903b436701e8aa610b (patch) | |
tree | 290db467d9217ac53a4e6f799a3f7547a3da48a4 /drivers/net | |
parent | c527ce92511cbf723c2ca77bee1cf9ecf83dac81 (diff) | |
download | u-boot-imx-03f3d8d3b39cf85c0ce7ca903b436701e8aa610b.zip u-boot-imx-03f3d8d3b39cf85c0ce7ca903b436701e8aa610b.tar.gz u-boot-imx-03f3d8d3b39cf85c0ce7ca903b436701e8aa610b.tar.bz2 |
lan91c96/smc91111/smc911x: get mac address from environment
The environment is the canonical storage location of the mac address, so
we're killing off the global data location and moving everything to
querying the env directly.
Also, do not bother checking the EEPROM if the env is setup. This
simplifies the code greatly.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Wolfgang Dnek <wd@denx.de>
CC: Ben Warren <biggerbadderben@gmail.com>
CC: Rolf Offermanns <rof@sysgo.de>
CC: Erik Stahlman <erik@vt.edu>
CC: Daris A Nevil <dnevil@snmc.com>
CC: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/lan91c96.c | 75 | ||||
-rw-r--r-- | drivers/net/smc91111.c | 72 | ||||
-rw-r--r-- | drivers/net/smc911x.c | 14 |
3 files changed, 29 insertions, 132 deletions
diff --git a/drivers/net/lan91c96.c b/drivers/net/lan91c96.c index 318bdf4..65565bc 100644 --- a/drivers/net/lan91c96.c +++ b/drivers/net/lan91c96.c @@ -606,10 +606,8 @@ static int smc_open (bd_t *bd) SMC_SELECT_BANK (1); err = smc_get_ethaddr (bd); /* set smc_mac_addr, and sync it with u-boot globals */ - if (err < 0) { - memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */ - return (-1); /* upper code ignores this, but NOT bi_enetaddr */ - } + if (err < 0) + return -1; #ifdef USE_32_BIT for (i = 0; i < 6; i += 2) { word address; @@ -869,69 +867,20 @@ static int smc_hw_init () int smc_get_ethaddr (bd_t * bd) { - int env_size = 0; - int rom_valid = 0; - int env_present = 0; - int reg = 0; - char *s = NULL; - char *e = NULL; - char *v_mac, es[] = "11:22:33:44:55:66"; - char s_env_mac[64]; - uchar v_env_mac[6]; - uchar v_rom_mac[6]; - - env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac)); - if (env_size != sizeof(es)) { /* Ignore if env is bad or not set */ - printf ("\n*** Warning: ethaddr is not set properly, ignoring!!\n"); - } else { - env_present = 1; - s = s_env_mac; - - for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */ - v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - } + uchar v_mac[6]; - rom_valid = get_rom_mac (v_rom_mac); /* get ROM mac value if any */ - - if (!env_present) { /* if NO env */ - if (rom_valid) { /* but ROM is valid */ - v_mac = (char *)v_rom_mac; - sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X", - v_mac[0], v_mac[1], v_mac[2], v_mac[3], - v_mac[4], v_mac[5]); - setenv ("ethaddr", s_env_mac); - } else { /* no env, bad ROM */ - printf ("\n*** ERROR: ethaddr is NOT set !!\n"); - return (-1); + if (!eth_getenv_enetaddr("ethaddr", v_mac)) { + /* get ROM mac value if any */ + if (!get_rom_mac(v_mac)) { + printf("\n*** ERROR: ethaddr is NOT set !!\n"); + return -1; } - } else { /* good env, don't care ROM */ - v_mac = (char *)v_env_mac; /* always use a good env over a ROM */ + eth_setenv_enetaddr("ethaddr", v_mac); } - if (env_present && rom_valid) { /* if both env and ROM are good */ - if (memcmp (v_env_mac, v_rom_mac, 6) != 0) { - printf ("\nWarning: MAC addresses don't match:\n"); - printf ("\tHW MAC address: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - v_rom_mac[0], v_rom_mac[1], - v_rom_mac[2], v_rom_mac[3], - v_rom_mac[4], v_rom_mac[5] ); - printf ("\t\"ethaddr\" value: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - v_env_mac[0], v_env_mac[1], - v_env_mac[2], v_env_mac[3], - v_env_mac[4], v_env_mac[5]) ; - debug ("### Set MAC addr from environment\n"); - } - } - memcpy (bd->bi_enetaddr, v_mac, 6); /* update global address to match env (allows env changing) */ - smc_set_mac_addr ((unsigned char *)v_mac); /* use old function to update smc default */ - PRINTK("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n", v_mac[0], v_mac[1], - v_mac[2], v_mac[3], v_mac[4], v_mac[5]); - return (0); + smc_set_mac_addr(v_mac); /* use old function to update smc default */ + PRINTK("Using MAC Address %pM\n", v_mac); + return 0; } /* diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c index 82abb02..b41e4d2 100644 --- a/drivers/net/smc91111.c +++ b/drivers/net/smc91111.c @@ -834,10 +834,8 @@ static int smc_open (bd_t * bd) SMC_SELECT_BANK (1); err = smc_get_ethaddr (bd); /* set smc_mac_addr, and sync it with u-boot globals */ - if (err < 0) { - memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */ - return (-1); /* upper code ignores this, but NOT bi_enetaddr */ - } + if (err < 0) + return -1; #ifdef USE_32_BIT for (i = 0; i < 6; i += 2) { word address; @@ -1535,66 +1533,20 @@ int eth_send(volatile void *packet, int length) { int smc_get_ethaddr (bd_t * bd) { - int env_size, rom_valid, env_present = 0, reg; - char *s = NULL, *e, es[] = "11:22:33:44:55:66"; - char s_env_mac[64]; - uchar v_env_mac[6], v_rom_mac[6], *v_mac; - - env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac)); - if ((env_size > 0) && (env_size < sizeof (es))) { /* exit if env is bad */ - printf ("\n*** ERROR: ethaddr is not set properly!!\n"); - return (-1); - } + uchar v_mac[6]; - if (env_size > 0) { - env_present = 1; - s = s_env_mac; - } - - for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */ - v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - - rom_valid = get_rom_mac (v_rom_mac); /* get ROM mac value if any */ - - if (!env_present) { /* if NO env */ - if (rom_valid) { /* but ROM is valid */ - v_mac = v_rom_mac; - sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X", - v_mac[0], v_mac[1], v_mac[2], v_mac[3], - v_mac[4], v_mac[5]); - setenv ("ethaddr", s_env_mac); - } else { /* no env, bad ROM */ - printf ("\n*** ERROR: ethaddr is NOT set !!\n"); - return (-1); + if (!eth_getenv_enetaddr("ethaddr", v_mac)) { + /* get ROM mac value if any */ + if (!get_rom_mac(v_mac)) { + printf("\n*** ERROR: ethaddr is NOT set !!\n"); + return -1; } - } else { /* good env, don't care ROM */ - v_mac = v_env_mac; /* always use a good env over a ROM */ + eth_setenv_enetaddr("ethaddr", v_mac); } - if (env_present && rom_valid) { /* if both env and ROM are good */ - if (memcmp (v_env_mac, v_rom_mac, 6) != 0) { - printf ("\nWarning: MAC addresses don't match:\n"); - printf ("\tHW MAC address: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - v_rom_mac[0], v_rom_mac[1], - v_rom_mac[2], v_rom_mac[3], - v_rom_mac[4], v_rom_mac[5] ); - printf ("\t\"ethaddr\" value: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - v_env_mac[0], v_env_mac[1], - v_env_mac[2], v_env_mac[3], - v_env_mac[4], v_env_mac[5]) ; - debug ("### Set MAC addr from environment\n"); - } - } - memcpy (bd->bi_enetaddr, v_mac, 6); /* update global address to match env (allows env changing) */ - smc_set_mac_addr ((uchar *)v_mac); /* use old function to update smc default */ - PRINTK("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n", v_mac[0], v_mac[1], - v_mac[2], v_mac[3], v_mac[4], v_mac[5]); - return (0); + smc_set_mac_addr(v_mac); /* use old function to update smc default */ + PRINTK("Using MAC Address %pM\n", v_mac); + return 0; } int get_rom_mac (uchar *v_rom_mac) diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c index 1ded8f0..30f2dc2 100644 --- a/drivers/net/smc911x.c +++ b/drivers/net/smc911x.c @@ -39,15 +39,10 @@ void pkt_data_push(u32 addr, u32 val) \ static int smx911x_handle_mac_address(bd_t *bd) { unsigned long addrh, addrl; - unsigned char *m = bd->bi_enetaddr; + uchar m[6]; /* if the environment has a valid mac address then use it */ - if ((m[0] | m[1] | m[2] | m[3] | m[4] | m[5])) { - addrl = m[0] | m[1] << 8 | m[2] << 16 | m[3] << 24; - addrh = m[4] | m[5] << 8; - smc911x_set_mac_csr(ADDRH, addrh); - smc911x_set_mac_csr(ADDRL, addrl); - } else { + if (!eth_getenv_enetaddr("ethaddr", m)) { /* if not, try to get one from the eeprom */ addrh = smc911x_get_mac_csr(ADDRH); addrl = smc911x_get_mac_csr(ADDRL); @@ -65,10 +60,11 @@ static int smx911x_handle_mac_address(bd_t *bd) "and no eeprom found\n"); return -1; } + + eth_setenv_enetaddr("ethaddr", m); } - printf(DRIVERNAME ": MAC %02x:%02x:%02x:%02x:%02x:%02x\n", - m[0], m[1], m[2], m[3], m[4], m[5]); + printf(DRIVERNAME ": MAC %pM\n", m); return 0; } |