@ -28,16 +28,19 @@
# include <linux/ctype.h>
# include <linux/ctype.h>
typedef struct {
typedef struct {
unsigned char id [ 4 ] ; /* 0x0000 - 0x0003 */
u8 id [ 4 ] ; /* 0x0000 - 0x0003 EEPROM Tag */
unsigned char sn [ 12 ] ; /* 0x0004 - 0x000F */
u8 sn [ 12 ] ; /* 0x0004 - 0x000F Serial Number */
unsigned char errata [ 5 ] ; /* 0x0010 - 0x0014 */
u8 errata [ 5 ] ; /* 0x0010 - 0x0014 Errata Level */
unsigned char date [ 7 ] ; /* 0x0015 - 0x001a */
u8 date [ 6 ] ; /* 0x0015 - 0x001a Build Date */
unsigned char res_1 [ 37 ] ; /* 0x001b - 0x003f */
u8 res_0 ; /* 0x001b Reserved */
unsigned char tab_size ; /* 0x0040 */
u8 version [ 4 ] ; /* 0x001c - 0x001f Version */
unsigned char tab_flag ; /* 0x0041 */
u8 tempcal [ 8 ] ; /* 0x0020 - 0x0027 Temperature Calibration Factors*/
unsigned char mac [ 8 ] [ 6 ] ; /* 0x0042 - 0x0071 */
u8 tempcalsys [ 2 ] ; /* 0x0028 - 0x0029 System Temperature Calibration Factors*/
unsigned char res_2 [ 126 ] ; /* 0x0072 - 0x00ef */
u8 res_1 [ 22 ] ; /* 0x0020 - 0x003f Reserved */
unsigned int crc ; /* 0x00f0 - 0x00f3 crc32 checksum */
u8 mac_size ; /* 0x0040 Mac table size */
u8 mac_flag ; /* 0x0041 Mac table flags */
u8 mac [ 8 ] [ 6 ] ; /* 0x0042 - 0x0071 Mac addresses */
u32 crc ; /* 0x0072 crc32 checksum */
} EEPROM_data ;
} EEPROM_data ;
static EEPROM_data mac_data ;
static EEPROM_data mac_data ;
@ -45,28 +48,57 @@ static EEPROM_data mac_data;
int mac_show ( void )
int mac_show ( void )
{
{
int i ;
int i ;
u8 mac_size ;
unsigned char ethaddr [ 8 ] [ 18 ] ;
unsigned char ethaddr [ 8 ] [ 18 ] ;
unsigned char enetvar [ 32 ] ;
/* Show EEPROM tagID,
* always the four characters ' NXID ' .
*/
printf ( " ID " ) ;
for ( i = 0 ; i < 4 ; i + + )
printf ( " %c " , mac_data . id [ i ] ) ;
printf ( " \n " ) ;
/* Show Serial number,
* 0 to 11 charaters of errata information .
*/
printf ( " SN " ) ;
for ( i = 0 ; i < 12 ; i + + )
printf ( " %c " , mac_data . sn [ i ] ) ;
printf ( " \n " ) ;
printf ( " ID %c%c%c%c \n " ,
/* Show Errata Level,
mac_data . id [ 0 ] ,
* 0 to 4 characters of errata information .
mac_data . id [ 1 ] ,
*/
mac_data . id [ 2 ] ,
printf ( " Errata " ) ;
mac_data . id [ 3 ] ) ;
for ( i = 0 ; i < 5 ; i + + )
printf ( " Errata %c%c%c%c%c \n " ,
printf ( " %c " , mac_data . errata [ i ] ) ;
mac_data . errata [ 0 ] ,
printf ( " \n " ) ;
mac_data . errata [ 1 ] ,
mac_data . errata [ 2 ] ,
/* Show Build Date,
mac_data . errata [ 3 ] ,
* BCD date values , as YYMMDDhhmmss .
mac_data . errata [ 4 ] ) ;
*/
printf ( " Date %c%c%c%c%c%c%c \n " ,
printf ( " Date 20%02x \ /%02x \ /%02x %02x:%02x:%02x \n " ,
mac_data . date [ 0 ] ,
mac_data . date [ 0 ] ,
mac_data . date [ 1 ] ,
mac_data . date [ 1 ] ,
mac_data . date [ 2 ] ,
mac_data . date [ 2 ] ,
mac_data . date [ 3 ] ,
mac_data . date [ 3 ] ,
mac_data . date [ 4 ] ,
mac_data . date [ 4 ] ,
mac_data . date [ 5 ] ,
mac_data . date [ 5 ] ) ;
mac_data . date [ 6 ] ) ;
for ( i = 0 ; i < 8 ; i + + ) {
/* Show MAC table size,
* Value from 0 to 7 indicating how many MAC
* addresses are stored in the system EEPROM .
*/
if ( ( mac_data . mac_size > 0 ) & & ( mac_data . mac_size < = 8 ) )
mac_size = mac_data . mac_size ;
else
mac_size = 8 ; /* Set the max size */
printf ( " MACSIZE %x \n " , mac_size ) ;
/* Show Mac addresses */
for ( i = 0 ; i < mac_size ; i + + ) {
sprintf ( ( char * ) ethaddr [ i ] ,
sprintf ( ( char * ) ethaddr [ i ] ,
" %02x:%02x:%02x:%02x:%02x:%02x " ,
" %02x:%02x:%02x:%02x:%02x:%02x " ,
mac_data . mac [ i ] [ 0 ] ,
mac_data . mac [ i ] [ 0 ] ,
@ -76,12 +108,12 @@ int mac_show(void)
mac_data . mac [ i ] [ 4 ] ,
mac_data . mac [ i ] [ 4 ] ,
mac_data . mac [ i ] [ 5 ] ) ;
mac_data . mac [ i ] [ 5 ] ) ;
printf ( " MAC %d %s \n " , i , ethaddr [ i ] ) ;
printf ( " MAC %d %s \n " , i , ethaddr [ i ] ) ;
}
setenv ( " ethaddr " , ( char * ) ethaddr [ 0 ] ) ;
sprintf ( ( char * ) enetvar ,
setenv ( " eth1addr " , ( char * ) ethaddr [ 1 ] ) ;
i ? " eth%daddr " : " ethaddr " , i ) ;
setenv ( " eth2addr " , ( char * ) ethaddr [ 2 ] ) ;
setenv ( ( char * ) enetvar , ( char * ) ethaddr [ i ] ) ;
setenv ( " eth3addr " , ( char * ) ethaddr [ 3 ] ) ;
}
return 0 ;
return 0 ;
}
}
@ -120,17 +152,14 @@ int mac_prog(void)
unsigned char dev = ID_EEPROM_ADDR , * ptr ;
unsigned char dev = ID_EEPROM_ADDR , * ptr ;
unsigned char * eeprom_data = ( unsigned char * ) ( & mac_data ) ;
unsigned char * eeprom_data = ( unsigned char * ) ( & mac_data ) ;
for ( i = 0 ; i < sizeof ( mac_data . res_1 ) ; i + + )
mac_data . res_0 = 0 ;
mac_data . res_1 [ i ] = 0 ;
memset ( ( void * ) mac_data . res_1 , 0 , sizeof ( mac_data . res_1 ) ) ;
for ( i = 0 ; i < sizeof ( mac_data . res_2 ) ; i + + )
mac_data . res_2 [ i ] = 0 ;
length = sizeof ( EEPROM_data ) ;
length = sizeof ( EEPROM_data ) ;
crc = crc32 ( crc , eeprom_data , length - 4 ) ;
crc = crc32 ( crc , eeprom_data , length - 4 ) ;
mac_data . crc = crc ;
mac_data . crc = crc ;
for ( i = 0 , ptr = eeprom_data ; i < length ; i + = 8 , ptr + = 8 ) {
for ( i = 0 , ptr = eeprom_data ; i < length ; i + = 8 , ptr + = 8 ) {
ret =
ret = i2c_write ( dev , i , 1 , ptr , min ( ( length - i ) , 8 ) ) ;
i2c_write ( dev , i , 1 , ptr ,
( length - i ) < 8 ? ( length - i ) : 8 ) ;
udelay ( 5000 ) ; /* 5ms write cycle timing */
udelay ( 5000 ) ; /* 5ms write cycle timing */
if ( ret )
if ( ret )
break ;
break ;
@ -179,12 +208,13 @@ int do_mac(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
}
}
break ;
break ;
case ' d ' : /* date */
case ' d ' : /* date */
for ( i = 0 ; i < 7 ; i + + ) {
mac_val = simple_strtoull ( argv [ 2 ] , NULL , 16 ) ;
mac_data . date [ i ] = argv [ 2 ] [ i ] ;
for ( i = 0 ; i < 6 ; i + + ) {
mac_data . date [ i ] = ( mac_val > > ( 40 - 8 * i ) ) ;
}
}
break ;
break ;
case ' p ' : /* nu mber of port s */
case ' p ' : /* mac ta bl e size */
mac_data . tab _size =
mac_data . mac _size =
( unsigned char ) simple_strtoul ( argv [ 2 ] , NULL , 16 ) ;
( unsigned char ) simple_strtoul ( argv [ 2 ] , NULL , 16 ) ;
break ;
break ;
case ' 0 ' : /* mac 0 */
case ' 0 ' : /* mac 0 */