powerpc/eeprom: cleanup mac command
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
Change the help message to be more helpful. Print argument format. Fix MAX_NUM_PORTS to comply with v1 NXID format. Accept hexadecimal and decimal for port count and index.
--- board/freescale/common/sys_eeprom.c | 8 ++++---- common/cmd_mac.c | 29 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-)
board/freescale/common/sys_eeprom.c +4 -4
@@ -34,7 +34,7 @@#endif #ifdef CONFIG_SYS_I2C_EEPROM_NXID -#define MAX_NUM_PORTS 23 +#define MAX_NUM_PORTS 31#define NXID_VERSION 1#endif
@@ -398,11 +398,11 @@ int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])set_date (argv[2 ]);break ;case 'p' :/* MAC table size */ - e.mac_count =simple_strtoul (argv[2 ],NULL ,16 ); + e.mac_count =simple_strtoul (argv[2 ],NULL ,0 );update_crc ();break ; - case '0' ... '9': /* "mac 0" through "mac 22" */ -set_mac_address (simple_strtoul (argv[1 ],NULL ,10 ), argv[2 ]); + case '0' ... '9': /* "mac 0" through "mac 31" */ +set_mac_address (simple_strtoul (argv[1 ],NULL ,0 ), argv[2 ]);break ;case 'h' :/* help */ default :
common/cmd_mac.c +17 -12
@@ -29,21 +29,26 @@ extern int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);U_BOOT_CMD ( mac,3 ,1 , do_mac,"display and program the system ID and MAC addresses in EEPROM" , -"[read|save|id|num|errata|date|ports|0|1|2|3|4|5|6|7]\n" + "without argument\n" + " - show content of system ID and MAC addresses\n" "read\n" -" - show content of EEPROM\n" + " - read EEPROM without showing\n" "mac save\n" " - save to the EEPROM\n" "mac id\n" -" - program system id\n" -"mac num\n" -" - program system serial number\n" -"mac errata\n" -" - program errata data\n" -"mac date\n" -" - program date\n" -"mac ports\n" + " - program system id (fixed)\n" + "mac num <string>\n" + " - program <string> as system serial number\n" + "mac errata <string>\n" + " - program <string> as errata data\n" + "mac date <YYMMDDhhmmss>\n" + " - program timestamp\n" + "mac ports <n>\n" " - program the number of ports\n" -"mac X\n" -" - program the MAC address for port X [X=0...7]" + "mac <n> <XX:XX:XX:XX:XX:XX>\n" +#ifdef CONFIG_SYS_I2C_EEPROM_NXID + " - program the MAC address for port n [n=0...30]" +#else +" - program the MAC address for port n [n=0...7]" +#endif );
Signature · 1 line
1.7.0.4
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
Dear York Sun,
Quoted 3 lines · In message <[email protected]> you wrote:
Change the help message to be more helpful. Print argument format. Fix
MAX_NUM_PORTSto comply with v1 NXID format. Accept hexadecimal and decimal for port count and index.
...
board/freescale/common/sys_eeprom.c int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 405
Quoted 9 lines
board/freescale/common/sys_eeprom.c +3
-3case 'p' :/* MAC table size */ - e.mac_count =simple_strtoul (argv[2 ],NULL ,16 ); + e.mac_count =simple_strtoul (argv[2 ],NULL ,0 );update_crc ();break ; - case '0' ... '9': /* "mac 0" through "mac 22" */ -set_mac_address (simple_strtoul (argv[1 ],NULL ,10 ), argv[2 ]); + case '0' ... '9': /* "mac 0" through "mac 31" */ +set_mac_address (simple_strtoul (argv[1 ],NULL ,0 ), argv[2 ]);
These changes silently change the behaviour of the command. So far, an argument line "24" would be parsed as hex number (i. e. result in decimal value 36); with this change it suddenly becomes devcimal 24, which is quite unexpected.
There are very few exceptions wher eU-Boot uses and expects decimal numbers, and I strongly recommend not to add any new such inconsistencies.
common/cmd_mac.c extern int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); · line 50
Quoted 2 lines
common/cmd_mac.c +2
-0+#ifdef CONFIG_SYS_I2C_EEPROM_NXID +" - program the MAC address for port n [n=0...30]"
0...30 ? The code above says "mac 0" through "mac 31"? Or is it 0 ... 22 ?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Always try to do things in chronological order; it's less confusing that way.
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
Quoted 4 lines · Wolfgang Denk
These changes silently change the behaviour of the command. ?So far, an argument line "24" would be parsed as hex number (i. e. result in decimal value 36); with this change it suddenly becomes devcimal 24, which is quite unexpected.
Support for numbers larger than 9 is new, so very few people would be affected.
Quoted 3 lines
There are very few exceptions wher eU-Boot uses and expects decimal numbers, and I strongly recommend not to add any new such inconsistencies.
I understand, except that in this case, it's counter-intuitive. No one is going to think to do this:
mac ports b
to set the number of ports to 11, but that's what you have to do.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
Dear Tabi Timur-B04825,
Quoted 11 lines · In message <CAOZdJXUhGKnFCkpS1bPkCHswsvqn-Ki8y=aXZH51_fZKWT8Qmw@mail.gmail.com>…
Quoted 4 lines
There are very few exceptions wher eU-Boot uses and expects decimal numbers, and I strongly recommend not to add any new such inconsistencies.
I understand, except that in this case, it's counter-intuitive. No one is going to think to do this:
mac ports b
to set the number of ports to 11, but that's what you have to do.
I'm not sure how you counted to get the "no one" result, but this is _exactly_ what I would do, knowing very well that "mac ports 11" would mean a decimal value of 17.
So far, the only command (that I remember) that accepts decimal argument is "sleep", and I'm still angry with myself that I let this slip through.
Please do not add more such inconsistencies.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Teenagers are people who express a burning desire to be different by dressing exactly alike. There are some strings. They're just not attached.
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
In reply to Wolfgang DenkWolfgang,
Quoted 23 lines · Wolfgang Denk
Dear York Sun,
Quoted 3 lines · In message <[email protected]> you wrote:
Change the help message to be more helpful. Print argument format. Fix
MAX_NUM_PORTSto comply with v1 NXID format. Accept hexadecimal and decimal for port count and index....
board/freescale/common/sys_eeprom.c int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 405
Quoted 9 lines
board/freescale/common/sys_eeprom.c +3
-3case 'p' :/* MAC table size */ - e.mac_count =simple_strtoul (argv[2 ],NULL ,16 ); + e.mac_count =simple_strtoul (argv[2 ],NULL ,0 );update_crc ();break ; - case '0' ... '9': /* "mac 0" through "mac 22" */ -set_mac_address (simple_strtoul (argv[1 ],NULL ,10 ), argv[2 ]); + case '0' ... '9': /* "mac 0" through "mac 31" */ +set_mac_address (simple_strtoul (argv[1 ],NULL ,0 ), argv[2 ]);These changes silently change the behaviour of the command. So far, an argument line "24" would be parsed as hex number (i. e. result in decimal value 36); with this change it suddenly becomes devcimal 24, which is quite unexpected.
Quoted 3 lines
There are very few exceptions wher eU-Boot uses and expects decimal numbers, and I strongly recommend not to add any new such inconsistencies.
Changing back to hex number is not a problem. But it brings a problem when trying to set mac address to ports 10-15. For example, for port 14, you may want to use
mac e xxxxxxxx
where 'e' is another defined command. In order to make this work, we need to use two bytes for cmd.
Back to my current patch, it was from another nice feedback. To accept both hex and decimal. In order to use hex, you will have to prefix it with 0x.
Regards,
York
PATCH v4 1/1 powerpc/eeprom: cleanup mac command
Dear York Sun,
Quoted 5 lines · In message <1318631500.7780.56.camel@oslab-l1> you wrote:
Quoted 4 lines
There are very few exceptions wher eU-Boot uses and expects decimal numbers, and I strongly recommend not to add any new such inconsistencies.
Quoted 8 lines
Changing back to hex number is not a problem. But it brings a problem when trying to set mac address to ports 10-15. For example, for port 14, you may want to use
mac e xxxxxxxx
where 'e' is another defined command. In order to make this work, we need to use two bytes for cmd.
No, not really.
Instead you should fix the command decode. If there are potential confusions with the "mac errata" command then it's obviously not sufficient to compare just the first character of the sub-command name.
Frankly, the whole implementation of this command is a mess.
It is IMO a major design bug that the command accepts sub-commands, but then does not use a sub-command to program the MAC address for port n.
Instead of implementing your own (broken, as we see now) way to implement sub-commands, you should use the standard way with a sub-command table as used elsewhere (thenyou get correct decoding for free) - of course, you need to get rid of the inconsistency in your command interface first.
My recommendation is therefor: 1) introduce a "mac" subcommand for programming the MAC (this solves the decode issue), and 2) convert the code to proper sub-command decoding.
Quoted 3 lines
Back to my current patch, it was from another nice feedback. To accept both hex and decimal. In order to use hex, you will have to prefix it with 0x.
Yes, that is what your patch would do. But the standard input bae in U-Boot is 16, not 10. So your patch introduces inconsistent behaviour, which is why I NAKed it.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
No journaling file system can recover your data if the disk dies.
- Steve Rago in <[email protected]>