[U-Boot] [PATCH 00/30] standardize mac address handling in u-boot (v2)

this set of patches aims to standardize the mac address handling in all of u-boot by doing the following: - add helper funcs for working with mac addresses (binary & string) - add format strings from Linux for printf-ing mac addresses - convert all duplicated code to use aforementioned helper funcs - convert all places to get the mac address from the environment - drop the global data instances of bi_enet*addr - document the whole damned thing
ive taken pains to make sure the patchset doesnt break along the way (in terms of doing bisection and such). but in general, the interdependency looks something like: - add util funcs - convert net/boards/drivers/cpu/commands from global data to env - convert arch/board.c init to not touch global data - remove global data from all arch headers
the ppc steps with load_sernum_ethaddr() are a little hairy due to the spread of code and trying to make sure things don't break bisection. but the other option is to squash all these commits (the common ppc board code as well as each individual board) into one change. doesn't matter to me either way.
v2 of the patchset brings these changes: - import updated printf modifiers from the kernel - convert str_enetaddr() to %pM - convert print_IPaddr() to %pI4 - convert board_get_enetaddr() to board specific code - misc fixes/changes based on feedback from people
while the new printf code is bigger by about 900bytes, i think we make up most of that by converting str_enetaddr/print_IPaddr users over to it.
currently this patch series is maintained in my tree: git://www.denx.de/git/u-boot-blackfin.git macaddr
Mike Frysinger (30): vsprintf: pull updates from Linux kernel convert print_IPaddr() to %pI4 net: new utility functions for working with enetaddr's doc/README.enetaddr: document proper MAC usage Blackfin: bfin_mac: force boards to setup the MAC themselves net: get mac address from environment and use eth util funcs bdinfo: get mac address from environment bootvx: get mac address from environment lynxkdi: get mac address from environment nvedit: do not update global bi_enetaddr and do not call eth_set_enetaddr() AmigaOneG3SE/enet: get mac address from environment boards: get mac address from environment drivers/net/: get mac address from environment bcm570x: get mac address from environment cs8900: get mac address from environment sh_eth: get mac address from environment lan91c96/smc91111/smc911x: get mac address from environment cpu/: get mac address from environment npe: get mac address from environment lib_*/board.c: do not initialize bi_enet*addr in global data nx823: get mac address from environment arm: get mac address from environment boards: move board_get_enetaddr() into board-specific init cmc_pu2: get mac address from environment pcs440ep: get mac address from environment and move load_sernum_ethaddr() to board init kup4k/kup4x: rename load_sernum_ethaddr() to kup_load_sernum_ethaddr() tqm8xx: rename load_sernum_ethaddr() to tqc_load_sernum_ethaddr() ppc: mark global bi_enet*addr as legacy drop now unused load_sernum_ethaddr() function remove bi_enet*addr from global data for all arches
board/MAI/AmigaOneG3SE/enet.c | 42 +--- board/RPXClassic/RPXClassic.c | 16 +- board/cmc_pu2/load_sernum_ethaddr.c | 18 +- board/etin/debris/debris.c | 10 +- board/keymile/mgcoge/mgcoge.c | 4 +- board/keymile/mgsuvd/mgsuvd.c | 4 +- board/kup/common/load_sernum_ethaddr.c | 2 +- board/kup/kup4k/kup4k.c | 3 + board/kup/kup4x/kup4x.c | 4 +- board/m501sk/m501sk.c | 5 - board/mbx8xx/mbx8xx.c | 14 +- board/mpl/vcma9/cmd_vcma9.c | 11 +- board/muas3001/muas3001.c | 4 +- board/netstal/common/nm_bsp.c | 40 +-- board/nx823/flash.c | 5 +- board/nx823/nx823.c | 41 +-- board/pcs440ep/pcs440ep.c | 31 +-- board/pn62/pn62.c | 24 +- board/sandburst/common/sb_common.c | 4 +- board/sandburst/common/sb_common.h | 1 + board/sandburst/karef/karef.c | 29 ++ board/sandburst/metrobox/metrobox.c | 29 ++ board/siemens/IAD210/IAD210.c | 14 +- board/sixnet/sixnet.c | 11 +- board/tqc/tqm8xx/load_sernum_ethaddr.c | 2 +- board/tqc/tqm8xx/tqm8xx.c | 3 + board/v38b/v38b.c | 12 + board/xilinx/xilinx_enet/emac_adapter.c | 8 +- board/xpedite1k/xpedite1k.c | 51 +++- common/cmd_bdinfo.c | 166 ++++-------- common/cmd_elf.c | 6 +- common/cmd_ide.c | 10 +- common/cmd_nvedit.c | 24 +-- common/lynxkdi.c | 2 +- cpu/arm920t/at91rm9200/ether.c | 8 +- cpu/ixp/npe/npe.c | 36 +-- cpu/mpc512x/cpu.c | 6 +- cpu/mpc5xxx/cpu.c | 6 +- cpu/mpc8260/ether_fcc.c | 4 +- cpu/mpc8260/ether_scc.c | 4 +- cpu/ppc4xx/cpu_init.c | 14 +- disk/part.c | 2 +- doc/README.enetaddr | 97 +++++++ drivers/net/3c589.c | 7 +- drivers/net/4xx_enet.c | 13 +- drivers/net/bcm570x.c | 4 +- drivers/net/bcm570x_lm.h | 2 +- drivers/net/bfin_mac.c | 16 +- drivers/net/bfin_mac.h | 2 +- drivers/net/cs8900.c | 56 +--- drivers/net/dc2114x.c | 9 +- drivers/net/dm9000x.c | 26 +-- drivers/net/enc28j60.c | 4 +- drivers/net/fsl_mcdmafec.c | 11 +- drivers/net/ks8695eth.c | 8 +- drivers/net/lan91c96.c | 75 +---- drivers/net/mcffec.c | 10 +- drivers/net/rtl8019.c | 14 +- drivers/net/rtl8169.c | 2 +- drivers/net/s3c4510b_eth.c | 2 +- drivers/net/s3c4510b_eth.h | 2 +- drivers/net/sh_eth.c | 28 +-- drivers/net/smc91111.c | 72 +---- drivers/net/smc911x.c | 14 +- drivers/net/tigon3.c | 7 +- drivers/net/xilinx_emac.c | 12 +- drivers/net/xilinx_emaclite.c | 11 +- include/asm-arm/u-boot.h | 5 - include/asm-avr32/u-boot.h | 1 - include/asm-blackfin/u-boot.h | 1 - include/asm-i386/u-boot.h | 1 - include/asm-m68k/u-boot.h | 13 - include/asm-microblaze/u-boot.h | 1 - include/asm-mips/u-boot.h | 1 - include/asm-nios/u-boot.h | 1 - include/asm-nios2/u-boot.h | 1 - include/asm-ppc/u-boot.h | 14 +- include/asm-sh/u-boot.h | 1 - include/asm-sparc/u-boot.h | 12 - include/common.h | 9 - include/configs/IAD210.h | 1 + include/configs/MBX860T.h | 2 + include/configs/RPXClassic.h | 1 + include/configs/XPEDITE1K.h | 1 + include/configs/cmc_pu2.h | 1 + include/configs/v38b.h | 1 + include/net.h | 6 +- lib_arm/board.c | 47 +--- lib_blackfin/board.c | 48 +--- lib_generic/vsprintf.c | 479 ++++++++++++++++++++++++------- lib_i386/board.c | 17 -- lib_m68k/board.c | 38 --- lib_microblaze/board.c | 8 - lib_mips/board.c | 8 - lib_nios/board.c | 5 - lib_nios2/board.c | 5 - lib_ppc/board.c | 92 +------ lib_sh/board.c | 10 - lib_sparc/board.c | 19 -- net/bootp.c | 29 +-- net/eth.c | 76 +++-- net/net.c | 30 +-- net/nfs.c | 10 +- net/tftp.c | 10 +- post/cpu/mpc8xx/ether.c | 4 +- 105 files changed, 1055 insertions(+), 1188 deletions(-) create mode 100644 doc/README.enetaddr

