fsl: simplify the "mac id" command, improve boot-time informational message
PATCH 1/1 fsl: simplify the "mac id" command, improve boot-time informational message
The "mac id" command took a 4-character parameter as the identifier string. However, for any given board, only one kind of identifier is acceptable, so it makes no sense to ask the user to type it in. Instead, if the user enters "mac id", the identifier (and also the version, if it's NXID) will automatically be set to the correct value.
Improve the message that is displayed when EEPROM is read during boot. It now displays "EEPROM:" and then either an error message or the EEPROM identifier if successful.
If the identifier in EEPROM is valid, then always reject a bad CRC, even if the CRC field has not been initialized.
Don't force the MAC address count to MAX_NUM_PORTS or less. Forcing the value to be changed resulting in an in-memory copy that does not match what's in hardware, even though the user did not request that change.
Finally, always update the CRC value in the in-memory copy after any field is changed, so that the CRC is always correct.
--- board/freescale/common/sys_eeprom.c | 79 +++++++++++++++++++++-------------- lib_ppc/board.c | 1 + 2 files changed, 48 insertions(+), 32 deletions(-)
board/freescale/common/sys_eeprom.c +47 -32
@@ -186,12 +186,25 @@ static int read_eeprom(void) }/** +* update_crc - update the CRC +* +* This function should be called after each update to the EEPROM structure, +* to make sure the CRC is always correct. +*/ +static void update_crc (void ) +{ +u32 crc; + + crc =crc32 (0 , (void *)&e,sizeof (e) -4 ); + e.crc =cpu_to_be32 (crc); +} + +/** * prog_eeprom - write the EEPROM from memory */ static int prog_eeprom (void ) { -int ret, i, length; -unsigned int crc; +int ret, i;void *p;#ifdef CONFIG_SYS_EEPROM_BUS_NUM unsigned int bus;
@@ -204,19 +217,16 @@ static int prog_eeprom(void)#else memset (e.res_0,0xFF ,sizeof (e.res_0));#endif - - length =sizeof (e); - crc =crc32 (0 , (void *)&e, length -4 ); - e.crc =cpu_to_be32 (crc); +update_crc ();#ifdef CONFIG_SYS_EEPROM_BUS_NUM bus =i2c_get_bus_num ();i2c_set_bus_num (CONFIG_SYS_EEPROM_BUS_NUM );#endif -for (i =0 , p = &e; i < length; i +=8 , p +=8 ) { +for (i =0 , p = &e; i <sizeof (e); i +=8 , p +=8 ) { ret =i2c_write (CONFIG_SYS_I2C_EEPROM_ADDR , i,CONFIG_SYS_I2C_EEPROM_ADDR_LEN , - p,min ((length - i),8 )); + p,min ((sizeof (e) - i),8 ));if (ret)break ;udelay (5000 );/* 5ms write cycle timing */
@@ -273,6 +283,8 @@ static void set_date(const char *string)for (i =0 ; i <6 ; i++) e.date[i] =h2i (string[2 * i]) <<4 |h2i (string[2 * i +1 ]); + +update_crc (); }/**
@@ -297,11 +309,12 @@ static void set_mac_address(unsigned int index, const char *string)if (*p ==':' ) p++; } + +update_crc (); }int do_mac (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) { -int i;char cmd;if (argc ==1 ) {
@@ -316,9 +329,13 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])return 0 ; } -if ((cmd =='i' ) && (argc >2 )) { -for (i =0 ; i <4 ; i++) - e.id[i] = argv[2 ][i]; +if (cmd =='i' ) { +#ifdef CONFIG_SYS_I2C_EEPROM_NXID +memcpy (e.id,"NXID" ,sizeof (e.id)); + e.version =0 ; +#else +memcpy (e.id,"CCID" ,sizeof (e.id)); +#endif return 0 ; }
@@ -346,6 +363,7 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])case 'n' :/* serial number */ memset (e.sn,0 ,sizeof (e.sn));strncpy ((char *)e.sn, argv[2 ],sizeof (e.sn) -1 ); +update_crc ();break ;case 'e' :/* errata */ #ifdef CONFIG_SYS_I2C_EEPROM_NXID
@@ -355,12 +373,14 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) e.errata[0 ] = argv[2 ][0 ]; e.errata[1 ] = argv[2 ][1 ];#endif +update_crc ();break ;case 'd' :/* date BCD format YYMMDDhhmmss */ set_date (argv[2 ]);break ;case 'p' :/* MAC table size */ e.mac_count =simple_strtoul (argv[2 ],NULL ,16 ); +update_crc ();break ; case '0' ... '7': /* "mac 0" through "mac 7" */set_mac_address (cmd -'0' , argv[2 ]);
@@ -388,6 +408,7 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])int mac_read_from_eeprom (void ) {unsigned int i; +u32 crc;if (read_eeprom ()) {printf ("Read failed.\n" );
@@ -395,31 +416,18 @@ int mac_read_from_eeprom(void) }if (!is_valid) { -printf ("Invalid ID (%02x %02x %02x %02x)\n" , e.id[0 ], e.id[1 ], e.id[2 ], e.id[3 ]); +printf ("Invalid ID (%02x %02x %02x %02x)\n" , + e.id[0 ], e.id[1 ], e.id[2 ], e.id[3 ]);return -1 ; } -if (be32_to_cpu (e.crc) !=0xFFFFFFFF ) { -u32 crc =crc32 (0 , (void *)&e,sizeof (e) -4 ); - -if (crc !=be32_to_cpu (e.crc)) { -printf ("CRC mismatch (%08x != %08x).\n" , crc, -be32_to_cpu (e.crc)); -return -1 ; - } - } - -/* Check the number of MAC addresses which is limited to -* MAX_NUM_PORTS. -*/ -if (e.mac_count >MAX_NUM_PORTS ) { -printf ("Warning: The number of MAC addresses is greater" -" than %u, force it to %u.\n" ,MAX_NUM_PORTS , -MAX_NUM_PORTS ); - e.mac_count =MAX_NUM_PORTS ; + crc =crc32 (0 , (void *)&e,sizeof (e) -4 ); +if (crc !=be32_to_cpu (e.crc)) { +printf ("CRC mismatch (%08x != %08x)\n" , crc,be32_to_cpu (e.crc)); +return -1 ; } -for (i =0 ; i < e.mac_count; i++) { +for (i =0 ; i <min (e.mac_count,MAX_NUM_PORTS ); i++) {if (memcmp (&e.mac[i],"\0\0\0\0\0\0" ,6 ) &&memcmp (&e.mac[i],"\xFF\xFF\xFF\xFF\xFF\xFF" ,6 )) {char ethaddr[18 ];
@@ -441,6 +449,13 @@ int mac_read_from_eeprom(void) } } +#ifdef CONFIG_SYS_I2C_EEPROM_NXID +printf ("%c%c%c%c v%u\n" , e.id[0 ], e.id[1 ], e.id[2 ], e.id[3 ], +be32_to_cpu (e.version)); +#else +printf ("%c%c%c%c\n" , e.id[0 ], e.id[1 ], e.id[2 ], e.id[3 ]); +#endif +return 0 ; }
lib_ppc/board.c +1 -0
@@ -889,6 +889,7 @@ void board_init_r (gd_t *id, ulong dest_addr)#endif #if defined (CONFIG_ID_EEPROM ) || defined (CONFIG_SYS_I2C_MAC_OFFSET ) +puts ("EEPROM: " );mac_read_from_eeprom ();#endif
Signature · 1 line
1.6.0.6
PATCH 1/1 fsl: simplify the "mac id" command, improve boot-time informational message
Quoted 35 lines · Timur Tabi
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will automatically be set to the correct value.Improve the message that is displayed when EEPROM is read during boot. It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.Don't force the MAC address count to
MAX_NUM_PORTSor less. Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.Signed-off-by Timur Tabi <[email protected]>---
board/freescale/common/sys_eeprom.c| 79 +++++++++++++++++++++-------------- lib_ppc/board.c | 1 + 2 files changed, 48 insertions(+), 32 deletions(-)
[snip]
lib_ppc/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 895
Quoted 12 lines
lib_ppc/board.c +1
-0@@ -889,6 +889,7 @@ void board_init_r (gd_t *id, ulong dest_addr)#endif #if defined (CONFIG_ID_EEPROM ) || defined (CONFIG_SYS_I2C_MAC_OFFSET ) +puts ("EEPROM: " );mac_read_from_eeprom ();#endif
Wolfgang,
Please ack this bit.
- k
PATCH 1/1 fsl: simplify the "mac id" command, improve boot-time informational message
Wolfgang? Are you okay with this part of my patch?
Quoted 64 lines · Kumar Gala
Quoted 35 lines · Timur Tabi
The "mac id" command took a 4-character parameter as the identifier string.
However, for any given board, only one kind of identifier is acceptable, so it
makes no sense to ask the user to type it in. ?Instead, if the user enters
"mac id", the identifier (and also the version, if it's NXID) will automatically be set to the correct value.Improve the message that is displayed when EEPROM is read during boot. ?It now
displays "EEPROM:" and then either an error message or the EEPROM identifier
if successful.If the identifier in EEPROM is valid, then always reject a bad CRC, even if the
CRC field has not been initialized.Don't force the MAC address count to
MAX_NUM_PORTSor less. ?Forcing the value
to be changed resulting in an in-memory copy that does not match what's in
hardware, even though the user did not request that change.Finally, always update the CRC value in the in-memory copy after any field
is changed, so that the CRC is always correct.Signed-off-by Timur Tabi <[email protected]>---
board/freescale/common/sys_eeprom.c| ? 79 +++++++++++++++++++++-------------- lib_ppc/board.c ? ? ? ? ? ? ? ? ? ? | ? ?1 + 2 files changed, 48 insertions(+), 32 deletions(-)[snip]
lib_ppc/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 895
Quoted 12 lines
lib_ppc/board.c +1
-0@@ -889,6 +889,7 @@ void board_init_r (gd_t *id, ulong dest_addr)#endif #if defined (CONFIG_ID_EEPROM ) || defined (CONFIG_SYS_I2C_MAC_OFFSET ) + ? ? puts("EEPROM: "); ? ? ? mac_read_from_eeprom();#endif Wolfgang,
Please ack this bit.
- k
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale