From a9593fc6b260578a23fdac7474e4c8886ff3c5e6 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Sat, 24 Aug 2013 23:37:57 +0200 Subject: [PATCH] Several changes regarding MAC address --- u-boot/cpu/mips/ar7240/ag7240.c | 10 +++++---- u-boot/cpu/mips/ar7240/ag934x.c | 12 +++++----- u-boot/lib_mips/board.c | 39 +++++++++++++++++++++++---------- u-boot/net/bootp.c | 18 ++++----------- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/u-boot/cpu/mips/ar7240/ag7240.c b/u-boot/cpu/mips/ar7240/ag7240.c index ced70b6..9dec7c1 100755 --- a/u-boot/cpu/mips/ar7240/ag7240.c +++ b/u-boot/cpu/mips/ar7240/ag7240.c @@ -457,7 +457,12 @@ static void ag7240_get_ethaddr(struct eth_device *dev) { // get MAC address from flash and check it memcpy(buffer, (void *)(CFG_FLASH_BASE + OFFSET_MAC_DATA_BLOCK + OFFSET_MAC_ADDRESS), 6); - // check LSBit and second LCBit in MSByte of vendor part -> both of them should be 0 + /* + * check first LSBit (I/G bit) and second LSBit (U/L bit) in MSByte of vendor part + * both of them should be 0: + * I/G bit == 0 -> Individual MAC address (unicast address) + * U/L bit == 0 -> Burned-In-Address (BIA) MAC address + */ if(CHECK_BIT((buffer[0] & 0xFF), 0) == 0 && CHECK_BIT((buffer[0] & 0xFF), 1) == 0){ mac[0] = (buffer[0] & 0xFF); mac[1] = (buffer[1] & 0xFF); @@ -473,8 +478,6 @@ static void ag7240_get_ethaddr(struct eth_device *dev) { mac[3] = 0x09; mac[4] = 0x0b; mac[5] = 0xad; - - printf("## Error: MAC address stored in flash is invalid!\nUsing fixed address!\n"); } #else // 00-03-7F (Atheros Communications, Inc.) @@ -484,7 +487,6 @@ static void ag7240_get_ethaddr(struct eth_device *dev) { mac[3] = 0x09; mac[4] = 0x0b; mac[5] = 0xad; - printf("## Error: using fixed MAC address!\n"); #endif } diff --git a/u-boot/cpu/mips/ar7240/ag934x.c b/u-boot/cpu/mips/ar7240/ag934x.c index 14b8c1c..e68c9e9 100755 --- a/u-boot/cpu/mips/ar7240/ag934x.c +++ b/u-boot/cpu/mips/ar7240/ag934x.c @@ -519,13 +519,18 @@ static void ag7240_halt(struct eth_device *dev){ */ static void ag7240_get_ethaddr(struct eth_device *dev){ unsigned char *mac = dev->enetaddr; +#ifdef OFFSET_MAC_ADDRESS unsigned char buffer[6]; -#ifdef OFFSET_MAC_ADDRESS // get MAC address from flash and check it memcpy(buffer, (void *)(CFG_FLASH_BASE + OFFSET_MAC_DATA_BLOCK + OFFSET_MAC_ADDRESS), 6); - // check LSBit and second LCBit in MSByte of vendor part -> both of them should be 0 + /* + * check first LSBit (I/G bit) and second LSBit (U/L bit) in MSByte of vendor part + * both of them should be 0: + * I/G bit == 0 -> Individual MAC address (unicast address) + * U/L bit == 0 -> Burned-In-Address (BIA) MAC address + */ if(CHECK_BIT((buffer[0] & 0xFF), 0) == 0 && CHECK_BIT((buffer[0] & 0xFF), 1) == 0){ mac[0] = (buffer[0] & 0xFF); mac[1] = (buffer[1] & 0xFF); @@ -541,8 +546,6 @@ static void ag7240_get_ethaddr(struct eth_device *dev){ mac[3] = 0x09; mac[4] = 0x0b; mac[5] = 0xad; - - printf("## Error: MAC address stored in flash is invalid!\nUsing fixed address!\n"); } #else // 00-03-7F (Atheros Communications, Inc.) @@ -552,7 +555,6 @@ static void ag7240_get_ethaddr(struct eth_device *dev){ mac[3] = 0x09; mac[4] = 0x0b; mac[5] = 0xad; - printf("## Error: Using fixed MAC address!\n"); #endif } diff --git a/u-boot/lib_mips/board.c b/u-boot/lib_mips/board.c index 63a9321..a5423db 100755 --- a/u-boot/lib_mips/board.c +++ b/u-boot/lib_mips/board.c @@ -39,6 +39,8 @@ DECLARE_GLOBAL_DATA_PTR; #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN #endif +#define CHECK_BIT(var,pos) ((var) & (1<<(pos))) + extern ulong uboot_end_data; extern ulong uboot_end; @@ -294,7 +296,6 @@ void board_init_r(gd_t *id, ulong dest_addr){ extern char * env_name_spec; #endif bd_t *bd; - int i; char *s; unsigned char buffer[6]; @@ -364,21 +365,37 @@ void board_init_r(gd_t *id, ulong dest_addr){ /* board MAC address */ #if defined(OFFSET_MAC_ADDRESS) memcpy(buffer, (void *)(CFG_FLASH_BASE + OFFSET_MAC_DATA_BLOCK + OFFSET_MAC_ADDRESS), 6); + + /* + * check first LSBit (I/G bit) and second LSBit (U/L bit) in MSByte of vendor part + * both of them should be 0: + * I/G bit == 0 -> Individual MAC address (unicast address) + * U/L bit == 0 -> Burned-In-Address (BIA) MAC address + */ + if(CHECK_BIT((buffer[0] & 0xFF), 0) != 0 || CHECK_BIT((buffer[0] & 0xFF), 1) != 0){ + // 00-03-7F (Atheros Communications, Inc.) + bd->bi_enetaddr[0] = 0x00; + bd->bi_enetaddr[1] = 0x03; + bd->bi_enetaddr[2] = 0x7f; + bd->bi_enetaddr[3] = 0x09; + bd->bi_enetaddr[4] = 0x0b; + bd->bi_enetaddr[5] = 0xad; + + printf("## Error: MAC is invalid, using fixed!\n\n"); + } #else // fake MAC // 00-03-7F (Atheros Communications, Inc.) - buffer[0] = 0x00; - buffer[1] = 0x03; - buffer[2] = 0x7f; - buffer[3] = 0x09; - buffer[4] = 0x0b; - buffer[5] = 0xad; + bd->bi_enetaddr[0] = 0x00; + bd->bi_enetaddr[1] = 0x03; + bd->bi_enetaddr[2] = 0x7f; + bd->bi_enetaddr[3] = 0x09; + bd->bi_enetaddr[4] = 0x0b; + bd->bi_enetaddr[5] = 0xad; + + printf("** Warning: using fixed MAC address!\n\n"); #endif - for(i = 0; i < 6; ++i){ - bd->bi_enetaddr[i] = buffer[i]; - } - /* IP Address */ bd->bi_ip_addr = getenv_IPaddr("ipaddr"); diff --git a/u-boot/net/bootp.c b/u-boot/net/bootp.c index f2fce9c..7587783 100755 --- a/u-boot/net/bootp.c +++ b/u-boot/net/bootp.c @@ -614,21 +614,11 @@ void 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; - - for (reg = 0; reg < 6; ++reg) { - bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0; - if(s){ - s = (*e) ? e+1 : e; - } - } + memcpy(bi_enetaddr, NetOurEther, 6); #ifdef DEBUG puts("BootpRequest => Our Mac: "); @@ -639,8 +629,8 @@ void BootpRequest(void){ #endif /* DEBUG */ /* Mac-Manipulation 2 get seed1 */ - tst1=0; - tst2=0; + tst1 = 0; + tst2 = 0; for(reg = 2; reg < 6; reg++){ tst1 = tst1 << 8; @@ -655,7 +645,7 @@ void BootpRequest(void){ seed1 = tst1^tst2; /* Mirror seed1*/ - m_mask=0x1; + m_mask = 0x1; for(reg = 1;reg <= 32; reg++){ m_value |= (m_mask & seed1); -- 2.25.1