This brings in support for the %p modifier which allows us to easily print out things like ip addresses, mac addresses, and pointers.
It also converts the rarely used 'q' length modifier to the common 'L' modifier when dealing with quad types.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- common/cmd_ide.c | 10 +- disk/part.c | 2 +- lib_generic/vsprintf.c | 479 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 379 insertions(+), 112 deletions(-)
diff --git a/common/cmd_ide.c b/common/cmd_ide.c index 8c6ed35..9bc6b4a 100644 --- a/common/cmd_ide.c +++ b/common/cmd_ide.c @@ -303,7 +303,7 @@ int do_ide (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_SYS_64BIT_LBA lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
- printf ("\nIDE read: device %d block # %qd, count %ld ... ", + printf ("\nIDE read: device %d block # %Ld, count %ld ... ", curr_device, blk, cnt); #else lbaint_t blk = simple_strtoul(argv[3], NULL, 16); @@ -332,7 +332,7 @@ int do_ide (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_SYS_64BIT_LBA lbaint_t blk = simple_strtoull(argv[3], NULL, 16);
- printf ("\nIDE write: device %d block # %qd, count %ld ... ", + printf ("\nIDE write: device %d block # %Ld, count %ld ... ", curr_device, blk, cnt); #else lbaint_t blk = simple_strtoul(argv[3], NULL, 16); @@ -1315,7 +1315,7 @@ ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer) lba48 = 1; } #endif - debug ("ide_read dev %d start %qX, blocks %lX buffer at %lX\n", + debug ("ide_read dev %d start %LX, blocks %lX buffer at %lX\n", device, blknr, blkcnt, (ulong)buffer);
ide_led (DEVICE_LED(device), 1); /* LED on */ @@ -1403,7 +1403,7 @@ ulong ide_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
if ((c&(ATA_STAT_DRQ|ATA_STAT_BUSY|ATA_STAT_ERR)) != ATA_STAT_DRQ) { #if defined(CONFIG_SYS_64BIT_LBA) && defined(CONFIG_SYS_64BIT_VSPRINTF) - printf ("Error (no IRQ) dev %d blk %qd: status 0x%02x\n", + printf ("Error (no IRQ) dev %d blk %Ld: status 0x%02x\n", device, blknr, c); #else printf ("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", @@ -1493,7 +1493,7 @@ ulong ide_write (int device, lbaint_t blknr, ulong blkcnt, void *buffer)
if ((c&(ATA_STAT_DRQ|ATA_STAT_BUSY|ATA_STAT_ERR)) != ATA_STAT_DRQ) { #if defined(CONFIG_SYS_64BIT_LBA) && defined(CONFIG_SYS_64BIT_VSPRINTF) - printf ("Error (no IRQ) dev %d blk %qd: status 0x%02x\n", + printf ("Error (no IRQ) dev %d blk %Ld: status 0x%02x\n", device, blknr, c); #else printf ("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", diff --git a/disk/part.c b/disk/part.c index e353cee..fdc49d3 100644 --- a/disk/part.c +++ b/disk/part.c @@ -184,7 +184,7 @@ void dev_print (block_dev_desc_t *dev_desc) printf (" Supports 48-bit addressing\n"); #endif #if defined(CONFIG_SYS_64BIT_LBA) && defined(CONFIG_SYS_64BIT_VSPRINTF) - printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%qd x %ld)\n", + printf (" Capacity: %ld.%ld MB = %ld.%ld GB (%Ld x %ld)\n", mb_quot, mb_rem, gb_quot, gb_rem, lba, diff --git a/lib_generic/vsprintf.c b/lib_generic/vsprintf.c index 767dde1..3ab1f5c 100644 --- a/lib_generic/vsprintf.c +++ b/lib_generic/vsprintf.c @@ -21,6 +21,31 @@ extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #endif
+#ifdef CONFIG_SYS_64BIT_VSPRINTF +# define NUM_TYPE long long +#else +# define NUM_TYPE long +#endif +#define noinline __attribute__((noinline)) + +#define do_div(n, base) ({ \ + unsigned int __res; \ + __res = ((unsigned NUM_TYPE) n) % base; \ + n = ((unsigned NUM_TYPE) n) / base; \ + __res; \ +}) + +const char hex_asc[] = "0123456789abcdef"; +#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] +#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] + +static inline char *pack_hex_byte(char *buf, u8 byte) +{ + *buf++ = hex_asc_hi(byte); + *buf++ = hex_asc_lo(byte); + return buf; +} + unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) { unsigned long result = 0,value; @@ -120,52 +145,132 @@ static int skip_atoi(const char **s) return i; }
+/* Decimal conversion is by far the most typical, and is used + * for /proc and /sys data. This directly impacts e.g. top performance + * with many processes running. We optimize it for speed + * using code from + * http://www.cs.uiowa.edu/~jones/bcd/decimal.html + * (with permission from the author, Douglas W. Jones). */ + +/* Formats correctly any integer in [0,99999]. + * Outputs from one to five digits depending on input. + * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */ +static char* put_dec_trunc(char *buf, unsigned q) +{ + unsigned d3, d2, d1, d0; + d1 = (q>>4) & 0xf; + d2 = (q>>8) & 0xf; + d3 = (q>>12); + + d0 = 6*(d3 + d2 + d1) + (q & 0xf); + q = (d0 * 0xcd) >> 11; + d0 = d0 - 10*q; + *buf++ = d0 + '0'; /* least significant digit */ + d1 = q + 9*d3 + 5*d2 + d1; + if (d1 != 0) { + q = (d1 * 0xcd) >> 11; + d1 = d1 - 10*q; + *buf++ = d1 + '0'; /* next digit */ + + d2 = q + 2*d2; + if ((d2 != 0) || (d3 != 0)) { + q = (d2 * 0xd) >> 7; + d2 = d2 - 10*q; + *buf++ = d2 + '0'; /* next digit */ + + d3 = q + 4*d3; + if (d3 != 0) { + q = (d3 * 0xcd) >> 11; + d3 = d3 - 10*q; + *buf++ = d3 + '0'; /* next digit */ + if (q != 0) + *buf++ = q + '0'; /* most sign. digit */ + } + } + } + return buf; +} +/* Same with if's removed. Always emits five digits */ +static char* put_dec_full(char *buf, unsigned q) +{ + /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ + /* but anyway, gcc produces better code with full-sized ints */ + unsigned d3, d2, d1, d0; + d1 = (q>>4) & 0xf; + d2 = (q>>8) & 0xf; + d3 = (q>>12); + + /* Possible ways to approx. divide by 10 */ + /* gcc -O2 replaces multiply with shifts and adds */ + // (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) + // (x * 0x67) >> 10: 1100111 + // (x * 0x34) >> 9: 110100 - same + // (x * 0x1a) >> 8: 11010 - same + // (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) + + d0 = 6*(d3 + d2 + d1) + (q & 0xf); + q = (d0 * 0xcd) >> 11; + d0 = d0 - 10*q; + *buf++ = d0 + '0'; + d1 = q + 9*d3 + 5*d2 + d1; + q = (d1 * 0xcd) >> 11; + d1 = d1 - 10*q; + *buf++ = d1 + '0'; + + d2 = q + 2*d2; + q = (d2 * 0xd) >> 7; + d2 = d2 - 10*q; + *buf++ = d2 + '0'; + + d3 = q + 4*d3; + q = (d3 * 0xcd) >> 11; /* - shorter code */ + /* q = (d3 * 0x67) >> 10; - would also work */ + d3 = d3 - 10*q; + *buf++ = d3 + '0'; + *buf++ = q + '0'; + return buf; +} +/* No inlining helps gcc to use registers better */ +static noinline char* put_dec(char *buf, unsigned NUM_TYPE num) +{ + while (1) { + unsigned rem; + if (num < 100000) + return put_dec_trunc(buf, num); + rem = do_div(num, 100000); + buf = put_dec_full(buf, rem); + } +} + #define ZEROPAD 1 /* pad with zero */ #define SIGN 2 /* unsigned/signed long */ #define PLUS 4 /* show plus */ #define SPACE 8 /* space if plus */ #define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ +#define SMALL 32 /* Must be 32 == 0x20 */ +#define SPECIAL 64 /* 0x */
-#ifdef CONFIG_SYS_64BIT_VSPRINTF -#define do_div(n,base) ({ \ - unsigned int __res; \ - __res = ((unsigned long long) n) % base; \ - n = ((unsigned long long) n) / base; \ - __res; \ -}) -#else -#define do_div(n,base) ({ \ - int __res; \ - __res = ((unsigned long) n) % base; \ - n = ((unsigned long) n) / base; \ - __res; \ -}) -#endif - -#ifdef CONFIG_SYS_64BIT_VSPRINTF -static char * number(char * str, long long num, unsigned int base, int size, int precision ,int type) -#else -static char * number(char * str, long num, unsigned int base, int size, int precision ,int type) -#endif +static char *number(char *buf, unsigned NUM_TYPE num, int base, int size, int precision, int type) { - char c,sign,tmp[66]; - const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; + /* we are called with base 8, 10 or 16, only, thus don't need "G..." */ + static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */ + + char tmp[66]; + char sign; + char locase; + int need_pfx = ((type & SPECIAL) && base != 10); int i;
- if (type & LARGE) - digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + /* locase = 0 or 0x20. ORing digits or letters with 'locase' + * produces same digits or (maybe lowercased) letters */ + locase = (type & SMALL); if (type & LEFT) type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; sign = 0; if (type & SIGN) { - if (num < 0) { + if ((signed NUM_TYPE) num < 0) { sign = '-'; - num = -num; + num = - (signed NUM_TYPE) num; size--; } else if (type & PLUS) { sign = '+'; @@ -175,68 +280,231 @@ static char * number(char * str, long num, unsigned int base, int size, int prec size--; } } - if (type & SPECIAL) { + if (need_pfx) { + size--; if (base == 16) - size -= 2; - else if (base == 8) size--; } + + /* generate full string in tmp[], in reverse order */ i = 0; if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div(num,base)]; + tmp[i++] = '0'; + /* Generic code, for any base: + else do { + tmp[i++] = (digits[do_div(num,base)] | locase); + } while (num != 0); + */ + else if (base != 10) { /* 8 or 16 */ + int mask = base - 1; + int shift = 3; + if (base == 16) shift = 4; + do { + tmp[i++] = (digits[((unsigned char)num) & mask] | locase); + num >>= shift; + } while (num); + } else { /* base 10 */ + i = put_dec(tmp, num) - tmp; + } + + /* printing 100 using %2d gives "100", not "00" */ if (i > precision) precision = i; + /* leading space padding */ size -= precision; - if (!(type&(ZEROPAD+LEFT))) - while(size-->0) - *str++ = ' '; + if (!(type & (ZEROPAD+LEFT))) + while(--size >= 0) + *buf++ = ' '; + /* sign */ if (sign) - *str++ = sign; - if (type & SPECIAL) { - if (base==8) - *str++ = '0'; - else if (base==16) { - *str++ = '0'; - *str++ = digits[33]; - } + *buf++ = sign; + /* "0x" / "0" prefix */ + if (need_pfx) { + *buf++ = '0'; + if (base == 16) + *buf++ = ('X' | locase); + } + /* zero or space padding */ + if (!(type & LEFT)) { + char c = (type & ZEROPAD) ? '0' : ' '; + while (--size >= 0) + *buf++ = c; } - if (!(type & LEFT)) - while (size-- > 0) - *str++ = c; - while (i < precision--) - *str++ = '0'; - while (i-- > 0) - *str++ = tmp[i]; - while (size-- > 0) - *str++ = ' '; - return str; + /* hmm even more zero padding? */ + while (i <= --precision) + *buf++ = '0'; + /* actual digits of result */ + while (--i >= 0) + *buf++ = tmp[i]; + /* trailing space padding */ + while (--size >= 0) + *buf++ = ' '; + return buf; }
-/* Forward decl. needed for IP address printing stuff... */ -int sprintf(char * buf, const char *fmt, ...); +static char *string(char *buf, char *s, int field_width, int precision, int flags) +{ + int len, i;
-int vsprintf(char *buf, const char *fmt, va_list args) + if (s == 0) + s = "<NULL>"; + + len = strnlen(s, precision); + + if (!(flags & LEFT)) + while (len < field_width--) + *buf++ = ' '; + for (i = 0; i < len; ++i) + *buf++ = *s++; + while (len < field_width--) + *buf++ = ' '; + return buf; +} + +#ifdef CONFIG_CMD_NET +static char *mac_address_string(char *buf, u8 *addr, int field_width, + int precision, int flags) { - int len; -#ifdef CONFIG_SYS_64BIT_VSPRINTF - unsigned long long num; -#else - unsigned long num; + char mac_addr[6 * 3]; /* (6 * 2 hex digits), 5 colons and trailing zero */ + char *p = mac_addr; + int i; + + for (i = 0; i < 6; i++) { + p = pack_hex_byte(p, addr[i]); + if (!(flags & SPECIAL) && i != 5) + *p++ = ':'; + } + *p = '\0'; + + return string(buf, mac_addr, field_width, precision, flags & ~SPECIAL); +} + +static char *ip6_addr_string(char *buf, u8 *addr, int field_width, + int precision, int flags) +{ + char ip6_addr[8 * 5]; /* (8 * 4 hex digits), 7 colons and trailing zero */ + char *p = ip6_addr; + int i; + + for (i = 0; i < 8; i++) { + p = pack_hex_byte(p, addr[2 * i]); + p = pack_hex_byte(p, addr[2 * i + 1]); + if (!(flags & SPECIAL) && i != 7) + *p++ = ':'; + } + *p = '\0'; + + return string(buf, ip6_addr, field_width, precision, flags & ~SPECIAL); +} + +static char *ip4_addr_string(char *buf, u8 *addr, int field_width, + int precision, int flags) +{ + char ip4_addr[4 * 4]; /* (4 * 3 decimal digits), 3 dots and trailing zero */ + char temp[3]; /* hold each IP quad in reverse order */ + char *p = ip4_addr; + int i, digits; + + for (i = 0; i < 4; i++) { + digits = put_dec_trunc(temp, addr[i]) - temp; + /* reverse the digits in the quad */ + while (digits--) + *p++ = temp[digits]; + if (i != 3) + *p++ = '.'; + } + *p = '\0'; + + return string(buf, ip4_addr, field_width, precision, flags & ~SPECIAL); +} #endif - int i, base; - char * str; - const char *s; + +/* + * Show a '%p' thing. A kernel extension is that the '%p' is followed + * by an extra set of alphanumeric characters that are extended format + * specifiers. + * + * Right now we handle: + * + * - 'M' For a 6-byte MAC address, it prints the address in the + * usual colon-separated hex notation + * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way (dot-separated + * decimal for v4 and colon separated network-order 16 bit hex for v6) + * - 'i' [46] for 'raw' IPv4/IPv6 addresses, IPv6 omits the colons, IPv4 is + * currently the same + * + * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 + * function pointers are really function descriptors, which contain a + * pointer to the real address. + */ +static char *pointer(const char *fmt, char *buf, void *ptr, int field_width, int precision, int flags) +{ + if (!ptr) + return string(buf, "(null)", field_width, precision, flags); + +#ifdef CONFIG_CMD_NET + switch (*fmt) { + case 'm': + flags |= SPECIAL; + /* Fallthrough */ + case 'M': + return mac_address_string(buf, ptr, field_width, precision, flags); + case 'i': + flags |= SPECIAL; + /* Fallthrough */ + case 'I': + if (fmt[1] == '6') + return ip6_addr_string(buf, ptr, field_width, precision, flags); + if (fmt[1] == '4') + return ip4_addr_string(buf, ptr, field_width, precision, flags); + flags &= ~SPECIAL; + break; + } +#endif + flags |= SMALL; + if (field_width == -1) { + field_width = 2*sizeof(void *); + flags |= ZEROPAD; + } + return number(buf, (unsigned long) ptr, 16, field_width, precision, flags); +} + +/** + * vsprintf - Format a string and place it in a buffer + * @buf: The buffer to place the result into + * @fmt: The format string to use + * @args: Arguments for the format string + * + * This function follows C99 vsprintf, but has some extensions: + * %pS output the name of a text symbol + * %pF output the name of a function pointer + * %pR output the address range in a struct resource + * + * The function returns the number of characters written + * into @buf. + * + * Call this function if you are already dealing with a va_list. + * You probably want sprintf() instead. + */ +int vsprintf(char *buf, const char *fmt, va_list args) +{ + unsigned NUM_TYPE num; + int base; + char *str;
int flags; /* flags to number() */
int field_width; /* width of output field */ int precision; /* min. # of digits for integers; max number of chars for from string */ - int qualifier; /* 'h', 'l', or 'q' for integer fields */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + /* 't' added for ptrdiff_t */ + + str = buf;
- for (str=buf ; *fmt ; ++fmt) { + for (; *fmt ; ++fmt) { if (*fmt != '%') { *str++ = *fmt; continue; @@ -252,7 +520,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) case ' ': flags |= SPACE; goto repeat; case '#': flags |= SPECIAL; goto repeat; case '0': flags |= ZEROPAD; goto repeat; - } + }
/* get field width */ field_width = -1; @@ -286,14 +554,13 @@ int vsprintf(char *buf, const char *fmt, va_list args) /* get the conversion qualifier */ qualifier = -1; if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || - *fmt == 'Z' || *fmt == 'z' || *fmt == 't' || - *fmt == 'q' ) { + *fmt == 'Z' || *fmt == 'z' || *fmt == 't') { qualifier = *fmt; - if (qualifier == 'l' && *(fmt+1) == 'l') { - qualifier = 'q'; + ++fmt; + if (qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; ++fmt; } - ++fmt; }
/* default base */ @@ -310,32 +577,18 @@ int vsprintf(char *buf, const char *fmt, va_list args) continue;
case 's': - s = va_arg(args, char *); - if (!s) - s = "<NULL>"; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) - while (len < field_width--) - *str++ = ' '; - for (i = 0; i < len; ++i) - *str++ = *s++; - while (len < field_width--) - *str++ = ' '; + str = string(str, va_arg(args, char *), field_width, precision, flags); continue;
case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, - (unsigned long) va_arg(args, void *), 16, - field_width, precision, flags); + str = pointer(fmt+1, str, + va_arg(args, void *), + field_width, precision, flags); + /* Skip all alphanumeric pointer suffixes */ + while (isalnum(fmt[1])) + fmt++; continue;
- case 'n': if (qualifier == 'l') { long * ip = va_arg(args, long *); @@ -355,9 +608,9 @@ int vsprintf(char *buf, const char *fmt, va_list args) base = 8; break;
- case 'X': - flags |= LARGE; case 'x': + flags |= SMALL; + case 'X': base = 16; break;
@@ -376,12 +629,14 @@ int vsprintf(char *buf, const char *fmt, va_list args) continue; } #ifdef CONFIG_SYS_64BIT_VSPRINTF - if (qualifier == 'q') /* "quad" for 64 bit variables */ + if (qualifier == 'L') /* "quad" for 64 bit variables */ num = va_arg(args, unsigned long long); else #endif if (qualifier == 'l') { num = va_arg(args, unsigned long); + if (flags & SIGN) + num = (signed long) num; } else if (qualifier == 'Z' || qualifier == 'z') { num = va_arg(args, size_t); } else if (qualifier == 't') { @@ -389,17 +644,29 @@ int vsprintf(char *buf, const char *fmt, va_list args) } else if (qualifier == 'h') { num = (unsigned short) va_arg(args, int); if (flags & SIGN) - num = (short) num; - } else if (flags & SIGN) - num = va_arg(args, int); - else + num = (signed short) num; + } else { num = va_arg(args, unsigned int); + if (flags & SIGN) + num = (signed int) num; + } str = number(str, num, base, field_width, precision, flags); } *str = '\0'; return str-buf; }
+/** + * sprintf - Format a string and place it in a buffer + * @buf: The buffer to place the result into + * @fmt: The format string to use + * @...: Arguments for the format string + * + * The function returns the number of characters written + * into @buf. + * + * See the vsprintf() documentation for format string extensions over C99. + */ int sprintf(char * buf, const char *fmt, ...) { va_list args;

On 00:10 Tue 17 Feb , Mike Frysinger wrote:
This brings in support for the %p modifier which allows us to easily print out things like ip addresses, mac addresses, and pointers.
It also converts the rarely used 'q' length modifier to the common 'L' modifier when dealing with quad types.
Signed-off-by: Mike Frysinger vapier@gentoo.org
what will be the overhead for the boards?
Best Regards, J.

On Wednesday 18 February 2009 10:18:59 Jean-Christophe PLAGNIOL-VILLARD wrote:
On 00:10 Tue 17 Feb , Mike Frysinger wrote:
This brings in support for the %p modifier which allows us to easily print out things like ip addresses, mac addresses, and pointers.
It also converts the rarely used 'q' length modifier to the common 'L' modifier when dealing with quad types.
what will be the overhead for the boards?
i dont understand the question -mike

On 11:40 Wed 18 Feb , Mike Frysinger wrote:
On Wednesday 18 February 2009 10:18:59 Jean-Christophe PLAGNIOL-VILLARD wrote:
On 00:10 Tue 17 Feb , Mike Frysinger wrote:
This brings in support for the %p modifier which allows us to easily print out things like ip addresses, mac addresses, and pointers.
It also converts the rarely used 'q' length modifier to the common 'L' modifier when dealing with quad types.
what will be the overhead for the boards?
i dont understand the question
what the size impact?
Best Regards, J.

On Wed 18 February 2009 11:55:55 Jean-Christophe PLAGNIOL-VILLARD wrote:
On 11:40 Wed 18 Feb , Mike Frysinger wrote:
On Wed 18 February 2009 10:18:59 Jean-Christophe PLAGNIOL-VILLARD wrote:
On 00:10 Tue 17 Feb , Mike Frysinger wrote:
This brings in support for the %p modifier which allows us to easily print out things like ip addresses, mac addresses, and pointers.
It also converts the rarely used 'q' length modifier to the common 'L' modifier when dealing with quad types.
what will be the overhead for the boards?
i dont understand the question
what the size impact?
i mentioned that in the summary for the patch series -mike

Now that our printf functions support the %pI4 modifier like the kernel, let's drop the inflexible print_IPaddr() function and covert over to the %pI4 modifier.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- common/cmd_bdinfo.c | 48 +++++++++++++++++++----------------------------- include/net.h | 3 --- net/bootp.c | 18 +++++------------- net/net.c | 13 +------------ net/nfs.c | 10 ++++------ net/tftp.c | 10 ++++------ 6 files changed, 33 insertions(+), 69 deletions(-)
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c index b2d6f84..6af5749 100644 --- a/common/cmd_bdinfo.c +++ b/common/cmd_bdinfo.c @@ -26,7 +26,6 @@ */ #include <common.h> #include <command.h> -#include <net.h> /* for print_IPaddr */
DECLARE_GLOBAL_DATA_PTR;
@@ -134,8 +133,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #ifdef CONFIG_HERMES print_str ("ethspeed", strmhz(buf, bd->bi_ethspeed)); #endif - puts ("\nIP addr = "); print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %6ld bps\n", bd->bi_baudrate ); + printf ("IP addr = %pI4\n", &bd->bi_ip_addr); + printf ("baudrate = %6ld bps\n", bd->bi_baudrate ); return 0; }
@@ -156,9 +155,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (i=0; i<6; ++i) { printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %ld bps\n", bd->bi_baudrate); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); + printf ("baudrate = %ld bps\n", bd->bi_baudrate);
return 0; } @@ -188,11 +186,10 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (i=0; i<6; ++i) { printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif
- printf ("\nbaudrate = %ld bps\n", bd->bi_baudrate); + printf ("baudrate = %ld bps\n", bd->bi_baudrate);
return 0; } @@ -216,10 +213,9 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (i=0; i<6; ++i) { printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif - printf ("\nbaudrate = %ld bps\n", (ulong)bd->bi_baudrate); + printf ("baudrate = %ld bps\n", (ulong)bd->bi_baudrate); return 0; }
@@ -255,10 +251,9 @@ int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) for (i = 0; i < 6; ++i) { printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts("\nIP addr = "); - print_IPaddr(bd->bi_ip_addr); + printf("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif - printf("\nbaudrate = %6ld bps\n", bd->bi_baudrate); + printf("baudrate = %6ld bps\n", bd->bi_baudrate); return 0; }
@@ -320,10 +315,9 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif
- puts ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif - printf ("\nbaudrate = %ld bps\n", bd->bi_baudrate); + printf ("baudrate = %ld bps\n", bd->bi_baudrate);
return 0; } @@ -354,9 +348,8 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) puts("ethaddr ="); for (i = 0; i < 6; ++i) printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - puts("\nip_addr = "); - print_IPaddr(bd->bi_ip_addr); - printf("\nbaudrate = %d bps\n", bd->bi_baudrate); + printf("ip_addr = %pI4\n", &bd->bi_ip_addr); + printf("baudrate = %d bps\n", bd->bi_baudrate);
return 0; } @@ -379,9 +372,8 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (i=0; i<6; ++i) { printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts ("\nip_addr = "); - print_IPaddr (bd->bi_ip_addr); - printf ("\nbaudrate = %d bps\n", bd->bi_baudrate); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); + printf ("baudrate = %d bps\n", bd->bi_baudrate);
return 0; } @@ -409,12 +401,10 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) for (i=0; i<6; ++i) { printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); } - puts ( "\n" - "ip_addr = "); - print_IPaddr (bd->bi_ip_addr); + puts ( "\n" ); + printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif - printf ("\n" - "baudrate = %d bps\n", bd->bi_baudrate); + printf ("baudrate = %d bps\n", bd->bi_baudrate);
return 0; } diff --git a/include/net.h b/include/net.h index b192db1..bd061d9 100644 --- a/include/net.h +++ b/include/net.h @@ -408,9 +408,6 @@ extern int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, i /* Processes a received packet */ extern void NetReceive(volatile uchar *, int);
-/* Print an IP address on the console */ -extern void print_IPaddr (IPaddr_t); - /* * The following functions are a bit ugly, but necessary to deal with * alignment restrictions on ARM. diff --git a/net/bootp.c b/net/bootp.c index 83465e4..d1cbd39 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -271,17 +271,11 @@ static void BootpVendorProcess (u8 * ext, int size)
#ifdef DEBUG_BOOTP_EXT puts ("[BOOTP] Received fields: \n"); - if (NetOurSubnetMask) { - puts ("NetOurSubnetMask : "); - print_IPaddr (NetOurSubnetMask); - putc ('\n'); - } + if (NetOurSubnetMask) + printf ("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
- if (NetOurGatewayIP) { - puts ("NetOurGatewayIP : "); - print_IPaddr (NetOurGatewayIP); - putc ('\n'); - } + if (NetOurGatewayIP) + printf ("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
if (NetBootFileSize) { printf ("NetBootFileSize : %d\n", NetBootFileSize); @@ -942,9 +936,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); BootpCopyNetParams(bp); /* Store net params from reply */ dhcp_state = BOUND; - puts ("DHCP client bound to address "); - print_IPaddr(NetOurIP); - putc ('\n'); + printf ("DHCP client bound to address %pI4\n", &NetOurIP);
/* Obey the 'autoload' setting */ if ((s = getenv("autoload")) != NULL) { diff --git a/net/net.c b/net/net.c index 459baf4..9740f38 100644 --- a/net/net.c +++ b/net/net.c @@ -1445,9 +1445,7 @@ NetReceive(volatile uchar * inpkt, int len) case ICMP_REDIRECT: if (icmph->code != ICMP_REDIR_HOST) return; - puts (" ICMP Host Redirect to "); - print_IPaddr(icmph->un.gateway); - putc(' '); + printf (" ICMP Host Redirect to %pI4 ", &icmph->un.gateway); return; #if defined(CONFIG_CMD_PING) case ICMP_ECHO_REPLY: @@ -1789,15 +1787,6 @@ ushort string_to_VLAN(char *s) return htons(id); }
-void print_IPaddr (IPaddr_t x) -{ - char tmp[16]; - - ip_to_string (x, tmp); - - puts (tmp); -} - IPaddr_t getenv_IPaddr (char *var) { return (string_to_ip(getenv(var))); diff --git a/net/nfs.c b/net/nfs.c index f290014..0101629 100644 --- a/net/nfs.c +++ b/net/nfs.c @@ -741,18 +741,16 @@ NfsStart (void) printf ("Using %s device\n", eth_get_name()); #endif
- puts ("File transfer via NFS from server "); print_IPaddr (NfsServerIP); - puts ("; our IP address is "); print_IPaddr (NetOurIP); + printf("File transfer via NFS from server %pI4" + "; our IP address is %pI4", &NfsServerIP, &NetOurIP);
/* Check if we need to send across this subnet */ if (NetOurGatewayIP && NetOurSubnetMask) { IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask;
- if (OurNet != ServerNet) { - puts ("; sending through gateway "); - print_IPaddr (NetOurGatewayIP) ; - } + if (OurNet != ServerNet) + printf("; sending through gateway %pI4", &NetOurGatewayIP); } printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
diff --git a/net/tftp.c b/net/tftp.c index 3dac3d8..b0f1cca 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -508,18 +508,16 @@ TftpStart (void) #if defined(CONFIG_NET_MULTI) printf ("Using %s device\n", eth_get_name()); #endif - puts ("TFTP from server "); print_IPaddr (TftpServerIP); - puts ("; our IP address is "); print_IPaddr (NetOurIP); + printf("TFTP from server %pI4" + "; our IP address is %pI4", &TftpServerIP, &NetOurIP);
/* Check if we need to send across this subnet */ if (NetOurGatewayIP && NetOurSubnetMask) { IPaddr_t OurNet = NetOurIP & NetOurSubnetMask; IPaddr_t ServerNet = TftpServerIP & NetOurSubnetMask;
- if (OurNet != ServerNet) { - puts ("; sending through gateway "); - print_IPaddr (NetOurGatewayIP) ; - } + if (OurNet != ServerNet) + printf("; sending through gateway %pI4", &NetOurGatewayIP); } putc ('\n');

Declare new utility functions for converting between the environment variables (eth*addr) and the binary MAC address representation. This way we can unify all the random places that already do this kind of thing.
The functions in question: eth_parse_enetaddr - "..." -> {...} eth_getenv_enetaddr - env -> {...} eth_setenv_enetaddr - {...} -> env
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- include/net.h | 3 ++ net/eth.c | 76 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 31 deletions(-)
diff --git a/include/net.h b/include/net.h index bd061d9..5a1d36e 100644 --- a/include/net.h +++ b/include/net.h @@ -120,6 +120,9 @@ extern struct eth_device *eth_get_dev_by_name(char *devname); /* get device */ extern struct eth_device *eth_get_dev_by_index(int index); /* get dev @ index */ extern int eth_get_dev_index (void); /* get the device index */ extern void eth_set_enetaddr(int num, char* a); /* Set new MAC address */ +extern void eth_parse_enetaddr(const char *addr, uchar *enetaddr); +extern int eth_getenv_enetaddr(char *name, uchar *enetaddr); +extern int eth_setenv_enetaddr(char *name, const uchar *enetaddr);
extern int eth_init(bd_t *bis); /* Initialize the device */ extern int eth_send(volatile void *packet, int length); /* Send a packet */ diff --git a/net/eth.c b/net/eth.c index ec2ef1a..24ecfa1 100644 --- a/net/eth.c +++ b/net/eth.c @@ -26,6 +26,42 @@ #include <net.h> #include <miiphy.h>
+#ifdef CONFIG_CMD_NET +void eth_parse_enetaddr(const char *addr, uchar *enetaddr) +{ + char *end; + int i; + + for (i = 0; i < 6; ++i) { + enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; + if (addr) + addr = (*end) ? end + 1 : end; + } +} + +int eth_getenv_enetaddr(char *name, uchar *enetaddr) +{ + int ret = 0; + char *addr; + + addr = getenv(name); + if (!addr) + ret = -1; + eth_parse_enetaddr(addr, enetaddr); + + return ret; +} + +int eth_setenv_enetaddr(char *name, const uchar *enetaddr) +{ + char buf[20]; + + sprintf(buf, "%pM", enetaddr); + + return setenv(name, buf); +} +#endif + #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
/* @@ -153,8 +189,7 @@ int eth_initialize(bd_t *bis) { char enetvar[32]; unsigned char env_enetaddr[6]; - int i, eth_number = 0; - char *tmp, *end; + int eth_number = 0;
eth_devices = NULL; eth_current = NULL; @@ -194,13 +229,7 @@ int eth_initialize(bd_t *bis) }
sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number); - tmp = getenv (enetvar); - - for (i=0; i<6; i++) { - env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; - if (tmp) - tmp = (*end) ? end+1 : end; - } + eth_getenv_enetaddr(enetvar, env_enetaddr);
if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) { if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) && @@ -208,16 +237,10 @@ int eth_initialize(bd_t *bis) { printf ("\nWarning: %s MAC addresses don't match:\n", dev->name); - printf ("Address in SROM is " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - dev->enetaddr[0], dev->enetaddr[1], - dev->enetaddr[2], dev->enetaddr[3], - dev->enetaddr[4], dev->enetaddr[5]); - printf ("Address in environment is " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - env_enetaddr[0], env_enetaddr[1], - env_enetaddr[2], env_enetaddr[3], - env_enetaddr[4], env_enetaddr[5]); + printf ("Address in SROM is %pM\n", + dev->enetaddr); + printf ("Address in environment is %pM\n", + env_enetaddr); }
memcpy(dev->enetaddr, env_enetaddr, 6); @@ -246,19 +269,13 @@ int eth_initialize(bd_t *bis) void eth_set_enetaddr(int num, char *addr) { struct eth_device *dev; unsigned char enetaddr[6]; - char *end; - int i;
debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr);
if (!eth_devices) return;
- for (i=0; i<6; i++) { - enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; - if (addr) - addr = (*end) ? end+1 : end; - } + eth_parse_enetaddr(addr, enetaddr);
dev = eth_devices; while(num-- > 0) { @@ -269,11 +286,8 @@ void eth_set_enetaddr(int num, char *addr) { }
debug ( "Setting new HW address on %s\n" - "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n", - dev->name, - enetaddr[0], enetaddr[1], - enetaddr[2], enetaddr[3], - enetaddr[4], enetaddr[5]); + "New Address is %pM\n", + dev->name, enetaddr);
memcpy(dev->enetaddr, enetaddr, 6); }

On Tuesday 17 February 2009 00:10:24 Mike Frysinger wrote:
+int eth_getenv_enetaddr(char *name, uchar *enetaddr) +{
- int ret = 0;
- char *addr;
- addr = getenv(name);
- if (!addr)
ret = -1;
- eth_parse_enetaddr(addr, enetaddr);
- return ret;
+}
the return value isnt shaping up the way i expected in most every other place. i'll change it to read: return is_valid_ether_addr(enetaddr);
that way it'll behave as expected: 0->failure, 1->success -mike

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- doc/README.enetaddr | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) create mode 100644 doc/README.enetaddr
diff --git a/doc/README.enetaddr b/doc/README.enetaddr new file mode 100644 index 0000000..084a287 --- /dev/null +++ b/doc/README.enetaddr @@ -0,0 +1,97 @@ +--------------------------------- + Ethernet Address (MAC) Handling +--------------------------------- + +There are a variety of places in U-Boot where the MAC address is used, parsed, +and stored. This document covers proper usage of each location and the moving +of data between them. + +----------- + Locations +----------- + +Here are the places where MAC addresses might be stored: + + - board-specific location (eeprom, dedicated flash, ...) + Note: only used when mandatory due to hardware design etc... + + - environment ("ethaddr", "eth1addr", ...) (see CONFIG_ETHADDR) + Note: this is the preferred way to permanently store MAC addresses + + - ethernet data (struct eth_device -> enetaddr) + Note: these are temporary copies of the MAC address which exist only + after the respective init steps have run and only to make usage + in other places easier (to avoid constant env lookup/parsing) + + - struct bd_info and/or device tree + Note: these are temporary copies of the MAC address only for the + purpose of passing this information to an OS kernel we are about + to boot + +------- + Usage +------- + +If the hardware design mandates that the MAC address is stored in some special +place (like EEPROM etc...), then the board specific init code (such as the +board-specific misc_init_r() function) is responsible for locating the MAC +address(es) and initializing the respective environment variable(s) from it. +Note that this shall be done if, and only if, the environment does not already +contain these environment variables, i.e. existing variable definitions must +not be overwritten. + +During runtime, the ethernet layer will use the environment variables to sync +the MAC addresses to the ethernet structures. All ethernet driver code should +then only use the enetaddr member of the eth_device structure. This is done +on every network command, so the ethernet copies will stay in sync. + +Any other code that wishes to access the MAC address should query the +environment directly. The helper functions documented below should make +working with this storage much smoother. + +--------- + Helpers +--------- + +To assist in the management of these layers, a few helper functions exist. You +should use these rather than attempt to do any kind of parsing/manipulation +yourself as many common errors have arisen in the past. + + * void eth_parse_enetaddr(const char *addr, uchar *enetaddr); + +Convert a string representation of a MAC address to the binary version. +char *addr = "00:11:22:33:44:55"; +uchar enetaddr[6]; +eth_parse_enetaddr(addr, enetaddr); +/* enetaddr now equals { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } */ + + * int eth_getenv_enetaddr(char *name, uchar *enetaddr); + +Look up an environment variable and convert the stored address. If the env var +is not set, then the function returns -1. Otherwise, the conversion occurs and +returns 0. +uchar enetaddr[6]; +if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + /* "ethaddr" is not set in the environment */ + ... try and setup "ethaddr" in the env ... +} +/* enetaddr is now set to the value stored in the ethaddr env var */ + + * int eth_setenv_enetaddr(char *name, const uchar *enetaddr); + +Store the MAC address into the named environment variable. The return value is +the same as the setenv() function. +uchar enetaddr[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; +eth_setenv_enetaddr("ethaddr", enetaddr); +/* the "ethaddr" env var should now be set to "00:11:22:33:44:55" */ + + * the %pM format modifier + +The %pM format modifier can be used with any standard printf function to format +the binary 6 byte array representation of a MAC address. +uchar enetaddr[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; +printf("The MAC is %pM\n", enetaddr); + +char buf[20]; +sprintf(buf, "%pM", enetaddr); +/* the buf variable is now set to "00:11:22:33:44:55" */

Since the on-chip MAC does not have an eeprom or similar interface, force all Blackfin boards that use this driver to setup the board data with a proper MAC.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- drivers/net/bfin_mac.c | 16 ++++++++-------- drivers/net/bfin_mac.h | 2 +- lib_blackfin/board.c | 48 ++---------------------------------------------- 3 files changed, 11 insertions(+), 55 deletions(-)
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c index 23f934a..12d98c2 100644 --- a/drivers/net/bfin_mac.c +++ b/drivers/net/bfin_mac.c @@ -315,7 +315,7 @@ static int bfin_EMAC_init(struct eth_device *dev, bd_t *bd) return -1;
/* Initialize EMAC address */ - bfin_EMAC_setup_addr(bd); + bfin_EMAC_setup_addr(dev->enetaddr);
/* Initialize TX and RX buffer */ for (i = 0; i < PKTBUFSRX; i++) { @@ -373,16 +373,16 @@ static void bfin_EMAC_halt(struct eth_device *dev)
}
-void bfin_EMAC_setup_addr(bd_t *bd) +void bfin_EMAC_setup_addr(uchar *enetaddr) { *pEMAC_ADDRLO = - bd->bi_enetaddr[0] | - bd->bi_enetaddr[1] << 8 | - bd->bi_enetaddr[2] << 16 | - bd->bi_enetaddr[3] << 24; + enetaddr[0] | + enetaddr[1] << 8 | + enetaddr[2] << 16 | + enetaddr[3] << 24; *pEMAC_ADDRHI = - bd->bi_enetaddr[4] | - bd->bi_enetaddr[5] << 8; + enetaddr[4] | + enetaddr[5] << 8; }
ADI_ETHER_BUFFER *SetupRxBuffer(int no) diff --git a/drivers/net/bfin_mac.h b/drivers/net/bfin_mac.h index 084f533..8f467a3 100644 --- a/drivers/net/bfin_mac.h +++ b/drivers/net/bfin_mac.h @@ -61,6 +61,6 @@ static void bfin_EMAC_halt(struct eth_device *dev); static int bfin_EMAC_send(struct eth_device *dev, volatile void *packet, int length); static int bfin_EMAC_recv(struct eth_device *dev);
-static void bfin_EMAC_setup_addr(bd_t *bd); +void bfin_EMAC_setup_addr(uchar *enetaddr);
#endif diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c index c223711..537f69a 100644 --- a/lib_blackfin/board.c +++ b/lib_blackfin/board.c @@ -106,10 +106,6 @@ static void display_global_data(void) printf(" \-bd: %x\n", gd->bd); printf(" |-bi_baudrate: %x\n", bd->bi_baudrate); printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr); - printf(" |-bi_enetaddr: %x %x %x %x %x %x\n", - bd->bi_enetaddr[0], bd->bi_enetaddr[1], - bd->bi_enetaddr[2], bd->bi_enetaddr[3], - bd->bi_enetaddr[4], bd->bi_enetaddr[5]); printf(" |-bi_boot_params: %x\n", bd->bi_boot_params); printf(" |-bi_memstart: %x\n", bd->bi_memstart); printf(" |-bi_memsize: %x\n", bd->bi_memsize); @@ -338,35 +334,6 @@ void board_init_r(gd_t * id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate();
-#ifdef CONFIG_CMD_NET - /* board MAC address */ - s = getenv("ethaddr"); - if (s == NULL) { -# ifndef CONFIG_ETHADDR -# if 0 - if (!board_get_enetaddr(bd->bi_enetaddr)) { - char nid[20]; - sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X", - bd->bi_enetaddr[0], bd->bi_enetaddr[1], - bd->bi_enetaddr[2], bd->bi_enetaddr[3], - bd->bi_enetaddr[4], bd->bi_enetaddr[5]); - setenv("ethaddr", nid); - } -# endif -# endif - } else { - int i; - char *e; - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16); - s = (*e) ? e + 1 : e; - } - } - - /* IP Address */ - bd->bi_ip_addr = getenv_IPaddr("ipaddr"); -#endif - /* Initialize devices */ devices_init(); jumptable_init(); @@ -393,21 +360,10 @@ void board_init_r(gd_t * id, ulong dest_addr) #endif
#ifdef CONFIG_CMD_NET + /* IP Address */ + bd->bi_ip_addr = getenv_IPaddr("ipaddr"); printf("Net: "); eth_initialize(gd->bd); - if ((s = getenv("ethaddr"))) { -# ifndef CONFIG_NET_MULTI - size_t i; - char *e; - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16); - s = (*e) ? e + 1 : e; - } -# endif - printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", - bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2], - bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); - } #endif
display_global_data();

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- net/bootp.c | 13 ++----------- net/net.c | 17 +++++------------ 2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/net/bootp.c b/net/bootp.c index d1cbd39..3dea70a 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -573,21 +573,12 @@ BootpRequest (void) #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ unsigned char bi_enetaddr[6]; int reg; - char *e,*s; - char tmp[64]; ulong tst1, tst2, sum, m_mask, m_value = 0;
if (BootpTry ==0) { /* get our mac */ - reg = getenv_r ("ethaddr", tmp, sizeof(tmp)); - s = (reg > 0) ? tmp : NULL; + eth_getenv_enetaddr("ethaddr", bi_enetaddr);
- for (reg=0; reg<6; ++reg) { - bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) { - s = (*e) ? e+1 : e; - } - } #ifdef DEBUG puts ("BootpRequest => Our Mac: "); for (reg=0; reg<6; reg++) { diff --git a/net/net.c b/net/net.c index 9740f38..3fe5cb8 100644 --- a/net/net.c +++ b/net/net.c @@ -330,7 +330,7 @@ restart: #ifdef CONFIG_NET_MULTI memcpy (NetOurEther, eth_get_dev()->enetaddr, 6); #else - memcpy (NetOurEther, bd->bi_enetaddr, 6); + eth_getenv_enetaddr("ethaddr", NetOurEther); #endif
NetState = NETLOOP_CONTINUE; @@ -693,8 +693,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len) }
#ifdef ET_DEBUG - printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n", - dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]); + printf("sending UDP to %08lx/%pM\n", dest, ether); #endif
pkt = (uchar *)NetTxPacket; @@ -915,11 +914,7 @@ int CDPSendTrigger(void) #ifdef CONFIG_CDP_DEVICE_ID *s++ = htons(CDP_DEVICE_ID_TLV); *s++ = htons(CONFIG_CDP_DEVICE_ID); - memset(buf, 0, sizeof(buf)); - sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%02X%02X%02X%02X%02X%02X", - NetOurEther[0] & 0xff, NetOurEther[1] & 0xff, - NetOurEther[2] & 0xff, NetOurEther[3] & 0xff, - NetOurEther[4] & 0xff, NetOurEther[5] & 0xff); + sprintf(buf, "%pM", NetOurEther); memcpy((uchar *)s, buf, 16); s += 16 / 2; #endif @@ -1319,10 +1314,8 @@ NetReceive(volatile uchar * inpkt, int len) if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC) break; #ifdef ET_DEBUG - printf("Got ARP REPLY, set server/gtwy eth addr (%02x:%02x:%02x:%02x:%02x:%02x)\n", - arp->ar_data[0], arp->ar_data[1], - arp->ar_data[2], arp->ar_data[3], - arp->ar_data[4], arp->ar_data[5]); + printf("Got ARP REPLY, set server/gtwy eth addr (%pM)\n", + arp->ar_data); #endif
tmp = NetReadIP(&arp->ar_data[6]);

On Tue, 2009-02-17 at 00:10 -0500, Mike Frysinger wrote:
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com
net/bootp.c | 13 ++----------- net/net.c | 17 +++++------------ 2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/net/bootp.c b/net/bootp.c index d1cbd39..3dea70a 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -573,21 +573,12 @@ BootpRequest (void) #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ unsigned char bi_enetaddr[6]; int reg;
char *e,*s;
char tmp[64]; ulong tst1, tst2, sum, m_mask, m_value = 0;
if (BootpTry ==0) { /* get our mac */
reg = getenv_r ("ethaddr", tmp, sizeof(tmp));
s = (reg > 0) ? tmp : NULL;
eth_getenv_enetaddr("ethaddr", bi_enetaddr);
for (reg=0; reg<6; ++reg) {
bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
if (s) {
s = (*e) ? e+1 : e;
}
}
#ifdef DEBUG puts ("BootpRequest => Our Mac: "); for (reg=0; reg<6; reg++) { diff --git a/net/net.c b/net/net.c index 9740f38..3fe5cb8 100644 --- a/net/net.c +++ b/net/net.c @@ -330,7 +330,7 @@ restart: #ifdef CONFIG_NET_MULTI memcpy (NetOurEther, eth_get_dev()->enetaddr, 6); #else
- memcpy (NetOurEther, bd->bi_enetaddr, 6);
- eth_getenv_enetaddr("ethaddr", NetOurEther);
#endif
NetState = NETLOOP_CONTINUE; @@ -693,8 +693,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len) }
#ifdef ET_DEBUG
- printf("sending UDP to %08lx/%02x:%02x:%02x:%02x:%02x:%02x\n",
dest, ether[0], ether[1], ether[2], ether[3], ether[4], ether[5]);
- printf("sending UDP to %08lx/%pM\n", dest, ether);
#endif
pkt = (uchar *)NetTxPacket; @@ -915,11 +914,7 @@ int CDPSendTrigger(void) #ifdef CONFIG_CDP_DEVICE_ID *s++ = htons(CDP_DEVICE_ID_TLV); *s++ = htons(CONFIG_CDP_DEVICE_ID);
- memset(buf, 0, sizeof(buf));
- sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%02X%02X%02X%02X%02X%02X",
NetOurEther[0] & 0xff, NetOurEther[1] & 0xff,
NetOurEther[2] & 0xff, NetOurEther[3] & 0xff,
NetOurEther[4] & 0xff, NetOurEther[5] & 0xff);
- sprintf(buf, "%pM", NetOurEther); memcpy((uchar *)s, buf, 16); s += 16 / 2;
It looks like CONFIG_CDP_DEVICE_ID_PREFIX was accidentally removed. The formatting of "%pM" will also have ':'s where the original field did not.
Awesome changes!
Best, Peter

On Tuesday 17 February 2009 11:21:42 Peter Tyser wrote:
On Tue, 2009-02-17 at 00:10 -0500, Mike Frysinger wrote:
@@ -915,11 +914,7 @@ int CDPSendTrigger(void) #ifdef CONFIG_CDP_DEVICE_ID *s++ = htons(CDP_DEVICE_ID_TLV); *s++ = htons(CONFIG_CDP_DEVICE_ID);
- memset(buf, 0, sizeof(buf));
- sprintf(buf, CONFIG_CDP_DEVICE_ID_PREFIX "%02X%02X%02X%02X%02X%02X",
NetOurEther[0] & 0xff, NetOurEther[1] & 0xff,
NetOurEther[2] & 0xff, NetOurEther[3] & 0xff,
NetOurEther[4] & 0xff, NetOurEther[5] & 0xff);
- sprintf(buf, "%pM", NetOurEther); memcpy((uchar *)s, buf, 16); s += 16 / 2;
It looks like CONFIG_CDP_DEVICE_ID_PREFIX was accidentally removed. The formatting of "%pM" will also have ':'s where the original field did not.
i think when i made the changes, i thought it was a snprintf(), and so dropped the "2nd argument". %pm should give us the right output. thanks for pointing it out. -mike

Add a new print_eth() function to automate the eth*addr env var acquisition and display. Affects all arches.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Nobuhiro Iwamatsu iwamatsu@nigauri.org CC: Scott McNutt smcnutt@psyent.com CC: Shinya Kuribayashi skuribay@ruby.dti.ne.jp CC: Michal Simek monstr@seznam.cz CC: Daniel Hellstrom daniel@gaisler.com CC: Ben Warren biggerbadderben@gmail.com --- common/cmd_bdinfo.c | 120 ++++++++++++++------------------------------------- 1 files changed, 32 insertions(+), 88 deletions(-)
diff --git a/common/cmd_bdinfo.c b/common/cmd_bdinfo.c index 6af5749..700314b 100644 --- a/common/cmd_bdinfo.c +++ b/common/cmd_bdinfo.c @@ -31,6 +31,8 @@ DECLARE_GLOBAL_DATA_PTR;
static void print_num(const char *, ulong);
+static void print_eth(int idx); + #ifndef CONFIG_ARM /* PowerPC and other */ static void print_lnum(const char *, u64);
@@ -39,7 +41,6 @@ static void print_str(const char *, const char *);
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd; char buf[32];
@@ -90,44 +91,21 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_str ("pevfreq", strmhz(buf, bd->bi_pevfreq)); #endif
- puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } - + print_eth(0); #if defined(CONFIG_HAS_ETH1) - puts ("\neth1addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]); - } + print_eth(1); #endif - #if defined(CONFIG_HAS_ETH2) - puts ("\neth2addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]); - } + print_eth(2); #endif - #if defined(CONFIG_HAS_ETH3) - puts ("\neth3addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]); - } + print_eth(3); #endif - #if defined(CONFIG_HAS_ETH4) - puts ("\neth4addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet4addr[i]); - } + print_eth(4); #endif - #if defined(CONFIG_HAS_ETH5) - puts ("\neth5addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet5addr[i]); - } + print_eth(5); #endif
#ifdef CONFIG_HERMES @@ -142,7 +120,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd;
print_num ("memstart", (ulong)bd->bi_memstart); @@ -151,10 +128,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_num ("flashsize", (ulong)bd->bi_flashsize); print_num ("flashoffset", (ulong)bd->bi_flashoffset);
- puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } + print_eth(0); printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); printf ("baudrate = %ld bps\n", bd->bi_baudrate);
@@ -165,9 +139,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { -#if defined(CONFIG_CMD_NET) - int i; -#endif bd_t *bd = gd->bd;
print_num ("mem start", (ulong)bd->bi_memstart); @@ -182,10 +153,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) #endif
#if defined(CONFIG_CMD_NET) - puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } + print_eth(0); printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif
@@ -197,7 +165,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd; print_num ("mem start ", (ulong)bd->bi_memstart); print_lnum ("mem size ", (u64)bd->bi_memsize); @@ -209,10 +176,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_num ("sram size ", (ulong)bd->bi_sramsize); #endif #if defined(CONFIG_CMD_NET) - puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } + print_eth(0); printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif printf ("baudrate = %ld bps\n", (ulong)bd->bi_baudrate); @@ -223,9 +187,6 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { bd_t *bd = gd->bd; -#if defined(CONFIG_CMD_NET) - int i; -#endif
#ifdef DEBUG print_num("bd address ", (ulong) bd); @@ -247,10 +208,7 @@ int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) CONFIG_SYS_GBL_DATA_SIZE);
#if defined(CONFIG_CMD_NET) - puts("ethaddr ="); - for (i = 0; i < 6; ++i) { - printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } + print_eth(0); printf("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif printf("baudrate = %6ld bps\n", bd->bi_baudrate); @@ -262,7 +220,6 @@ static void print_str(const char *, const char *);
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd; char buf[32];
@@ -289,30 +246,15 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_str ("vcofreq", strmhz(buf, bd->bi_vcofreq)); #endif #if defined(CONFIG_CMD_NET) - puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } - + print_eth(0); #if defined(CONFIG_HAS_ETH1) - puts ("\neth1addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet1addr[i]); - } + print_eth(1); #endif - #if defined(CONFIG_HAS_ETH2) - puts ("\neth2addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet2addr[i]); - } + print_eth(2); #endif - #if defined(CONFIG_HAS_ETH3) - puts ("\neth3addr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enet3addr[i]); - } + print_eth(3); #endif
printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); @@ -327,7 +269,6 @@ static void print_str(const char *, const char *);
int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd; char buf[32];
@@ -345,9 +286,7 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_num("flashsize", (ulong)bd->bi_flashsize); print_num("flashoffset", (ulong)bd->bi_flashoffset);
- puts("ethaddr ="); - for (i = 0; i < 6; ++i) - printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); + print_eth(0); printf("ip_addr = %pI4\n", &bd->bi_ip_addr); printf("baudrate = %d bps\n", bd->bi_baudrate);
@@ -358,7 +297,6 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - int i; bd_t *bd = gd->bd;
print_num ("boot_params", (ulong)bd->bi_boot_params); @@ -368,10 +306,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) print_num ("flashsize", (ulong)bd->bi_flashsize); print_num ("flashoffset", (ulong)bd->bi_flashoffset);
- puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } + print_eth(0); printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); printf ("baudrate = %d bps\n", bd->bi_baudrate);
@@ -397,11 +332,7 @@ int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) }
#if defined(CONFIG_CMD_NET) - puts ("ethaddr ="); - for (i=0; i<6; ++i) { - printf ("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]); - } - puts ( "\n" ); + print_eth(0); printf ("ip_addr = %pI4\n", &bd->bi_ip_addr); #endif printf ("baudrate = %d bps\n", bd->bi_baudrate); @@ -416,6 +347,19 @@ static void print_num(const char *name, ulong value) printf ("%-12s= 0x%08lX\n", name, value); }
+static void print_eth(int idx) +{ + char name[10], *val; + if (idx) + sprintf(name, "eth%iaddr", idx); + else + strcpy(name, "ethaddr"); + val = getenv(name); + if (!val) + val = "(not set)"; + printf("%-12s= %s\n", name, val); +} + #ifndef CONFIG_ARM static void print_lnum(const char *name, u64 value) {

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Niklaus Giger niklaus.giger@member.fsf.org CC: Ben Warren biggerbadderben@gmail.com --- common/cmd_elf.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/common/cmd_elf.c b/common/cmd_elf.c index 19e1249..4a3fff1 100644 --- a/common/cmd_elf.c +++ b/common/cmd_elf.c @@ -131,10 +131,12 @@ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
#if defined(CONFIG_WALNUT) tmp = (char *) CONFIG_SYS_NVRAM_BASE_ADDR + 0x500; - memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[3], 3); + eth_getenv_enetaddr("ethaddr", build_buf); + memcpy(tmp, &build_buf[3], 3); #elif defined(CONFIG_SYS_VXWORKS_MAC_PTR) tmp = (char *) CONFIG_SYS_VXWORKS_MAC_PTR; - memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[0], 6); + eth_getenv_enetaddr("ethaddr", build_buf); + memcpy(tmp, build_buf, 6); #else puts ("## Ethernet MAC address not copied to NV RAM\n"); #endif

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- common/lynxkdi.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/lynxkdi.c b/common/lynxkdi.c index 5f12b0d..17b0607 100644 --- a/common/lynxkdi.c +++ b/common/lynxkdi.c @@ -33,7 +33,7 @@ void lynxkdi_boot (image_header_t *hdr) kbd = gd->bd; parms->clock_ref = kbd->bi_busfreq; parms->dramsz = kbd->bi_memsize; - memcpy (parms->ethaddr, kbd->bi_enetaddr, 6); + eth_getenv_enetaddr("ethaddr", parms->ethaddr); mtspr (SPRN_SPRG2, 0x0020);
/* Do a simple check for Bluecat so we can pass the

Since the ethernet layer handles updating of device addresses itself from the environment, there is no point in calling eth_set_enetaddr().
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- common/cmd_nvedit.c | 24 +----------------------- 1 files changed, 1 insertions(+), 23 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 1fcb4c9..da69f9b 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -277,18 +277,6 @@ int _do_setenv (int flag, int argc, char *argv[]) *++env = '\0'; }
-#ifdef CONFIG_NET_MULTI - if (strncmp(name, "eth", 3) == 0) { - char *end; - int num = simple_strtoul(name+3, &end, 10); - - if (strcmp(end, "addr") == 0) { - eth_set_enetaddr(num, argv[2]); - } - } -#endif - - /* Delete only ? */ if ((argc < 3) || argv[2] == NULL) { env_crc_update (); @@ -336,18 +324,8 @@ int _do_setenv (int flag, int argc, char *argv[]) * entry in the enviornment is changed */
- if (strcmp(argv[1],"ethaddr") == 0) { - char *s = argv[2]; /* always use only one arg */ - char *e; - for (i=0; i<6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) s = (*e) ? e+1 : e; - } -#ifdef CONFIG_NET_MULTI - eth_set_enetaddr(0, argv[2]); -#endif + if (strcmp(argv[1],"ethaddr") == 0) return 0; - }
if (strcmp(argv[1],"ipaddr") == 0) { char *s = argv[2]; /* always use only one arg */

Always use the MAC address that is stored in the environment first before falling back to the ROM. This also cuts out any comparison steps: if the mac in the env is sane, the ROM is never consulted.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Thomas Frieden ThomasF@hyperion-entertainment.com CC: Ben Warren biggerbadderben@gmail.com --- board/MAI/AmigaOneG3SE/enet.c | 42 +++++++--------------------------------- 1 files changed, 8 insertions(+), 34 deletions(-)
diff --git a/board/MAI/AmigaOneG3SE/enet.c b/board/MAI/AmigaOneG3SE/enet.c index 0b4dfe6..ac969a9 100644 --- a/board/MAI/AmigaOneG3SE/enet.c +++ b/board/MAI/AmigaOneG3SE/enet.c @@ -600,7 +600,7 @@ static int eth_3com_init (struct eth_device *dev, bd_t * bis) ias_cmd = (struct descriptor *) &tx_ring[tx_cur]; ias_cmd->status = cpu_to_le32 (1 << 31); /* set DnIndicate bit. */ ias_cmd->next = 0; - ias_cmd->addr = cpu_to_le32 ((u32) & bis->bi_enetaddr[0]); + ias_cmd->addr = cpu_to_le32 ((u32) dev->enetaddr); ias_cmd->length = cpu_to_le32 (6 | LAST_FRAG);
/* Tell the adapter where the TX ring is located */ @@ -787,6 +787,10 @@ static void read_hw_addr (struct eth_device *dev, bd_t * bis) unsigned int checksum = 0; int i, j, timer;
+ /* First, try the env ... if that works, we're all done! */ + if (eth_getenv_enetaddr("ethaddr", hw_addr)) + goto Done; + /* Read the station address from the EEPROM. */
EL3WINDOW (dev, 0); @@ -827,40 +831,10 @@ static void read_hw_addr (struct eth_device *dev, bd_t * bis) hw_addr[j + 1] = (u8) ((ETH_INW (dev, j) >> 8) & 0xff); }
- for (i = 0; i < ETH_ALEN; i++) { - if (hw_addr[i] != bis->bi_enetaddr[i]) { -/* printf("Warning: HW address don't match:\n"); */ -/* printf("Address in 3Com Window 2 is " */ -/* "%02X:%02X:%02X:%02X:%02X:%02X\n", */ -/* hw_addr[0], hw_addr[1], hw_addr[2], */ -/* hw_addr[3], hw_addr[4], hw_addr[5]); */ -/* printf("Address used by U-Boot is " */ -/* "%02X:%02X:%02X:%02X:%02X:%02X\n", */ -/* bis->bi_enetaddr[0], bis->bi_enetaddr[1], */ -/* bis->bi_enetaddr[2], bis->bi_enetaddr[3], */ -/* bis->bi_enetaddr[4], bis->bi_enetaddr[5]); */ -/* goto Done; */ - char buffer[256]; - - if (bis->bi_enetaddr[0] == 0 - && bis->bi_enetaddr[1] == 0 - && bis->bi_enetaddr[2] == 0 - && bis->bi_enetaddr[3] == 0 - && bis->bi_enetaddr[4] == 0 - && bis->bi_enetaddr[5] == 0) { - - sprintf (buffer, - "%02X:%02X:%02X:%02X:%02X:%02X", - hw_addr[0], hw_addr[1], hw_addr[2], - hw_addr[3], hw_addr[4], hw_addr[5]); - setenv ("ethaddr", buffer); - } - } - } - - for (i = 0; i < ETH_ALEN; i++) - dev->enetaddr[i] = hw_addr[i]; + /* Save the result in the environment */ + eth_setenv_enetaddr("ethaddr", hw_addr);
Done: + memcpy(dev->enetaddr, hw_addr, 6); return; }

The boards that get converted here to use the environment for the mac address rather than global data: debris mgcoge mgsuvd muas3001 netstal pn62 sixnet vcma9 xilinx (the ones that use xilinx_enet)
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com CC: Sangmoon Kim dogoil@etinsys.com CC: Heiko Schocher hs@denx.de CC: David Mueller d.mueller@elsoft.ch CC: Niklaus Giger niklaus.giger@netstal.com CC: Wolfgang Grandegger wg@denx.de CC: Dave Ellis DGE@sixnetio.com CC: Ricardo Ribalda ricardo.ribalda@uam.es --- board/etin/debris/debris.c | 10 +++++-- board/keymile/mgcoge/mgcoge.c | 4 ++- board/keymile/mgsuvd/mgsuvd.c | 4 ++- board/mpl/vcma9/cmd_vcma9.c | 11 +++----- board/muas3001/muas3001.c | 4 ++- board/netstal/common/nm_bsp.c | 40 +++++++----------------------- board/pn62/pn62.c | 24 ++++++------------ board/sixnet/sixnet.c | 11 +++----- board/xilinx/xilinx_enet/emac_adapter.c | 8 ++++- 9 files changed, 48 insertions(+), 68 deletions(-)
diff --git a/board/etin/debris/debris.c b/board/etin/debris/debris.c index 227c49a..a971af3 100644 --- a/board/etin/debris/debris.c +++ b/board/etin/debris/debris.c @@ -173,9 +173,13 @@ void nvram_write(long dest, const void *src, size_t count)
int misc_init_r(void) { - /* Write ethernet addr in NVRAM for VxWorks */ - nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS, - (char*)&gd->bd->bi_enetaddr[0], 6); + uchar ethaddr[6]; + + if (eth_getenv_enetaddr("ethaddr", ethaddr)) + /* Write ethernet addr in NVRAM for VxWorks */ + nvram_write(CONFIG_ENV_ADDR + CONFIG_SYS_NVRAM_VXWORKS_OFFS, + ethaddr, 6); + return 0; }
diff --git a/board/keymile/mgcoge/mgcoge.c b/board/keymile/mgcoge/mgcoge.c index 5c50739..54e7c25 100644 --- a/board/keymile/mgcoge/mgcoge.c +++ b/board/keymile/mgcoge/mgcoge.c @@ -325,6 +325,7 @@ void ft_blob_update (void *blob, bd_t *bd) { ulong memory_data[2] = {0}; ulong flash_data[8] = {0}; + uchar enetaddr[6];
memory_data[0] = cpu_to_be32 (bd->bi_memstart); memory_data[1] = cpu_to_be32 (bd->bi_memsize); @@ -341,8 +342,9 @@ void ft_blob_update (void *blob, bd_t *bd) fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data, sizeof (flash_data)); /* MAC addr */ + eth_getenv_enetaddr("ethaddr", enetaddr); fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address", - bd->bi_enetaddr, sizeof (u8) * 6); + enetaddr, sizeof (u8) * 6); }
void ft_board_setup (void *blob, bd_t *bd) diff --git a/board/keymile/mgsuvd/mgsuvd.c b/board/keymile/mgsuvd/mgsuvd.c index 02baf62..dbdafeb 100644 --- a/board/keymile/mgsuvd/mgsuvd.c +++ b/board/keymile/mgsuvd/mgsuvd.c @@ -168,6 +168,7 @@ void ft_blob_update (void *blob, bd_t *bd) ulong brg_data[1] = {0}; ulong memory_data[2] = {0}; ulong flash_data[4] = {0}; + uchar enetaddr[6];
memory_data[0] = cpu_to_be32 (bd->bi_memstart); memory_data[1] = cpu_to_be32 (bd->bi_memsize); @@ -185,8 +186,9 @@ void ft_blob_update (void *blob, bd_t *bd) sizeof (brg_data));
/* MAC adr */ + eth_getenv_enetaddr("ethaddr", enetaddr); fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address", - bd->bi_enetaddr, sizeof (u8) * 6); + enetaddr, sizeof (u8) * 6); }
void ft_board_setup(void *blob, bd_t *bd) diff --git a/board/mpl/vcma9/cmd_vcma9.c b/board/mpl/vcma9/cmd_vcma9.c index 2748fa9..7d2aa3c 100644 --- a/board/mpl/vcma9/cmd_vcma9.c +++ b/board/mpl/vcma9/cmd_vcma9.c @@ -76,21 +76,18 @@ int do_vcma9(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) cs8900_e2prom_write(addr, data); } else if (strcmp(argv[2], "setaddr") == 0) { uchar addr, i, csum; ushort data; + uchar ethaddr[6];
/* check for valid ethaddr */ - for (i = 0; i < 6; i++) - if (gd->bd->bi_enetaddr[i] != 0) - break; - - if (i < 6) { + if (eth_getenv_enetaddr("ethaddr", ethaddr)) { addr = 1; data = 0x2158; cs8900_e2prom_write(addr, data); csum = cs8900_chksum(data); addr++; for (i = 0; i < 6; i+=2) { - data = gd->bd->bi_enetaddr[i+1] << 8 | - gd->bd->bi_enetaddr[i]; + data = enetaddr[i+1] << 8 | + enetaddr[i]; cs8900_e2prom_write(addr, data); csum += cs8900_chksum(data); addr++; diff --git a/board/muas3001/muas3001.c b/board/muas3001/muas3001.c index 6b1e59f..8f83dd9 100644 --- a/board/muas3001/muas3001.c +++ b/board/muas3001/muas3001.c @@ -346,7 +346,9 @@ void ft_blob_update (void *blob, bd_t *bd) /* MAC Adresse */ nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet"); if (nodeoffset >= 0) { - ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr, + uchar ethaddr[6]; + eth_getenv_enetaddr("ethaddr", ethaddr); + ret = fdt_setprop (blob, nodeoffset, "mac-address", ethaddr, sizeof (uchar) * 6); if (ret < 0) printf ("ft_blob_update): cannot set /soc/cpm/ethernet/mac-address " diff --git a/board/netstal/common/nm_bsp.c b/board/netstal/common/nm_bsp.c index e38b706..237f4ed 100644 --- a/board/netstal/common/nm_bsp.c +++ b/board/netstal/common/nm_bsp.c @@ -83,40 +83,20 @@ void set_params_for_sw_install(int install_requested, char *board_name )
void common_misc_init_r(void) { - char *s = getenv(DEFAULT_ETH_ADDR); - char *e; - int i; - u32 serial = get_serial_number(); IPaddr_t ipaddr; char *ipstring; + uchar ethaddr[6];
- for (i = 0; i < 6; ++i) { - gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - - if (gd->bd->bi_enetaddr[3] == 0 && - gd->bd->bi_enetaddr[4] == 0 && - gd->bd->bi_enetaddr[5] == 0) { - char ethaddr[22]; - + if (!eth_getenv_enetaddr(DEFAULT_ETH_ADDR, ethaddr)) { /* Must be in sync with CONFIG_ETHADDR */ - gd->bd->bi_enetaddr[0] = 0x00; - gd->bd->bi_enetaddr[1] = 0x60; - gd->bd->bi_enetaddr[2] = 0x13; - gd->bd->bi_enetaddr[3] = (serial >> 16) & 0xff; - gd->bd->bi_enetaddr[4] = (serial >> 8) & 0xff; - gd->bd->bi_enetaddr[5] = hcu_get_slot(); - sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X%c", - gd->bd->bi_enetaddr[0], gd->bd->bi_enetaddr[1], - gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3], - gd->bd->bi_enetaddr[4], - gd->bd->bi_enetaddr[5], - 0) ; - printf("%s: Setting eth %s serial 0x%x\n", __FUNCTION__, - ethaddr, serial); - setenv(DEFAULT_ETH_ADDR, ethaddr); + u32 serial = get_serial_number(); + ethaddr[0] = 0x00; + ethaddr[1] = 0x60; + ethaddr[2] = 0x13; + ethaddr[3] = (serial >> 16) & 0xff; + ethaddr[4] = (serial >> 8) & 0xff; + ethaddr[5] = hcu_get_slot(); + eth_setenv_enetaddr(DEFAULT_ETH_ADDR, ethaddr); }
/* IP-Adress update */ diff --git a/board/pn62/pn62.c b/board/pn62/pn62.c index 1b545bf..53d7e57 100644 --- a/board/pn62/pn62.c +++ b/board/pn62/pn62.c @@ -30,7 +30,7 @@ DECLARE_GLOBAL_DATA_PTR;
static int get_serial_number (char *string, int size); -static int get_mac_address (int id, u8 * mac, char *string, int size); +static void get_mac_address(int id, u8 *mac);
#ifdef CONFIG_SHOW_BOOT_PROGRESS void show_boot_progress (int phase) @@ -138,18 +138,16 @@ int misc_init_r (void) } show_startup_phase (9);
- if (getenv ("ethaddr") == NULL && - get_mac_address (0, mac, str, sizeof (str)) > 0) { - setenv ("ethaddr", str); - memcpy (gd->bd->bi_enetaddr, mac, 6); + if (!eth_getenv_enetaddr("ethaddr", mac)) { + get_mac_address(0, mac); + eth_setenv_enetaddr("ethaddr", mac); } show_startup_phase (10);
#ifdef CONFIG_HAS_ETH1 - if (getenv ("eth1addr") == NULL && - get_mac_address (1, mac, str, sizeof (str)) > 0) { - setenv ("eth1addr", str); - memcpy (gd->bd->bi_enet1addr, mac, 6); + if (!eth_getenv_enetaddr("eth1addr", mac)) { + get_mac_address(1, mac); + eth_setenv_enetaddr("eth1addr", mac); } #endif /* CONFIG_HAS_ETH1 */ show_startup_phase (11); @@ -177,15 +175,9 @@ static int get_serial_number (char *string, int size) return i; }
-static int get_mac_address (int id, u8 * mac, char *string, int size) +static void get_mac_address(int id, u8 *mac) { - if (size < 6 * 3) - return -1; - i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac); - return sprintf (string, "%02x:%02x:%02x:%02x:%02x:%02x", - mac[0], mac[1], mac[2], - mac[3], mac[4], mac[5]); }
int board_eth_init(bd_t *bis) diff --git a/board/sixnet/sixnet.c b/board/sixnet/sixnet.c index 3ed581e..4fcd84b 100644 --- a/board/sixnet/sixnet.c +++ b/board/sixnet/sixnet.c @@ -264,6 +264,7 @@ int misc_init_r (void) char* e; int reg; bd_t *bd = gd->bd; + uchar enetaddr[6];
memctl->memc_or2 = NVRAM_OR_PRELIM; memctl->memc_br2 = NVRAM_BR_VALUE; @@ -315,13 +316,9 @@ int misc_init_r (void) * is present it gets a unique address, otherwise it * shares the FEC address. */ - s = getenv("eth1addr"); - if (s == NULL) - s = getenv("ethaddr"); - for (reg=0; reg<6; ++reg) { - bd->bi_enet1addr[reg] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e+1 : e; + if (!eth_getenv_enetaddr("eth1addr", enetaddr)) { + eth_getenv_enetaddr("ethaddr", enetaddr); + eth_setenv_enetaddr("eth1addr", enetaddr); }
return (0); diff --git a/board/xilinx/xilinx_enet/emac_adapter.c b/board/xilinx/xilinx_enet/emac_adapter.c index 0b100d2..35bcc4d 100644 --- a/board/xilinx/xilinx_enet/emac_adapter.c +++ b/board/xilinx/xilinx_enet/emac_adapter.c @@ -74,6 +74,7 @@ eth_init(bd_t * bis) { u32 Options; XStatus Result; + uchar enetaddr[6];
#ifdef DEBUG printf("EMAC Initialization Started\n\r"); @@ -87,11 +88,14 @@ eth_init(bd_t * bis) /* make sure the Emac is stopped before it is started */ (void) XEmac_Stop(&Emac);
+ if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { #ifdef CONFIG_ENV_IS_NOWHERE - memcpy(bis->bi_enetaddr, EMACAddr, 6); + memcpy(enetaddr, EMACAddr, 6); + eth_setenv_enetaddr("ethaddr", enetaddr); #endif + }
- Result = XEmac_SetMacAddress(&Emac, bis->bi_enetaddr); + Result = XEmac_SetMacAddress(&Emac, enetaddr); if (Result != XST_SUCCESS) { return 0; }

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.
The drivers that get converted here: 3c589 4xx_enet dc2114x dm9000x enc28j60 fsl_mcdmafec ks8695eth mcffec rtl8019 rtl8169 s3c4510b_eth xilinx_emac xilinx_emaclite
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com CC: Rolf Offermanns rof@sysgo.de CC: Stefan Roese sr@denx.de CC: Sascha Hauer saschahauer@web.de CC: TsiChung Liew Tsi-Chung.Liew@freescale.com CC: Greg Ungerer greg.ungerer@opengear.com CC: Xue Ligong lgxue@hotmail.com CC: Wang Kehao <whut.edu.cn> CC: Masami Komiya mkomiya@sonare.it CC: Curt Brune curt@cucy.com CC: Michal SIMEK monstr@monstr.eu --- drivers/net/3c589.c | 7 +++++-- drivers/net/4xx_enet.c | 13 +++++-------- drivers/net/dc2114x.c | 9 ++++++--- drivers/net/dm9000x.c | 26 +++++++------------------- drivers/net/enc28j60.c | 4 +++- drivers/net/fsl_mcdmafec.c | 11 ++++++----- drivers/net/ks8695eth.c | 8 +------- drivers/net/mcffec.c | 10 +++++----- drivers/net/rtl8019.c | 14 ++++++++------ drivers/net/rtl8169.c | 2 +- drivers/net/s3c4510b_eth.c | 2 +- drivers/net/s3c4510b_eth.h | 2 +- drivers/net/xilinx_emac.c | 12 +++++++----- drivers/net/xilinx_emaclite.c | 11 +++++++---- 14 files changed, 63 insertions(+), 68 deletions(-)
diff --git a/drivers/net/3c589.c b/drivers/net/3c589.c index 0cf8dff..f2c7d32 100644 --- a/drivers/net/3c589.c +++ b/drivers/net/3c589.c @@ -259,10 +259,13 @@ static void el_reset(bd_t *bd)
/* set mac addr */ { - unsigned char *mac_addr = bd->bi_enetaddr; + uchar mac_addr[6]; int i;
- el_get_mac_addr( mac_addr ); + if (!eth_getenv_enetaddr("ethaddr", mac_addr)) { + el_get_mac_addr(mac_addr); + eth_setenv_enetaddr("ethaddr", mac_addr); + }
GO_WINDOW(2); VX_BUSY_WAIT; diff --git a/drivers/net/4xx_enet.c b/drivers/net/4xx_enet.c index 1978269..918373b 100644 --- a/drivers/net/4xx_enet.c +++ b/drivers/net/4xx_enet.c @@ -1927,24 +1927,22 @@ int ppc_4xx_eth_initialize (bd_t * bis) memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) { + int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START; switch (eth_num) { default: /* fall through */ case 0: - memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START], - bis->bi_enetaddr, 6); + eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]); hw_addr[eth_num] = 0x0; break; #ifdef CONFIG_HAS_ETH1 case 1: - memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START], - bis->bi_enet1addr, 6); + eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]); hw_addr[eth_num] = 0x100; break; #endif #ifdef CONFIG_HAS_ETH2 case 2: - memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START], - bis->bi_enet2addr, 6); + eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]); #if defined(CONFIG_460GT) hw_addr[eth_num] = 0x300; #else @@ -1954,8 +1952,7 @@ int ppc_4xx_eth_initialize (bd_t * bis) #endif #ifdef CONFIG_HAS_ETH3 case 3: - memcpy(ethaddr[eth_num + CONFIG_EMAC_NR_START], - bis->bi_enet3addr, 6); + eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]); #if defined(CONFIG_460GT) hw_addr[eth_num] = 0x400; #else diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c index c0137a7..5ae53e8 100644 --- a/drivers/net/dc2114x.c +++ b/drivers/net/dc2114x.c @@ -752,11 +752,14 @@ static void update_srom(struct eth_device *dev, bd_t *bis) 0x0000, 0x0000, 0x0000, 0x0000, /* 38 */ 0x0000, 0x0000, 0x0000, 0x4e07, /* 3c */ }; + uchar enetaddr[6];
/* Ethernet Addr... */ - eeprom[0x0a] = ((bis->bi_enetaddr[1] & 0xff) << 8) | (bis->bi_enetaddr[0] & 0xff); - eeprom[0x0b] = ((bis->bi_enetaddr[3] & 0xff) << 8) | (bis->bi_enetaddr[2] & 0xff); - eeprom[0x0c] = ((bis->bi_enetaddr[5] & 0xff) << 8) | (bis->bi_enetaddr[4] & 0xff); + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) + return; + eeprom[0x0a] = (enetaddr[1] << 8) | enetaddr[0]; + eeprom[0x0b] = (enetaddr[3] << 8) | enetaddr[2]; + eeprom[0x0c] = (enetaddr[5] << 8) | enetaddr[4];
for (i=0; i<0x40; i++) { write_srom(dev, DE4X5_APROM, i, eeprom[i]); diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index ffb739d..c52d307 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -287,6 +287,7 @@ eth_init(bd_t * bd) int i, oft, lnk; u8 io_mode; struct board_info *db = &dm9000_info; + uchar enetaddr[6];
DM9000_DBG("eth_init()\n");
@@ -345,32 +346,19 @@ eth_init(bd_t * bd) DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
/* Set Node address */ + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { #if !defined(CONFIG_AT91SAM9261EK) - for (i = 0; i < 6; i++) - ((u16 *) bd->bi_enetaddr)[i] = read_srom_word(i); + for (i = 0; i < 6; i++) + enetaddr[i] = read_srom_word(i); + eth_setenv_enetaddr("ethaddr", enetaddr); #endif - - if (is_zero_ether_addr(bd->bi_enetaddr) || - is_multicast_ether_addr(bd->bi_enetaddr)) { - /* try reading from environment */ - u8 i; - char *s, *e; - s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? - simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } }
- printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", bd->bi_enetaddr[0], - bd->bi_enetaddr[1], bd->bi_enetaddr[2], bd->bi_enetaddr[3], - bd->bi_enetaddr[4], bd->bi_enetaddr[5]); + printf("MAC: %pM\n", enetaddr);
/* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - DM9000_iow(oft, bd->bi_enetaddr[i]); + DM9000_iow(oft, enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) DM9000_iow(oft, 0xff);
diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 5c24b0d..3238a50 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -330,6 +330,7 @@ static int rxResetCounter = 0; int eth_init (bd_t * bis) { unsigned char estatVal; + uchar enetaddr[6];
/* configure GPIO */ (*((volatile unsigned long *) IO1DIR)) |= ENC_SPI_SLAVE_CS; @@ -351,7 +352,8 @@ int eth_init (bd_t * bis)
/* initialize controller */ encReset (); - encInit (bis->bi_enetaddr); + eth_getenv_enetaddr("ethaddr", enetaddr); + encInit (enetaddr);
m_nic_bfs (CTL_REG_ECON1, ENC_ECON1_RXEN); /* enable receive */
diff --git a/drivers/net/fsl_mcdmafec.c b/drivers/net/fsl_mcdmafec.c index d056010..35a6dfb 100644 --- a/drivers/net/fsl_mcdmafec.c +++ b/drivers/net/fsl_mcdmafec.c @@ -369,6 +369,7 @@ static int fec_init(struct eth_device *dev, bd_t * bd) struct fec_info_dma *info = dev->priv; volatile fecdma_t *fecp = (fecdma_t *) (info->iobase); int i; + uchar enetaddr[6];
#ifdef ET_DEBUG printf("fec_init: iobase 0x%08x ...\n", info->iobase); @@ -397,11 +398,11 @@ static int fec_init(struct eth_device *dev, bd_t * bd) fecp->eir = 0xffffffff;
/* Set station address */ - if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) { - fec_set_hwaddr(fecp, bd->bi_enetaddr); - } else { - fec_set_hwaddr(fecp, bd->bi_enet1addr); - } + if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) + eth_getenv_enetaddr("ethaddr", enetaddr); + else + eth_getenv_enetaddr("eth1addr", enetaddr); + fec_set_hwaddr(fecp, enetaddr);
/* Set Opcode/Pause Duration Register */ fecp->opd = 0x00010020; diff --git a/drivers/net/ks8695eth.c b/drivers/net/ks8695eth.c index 7f3e0c2..5ea6e7f 100644 --- a/drivers/net/ks8695eth.c +++ b/drivers/net/ks8695eth.c @@ -150,13 +150,7 @@ void eth_reset(bd_t *bd) ks8695_write(KS8695_LAN_DMA_RX, 0x71); ks8695_write(KS8695_LAN_DMA_RX_START, 0x1);
- printf("KS8695 ETHERNET: "); - for (i = 0; (i < 5); i++) { - bd->bi_enetaddr[i] = eth_mac[i]; - printf("%02x:", eth_mac[i]); - } - bd->bi_enetaddr[i] = eth_mac[i]; - printf("%02x\n", eth_mac[i]); + printf("KS8695 ETHERNET: %pM\n", eth_mac); }
/****************************************************************************/ diff --git a/drivers/net/mcffec.c b/drivers/net/mcffec.c index 18240a8..64be5de 100644 --- a/drivers/net/mcffec.c +++ b/drivers/net/mcffec.c @@ -416,7 +416,7 @@ int fec_init(struct eth_device *dev, bd_t * bd) struct fec_info_s *info = dev->priv; volatile fec_t *fecp = (fec_t *) (info->iobase); int i; - u8 *ea = NULL; + uchar ea[6];
fecpin_setclear(dev, 1);
@@ -444,25 +444,25 @@ int fec_init(struct eth_device *dev, bd_t * bd) if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) { #ifdef CONFIG_SYS_FEC1_IOBASE volatile fec_t *fecp1 = (fec_t *) (CONFIG_SYS_FEC1_IOBASE); - ea = &bd->bi_enet1addr[0]; + eth_getenv_enetaddr("eth1addr", ea); fecp1->palr = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); fecp1->paur = (ea[4] << 24) | (ea[5] << 16); #endif - ea = &bd->bi_enetaddr[0]; + eth_getenv_enetaddr("ethaddr", ea); fecp->palr = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); fecp->paur = (ea[4] << 24) | (ea[5] << 16); } else { #ifdef CONFIG_SYS_FEC0_IOBASE volatile fec_t *fecp0 = (fec_t *) (CONFIG_SYS_FEC0_IOBASE); - ea = &bd->bi_enetaddr[0]; + eth_getenv_enetaddr("ethaddr", ea); fecp0->palr = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); fecp0->paur = (ea[4] << 24) | (ea[5] << 16); #endif #ifdef CONFIG_SYS_FEC1_IOBASE - ea = &bd->bi_enet1addr[0]; + eth_getenv_enetaddr("eth1addr", ea); fecp->palr = (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]); fecp->paur = (ea[4] << 24) | (ea[5] << 16); diff --git a/drivers/net/rtl8019.c b/drivers/net/rtl8019.c index 3ddf917..f516afe 100644 --- a/drivers/net/rtl8019.c +++ b/drivers/net/rtl8019.c @@ -91,6 +91,7 @@ void eth_halt (void)
int eth_init (bd_t * bd) { + uchar enetaddr[6]; eth_reset (); put_reg (RTL8019_COMMAND, RTL8019_PAGE0STOP); put_reg (RTL8019_DATACONFIGURATION, 0x48); @@ -105,12 +106,13 @@ int eth_init (bd_t * bd) put_reg (RTL8019_INTERRUPTSTATUS, 0xff); put_reg (RTL8019_INTERRUPTMASK, 0x11); /*b; */ put_reg (RTL8019_COMMAND, RTL8019_PAGE1STOP); - put_reg (RTL8019_PHYSICALADDRESS0, bd->bi_enetaddr[0]); - put_reg (RTL8019_PHYSICALADDRESS1, bd->bi_enetaddr[1]); - put_reg (RTL8019_PHYSICALADDRESS2, bd->bi_enetaddr[2]); - put_reg (RTL8019_PHYSICALADDRESS3, bd->bi_enetaddr[3]); - put_reg (RTL8019_PHYSICALADDRESS4, bd->bi_enetaddr[4]); - put_reg (RTL8019_PHYSICALADDRESS5, bd->bi_enetaddr[5]); + eth_getenv_enetaddr("ethaddr", enetaddr); + put_reg (RTL8019_PHYSICALADDRESS0, enetaddr[0]); + put_reg (RTL8019_PHYSICALADDRESS1, enetaddr[1]); + put_reg (RTL8019_PHYSICALADDRESS2, enetaddr[2]); + put_reg (RTL8019_PHYSICALADDRESS3, enetaddr[3]); + put_reg (RTL8019_PHYSICALADDRESS4, enetaddr[4]); + put_reg (RTL8019_PHYSICALADDRESS5, enetaddr[5]); put_reg (RTL8019_MULTIADDRESS0, 0x00); put_reg (RTL8019_MULTIADDRESS1, 0x00); put_reg (RTL8019_MULTIADDRESS2, 0x00); diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c index e9f6391..f8c14b4 100644 --- a/drivers/net/rtl8169.c +++ b/drivers/net/rtl8169.c @@ -750,7 +750,7 @@ static int rtl_init(struct eth_device *dev, bd_t *bis)
/* Get MAC address. FIXME: read EEPROM */ for (i = 0; i < MAC_ADDR_LEN; i++) - bis->bi_enetaddr[i] = dev->enetaddr[i] = RTL_R8(MAC0 + i); + dev->enetaddr[i] = RTL_R8(MAC0 + i);
#ifdef DEBUG_RTL8169 printf("chipset = %d\n", tpc->chipset); diff --git a/drivers/net/s3c4510b_eth.c b/drivers/net/s3c4510b_eth.c index 6dcb244..818ed3d 100644 --- a/drivers/net/s3c4510b_eth.c +++ b/drivers/net/s3c4510b_eth.c @@ -100,7 +100,7 @@ int eth_init(bd_t *bis) ETH *eth = &m_eth;
/* store our MAC address */ - eth->m_mac = bis->bi_enetaddr; + eth_getenv_enetaddr("ethaddr", eth->m_mac);
/* setup DBMA and MAC */ PUT_REG( REG_BDMARXCON, ETH_BRxRS); /* reset BDMA RX machine */ diff --git a/drivers/net/s3c4510b_eth.h b/drivers/net/s3c4510b_eth.h index 048307f..18a52a7 100644 --- a/drivers/net/s3c4510b_eth.h +++ b/drivers/net/s3c4510b_eth.h @@ -296,7 +296,7 @@ typedef struct __ETH { TX_FrameDescriptor *m_baseTX_FD; /* pointer to base TX frame descriptor */ RX_FrameDescriptor *m_curRX_FD; /* pointer to current RX frame descriptor */ RX_FrameDescriptor *m_baseRX_FD; /* pointer to base RX frame descriptor */ - u8 *m_mac; /* pointer to our MAC address */ + u8 m_mac[6]; /* pointer to our MAC address */ } ETH;
#endif diff --git a/drivers/net/xilinx_emac.c b/drivers/net/xilinx_emac.c index c7f1a2a..a489aa9 100644 --- a/drivers/net/xilinx_emac.c +++ b/drivers/net/xilinx_emac.c @@ -166,6 +166,7 @@ void eth_halt(void)
int eth_init(bd_t * bis) { + uchar enetaddr[6]; u32 helpreg; debug ("EMAC Initialization Started\n\r");
@@ -200,15 +201,16 @@ int eth_init(bd_t * bis) helpreg &= ~(XEM_ECR_XMIT_ENABLE_MASK | XEM_ECR_RECV_ENABLE_MASK); out_be32 (emac.baseaddress + XEM_ECR_OFFSET, helpreg);
- if (!getenv("ethaddr")) { - memcpy(bis->bi_enetaddr, emacaddr, ENET_ADDR_LENGTH); + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + memcpy(enetaddr, emacaddr, ENET_ADDR_LENGTH); + eth_setenv_enetaddr("ethaddr", enetaddr); }
/* Set the device station address high and low registers */ - helpreg = (bis->bi_enetaddr[0] << 8) | bis->bi_enetaddr[1]; + helpreg = (enetaddr[0] << 8) | enetaddr[1]; out_be32 (emac.baseaddress + XEM_SAH_OFFSET, helpreg); - helpreg = (bis->bi_enetaddr[2] << 24) | (bis->bi_enetaddr[3] << 16) | - (bis->bi_enetaddr[4] << 8) | bis->bi_enetaddr[5]; + helpreg = (enetaddr[2] << 24) | (enetaddr[3] << 16) | + (enetaddr[4] << 8) | enetaddr[5]; out_be32 (emac.baseaddress + XEM_SAL_OFFSET, helpreg);
helpreg = XEM_ECR_UNICAST_ENABLE_MASK | XEM_ECR_BROAD_ENABLE_MASK | diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 0e96ef1..cf39573 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -140,12 +140,15 @@ void eth_halt (void)
int eth_init (bd_t * bis) { + uchar enetaddr[6]; + debug ("EmacLite Initialization Started\n"); memset (&emaclite, 0, sizeof (xemaclite)); emaclite.baseaddress = XILINX_EMACLITE_BASEADDR;
- if (!getenv("ethaddr")) { - memcpy(bis->bi_enetaddr, emacaddr, ENET_ADDR_LENGTH); + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + memcpy(enetaddr, emacaddr, ENET_ADDR_LENGTH); + eth_setenv_enetaddr("ethaddr", enetaddr); }
/* @@ -154,7 +157,7 @@ int eth_init (bd_t * bis) /* Restart PING TX */ out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET, 0); /* Copy MAC address */ - xemaclite_alignedwrite (bis->bi_enetaddr, + xemaclite_alignedwrite (enetaddr, emaclite.baseaddress, ENET_ADDR_LENGTH); /* Set the length */ out_be32 (emaclite.baseaddress + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH); @@ -167,7 +170,7 @@ int eth_init (bd_t * bis) #ifdef CONFIG_XILINX_EMACLITE_TX_PING_PONG /* The same operation with PONG TX */ out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET, 0); - xemaclite_alignedwrite (bis->bi_enetaddr, emaclite.baseaddress + + xemaclite_alignedwrite (enetaddr, emaclite.baseaddress + XEL_BUFFER_OFFSET, ENET_ADDR_LENGTH); out_be32 (emaclite.baseaddress + XEL_TPLR_OFFSET, ENET_ADDR_LENGTH); out_be32 (emaclite.baseaddress + XEL_TSR_OFFSET + XEL_BUFFER_OFFSET,

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.
Since the address is in the PLM_DEVICE_BLOCK structure already, there is no need to pass the NodeAddress as a second parameter. So drop the second argument to the LM_SetMacAddress() function (and update the tigon3 driver accordingly).
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- drivers/net/bcm570x.c | 4 ++-- drivers/net/bcm570x_lm.h | 2 +- drivers/net/tigon3.c | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/net/bcm570x.c b/drivers/net/bcm570x.c index 185764e..c250d44 100644 --- a/drivers/net/bcm570x.c +++ b/drivers/net/bcm570x.c @@ -450,8 +450,8 @@ int eth_init (bd_t * bis) + 1); strcpy (pUmDevice->name, board_info[bcm570xDevices[i].board_id].name);
- memcpy (pDevice->NodeAddress, bis->bi_enetaddr, 6); - LM_SetMacAddress (pDevice, bis->bi_enetaddr); + eth_getenv_enetaddr("ethaddr", pDevice->NodeAddress); + LM_SetMacAddress (pDevice); /* Init queues .. */ QQ_InitQueue (&pUmDevice->rx_out_of_buf_q.Container, MAX_RX_PACKET_DESC_COUNT); diff --git a/drivers/net/bcm570x_lm.h b/drivers/net/bcm570x_lm.h index 2ea6ca8..c07b767 100644 --- a/drivers/net/bcm570x_lm.h +++ b/drivers/net/bcm570x_lm.h @@ -371,7 +371,7 @@ LM_STATUS LM_Abort (PLM_DEVICE_BLOCK pDevice); LM_STATUS LM_MulticastAdd (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress); LM_STATUS LM_MulticastDel (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress); LM_STATUS LM_MulticastClear (PLM_DEVICE_BLOCK pDevice); -LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMacAddress); +LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice); LM_STATUS LM_LoopbackAddress (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pAddress);
LM_UINT32 LM_GetCrcCounter (PLM_DEVICE_BLOCK pDevice); diff --git a/drivers/net/tigon3.c b/drivers/net/tigon3.c index e4e004e..33cb447 100644 --- a/drivers/net/tigon3.c +++ b/drivers/net/tigon3.c @@ -2463,7 +2463,7 @@ LM_STATUS LM_ResetAdapter (PLM_DEVICE_BLOCK pDevice) #endif /* T3_JUMBO_RCV_ENTRY_COUNT */
/* Configure the MAC address. */ - LM_SetMacAddress (pDevice, pDevice->NodeAddress); + LM_SetMacAddress (pDevice);
/* Initialize the transmit random backoff seed. */ Value32 = (pDevice->NodeAddress[0] + pDevice->NodeAddress[1] + @@ -3428,7 +3428,7 @@ LM_STATUS LM_Halt (PLM_DEVICE_BLOCK pDevice) (pDevice->SubsystemId << 16) | pDevice->SubsystemVendorId);
/* Reprogram the MAC address. */ - LM_SetMacAddress (pDevice, pDevice->NodeAddress); + LM_SetMacAddress (pDevice);
return LM_STATUS_SUCCESS; } /* LM_Halt */ @@ -3833,9 +3833,10 @@ LM_STATUS LM_MulticastClear (PLM_DEVICE_BLOCK pDevice) /* */ /* Return: */ /******************************************************************************/ -LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMacAddress) +LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice) { LM_UINT32 j; + PLM_UINT8 pMacAddress = pDevice->NodeAddress;
for (j = 0; j < 4; j++) { REG_WR (pDevice, MacCtrl.MacAddr[j].High,

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.
The cs8900 driver also changes slightly in that the hardware is not consulted if the mac address in the env is sane.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Marius Groeger mgroeger@sysgo.de CC: Ben Warren biggerbadderben@gmail.com --- drivers/net/cs8900.c | 56 ++++++++++++++----------------------------------- 1 files changed, 16 insertions(+), 40 deletions(-)
diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c index 35a9baf..0557fcd 100644 --- a/drivers/net/cs8900.c +++ b/drivers/net/cs8900.c @@ -110,18 +110,14 @@ static void eth_reginit (void) put_reg (PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx); }
-void cs8900_get_enetaddr (uchar * addr) +void cs8900_get_enetaddr (void) { int i; - unsigned char env_enetaddr[6]; - char *tmp = getenv ("ethaddr"); - char *end; - - for (i=0; i<6; i++) { - env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; - if (tmp) - tmp = (*end) ? end+1 : end; - } + uchar enetaddr[6]; + + /* if the env is setup, then bail */ + if (eth_getenv_enetaddr("ethaddr", enetaddr)) + return;
/* verify chip id */ if (get_reg_init_bus (PP_ChipID) != 0x630e) @@ -135,35 +131,12 @@ void cs8900_get_enetaddr (uchar * addr) unsigned int Addr;
Addr = get_reg (PP_IA + i * 2); - addr[i * 2] = Addr & 0xFF; - addr[i * 2 + 1] = Addr >> 8; + enetaddr[i * 2] = Addr & 0xFF; + enetaddr[i * 2 + 1] = Addr >> 8; }
- if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6) != 0 && - memcmp(env_enetaddr, addr, 6) != 0) { - printf ("\nWarning: MAC addresses don't match:\n"); - printf ("\tHW MAC address: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - addr[0], addr[1], - addr[2], addr[3], - addr[4], addr[5] ); - printf ("\t"ethaddr" value: " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - env_enetaddr[0], env_enetaddr[1], - env_enetaddr[2], env_enetaddr[3], - env_enetaddr[4], env_enetaddr[5]) ; - debug ("### Set MAC addr from environment\n"); - memcpy (addr, env_enetaddr, 6); - } - if (!tmp) { - char ethaddr[20]; - sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X", - addr[0], addr[1], - addr[2], addr[3], - addr[4], addr[5]) ; - debug ("### Set environment from HW MAC addr = "%s"\n", ethaddr); - setenv ("ethaddr", ethaddr); - } + eth_setenv_enetaddr("ethaddr", enetaddr); + debug("### Set environment from HW MAC addr = "%pM"\n", enetaddr); } }
@@ -178,6 +151,8 @@ void eth_halt (void)
int eth_init (bd_t * bd) { + uchar *enetaddr[6]; + /* verify chip id */ if (get_reg_init_bus (PP_ChipID) != 0x630e) { printf ("CS8900 Ethernet chip not found?!\n"); @@ -186,9 +161,10 @@ int eth_init (bd_t * bd)
eth_reset (); /* set the ethernet address */ - put_reg (PP_IA + 0, bd->bi_enetaddr[0] | (bd->bi_enetaddr[1] << 8)); - put_reg (PP_IA + 2, bd->bi_enetaddr[2] | (bd->bi_enetaddr[3] << 8)); - put_reg (PP_IA + 4, bd->bi_enetaddr[4] | (bd->bi_enetaddr[5] << 8)); + eth_getenv_enetaddr("ethaddr", enetaddr); + put_reg (PP_IA + 0, enetaddr[0] | (enetaddr[1] << 8)); + put_reg (PP_IA + 2, enetaddr[2] | (enetaddr[3] << 8)); + put_reg (PP_IA + 4, enetaddr[4] | (enetaddr[5] << 8));
eth_reginit (); return 0;

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.
The sh_eth driver can also be simplified a bit by using enetaddr member of the eth_device structure.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Nobuhiro Iwamatsu iwamatsu@nigauri.org CC: Carlos Munoz carlos@kenati.com CC: Ben Warren biggerbadderben@gmail.com --- drivers/net/sh_eth.c | 28 ++++++---------------------- 1 files changed, 6 insertions(+), 22 deletions(-)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index ebe8588..a47c0dd 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -514,6 +514,7 @@ static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd) int port = eth->port, ret = 0; u32 val, phy_status; struct sh_eth_info *port_info = ð->port_info[port]; + struct eth_device *dev = port_info->dev;
/* Configure e-dmac registers */ outl((inl(EDMR(port)) & ~EMDR_DESC_R) | EDMR_EL, EDMR(port)); @@ -529,11 +530,11 @@ static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd) outl(0, ECSIPR(port));
/* Set Mac address */ - val = bd->bi_enetaddr[0] << 24 | bd->bi_enetaddr[1] << 16 | - bd->bi_enetaddr[2] << 8 | bd->bi_enetaddr[3]; + val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 | + dev->enetaddr[2] << 8 | dev->enetaddr[3]; outl(val, MAHR(port));
- val = bd->bi_enetaddr[4] << 8 | bd->bi_enetaddr[5]; + val = dev->enetaddr[4] << 8 | dev->enetaddr[5]; outl(val, MALR(port));
outl(RFLR_RFL_MIN, RFLR(port)); @@ -589,24 +590,6 @@ static void sh_eth_stop(struct sh_eth_dev *eth) outl(~EDRRR_R, EDRRR(eth->port)); }
-static int sh_eth_get_mac(bd_t *bd) -{ - char *s, *e; - - s = getenv("ethaddr"); - if (s != NULL) { - int i; - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - } else { - puts("Please set MAC address\n"); - } - return 0; -} - int sh_eth_init(struct eth_device *dev, bd_t *bd) { int ret = 0; @@ -682,7 +665,8 @@ int sh_eth_initialize(bd_t *bd) /* Register Device to EtherNet subsystem */ eth_register(dev);
- sh_eth_get_mac(bd); + if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr)) + puts("Please set MAC address\n");
return ret;

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 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 --- drivers/net/lan91c96.c | 75 +++++++---------------------------------------- drivers/net/smc91111.c | 72 +++++++-------------------------------------- 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 9cc4fce..3038faf 100644 --- a/drivers/net/smc911x.c +++ b/drivers/net/smc911x.c @@ -434,15 +434,10 @@ void smc911x_set_mac_csr(u8 reg, u32 data) 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); @@ -460,10 +455,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; }

Dear Mike,
In message 1234847451-3210-18-git-send-email-vapier@gentoo.org you wrote:
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.
...
This patch (see also commit 03f3d8d3b39c, http://git.denx.de/?p=u-boot.git;a=commit;h=03f3d8d3b39cf85c0ce7ca903b436701...) changed behaviour of some network drivers.
As I just learned (sorry, I missed this in the initial review) it drops a warning printed by the old code, when there were valid MAC addresses stored both in the U-Boot environment ("ethaddr" variable) and in the controller's EEPROM:
- 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");
}
- }
This affects other drivers as well (cs8900 for example, in another patch).
Can you please explain what your rationale was for removing this code?
I always found it pretty useful, and am missing it now ;-)
[Note that board/davinci/common/misc.c was added which uses this code, sso one way or another a cleanup is needed.]
Best regards,
Wolfgang Denk

On Tuesday 09 June 2009 07:53:11 Wolfgang Denk wrote:
Dear Mike,
In message 1234847451-3210-18-git-send-email-vapier@gentoo.org you wrote:
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.
...
This patch (see also commit 03f3d8d3b39c, http://git.denx.de/?p=u-boot.git;a=commit;h=03f3d8d3b39cf85c0ce7ca903b43670 1e8aa610b) changed behaviour of some network drivers.
As I just learned (sorry, I missed this in the initial review) it drops a warning printed by the old code, when there were valid MAC addresses stored both in the U-Boot environment ("ethaddr" variable)
and in the controller's EEPROM:
- 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");
}
- }
This affects other drivers as well (cs8900 for example, in another patch).
Can you please explain what your rationale was for removing this code?
i thought the u-boot design was to not touch hardware it shouldnt be. if the canonical location for eth addr is the env, then what is in the attached eeproms is irrelevant as it wont be used if the env is available. it's also not specific to either of these drivers, so if we did choose to make this behavior optional via some define, it would make more sense to do it in the common eth code rather than copying & pasting it everywhere. -mike

Dear Mike Frysinger,
In message 200906092030.49884.vapier@gentoo.org you wrote:
This patch (see also commit 03f3d8d3b39c, http://git.denx.de/?p=u-boot.git;a=commit;h=03f3d8d3b39cf85c0ce7ca903b43670 1e8aa610b) changed behaviour of some network drivers.
As I just learned (sorry, I missed this in the initial review) it drops a warning printed by the old code, when there were valid MAC addresses stored both in the U-Boot environment ("ethaddr" variable)
and in the controller's EEPROM:
- 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");
}
- }
This affects other drivers as well (cs8900 for example, in another patch).
Can you please explain what your rationale was for removing this code?
i thought the u-boot design was to not touch hardware it shouldnt be. if the
Um...yes - but what has thjis to do with that here?
canonical location for eth addr is the env, then what is in the attached eeproms is irrelevant as it wont be used if the env is available. it's also
But printing a warning message is probably still a pretty good idea, especially since you don't know what the driver in some OS will do that might be bootet later - and not only users, even some servers and routers may get confused when a device changes MAC addresses like that.
not specific to either of these drivers, so if we did choose to make this behavior optional via some define, it would make more sense to do it in the common eth code rather than copying & pasting it everywhere.
Agreed. Do you think you have time and resources to craft such a patch?
Thanks in advance.
Best regards,
Wolfgang Denk

On Monday 13 July 2009 17:58:18 Wolfgang Denk wrote:
Mike Frysinger wrote:
This patch (see also commit 03f3d8d3b39c, http://git.denx.de/?p=u-boot.git;a=commit;h=03f3d8d3b39cf85c0ce7ca903b4 3670 1e8aa610b) changed behaviour of some network drivers.
As I just learned (sorry, I missed this in the initial review) it drops a warning printed by the old code, when there were valid MAC addresses stored both in the U-Boot environment ("ethaddr" variable)
and in the controller's EEPROM:
- 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");
}
- }
This affects other drivers as well (cs8900 for example, in another patch).
Can you please explain what your rationale was for removing this code?
i thought the u-boot design was to not touch hardware it shouldnt be. if the
Um...yes - but what has thjis to do with that here?
a valid mac exists in the environment already, so u-boot should not be checking the MAC address
canonical location for eth addr is the env, then what is in the attached eeproms is irrelevant as it wont be used if the env is available. it's also
But printing a warning message is probably still a pretty good idea, especially since you don't know what the driver in some OS will do that might be bootet later - and not only users, even some servers and routers may get confused when a device changes MAC addresses like that.
makes sense to me
not specific to either of these drivers, so if we did choose to make this behavior optional via some define, it would make more sense to do it in the common eth code rather than copying & pasting it everywhere.
Agreed. Do you think you have time and resources to craft such a patch?
net/eth.c:eth_initialize() already has the logic to handle this, but that only applies to NET_MULTI drivers. and most do not take advantage of it. i think the documentation should be updated like so: in the driver function that calls eth_register(), the driver should initialize dev->enetaddr to the MAC found in the hardware (if possible) and then applicable drivers should be fixed. if we agree on this route, i can do a quick scan of the net drivers and post relevant patches.
in the case of a mismatch, we would see from the common eth code: Warning: Blackfin EMAC MAC addresses don't match: Address in SROM is 0a:0a:0a:0a:0a:0a Address in environment is 00:e0:22:fe:44:ec
the smsc drivers however are not in the NET_MULTI category -- they dont use any of the common ethernet stack. so once they are converted to NET_MULTI, they'll get this functionality for free (when exactly were we adding #warning about non-NET_MULTI usage ?). so rather than expend effort on restoring duplicate code, how about interested parties convert the driver ;). -mike

Hi Mike,
Mike Frysinger wrote:
<snip> >> not specific to either of these drivers, so if we did choose to make this >> behavior optional via some define, it would make more sense to do it in >> the common eth code rather than copying & pasting it everywhere. >> > Agreed. Do you think you have time and resources to craft such a patch? >
net/eth.c:eth_initialize() already has the logic to handle this, but that only applies to NET_MULTI drivers. and most do not take advantage of it. i think the documentation should be updated like so: in the driver function that calls eth_register(), the driver should initialize dev->enetaddr to the MAC found in the hardware (if possible) and then applicable drivers should be fixed. if we agree on this route, i can do a quick scan of the net drivers and post relevant patches.
That'd be great. You've done good work bringing consistency to the code.
in the case of a mismatch, we would see from the common eth code: Warning: Blackfin EMAC MAC addresses don't match: Address in SROM is 0a:0a:0a:0a:0a:0a Address in environment is 00:e0:22:fe:44:ec
the smsc drivers however are not in the NET_MULTI category -- they dont use any of the common ethernet stack. so once they are converted to NET_MULTI, they'll get this functionality for free (when exactly were we adding #warning about non-NET_MULTI usage ?). so rather than expend effort on restoring duplicate code, how about interested parties convert the driver ;). -mike
The #warning patch is done but not submitted. Pretty lame, I know, but it's been a crazy summer. I have the SMSC driver mostly ported but don't have any hardware to test on. I guess there are 3 days left in this merge window to get the ball rolling... If anybody else has already done this, please submit.
regards, Ben

On Thursday 16 July 2009 13:41:30 Ben Warren wrote:
Mike Frysinger wrote:
the smsc drivers however are not in the NET_MULTI category -- they dont use any of the common ethernet stack. so once they are converted to NET_MULTI, they'll get this functionality for free (when exactly were we adding #warning about non-NET_MULTI usage ?). so rather than expend effort on restoring duplicate code, how about interested parties convert the driver ;). -mike
The #warning patch is done but not submitted. Pretty lame, I know, but it's been a crazy summer. I have the SMSC driver mostly ported but don't have any hardware to test on. I guess there are 3 days left in this merge window to get the ball rolling... If anybody else has already done this, please submit.
i can test SMC911X and SMC91111 with real hardware -mike

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.
The cpus that get converted here: at91rm9200 mpc512x mpc5xxx mpc8260 mpc8xx ppc4xx
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com CC: John Rigby jrigby@freescale.com CC: Stefan Roese sr@denx.de --- cpu/arm920t/at91rm9200/ether.c | 8 +++++--- cpu/mpc512x/cpu.c | 6 ++++-- cpu/mpc5xxx/cpu.c | 6 ++++-- cpu/mpc8260/ether_fcc.c | 4 ++-- cpu/mpc8260/ether_scc.c | 4 ++-- cpu/ppc4xx/cpu_init.c | 14 ++++++++------ post/cpu/mpc8xx/ether.c | 4 ++-- 7 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/cpu/arm920t/at91rm9200/ether.c b/cpu/arm920t/at91rm9200/ether.c index f20e070..b00b948 100644 --- a/cpu/arm920t/at91rm9200/ether.c +++ b/cpu/arm920t/at91rm9200/ether.c @@ -155,6 +155,7 @@ int eth_init (bd_t * bd) { int ret; int i; + uchar enetaddr[6];
p_mac = AT91C_BASE_EMAC;
@@ -190,9 +191,10 @@ int eth_init (bd_t * bd) rbfdt[RBF_FRAMEMAX - 1].addr |= RBF_WRAP; rbfp = &rbfdt[0];
- p_mac->EMAC_SA2L = (bd->bi_enetaddr[3] << 24) | (bd->bi_enetaddr[2] << 16) - | (bd->bi_enetaddr[1] << 8) | (bd->bi_enetaddr[0]); - p_mac->EMAC_SA2H = (bd->bi_enetaddr[5] << 8) | (bd->bi_enetaddr[4]); + eth_getenv_enetaddr("ethaddr", enetaddr); + p_mac->EMAC_SA2L = (enetaddr[3] << 24) | (enetaddr[2] << 16) + | (enetaddr[1] << 8) | (enetaddr[0]); + p_mac->EMAC_SA2H = (enetaddr[5] << 8) | (enetaddr[4]);
p_mac->EMAC_RBQP = (long) (&rbfdt[0]); p_mac->EMAC_RSR &= ~(AT91C_EMAC_RSR_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA); diff --git a/cpu/mpc512x/cpu.c b/cpu/mpc512x/cpu.c index b9069b0..be532af 100644 --- a/cpu/mpc512x/cpu.c +++ b/cpu/mpc512x/cpu.c @@ -148,15 +148,17 @@ static void old_ft_cpu_setup(void *blob, bd_t *bd) * avoid fixing up by path because that * produces scary error messages */ + uchar enetaddr[6];
/* * old device trees have ethernet nodes with * device_type = "network" */ + eth_getenv_enetaddr("ethaddr", enetaddr); do_fixup_by_prop(blob, "device_type", "network", 8, - "local-mac-address", bd->bi_enetaddr, 6, 0); + "local-mac-address", enetaddr, 6, 0); do_fixup_by_prop(blob, "device_type", "network", 8, - "address", bd->bi_enetaddr, 6, 0); + "address", enetaddr, 6, 0); /* * old device trees have soc nodes with * device_type = "soc" diff --git a/cpu/mpc5xxx/cpu.c b/cpu/mpc5xxx/cpu.c index 9c6ab76..ad5ef8e 100644 --- a/cpu/mpc5xxx/cpu.c +++ b/cpu/mpc5xxx/cpu.c @@ -121,6 +121,7 @@ void ft_cpu_setup(void *blob, bd_t *bd) int div = in_8((void*)CONFIG_SYS_MBAR + 0x204) & 0x0020 ? 8 : 4; char * cpu_path = "/cpus/" OF_CPU; #ifdef CONFIG_MPC5xxx_FEC + uchar *enetaddr[6]; char * eth_path = "/" OF_SOC "/ethernet@3000"; #endif
@@ -131,8 +132,9 @@ void ft_cpu_setup(void *blob, bd_t *bd) do_fixup_by_path_u32(blob, "/" OF_SOC, "system-frequency", bd->bi_busfreq*div, 1); #ifdef CONFIG_MPC5xxx_FEC - do_fixup_by_path(blob, eth_path, "mac-address", bd->bi_enetaddr, 6, 0); - do_fixup_by_path(blob, eth_path, "local-mac-address", bd->bi_enetaddr, 6, 0); + eth_getenv_enetaddr("ethaddr", enetaddr); + do_fixup_by_path(blob, eth_path, "mac-address", enetaddr, 6, 0); + do_fixup_by_path(blob, eth_path, "local-mac-address", enetaddr, 6, 0); #endif } #endif diff --git a/cpu/mpc8260/ether_fcc.c b/cpu/mpc8260/ether_fcc.c index 3ab57eb..5ac02a0 100644 --- a/cpu/mpc8260/ether_fcc.c +++ b/cpu/mpc8260/ether_fcc.c @@ -654,7 +654,7 @@ eth_loopback_test (void)
puts ("FCC Ethernet External loopback test\n");
- memcpy (NetOurEther, gd->bd->bi_enetaddr, 6); + eth_getenv_enetaddr("ethaddr", NetOurEther);
/* * global initialisations for all FCC channels @@ -841,7 +841,7 @@ eth_loopback_test (void) * So, far we have only been given one Ethernet address. We use * the same address for all channels */ -#define ea gd->bd->bi_enetaddr +#define ea NetOurEther fpp->fen_paddrh = (ea[5] << 8) + ea[4]; fpp->fen_paddrm = (ea[3] << 8) + ea[2]; fpp->fen_paddrl = (ea[1] << 8) + ea[0]; diff --git a/cpu/mpc8260/ether_scc.c b/cpu/mpc8260/ether_scc.c index 3671ef1..432111d 100644 --- a/cpu/mpc8260/ether_scc.c +++ b/cpu/mpc8260/ether_scc.c @@ -199,6 +199,7 @@ static int sec_init(struct eth_device *dev, bd_t *bis) volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; scc_enet_t *pram_ptr; uint dpaddr; + uchar ea[6];
rxIdx = 0; txIdx = 0; @@ -261,11 +262,10 @@ static int sec_init(struct eth_device *dev, bd_t *bis) pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */ pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
-# define ea bis->bi_enetaddr + eth_getenv_enetaddr("ethaddr", ea); pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4]; pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2]; pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0]; -# undef ea
pram_ptr->sen_pper = 0x0; /* Persistence (unused) */
diff --git a/cpu/ppc4xx/cpu_init.c b/cpu/ppc4xx/cpu_init.c index b5d81f2..a8f589a 100644 --- a/cpu/ppc4xx/cpu_init.c +++ b/cpu/ppc4xx/cpu_init.c @@ -324,6 +324,7 @@ int cpu_init_r (void) #if defined(CONFIG_405GP) || defined(CONFIG_405EP) bd_t *bd = gd->bd; unsigned long reg; + uchar enetaddr[6]; #if defined(CONFIG_405GP) uint pvr = get_pvr(); #endif @@ -332,19 +333,20 @@ int cpu_init_r (void) * Write Ethernetaddress into on-chip register */ reg = 0x00000000; - reg |= bd->bi_enetaddr[0]; /* set high address */ + eth_getenv_enetaddr("ethaddr", enetaddr); + reg |= enetaddr[0]; /* set high address */ reg = reg << 8; - reg |= bd->bi_enetaddr[1]; + reg |= enetaddr[1]; out32 (EMAC_IAH, reg);
reg = 0x00000000; - reg |= bd->bi_enetaddr[2]; /* set low address */ + reg |= enetaddr[2]; /* set low address */ reg = reg << 8; - reg |= bd->bi_enetaddr[3]; + reg |= enetaddr[3]; reg = reg << 8; - reg |= bd->bi_enetaddr[4]; + reg |= enetaddr[4]; reg = reg << 8; - reg |= bd->bi_enetaddr[5]; + reg |= enetaddr[5]; out32 (EMAC_IAL, reg);
#if defined(CONFIG_405GP) diff --git a/post/cpu/mpc8xx/ether.c b/post/cpu/mpc8xx/ether.c index 5622cb7..fe6c39e 100644 --- a/post/cpu/mpc8xx/ether.c +++ b/post/cpu/mpc8xx/ether.c @@ -110,6 +110,7 @@ static RTXBD *rtx; static void scc_init (int scc_index) { bd_t *bd = gd->bd; + uchar ea[6];
static int proff[] = { PROFF_SCC1, PROFF_SCC2, PROFF_SCC3, PROFF_SCC4 }; @@ -296,11 +297,10 @@ CPM_CR_CH_SCC4 }; pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */ pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
-#define ea bd->bi_enetaddr + eth_getenv_enetaddr("ethaddr", ea); pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4]; pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2]; pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0]; -#undef ea
pram_ptr->sen_pper = 0x0; /* Persistence (unused) */ pram_ptr->sen_iaddr1 = 0x0; /* Individual Address Filter 1 (unused) */

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.
The resulting code can also be simplified even further.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Stefan Roese sr@denx.de CC: Ben Warren biggerbadderben@gmail.com --- cpu/ixp/npe/npe.c | 36 +++++++++++------------------------- 1 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/cpu/ixp/npe/npe.c b/cpu/ixp/npe/npe.c index 03e3bf7..2e68689 100644 --- a/cpu/ixp/npe/npe.c +++ b/cpu/ixp/npe/npe.c @@ -565,25 +565,19 @@ int npe_initialize(bd_t * bis) struct eth_device *dev; int eth_num = 0; struct npe *p_npe = NULL; + uchar enetaddr[6];
for (eth_num = 0; eth_num < CONFIG_SYS_NPE_NUMS; eth_num++) {
/* See if we can actually bring up the interface, otherwise, skip it */ - switch (eth_num) { - default: /* fall through */ - case 0: - if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) { - continue; - } - break; #ifdef CONFIG_HAS_ETH1 - case 1: - if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) { + if (eth_num == 1) { + if (!eth_getenv_enetaddr("eth1addr", enetaddr)) continue; - } - break; + } else #endif - } + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) + continue;
/* Allocate device structure */ dev = (struct eth_device *)malloc(sizeof(*dev)); @@ -603,22 +597,14 @@ int npe_initialize(bd_t * bis) } memset(p_npe, 0, sizeof(struct npe));
- switch (eth_num) { - default: /* fall through */ - case 0: - memcpy(dev->enetaddr, bis->bi_enetaddr, 6); - p_npe->eth_id = 0; - p_npe->phy_no = CONFIG_PHY_ADDR; - break; - + p_npe->eth_id = eth_num; + memcpy(dev->enetaddr, enetaddr, 6); #ifdef CONFIG_HAS_ETH1 - case 1: - memcpy(dev->enetaddr, bis->bi_enet1addr, 6); - p_npe->eth_id = 1; + if (eth_num == 1) p_npe->phy_no = CONFIG_PHY1_ADDR; - break; + else #endif - } + p_npe->phy_no = CONFIG_PHY_ADDR;
sprintf(dev->name, "NPE%d", eth_num); dev->priv = (void *)p_npe;

Since everyone is using the environment for mac address storage, there is no point in seeding the global data.
The arches that are converted here: i386 m68k microblaze mips nios nios2 sh sparc
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com CC: Daniel Hellstrom daniel@gaisler.com CC: Michal Simek monstr@seznam.cz CC: Shinya Kuribayashi skuribay@ruby.dti.ne.jp CC: Scott McNutt smcnutt@psyent.com CC: Nobuhiro Iwamatsu iwamatsu@nigauri.org --- lib_i386/board.c | 17 ----------------- lib_m68k/board.c | 38 -------------------------------------- lib_microblaze/board.c | 8 -------- lib_mips/board.c | 8 -------- lib_nios/board.c | 5 ----- lib_nios2/board.c | 5 ----- lib_sh/board.c | 10 ---------- lib_sparc/board.c | 19 ------------------- 8 files changed, 0 insertions(+), 110 deletions(-)
diff --git a/lib_i386/board.c b/lib_i386/board.c index 1734f86..29683ee 100644 --- a/lib_i386/board.c +++ b/lib_i386/board.c @@ -262,23 +262,6 @@ void start_i386boot (void) /* IP Address */ bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr");
- /* MAC Address */ - { - int i; - ulong reg; - char *s, *e; - char tmp[64]; - - i = getenv_r ("ethaddr", tmp, sizeof (tmp)); - s = (i > 0) ? tmp : NULL; - - for (reg = 0; reg < 6; ++reg) { - bd_data.bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - } - #if defined(CONFIG_PCI) /* * Do pci configuration diff --git a/lib_m68k/board.c b/lib_m68k/board.c index 583ce10..db45b00 100644 --- a/lib_m68k/board.c +++ b/lib_m68k/board.c @@ -584,44 +584,6 @@ void board_init_r (gd_t *id, ulong dest_addr) * where had to use getenv_r(), which can be pretty slow when * the environment is in EEPROM. */ - s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#ifdef CONFIG_HAS_ETH1 - /* handle the 2nd ethernet address */ - - s = getenv ("eth1addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#endif -#ifdef CONFIG_HAS_ETH2 - /* handle the 3rd ethernet address */ - - s = getenv ("eth2addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#endif - -#ifdef CONFIG_HAS_ETH3 - /* handle 4th ethernet address */ - s = getenv("eth3addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#endif - - /* IP Address */ bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
WATCHDOG_RESET (); diff --git a/lib_microblaze/board.c b/lib_microblaze/board.c index 30d7641..1a42640 100644 --- a/lib_microblaze/board.c +++ b/lib_microblaze/board.c @@ -173,14 +173,6 @@ void board_init (void) #endif
#if defined(CONFIG_CMD_NET) - /* board MAC address */ - s = getenv ("ethaddr"); - printf ("MAC:%s\n",s); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } /* IP Address */ bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); eth_init (bd); diff --git a/lib_mips/board.c b/lib_mips/board.c index dfe6831..6fc4845 100644 --- a/lib_mips/board.c +++ b/lib_mips/board.c @@ -401,14 +401,6 @@ void board_init_r (gd_t *id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate();
- /* board MAC address */ - s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - /* IP Address */ bd->bi_ip_addr = getenv_IPaddr("ipaddr");
diff --git a/lib_nios/board.c b/lib_nios/board.c index 024beb5..63e79ae 100644 --- a/lib_nios/board.c +++ b/lib_nios/board.c @@ -151,11 +151,6 @@ void board_init (void) env_relocate();
bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); - s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) s = (*e) ? e + 1 : e; - }
WATCHDOG_RESET (); devices_init(); diff --git a/lib_nios2/board.c b/lib_nios2/board.c index d759f0f..70fad1b 100644 --- a/lib_nios2/board.c +++ b/lib_nios2/board.c @@ -157,11 +157,6 @@ void board_init (void) env_relocate();
bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); - s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) s = (*e) ? e + 1 : e; - }
WATCHDOG_RESET (); devices_init(); diff --git a/lib_sh/board.c b/lib_sh/board.c index d4cc85c..2fd213b 100644 --- a/lib_sh/board.c +++ b/lib_sh/board.c @@ -125,17 +125,7 @@ static int sh_mem_env_init(void) static int sh_net_init(void) { DECLARE_GLOBAL_DATA_PTR; - char *s, *e; - int i; - gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); - s = getenv("ethaddr"); - for (i = 0; i < 6; ++i) { - gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - return 0; } #endif diff --git a/lib_sparc/board.c b/lib_sparc/board.c index e972d3e..2f3e673 100644 --- a/lib_sparc/board.c +++ b/lib_sparc/board.c @@ -390,25 +390,6 @@ void board_init_f(ulong bootflag) board_late_init(); #endif
- s = getenv("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - -#ifdef CONFIG_HAS_ETH1 - /* handle the 2nd ethernet address */ - - s = getenv("eth1addr"); - - for (i = 0; i < 6; ++i) { - bd->bi_enet1addr[i] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#endif - #ifdef CONFIG_ID_EEPROM mac_read_from_eeprom(); #endif

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.
For the nx823, the serial number is moved out of load_sernum_ethaddr() and into misc_init_r() as is the env setup. This lets us kill off the former function in the process.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/nx823/flash.c | 5 +++-- board/nx823/nx823.c | 41 ++++++++++++++++------------------------- lib_ppc/board.c | 4 ---- 3 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/board/nx823/flash.c b/board/nx823/flash.c index 194d841..336e704 100644 --- a/board/nx823/flash.c +++ b/board/nx823/flash.c @@ -27,8 +27,9 @@ #include <common.h> #include <mpc8xx.h>
+DECLARE_GLOBAL_DATA_PTR; + flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ -extern u_long *my_sernum; /* from nx823.c */
/*----------------------------------------------------------------------- * Protection Flags: @@ -346,7 +347,7 @@ int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) if (addr >= CONFIG_SYS_FLASH_SN_SECTOR && addr < CONFIG_SYS_FLASH_SN_BASE) { u_long dest = CONFIG_SYS_FLASH_SN_BASE; - u_short *sn = (u_short *)my_sernum; + u_short *sn = (u_short *)gd->bd->bi_sernum;
printf("(saving sernum)"); for (i=0; i<4; i++) diff --git a/board/nx823/nx823.c b/board/nx823/nx823.c index df9aaab..6ec29dc 100644 --- a/board/nx823/nx823.c +++ b/board/nx823/nx823.c @@ -360,39 +360,30 @@ static long int dram_size (long int mamr_value, long int *base, return (get_ram_size (base, maxsize)); }
-u_long *my_sernum; - int misc_init_r (void) { + int i; char tmp[50]; - u_char *e = gd->bd->bi_enetaddr; + uchar ethaddr[6]; + bd_t *bd = gd->bd; + ulong my_sernum = bd->bi_sernum;
- /* save serial numbre from flash (uniquely programmed) */ - my_sernum = malloc (8); - memcpy (my_sernum, gd->bd->bi_sernum, 8); + /* load unique serial number */ + for (i = 0; i < 8; ++i) + bd->bi_sernum[i] = *(u_char *) (CONFIG_SYS_FLASH_SN_BASE + i);
/* save env variables according to sernum */ sprintf (tmp, "%08lx%08lx", my_sernum[0], my_sernum[1]); setenv ("serial#", tmp);
- sprintf (tmp, "%02x:%02x:%02x:%02x:%02x:%02x", e[0], e[1], e[2], e[3], - e[4], e[5]); - setenv ("ethaddr", tmp); - return (0); -} - -void load_sernum_ethaddr (void) -{ - int i; - bd_t *bd = gd->bd; - - for (i = 0; i < 8; i++) { - bd->bi_sernum[i] = *(u_char *) (CONFIG_SYS_FLASH_SN_BASE + i); + if (!eth_getenv_enetaddr("ethaddr", ethaddr)) { + ethaddr[0] = 0x10; + ethaddr[1] = 0x20; + ethaddr[2] = 0x30; + ethaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2]; + ethaddr[4] = bd->bi_sernum[5]; + ethaddr[5] = bd->bi_sernum[6]; } - bd->bi_enetaddr[0] = 0x10; - bd->bi_enetaddr[1] = 0x20; - bd->bi_enetaddr[2] = 0x30; - bd->bi_enetaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2]; - bd->bi_enetaddr[4] = bd->bi_sernum[5]; - bd->bi_enetaddr[5] = bd->bi_sernum[6]; + + return 0; } diff --git a/lib_ppc/board.c b/lib_ppc/board.c index 3bcfb45..50d7ad2 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -903,10 +903,6 @@ void board_init_r (gd_t *id, ulong dest_addr) bd->bi_ethspeed = 0xFFFF; #endif
-#ifdef CONFIG_NX823 - load_sernum_ethaddr (); -#endif - #ifdef CONFIG_HAS_ETH1 /* handle the 2nd ethernet address */

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.
Some warts are remaining and should be killed off (by moving the func to the appropriate board init code): - davinci_eth_set_mac_addr - cs8900_get_enetaddr - smc_set_mac_addr
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- lib_arm/board.c | 43 +++++++++++-------------------------------- 1 files changed, 11 insertions(+), 32 deletions(-)
diff --git a/lib_arm/board.c b/lib_arm/board.c index 964f5cc..8fe2f41 100644 --- a/lib_arm/board.c +++ b/lib_arm/board.c @@ -73,7 +73,7 @@ const char version_string[] = U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
#ifdef CONFIG_DRIVER_CS8900 -extern void cs8900_get_enetaddr (uchar * addr); +extern void cs8900_get_enetaddr (void); #endif
#ifdef CONFIG_DRIVER_RTL8019 @@ -380,34 +380,6 @@ void start_armboot (void) /* IP Address */ gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
- /* MAC Address */ - { - int i; - ulong reg; - char *s, *e; - char tmp[64]; - - i = getenv_r ("ethaddr", tmp, sizeof (tmp)); - s = (i > 0) ? tmp : NULL; - - for (reg = 0; reg < 6; ++reg) { - gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } - -#ifdef CONFIG_HAS_ETH1 - i = getenv_r ("eth1addr", tmp, sizeof (tmp)); - s = (i > 0) ? tmp : NULL; - - for (reg = 0; reg < 6; ++reg) { - gd->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } -#endif - } - devices_init (); /* get the devices list going. */
#ifdef CONFIG_CMC_PU2 @@ -428,19 +400,26 @@ void start_armboot (void)
/* Perform network card initialisation if necessary */ #ifdef CONFIG_DRIVER_TI_EMAC + /* XXX: this needs to be moved to board init */ extern void davinci_eth_set_mac_addr (const u_int8_t *addr); if (getenv ("ethaddr")) { - davinci_eth_set_mac_addr(gd->bd->bi_enetaddr); + uchar enetaddr[6]; + eth_getenv_enetaddr("ethaddr", enetaddr); + davinci_eth_set_mac_addr(enetaddr); } #endif
#ifdef CONFIG_DRIVER_CS8900 - cs8900_get_enetaddr (gd->bd->bi_enetaddr); + /* XXX: this needs to be moved to board init */ + cs8900_get_enetaddr (); #endif
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96) + /* XXX: this needs to be moved to board init */ if (getenv ("ethaddr")) { - smc_set_mac_addr(gd->bd->bi_enetaddr); + uchar enetaddr[6]; + eth_getenv_enetaddr("ethaddr", enetaddr); + smc_set_mac_addr(enetaddr); } #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

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.
Rather than have the common ppc code have board-specific hooks, move the board_get_enetaddr() function into the board-specific init functions.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/RPXClassic/RPXClassic.c | 16 +++++++++-- board/mbx8xx/mbx8xx.c | 14 +++++++++- board/sandburst/common/sb_common.c | 4 +-- board/sandburst/common/sb_common.h | 1 + board/sandburst/karef/karef.c | 29 ++++++++++++++++++++ board/sandburst/metrobox/metrobox.c | 29 ++++++++++++++++++++ board/siemens/IAD210/IAD210.c | 14 +++++++++- board/v38b/v38b.c | 12 ++++++++ board/xpedite1k/xpedite1k.c | 51 +++++++++++++++++++++++++++------- include/common.h | 7 ----- include/configs/IAD210.h | 1 + include/configs/MBX860T.h | 2 + include/configs/RPXClassic.h | 1 + include/configs/XPEDITE1K.h | 1 + include/configs/v38b.h | 1 + lib_ppc/board.c | 28 ------------------- 16 files changed, 157 insertions(+), 54 deletions(-)
diff --git a/board/RPXClassic/RPXClassic.c b/board/RPXClassic/RPXClassic.c index 9fdf700..5aa713f 100644 --- a/board/RPXClassic/RPXClassic.c +++ b/board/RPXClassic/RPXClassic.c @@ -105,7 +105,7 @@ int checkboard (void) * board_get_enetaddr -- Read the MAC Address in the I2C EEPROM *----------------------------------------------------------------------------- */ -void board_get_enetaddr (uchar * enet) +static void board_get_enetaddr(uchar *enet) { int i; char buff[256], *cp; @@ -142,9 +142,19 @@ void board_get_enetaddr (uchar * enet) enet[3] |= 0x80; #endif
- printf ("MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n", - enet[0], enet[1], enet[2], enet[3], enet[4], enet[5]); + printf("MAC address = %pM\n", enet); +} + +int misc_init_r(void) +{ + uchar enetaddr[6]; + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + }
+ return 0; }
void rpxclassic_init (void) diff --git a/board/mbx8xx/mbx8xx.c b/board/mbx8xx/mbx8xx.c index af4f57d..a3bf1f7 100644 --- a/board/mbx8xx/mbx8xx.c +++ b/board/mbx8xx/mbx8xx.c @@ -241,7 +241,7 @@ static unsigned int get_reffreq (void) return *((ulong *) packet->data); }
-void board_get_enetaddr (uchar * addr) +static void board_get_enetaddr(uchar *addr) { int i; vpd_packet_t *packet; @@ -251,6 +251,18 @@ void board_get_enetaddr (uchar * addr) addr[i] = packet->data[i]; }
+int misc_init_r(void) +{ + uchar enetaddr[6]; + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + } + + return 0; +} + /* * Check Board Identity: */ diff --git a/board/sandburst/common/sb_common.c b/board/sandburst/common/sb_common.c index f6ea16f..b8160c8 100644 --- a/board/sandburst/common/sb_common.c +++ b/board/sandburst/common/sb_common.c @@ -394,9 +394,8 @@ int is_pci_host(struct pci_controller *hose) * mgmt mac address. * ************************************************************************/ -static int macaddr_idx = 0;
-void board_get_enetaddr (uchar * enet) +void board_get_enetaddr(int macaddr_idx, uchar *enet) { int i; unsigned short tmp; @@ -419,7 +418,6 @@ void board_get_enetaddr (uchar * enet) tmp += 31; memcpy(&enet[4], &tmp, 2);
- macaddr_idx++; } else { enet[0] = 0x02; enet[1] = 0x00; diff --git a/board/sandburst/common/sb_common.h b/board/sandburst/common/sb_common.h index 888e4f0..e652ba8 100644 --- a/board/sandburst/common/sb_common.h +++ b/board/sandburst/common/sb_common.h @@ -72,5 +72,6 @@ int sbcommon_get_master(void); int sbcommon_secondary_present(void); unsigned short sbcommon_get_serial_number(void); void sbcommon_fans(void); +void board_get_enetaddr(int macaddr_idx, uchar *enet);
#endif /* __SBCOMMON_H__ */ diff --git a/board/sandburst/karef/karef.c b/board/sandburst/karef/karef.c index 9b94af5..55310d7 100644 --- a/board/sandburst/karef/karef.c +++ b/board/sandburst/karef/karef.c @@ -354,6 +354,7 @@ int misc_init_r (void) { unsigned short sernum; char envstr[255]; + uchar enetaddr[6]; KAREF_FPGA_REGS_ST *karef_ps; OFEM_FPGA_REGS_ST *ofem_ps;
@@ -408,6 +409,34 @@ int misc_init_r (void) printf("fakeled is set. use 'setenv fakeled ; setenv bootdelay 5 ; saveenv' to recover\n"); }
+#ifdef CONFIG_HAS_ETH0 + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(0, enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH1 + if (!eth_getenv_enetaddr("eth1addr", enetaddr)) { + board_get_enetaddr(1, enetaddr); + eth_putenv_enetaddr("eth1addr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH2 + if (!eth_getenv_enetaddr("eth2addr", enetaddr)) { + board_get_enetaddr(2, enetaddr); + eth_putenv_enetaddr("eth2addr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH3 + if (!eth_getenv_enetaddr("eth3addr", enetaddr)) { + board_get_enetaddr(3, enetaddr); + eth_putenv_enetaddr("eth3addr", enetaddr); + } +#endif + return (0); }
diff --git a/board/sandburst/metrobox/metrobox.c b/board/sandburst/metrobox/metrobox.c index ec4c451..8bb8c02 100644 --- a/board/sandburst/metrobox/metrobox.c +++ b/board/sandburst/metrobox/metrobox.c @@ -321,6 +321,7 @@ int misc_init_r (void) { unsigned short sernum; char envstr[255]; + uchar enetaddr[6]; unsigned char opto_rev; OPTO_FPGA_REGS_ST *opto_ps;
@@ -379,6 +380,34 @@ int misc_init_r (void) } }
+#ifdef CONFIG_HAS_ETH0 + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(0, enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH1 + if (!eth_getenv_enetaddr("eth1addr", enetaddr)) { + board_get_enetaddr(1, enetaddr); + eth_putenv_enetaddr("eth1addr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH2 + if (!eth_getenv_enetaddr("eth2addr", enetaddr)) { + board_get_enetaddr(2, enetaddr); + eth_putenv_enetaddr("eth2addr", enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH3 + if (!eth_getenv_enetaddr("eth3addr", enetaddr)) { + board_get_enetaddr(3, enetaddr); + eth_putenv_enetaddr("eth3addr", enetaddr); + } +#endif + return (0); }
diff --git a/board/siemens/IAD210/IAD210.c b/board/siemens/IAD210/IAD210.c index e21bb24..67e5c8f 100644 --- a/board/siemens/IAD210/IAD210.c +++ b/board/siemens/IAD210/IAD210.c @@ -258,7 +258,7 @@ int board_early_init_f (void) return 0; }
-void board_get_enetaddr (uchar * addr) +static void board_get_enetaddr(uchar *addr) { int i; volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; @@ -284,3 +284,15 @@ void board_get_enetaddr (uchar * addr)
cpm->cp_rccr = rccrtmp; } + +int misc_init_r(void) +{ + uchar enetaddr[6]; + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + } + + return 0; +} diff --git a/board/v38b/v38b.c b/board/v38b/v38b.c index d774295..9e7c1d7 100644 --- a/board/v38b/v38b.c +++ b/board/v38b/v38b.c @@ -223,6 +223,18 @@ int board_early_init_r(void) return 0; }
+extern void board_get_enetaddr(uchar *enetaddr); +int misc_init_r(void) +{ + uchar enetaddr[6]; + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(enetaddr); + eth_putenv_enetaddr("ethaddr", enetaddr); + } + + return 0; +}
#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) void init_ide_reset(void) diff --git a/board/xpedite1k/xpedite1k.c b/board/xpedite1k/xpedite1k.c index 58bcfaf..cd1a368 100644 --- a/board/xpedite1k/xpedite1k.c +++ b/board/xpedite1k/xpedite1k.c @@ -335,29 +335,58 @@ ulong post_word_load (void) * board_get_enetaddr -- Read the MAC Addresses in the I2C EEPROM *----------------------------------------------------------------------------- */ -static int enetaddr_num = 0; -void board_get_enetaddr (uchar * enet) +static int read_i2c; +static void board_get_enetaddr(uchar *enet) { int i; unsigned char buff[0x100], *cp;
+ if (read_i2c) + return; + /* Initialize I2C */ i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
/* Read 256 bytes in EEPROM */ i2c_read (0x50, 0, 1, buff, 0x100);
- if (enetaddr_num == 0) { - cp = &buff[0xF4]; - enetaddr_num = 1; - } - else - cp = &buff[0xFA]; - + cp = &buff[0xF4]; for (i = 0; i < 6; i++,cp++) enet[i] = *cp;
- printf ("MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n", - enet[0], enet[1], enet[2], enet[3], enet[4], enet[5]); + printf("MAC address = %pM\n", enet); + read_i2c = 1; +} + +int misc_init_r(void) +{ + uchar enetaddr[6], i2c_enetaddr[6]; + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + board_get_enetaddr(i2c_enetaddr); + eth_putenv_enetaddr("ethaddr", i2c_enetaddr); + } + +#ifdef CONFIG_HAS_ETH1 + if (!eth_getenv_enetaddr("eth1addr", enetaddr)) { + board_get_enetaddr(i2c_enetaddr); + eth_putenv_enetaddr("eth1addr", i2c_enetaddr); + } +#endif + +#ifdef CONFIG_HAS_ETH2 + if (!eth_getenv_enetaddr("eth2addr", enetaddr)) { + board_get_enetaddr(i2c_enetaddr); + eth_putenv_enetaddr("eth2addr", i2c_enetaddr); + } +#endif
+#ifdef CONFIG_HAS_ETH3 + if (!eth_getenv_enetaddr("eth3addr", enetaddr)) { + board_get_enetaddr(i2c_enetaddr); + eth_putenv_enetaddr("eth3addr", i2c_enetaddr); + } +#endif + + return 0; } diff --git a/include/common.h b/include/common.h index afee188..1b76f9e 100644 --- a/include/common.h +++ b/include/common.h @@ -351,13 +351,6 @@ void board_serial_init (void); void board_ether_init (void); #endif
-#if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || \ - defined(CONFIG_IAD210) || defined(CONFIG_XPEDITE1K) || \ - defined(CONFIG_METROBOX) || defined(CONFIG_KAREF) || \ - defined(CONFIG_V38B) -void board_get_enetaddr (uchar *addr); -#endif - #ifdef CONFIG_HERMES /* $(BOARD)/hermes.c */ void hermes_start_lxt980 (int speed); diff --git a/include/configs/IAD210.h b/include/configs/IAD210.h index ca488c6..ea1e706 100644 --- a/include/configs/IAD210.h +++ b/include/configs/IAD210.h @@ -67,6 +67,7 @@
/* using this define saves us updating another source file */ #define CONFIG_BOARD_EARLY_INIT_F 1 +#define CONFIG_MISC_INIT_R
#undef CONFIG_BOOTARGS /* #define CONFIG_BOOTCOMMAND \ diff --git a/include/configs/MBX860T.h b/include/configs/MBX860T.h index 4cb3a69..0c28710 100644 --- a/include/configs/MBX860T.h +++ b/include/configs/MBX860T.h @@ -50,6 +50,8 @@ #undef CONFIG_8xx_TFTP_MODE #endif
+#define CONFIG_MISC_INIT_R + #define CONFIG_DRAM_SPEED (CONFIG_8xx_BUSCLOCK) /* MHz */ #define CONFIG_BOOTCOMMAND "bootm FE020000" /* autoboot command */ #define CONFIG_BOOTARGS " " diff --git a/include/configs/RPXClassic.h b/include/configs/RPXClassic.h index 162ef09..bec5278 100644 --- a/include/configs/RPXClassic.h +++ b/include/configs/RPXClassic.h @@ -53,6 +53,7 @@ #define CONFIG_SYS_DISCOVER_PHY 1 #define CONFIG_MII 1 #endif /* CONFIG_FEC_ENET */ +#define CONFIG_MISC_INIT_R
/* Video console (graphic: Epson SED13806 on ECCX board, no keyboard */ #if 1 diff --git a/include/configs/XPEDITE1K.h b/include/configs/XPEDITE1K.h index 8d44ec6..74e55c9 100644 --- a/include/configs/XPEDITE1K.h +++ b/include/configs/XPEDITE1K.h @@ -38,6 +38,7 @@ #define CONFIG_440 1 #define CONFIG_440GX 1 /* 440 GX */ #define CONFIG_BOARD_EARLY_INIT_F 1 /* Call board_pre_init */ +#define CONFIG_MISC_INIT_R #undef CONFIG_SYS_DRAM_TEST /* Disable-takes long time! */ #define CONFIG_SYS_CLK_FREQ 33333333 /* external freq to pll */
diff --git a/include/configs/v38b.h b/include/configs/v38b.h index fc7128e..92bcdb3 100644 --- a/include/configs/v38b.h +++ b/include/configs/v38b.h @@ -40,6 +40,7 @@
#define CONFIG_BOARD_EARLY_INIT_R 1 /* do board-specific init */ #define CONFIG_BOARD_EARLY_INIT_F 1 /* do board-specific init */ +#define CONFIG_MISC_INIT_R
#define CONFIG_SYS_XLB_PIPELINING 1 /* gives better performance */
diff --git a/lib_ppc/board.c b/lib_ppc/board.c index 50d7ad2..1160d2e 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -883,14 +883,6 @@ void board_init_r (gd_t *id, ulong dest_addr) #endif
s = getenv ("ethaddr"); -#if defined (CONFIG_MBX) || \ - defined (CONFIG_RPXCLASSIC) || \ - defined(CONFIG_IAD210) || \ - defined(CONFIG_V38B) - if (s == NULL) - board_get_enetaddr (bd->bi_enetaddr); - else -#endif for (i = 0; i < 6; ++i) { bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; if (s) @@ -918,11 +910,6 @@ void board_init_r (gd_t *id, ulong dest_addr) /* handle the 3rd ethernet address */
s = getenv ("eth2addr"); -#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF) - if (s == NULL) - board_get_enetaddr(bd->bi_enet2addr); - else -#endif for (i = 0; i < 6; ++i) { bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0; if (s) @@ -933,11 +920,6 @@ void board_init_r (gd_t *id, ulong dest_addr) #ifdef CONFIG_HAS_ETH3 /* handle 4th ethernet address */ s = getenv("eth3addr"); -#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF) - if (s == NULL) - board_get_enetaddr(bd->bi_enet3addr); - else -#endif for (i = 0; i < 6; ++i) { bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0; if (s) @@ -948,11 +930,6 @@ void board_init_r (gd_t *id, ulong dest_addr) #ifdef CONFIG_HAS_ETH4 /* handle 5th ethernet address */ s = getenv("eth4addr"); -#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF) - if (s == NULL) - board_get_enetaddr(bd->bi_enet4addr); - else -#endif for (i = 0; i < 6; ++i) { bd->bi_enet4addr[i] = s ? simple_strtoul (s, &e, 16) : 0; if (s) @@ -963,11 +940,6 @@ void board_init_r (gd_t *id, ulong dest_addr) #ifdef CONFIG_HAS_ETH5 /* handle 6th ethernet address */ s = getenv("eth5addr"); -#if defined(CONFIG_XPEDITE1K) || defined(CONFIG_METROBOX) || defined(CONFIG_KAREF) - if (s == NULL) - board_get_enetaddr(bd->bi_enet5addr); - else -#endif for (i = 0; i < 6; ++i) { bd->bi_enet5addr[i] = s ? simple_strtoul (s, &e, 16) : 0; if (s)

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 rename load_sernum_ethaddr() to misc_init_r() so we don't need to handle this board specially in common ARM code.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/cmc_pu2/load_sernum_ethaddr.c | 18 +++--------------- include/configs/cmc_pu2.h | 1 + lib_arm/board.c | 4 ---- 3 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/board/cmc_pu2/load_sernum_ethaddr.c b/board/cmc_pu2/load_sernum_ethaddr.c index 354566c..5ef9f20 100644 --- a/board/cmc_pu2/load_sernum_ethaddr.c +++ b/board/cmc_pu2/load_sernum_ethaddr.c @@ -66,14 +66,13 @@ int i2c_read (unsigned char chip, unsigned int addr, int alen, * Internal structure: see struct definition */
-void load_sernum_ethaddr (void) +void misc_init_r(void) { struct manufacturer_data data; - char ethaddr[18]; char serial [9]; unsigned short chksum; unsigned char *p; - unsigned short i, is, id; + unsigned short i;
#if !defined(CONFIG_HARD_I2C) && !defined(CONFIG_SOFT_I2C) #error you must define some I2C support (CONFIG_HARD_I2C or CONFIG_SOFT_I2C) @@ -97,17 +96,6 @@ void load_sernum_ethaddr (void) return; }
- /* copy MAC address */ - is = 0; - id = 0; - for (i = 0; i < 6; i++) { - sprintf (ðaddr[id], "%02x", data.macadr[is++]); - id += 2; - if (is < 6) - ethaddr[id++] = ':'; - } - ethaddr[id] = '\0'; /* just to be sure */ - /* copy serial number */ sprintf (serial, "%d", data.serial_number);
@@ -117,6 +105,6 @@ void load_sernum_ethaddr (void) }
if (getenv("ethaddr") == NULL) { - setenv ("ethaddr", ethaddr); + eth_setenv_enetaddr("ethaddr", data.macadr); } } diff --git a/include/configs/cmc_pu2.h b/include/configs/cmc_pu2.h index d9acb47..e5c74e1 100644 --- a/include/configs/cmc_pu2.h +++ b/include/configs/cmc_pu2.h @@ -143,6 +143,7 @@ #endif
+#define CONFIG_MISC_INIT_R #define CONFIG_SYS_LONGHELP
#define AT91_SMART_MEDIA_ALE (1 << 22) /* our ALE is AD22 */ diff --git a/lib_arm/board.c b/lib_arm/board.c index 8fe2f41..7199f52 100644 --- a/lib_arm/board.c +++ b/lib_arm/board.c @@ -382,10 +382,6 @@ void start_armboot (void)
devices_init (); /* get the devices list going. */
-#ifdef CONFIG_CMC_PU2 - load_sernum_ethaddr (); -#endif /* CONFIG_CMC_PU2 */ - jumptable_init ();
console_init_r (); /* fully init console as a device */

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.
Move all the work of load_sernum_ethaddr() into a local load_ethaddr() func and call that from misc_init_r(). We leave load_sernum_ethaddr() as a stub so that it can be removed from all places in a later commit.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Stefan Roese sr@denx.de CC: Ben Warren biggerbadderben@gmail.com --- board/pcs440ep/pcs440ep.c | 35 ++++++++++++++++++----------------- 1 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c index 5fd3291..067d959 100644 --- a/board/pcs440ep/pcs440ep.c +++ b/board/pcs440ep/pcs440ep.c @@ -182,14 +182,21 @@ int board_early_init_f(void) }
#define EEPROM_LEN 256 -void load_sernum_ethaddr (void) +static void load_ethaddr(void) { + int ok_ethaddr, ok_eth1addr; int ret; char buf[EEPROM_LEN]; char mac[32]; char *use_eeprom; u16 checksumcrc16 = 0;
+ /* If the env is sane, then nothing for us to do */ + ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf); + ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf); + if (ok_ethaddr && ok_eth1addr) + return; + /* read the MACs from EEprom */ status_led_set (0, STATUS_LED_ON); status_led_set (1, STATUS_LED_ON); @@ -207,22 +214,10 @@ void load_sernum_ethaddr (void) printf("%s: EEPROM Checksum not OK\n", __FUNCTION__); } else { /* get the MACs */ - sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x", - buf[3], - buf[4], - buf[5], - buf[6], - buf[7], - buf[8]); - setenv ("ethaddr", (char *) mac); - sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x", - buf[9], - buf[10], - buf[11], - buf[12], - buf[13], - buf[14]); - setenv ("eth1addr", (char *) mac); + if (!ok_ethaddr) + eth_setenv_enetaddr("ethaddr", &buf[3]); + if (!ok_eth1addr) + eth_setenv_enetaddr("eth1addr", &buf[9]); return; } } @@ -249,6 +244,10 @@ void load_sernum_ethaddr (void) return; }
+void load_sernum_ethaddr (void) +{ +} + #ifdef CONFIG_PREBOOT
static uchar kbd_magic_prefix[] = "key_magic"; @@ -446,6 +445,8 @@ int misc_init_r (void) uint pbcr; int size_val = 0;
+ load_ethaddr(); + /* Re-do sizing to get full correct info */ mtdcr(ebccfga, pb0cr); pbcr = mfdcr(ebccfgd);

