Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
Several changes regarding MAC address
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe2k committed Aug 24, 2013
1 parent d2bb828 commit a9593fc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
10 changes: 6 additions & 4 deletions u-boot/cpu/mips/ar7240/ag7240.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.)
Expand All @@ -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
}

Expand Down
12 changes: 7 additions & 5 deletions u-boot/cpu/mips/ar7240/ag934x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.)
Expand All @@ -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
}

Expand Down
39 changes: 28 additions & 11 deletions u-boot/lib_mips/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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");

Expand Down
18 changes: 4 additions & 14 deletions u-boot/net/bootp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: ");
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit a9593fc

Please sign in to comment.