[U-Boot] [PATCH] ne2000: take MAC address from config if available
Daniel Mack
daniel at caiaq.de
Wed Dec 3 02:01:54 CET 2008
This adds CONFIG_NE2000_NOPROM. If set, the ethernet MAC address is taken
from the environment variable 'ethaddr' and the NIC is configured
accordingly. Needed for boards that don't have an EEPROM to store this
setting permanently.
Signed-off-by: Daniel Mack <daniel at caiaq.de>
---
ne2000_base.c | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ne2000_base.c b/drivers/net/ne2000_base.c
index f93f932..86c1380 100644
--- a/drivers/net/ne2000_base.c
+++ b/drivers/net/ne2000_base.c
@@ -669,7 +669,6 @@ void uboot_push_tx_done(int key, int val) {
int eth_init(bd_t *bd) {
int r;
u8 dev_addr[6];
- char ethaddr[20];
PRINTK("### eth_init\n");
@@ -693,16 +692,35 @@ int eth_init(bd_t *bd) {
nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE;
- r = get_prom(dev_addr, nic.base);
- if (!r)
- return -1;
+#ifndef CONFIG_NE2000_NOPROM
+ {
+ char ethaddr[20];
+ r = get_prom(dev_addr, nic.base);
+ if (!r)
+ return -1;
+
+ sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
+ dev_addr[0], dev_addr[1],
+ dev_addr[2], dev_addr[3],
+ dev_addr[4], dev_addr[5]) ;
+ PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr);
+ setenv ("ethaddr", ethaddr);
+ }
+#else /* CONFIG_NE2000_NOPROM */
+ {
+ char *s = getenv("ethaddr");
- sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
- dev_addr[0], dev_addr[1],
- dev_addr[2], dev_addr[3],
- dev_addr[4], dev_addr[5]) ;
- PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr);
- setenv ("ethaddr", ethaddr);
+ if (!s) {
+ printf ("CONFIG_NE2000_NOPROM set but no "
+ "ethaddr given in environment.\n");
+ return -1;
+ }
+
+ /* convert the string notation */
+ for (r = 0; r < 6; r++)
+ dev_addr[r] = simple_strtol(s + (r * 3), NULL, 16);
+ }
+#endif
nic.data = nic.base + DP_DATA;
nic.tx_buf1 = START_PG;
More information about the U-Boot
mailing list