Rename load_sernum_ethaddr() to kup_load_sernum_ethaddr() and have board init code call it rather than the common ppc board code.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/kup/common/load_sernum_ethaddr.c | 6 +++++- board/kup/kup4k/kup4k.c | 3 +++ board/kup/kup4x/kup4x.c | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/board/kup/common/load_sernum_ethaddr.c b/board/kup/common/load_sernum_ethaddr.c index 741e9a5..5f725f8 100644 --- a/board/kup/common/load_sernum_ethaddr.c +++ b/board/kup/common/load_sernum_ethaddr.c @@ -51,7 +51,7 @@ #define ETHADDR_TOKEN "ethaddr=" #define LCD_TOKEN "lcd="
-void load_sernum_ethaddr (void) +void kup_load_sernum_ethaddr (void) { unsigned char *hwi; char *var; @@ -92,3 +92,7 @@ void load_sernum_ethaddr (void) } } } + +void load_sernum_ethaddr (void) +{ +} diff --git a/board/kup/kup4k/kup4k.c b/board/kup/kup4k/kup4k.c index df3ffb4..f49c85a 100644 --- a/board/kup/kup4k/kup4k.c +++ b/board/kup/kup4k/kup4k.c @@ -233,6 +233,8 @@ phys_size_t initdram (int board_type)
/* ------------------------------------------------------------------------- */
+extern void kup_load_sernum_ethaddr(void); + int misc_init_r (void) { #ifdef CONFIG_STATUS_LED @@ -250,6 +252,7 @@ int misc_init_r (void) immap->im_ioport.iop_papar &= ~0x80; immap->im_ioport.iop_padat |= 0x80; /* turn it off */ #endif + kup_load_sernum_ethaddr(); setenv("hw","4k"); poweron_key(); return (0); diff --git a/board/kup/kup4x/kup4x.c b/board/kup/kup4x/kup4x.c index c5b742d..b5b7595 100644 --- a/board/kup/kup4x/kup4x.c +++ b/board/kup/kup4x/kup4x.c @@ -292,10 +292,11 @@ static long int dram_size (long int mamr_value, long int *base, } #endif
+extern void kup_load_sernum_ethaddr(void); + int misc_init_r (void) { volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; - #ifdef CONFIG_IDE_LED /* Configure PA8 as output port */ immap->im_ioport.iop_padir |= 0x80; @@ -306,6 +307,7 @@ int misc_init_r (void) #ifdef KUP4X_USB usb_init_kup4x (); #endif + kup_load_sernum_ethaddr(); setenv ("hw", "4x"); poweron_key (); return (0);

Rename load_sernum_ethaddr() to tqc_load_sernum_ethaddr() and have board init code call it rather than the common ppc board code.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/tqc/tqm8xx/load_sernum_ethaddr.c | 6 +++++- board/tqc/tqm8xx/tqm8xx.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/board/tqc/tqm8xx/load_sernum_ethaddr.c b/board/tqc/tqm8xx/load_sernum_ethaddr.c index d269902..ea534f7 100644 --- a/board/tqc/tqm8xx/load_sernum_ethaddr.c +++ b/board/tqc/tqm8xx/load_sernum_ethaddr.c @@ -49,7 +49,7 @@ * 4) Number of additional MAC addresses */
-void load_sernum_ethaddr (void) +void tqc_load_sernum_ethaddr (void) { unsigned char *hwi; unsigned char serial [CONFIG_SYS_HWINFO_SIZE]; @@ -103,3 +103,7 @@ void load_sernum_ethaddr (void) setenv ((char *)"ethaddr", (char *)ethaddr); } } + +void load_sernum_ethaddr (void) +{ +} diff --git a/board/tqc/tqm8xx/tqm8xx.c b/board/tqc/tqm8xx/tqm8xx.c index e065d69..ca91554 100644 --- a/board/tqc/tqm8xx/tqm8xx.c +++ b/board/tqc/tqm8xx/tqm8xx.c @@ -449,11 +449,14 @@ int board_early_init_r (void)
#ifdef CONFIG_MISC_INIT_R +extern void tqc_load_sernum_ethaddr(void); int misc_init_r (void) { volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; volatile memctl8xx_t *memctl = &immap->im_memctl;
+ tqc_load_sernum_ethaddr(); + #ifdef CONFIG_SYS_OR_TIMING_FLASH_AT_50MHZ int scy, trlx, flash_or_timing, clk_diff;

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.
In the ppc case, these things are part of the legacy ABI, so keep them around but mark them as legacy so no new code will touch them.
Also stop calling load_sernum_ethaddr() since all boards now implement this as a stub.
Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- include/asm-ppc/u-boot.h | 14 ++++------ lib_ppc/board.c | 60 +++++---------------------------------------- 2 files changed, 13 insertions(+), 61 deletions(-)
diff --git a/include/asm-ppc/u-boot.h b/include/asm-ppc/u-boot.h index 7451905..e6c56e9 100644 --- a/include/asm-ppc/u-boot.h +++ b/include/asm-ppc/u-boot.h @@ -64,7 +64,7 @@ typedef struct bd_info { #endif unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ + unsigned char bi_enetaddr[6]; /* OLD: see README.enetaddr */ unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ @@ -101,21 +101,19 @@ typedef struct bd_info { #endif
#ifdef CONFIG_HAS_ETH1 - /* second onboard ethernet port */ - unsigned char bi_enet1addr[6]; + unsigned char bi_enet1addr[6]; /* OLD: see README.enetaddr */ #endif #ifdef CONFIG_HAS_ETH2 - /* third onboard ethernet port */ - unsigned char bi_enet2addr[6]; + unsigned char bi_enet2addr[6]; /* OLD: see README.enetaddr */ #endif #ifdef CONFIG_HAS_ETH3 - unsigned char bi_enet3addr[6]; + unsigned char bi_enet3addr[6]; /* OLD: see README.enetaddr */ #endif #ifdef CONFIG_HAS_ETH4 - unsigned char bi_enet4addr[6]; + unsigned char bi_enet4addr[6]; /* OLD: see README.enetaddr */ #endif #ifdef CONFIG_HAS_ETH5 - unsigned char bi_enet5addr[6]; + unsigned char bi_enet5addr[6]; /* OLD: see README.enetaddr */ #endif
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ diff --git a/lib_ppc/board.c b/lib_ppc/board.c index 1160d2e..165cd1f 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -882,12 +882,6 @@ void board_init_r (gd_t *id, ulong dest_addr) mac_read_from_eeprom(); #endif
- s = getenv ("ethaddr"); - for (i = 0; i < 6; ++i) { - bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } #ifdef CONFIG_HERMES if ((gd->board_type >> 16) == 2) bd->bi_ethspeed = gd->board_type & 0xFFFF; @@ -895,64 +889,24 @@ void board_init_r (gd_t *id, ulong dest_addr) bd->bi_ethspeed = 0xFFFF; #endif
+ /* kept around for legacy kernels only ... ignore the next section */ + eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr); #ifdef CONFIG_HAS_ETH1 - /* handle the 2nd ethernet address */ - - s = getenv ("eth1addr"); - - for (i = 0; i < 6; ++i) { - bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } + eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr); #endif #ifdef CONFIG_HAS_ETH2 - /* handle the 3rd ethernet address */ - - s = getenv ("eth2addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } + eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr); #endif - #ifdef CONFIG_HAS_ETH3 - /* handle 4th ethernet address */ - s = getenv("eth3addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } + eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr); #endif - #ifdef CONFIG_HAS_ETH4 - /* handle 5th ethernet address */ - s = getenv("eth4addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet4addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } + eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr); #endif - #ifdef CONFIG_HAS_ETH5 - /* handle 6th ethernet address */ - s = getenv("eth5addr"); - for (i = 0; i < 6; ++i) { - bd->bi_enet5addr[i] = s ? simple_strtoul (s, &e, 16) : 0; - if (s) - s = (*e) ? e + 1 : e; - } + eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr); #endif
-#if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \ - defined(CONFIG_TQM8272) || \ - defined(CONFIG_CCM) || defined(CONFIG_KUP4K) || \ - defined(CONFIG_KUP4X) || defined(CONFIG_PCS440EP) - load_sernum_ethaddr (); -#endif /* IP Address */ bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com --- board/kup/common/load_sernum_ethaddr.c | 4 ---- board/m501sk/m501sk.c | 5 ----- board/pcs440ep/pcs440ep.c | 4 ---- board/tqc/tqm8xx/load_sernum_ethaddr.c | 4 ---- include/common.h | 2 -- 5 files changed, 0 insertions(+), 19 deletions(-)
diff --git a/board/kup/common/load_sernum_ethaddr.c b/board/kup/common/load_sernum_ethaddr.c index 5f725f8..dc4fbfe 100644 --- a/board/kup/common/load_sernum_ethaddr.c +++ b/board/kup/common/load_sernum_ethaddr.c @@ -92,7 +92,3 @@ void kup_load_sernum_ethaddr (void) } } } - -void load_sernum_ethaddr (void) -{ -} diff --git a/board/m501sk/m501sk.c b/board/m501sk/m501sk.c index 65a8b29..dc5b786 100644 --- a/board/m501sk/m501sk.c +++ b/board/m501sk/m501sk.c @@ -105,11 +105,6 @@ uchar m501sk_gpio_clear(M501SK_PIO io) return status; }
-void load_sernum_ethaddr(void) -{ - return; -} - /* * Miscelaneous platform dependent initialisations */ diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c index 067d959..2727214 100644 --- a/board/pcs440ep/pcs440ep.c +++ b/board/pcs440ep/pcs440ep.c @@ -244,10 +244,6 @@ static void load_ethaddr(void) return; }
-void load_sernum_ethaddr (void) -{ -} - #ifdef CONFIG_PREBOOT
static uchar kbd_magic_prefix[] = "key_magic"; diff --git a/board/tqc/tqm8xx/load_sernum_ethaddr.c b/board/tqc/tqm8xx/load_sernum_ethaddr.c index ea534f7..970a952 100644 --- a/board/tqc/tqm8xx/load_sernum_ethaddr.c +++ b/board/tqc/tqm8xx/load_sernum_ethaddr.c @@ -103,7 +103,3 @@ void tqc_load_sernum_ethaddr (void) setenv ((char *)"ethaddr", (char *)ethaddr); } } - -void load_sernum_ethaddr (void) -{ -} diff --git a/include/common.h b/include/common.h index 1b76f9e..1dabe3b 100644 --- a/include/common.h +++ b/include/common.h @@ -363,8 +363,6 @@ void display_mem_map(void); void perform_soft_reset(void); #endif
-void load_sernum_ethaddr (void); - /* $(BOARD)/$(BOARD).c */ int board_early_init_f (void); int board_late_init (void);

Signed-off-by: Mike Frysinger vapier@gentoo.org CC: Ben Warren biggerbadderben@gmail.com CC: Daniel Hellstrom daniel@gaisler.com CC: Michal Simek monstr@seznam.cz CC: Shinya Kuribayashi skuribay@ruby.dti.ne.jp CC: Scott McNutt smcnutt@psyent.com CC: Nobuhiro Iwamatsu iwamatsu@nigauri.org --- include/asm-arm/u-boot.h | 5 ----- include/asm-avr32/u-boot.h | 1 - include/asm-blackfin/u-boot.h | 1 - include/asm-i386/u-boot.h | 1 - include/asm-m68k/u-boot.h | 13 ------------- include/asm-microblaze/u-boot.h | 1 - include/asm-mips/u-boot.h | 1 - include/asm-nios/u-boot.h | 1 - include/asm-nios2/u-boot.h | 1 - include/asm-sh/u-boot.h | 1 - include/asm-sparc/u-boot.h | 12 ------------ 11 files changed, 0 insertions(+), 38 deletions(-)
diff --git a/include/asm-arm/u-boot.h b/include/asm-arm/u-boot.h index b11d555..cfd5a9b 100644 --- a/include/asm-arm/u-boot.h +++ b/include/asm-arm/u-boot.h @@ -39,7 +39,6 @@ typedef struct bd_info { int bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ struct environment_s *bi_env; ulong bi_arch_number; /* unique id for this board */ ulong bi_boot_params; /* where this board expects params */ @@ -48,10 +47,6 @@ typedef struct bd_info { ulong start; ulong size; } bi_dram[CONFIG_NR_DRAM_BANKS]; -#ifdef CONFIG_HAS_ETH1 - /* second onboard ethernet port */ - unsigned char bi_enet1addr[6]; -#endif } bd_t;
#define bi_env_data bi_env->data diff --git a/include/asm-avr32/u-boot.h b/include/asm-avr32/u-boot.h index 85ef008..7e4001f 100644 --- a/include/asm-avr32/u-boot.h +++ b/include/asm-avr32/u-boot.h @@ -25,7 +25,6 @@ typedef struct bd_info { unsigned long bi_baudrate; unsigned long bi_ip_addr; - unsigned char bi_enetaddr[6]; unsigned char bi_phy_id[4]; struct environment_s *bi_env; unsigned long bi_board_number; diff --git a/include/asm-blackfin/u-boot.h b/include/asm-blackfin/u-boot.h index 9d2903b..a6e6cf0 100644 --- a/include/asm-blackfin/u-boot.h +++ b/include/asm-blackfin/u-boot.h @@ -31,7 +31,6 @@ typedef struct bd_info { int bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_boot_params; /* where this board expects params */ unsigned long bi_memstart; /* start of DRAM memory */ phys_size_t bi_memsize; /* size of DRAM memory in bytes */ diff --git a/include/asm-i386/u-boot.h b/include/asm-i386/u-boot.h index fc5a2ae..9a1eec0 100644 --- a/include/asm-i386/u-boot.h +++ b/include/asm-i386/u-boot.h @@ -46,7 +46,6 @@ typedef struct bd_info { unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ diff --git a/include/asm-m68k/u-boot.h b/include/asm-m68k/u-boot.h index 5a0d5fe..a0f2983 100644 --- a/include/asm-m68k/u-boot.h +++ b/include/asm-m68k/u-boot.h @@ -48,7 +48,6 @@ typedef struct bd_info { unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */ unsigned long bi_boot_params; /* where this board expects params */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ @@ -61,18 +60,6 @@ typedef struct bd_info { unsigned long bi_flbfreq; /* Flexbus Freq in MHz */ #endif unsigned long bi_baudrate; /* Console Baudrate */ - -#ifdef CONFIG_HAS_ETH1 - /* second onboard ethernet port */ - unsigned char bi_enet1addr[6]; -#endif -#ifdef CONFIG_HAS_ETH2 - /* third onboard ethernet port */ - unsigned char bi_enet2addr[6]; -#endif -#ifdef CONFIG_HAS_ETH3 - unsigned char bi_enet3addr[6]; -#endif } bd_t;
#endif /* __ASSEMBLY__ */ diff --git a/include/asm-microblaze/u-boot.h b/include/asm-microblaze/u-boot.h index 9db491e..543a6b1 100644 --- a/include/asm-microblaze/u-boot.h +++ b/include/asm-microblaze/u-boot.h @@ -41,7 +41,6 @@ typedef struct bd_info { unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_baudrate; /* Console Baudrate */ } bd_t;
diff --git a/include/asm-mips/u-boot.h b/include/asm-mips/u-boot.h index 9ecb9ac..d9c14ca 100644 --- a/include/asm-mips/u-boot.h +++ b/include/asm-mips/u-boot.h @@ -34,7 +34,6 @@ typedef struct bd_info { int bi_baudrate; /* serial console baudrate */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_arch_number; /* unique id for this board */ unsigned long bi_boot_params; /* where this board expects params */ unsigned long bi_memstart; /* start of DRAM memory */ diff --git a/include/asm-nios/u-boot.h b/include/asm-nios/u-boot.h index 3436185..bdb6cf2 100644 --- a/include/asm-nios/u-boot.h +++ b/include/asm-nios/u-boot.h @@ -41,7 +41,6 @@ typedef struct bd_info { unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_baudrate; /* Console Baudrate */ } bd_t;
diff --git a/include/asm-nios2/u-boot.h b/include/asm-nios2/u-boot.h index de8c405..ec844d0 100644 --- a/include/asm-nios2/u-boot.h +++ b/include/asm-nios2/u-boot.h @@ -40,7 +40,6 @@ typedef struct bd_info { unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_baudrate; /* Console Baudrate */ } bd_t;
diff --git a/include/asm-sh/u-boot.h b/include/asm-sh/u-boot.h index e89c193..27d43b9 100644 --- a/include/asm-sh/u-boot.h +++ b/include/asm-sh/u-boot.h @@ -34,7 +34,6 @@ typedef struct bd_info { unsigned long bi_sramstart; /* start of SRAM memory */ unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned long bi_baudrate; /* Console Baudrate */ unsigned long bi_boot_params; /* where this board expects params */ } bd_t; diff --git a/include/asm-sparc/u-boot.h b/include/asm-sparc/u-boot.h index c42e93c..209873f 100644 --- a/include/asm-sparc/u-boot.h +++ b/include/asm-sparc/u-boot.h @@ -52,22 +52,10 @@ typedef struct bd_info { unsigned long bi_sramsize; /* size of SRAM memory */ unsigned long bi_bootflags; /* boot / reboot flag (for LynxOS) */ unsigned long bi_ip_addr; /* IP Address */ - unsigned char bi_enetaddr[6]; /* Ethernet adress */ unsigned short bi_ethspeed; /* Ethernet speed in Mbps */ unsigned long bi_intfreq; /* Internal Freq, in MHz */ unsigned long bi_busfreq; /* Bus Freq, in MHz */ unsigned long bi_baudrate; /* Console Baudrate */ -#ifdef CONFIG_HAS_ETH1 - /* second onboard ethernet port */ - unsigned char bi_enet1addr[6]; -#endif -#ifdef CONFIG_HAS_ETH2 - /* third onboard ethernet port */ - unsigned char bi_enet2addr[6]; -#endif -#ifdef CONFIG_HAS_ETH3 - unsigned char bi_enet3addr[6]; -#endif } bd_t;
#endif /* __ASSEMBLY__ */
participants (5)
-
Ben Warren
-
Jean-Christophe PLAGNIOL-VILLARD
-
Mike Frysinger
-
Peter Tyser
-
Wolfgang Denk