[PATCH 0/6] cmd mac: separate implementations

There are three implementations of the 'mac' command:
* Freescale (NXP) * SiFive Unmatched * StarFive VisionFive 2
They all use different sets of sub-commands and hence should display a different long text help.
This series moves the command definition to the three implementations.
The following fixes are added for the StarFive implementation:
* Provide a hexdump if the data format is unknown. * Provide a raw sub-command to force a hexdump.
Heinrich Schuchardt (6): cmd: move mac command freescale: fix long help handling in mac command eeprom: SiFive Unmatched: re-implement mac command eeprom: starfive: re-implement mac command eeprom: starfive: raw dump if unsupported data version eeprom: starfive: add 'mac raw' command
board/freescale/common/sys_eeprom.c | 30 +++++++- .../unmatched/hifive-platform-i2c-eeprom.c | 30 +++++++- .../visionfive2/visionfive2-i2c-eeprom.c | 68 ++++++++++++------- cmd/Makefile | 1 - cmd/mac.c | 33 --------- 5 files changed, 98 insertions(+), 64 deletions(-) delete mode 100644 cmd/mac.c

Board specific implementations of the 'mac' command differ concerning the supported sub-commands.
Move the Freescale specific mac command definition to the board code.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- board/freescale/common/sys_eeprom.c | 22 +++++++++++++++++++ cmd/Makefile | 1 - cmd/mac.c | 33 ----------------------------- 3 files changed, 22 insertions(+), 34 deletions(-) delete mode 100644 cmd/mac.c
diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c index 431f8caeb0..d4a00fe920 100644 --- a/board/freescale/common/sys_eeprom.c +++ b/board/freescale/common/sys_eeprom.c @@ -623,3 +623,25 @@ unsigned int get_cpu_board_revision(void) return MPC85XX_CPU_BOARD_REV(be.major, be.minor); } #endif + +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|port_number]\n" + "mac read\n" + " - read EEPROM content into memory data structure\n" + "mac save\n" + " - save memory data structure to the EEPROM\n" + "mac id\n" + " - program system id per hard coded value\n" + "mac num string\n" + " - program system serial number to value string\n" + "mac errata string\n" + " - program errata data to value string\n" + "mac date YYMMDDhhmmss\n" + " - program date to string value YYMMDDhhmmss\n" + "mac ports N\n" + " - program the number of network ports to integer N\n" + "mac X string\n" + " - program MAC addr for port X [X=0,1..] to colon separated string" +); diff --git a/cmd/Makefile b/cmd/Makefile index 9bebf321c3..d515d241e6 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -107,7 +107,6 @@ obj-$(CONFIG_CMD_LICENSE) += license.o obj-y += load.o obj-$(CONFIG_CMD_LOG) += log.o obj-$(CONFIG_CMD_LSBLK) += lsblk.o -obj-$(CONFIG_ID_EEPROM) += mac.o obj-$(CONFIG_CMD_MD5SUM) += md5sum.o obj-$(CONFIG_CMD_MEMORY) += mem.o obj-$(CONFIG_CMD_IO) += io.o diff --git a/cmd/mac.c b/cmd/mac.c deleted file mode 100644 index a39e1168a5..0000000000 --- a/cmd/mac.c +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2006 Freescale Semiconductor - * York Sun (yorksun@freescale.com) - */ - -#include <common.h> -#include <command.h> - -extern int do_mac(struct cmd_tbl *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|port_number]\n" - "mac read\n" - " - read EEPROM content into memory data structure\n" - "mac save\n" - " - save memory data structure to the EEPROM\n" - "mac id\n" - " - program system id per hard coded value\n" - "mac num string\n" - " - program system serial number to value string\n" - "mac errata string\n" - " - program errata data to value string\n" - "mac date YYMMDDhhmmss\n" - " - program date to string value YYMMDDhhmmss\n" - "mac ports N\n" - " - program the number of network ports to integer N\n" - "mac X string\n" - " - program MAC addr for port X [X=0,1..] to colon separated string" -);

On Sat, Sep 30, 2023 at 02:01:42PM +0200, Heinrich Schuchardt wrote:
Board specific implementations of the 'mac' command differ concerning the supported sub-commands.
Move the Freescale specific mac command definition to the board code.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

CONFIG_SYS_LONGHELP=n we want to reduce the size of the U-Boot binary. The long text should be reduced to and empty string in this case.
There is not need to call cmd_usage() directly. It is sufficient to return CMD_RET_USAGE.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- board/freescale/common/sys_eeprom.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/board/freescale/common/sys_eeprom.c b/board/freescale/common/sys_eeprom.c index d4a00fe920..9363251dc2 100644 --- a/board/freescale/common/sys_eeprom.c +++ b/board/freescale/common/sys_eeprom.c @@ -424,7 +424,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) prog_eeprom(); break; default: - return cmd_usage(cmdtp); + return CMD_RET_USAGE; }
return 0; @@ -624,9 +624,8 @@ unsigned int get_cpu_board_revision(void) } #endif
-U_BOOT_CMD( - mac, 3, 1, do_mac, - "display and program the system ID and MAC addresses in EEPROM", +#ifdef CONFIG_SYS_LONGHELP +static char booti_help_text[] = "[read|save|id|num|errata|date|ports|port_number]\n" "mac read\n" " - read EEPROM content into memory data structure\n" @@ -643,5 +642,12 @@ U_BOOT_CMD( "mac ports N\n" " - program the number of network ports to integer N\n" "mac X string\n" - " - program MAC addr for port X [X=0,1..] to colon separated string" -); + " - program MAC addr for port X [X=0,1..] to colon separated string"; +#else + ""; +#endif + +U_BOOT_CMD( + mac, 3, 1, do_mac, + "display and program the system ID and MAC addresses in EEPROM", + booti_help_text);

On Sat, Sep 30, 2023 at 02:01:43PM +0200, Heinrich Schuchardt wrote:
CONFIG_SYS_LONGHELP=n we want to reduce the size of the U-Boot binary. The long text should be reduced to and empty string in this case.
There is not need to call cmd_usage() directly. It is sufficient to return CMD_RET_USAGE.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

The different implementations of the mac command have board or vendor specific sub-commands.
Add the command definition specific to the SiFive HiFive Unmatched board.
Don't call cmd_usage() directly but return CMD_RET_USAGE instead.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- .../unmatched/hifive-platform-i2c-eeprom.c | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/board/sifive/unmatched/hifive-platform-i2c-eeprom.c b/board/sifive/unmatched/hifive-platform-i2c-eeprom.c index 2b985b9b22..3c7ba4e0d3 100644 --- a/board/sifive/unmatched/hifive-platform-i2c-eeprom.c +++ b/board/sifive/unmatched/hifive-platform-i2c-eeprom.c @@ -426,7 +426,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) }
if (argc > 3) - return cmd_usage(cmdtp); + return CMD_RET_USAGE;
cmd = argv[1];
@@ -443,7 +443,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) }
if (argc != 3) - return cmd_usage(cmdtp); + return CMD_RET_USAGE;
if (!is_match_magic()) { printf("Please read the EEPROM ('read_eeprom') and/or initialize the EEPROM ('initialize') first.\n"); @@ -470,7 +470,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 0; }
- return cmd_usage(cmdtp); + return CMD_RET_USAGE; }
/** @@ -551,3 +551,27 @@ u8 get_pcb_revision_from_eeprom(void)
return be.pcb_revision; } + +#ifndef CONFIG_SPL_BUILD + +#ifdef CONFIG_SYS_LONGHELP +static char booti_help_text[] = + "- displays memory copy of EEPROM\n" + "mac read_eeprom - reads EEPROM into memory\n" + "mac initialize - initializes memory copy with magic number\n" + "mac write_eeprom - writes the EEPROM from memory\n" + "mac manuf_test_status [unknown|pass|fail] - sets test status in memory\n" + "mac_address <addr> - sets MAC address in memory\n" + "mac pcb_revision <rev> - sets PCB revision in memory\n" + "mac bom_variant <var> - sets BOM variant in memory\n" + "mac bom_revision <rev> - sets BOM revision in memory\n"; +#else + ""; +#endif + +U_BOOT_CMD( + mac, 3, 1, do_mac, + "display and program the board revision and MAC address in EEPROM", + booti_help_text); + +#endif /* CONFIG_SPL_BUILD */

On Sat, Sep 30, 2023 at 02:01:44PM +0200, Heinrich Schuchardt wrote:
The different implementations of the mac command have board or vendor specific sub-commands.
Add the command definition specific to the SiFive HiFive Unmatched board.
Don't call cmd_usage() directly but return CMD_RET_USAGE instead.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

The different implementations of the mac command have board or vendor specific sub-commands.
Add the command definition specific to the VisionFive 2 board.
Don't call cmd_usage() directly but return CMD_RET_USAGE instead.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- .../visionfive2/visionfive2-i2c-eeprom.c | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-)
diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c index befe7888c4..8d99249279 100644 --- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c +++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c @@ -404,29 +404,6 @@ static void set_product_id(char *string) update_crc(); }
-static int print_usage(void) -{ - printf("display and program the system ID and MAC addresses in EEPROM\n" - "[read_eeprom|initialize|write_eeprom|mac_address|pcb_revision|bom_revision|product_id]\n" - "mac read_eeprom\n" - " - read EEPROM content into memory data structure\n" - "mac write_eeprom\n" - " - save memory data structure to the EEPROM\n" - "mac initialize\n" - " - initialize the in-memory EEPROM copy with default data\n" - "mac mac0_address xx:xx:xx:xx:xx:xx\n" - " - stores a MAC0 address into the local EEPROM copy\n" - "mac mac1_address xx:xx:xx:xx:xx:xx\n" - " - stores a MAC1 address into the local EEPROM copy\n" - "mac pcb_revision <?>\n" - " - stores a StarFive PCB revision into the local EEPROM copy\n" - "mac bom_revision <A>\n" - " - stores a StarFive BOM revision into the local EEPROM copy\n" - "mac product_id <VF7110A1-2228-D008E000-xxxxxxxx>\n" - " - stores a StarFive product ID into the local EEPROM copy\n"); - return 0; -} - int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { char *cmd; @@ -437,7 +414,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) }
if (argc > 3) - return print_usage(); + return CMD_RET_USAGE;
cmd = argv[1];
@@ -453,7 +430,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) }
if (argc != 3) - return print_usage(); + return CMD_RET_USAGE;
if (is_match_magic()) { printf("Please read the EEPROM ('read_eeprom') and/or initialize the EEPROM ('initialize') first.\n"); @@ -477,7 +454,7 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 0; }
- return print_usage(); + return CMD_RET_USAGE; }
/** @@ -559,3 +536,36 @@ u32 get_ddr_size_from_eeprom(void)
return hextoul(&pbuf.eeprom.atom1.data.pstr[14], NULL); } + +#ifndef CONFIG_SPL_BUILD + +#ifdef CONFIG_SYS_LONGHELP +static char booti_help_text[] = + "\n" + " - display EEPROM content\n" + "mac read_eeprom\n" + " - read EEPROM content into memory data structure\n" + "mac write_eeprom\n" + " - save memory data structure to the EEPROM\n" + "mac initialize\n" + " - initialize the in-memory EEPROM copy with default data\n" + "mac mac0_address xx:xx:xx:xx:xx:xx\n" + " - stores a MAC0 address into the local EEPROM copy\n" + "mac mac1_address xx:xx:xx:xx:xx:xx\n" + " - stores a MAC1 address into the local EEPROM copy\n" + "mac pcb_revision <?>\n" + " - stores a StarFive PCB revision into the local EEPROM copy\n" + "mac bom_revision <A>\n" + " - stores a StarFive BOM revision into the local EEPROM copy\n" + "mac product_id <VF7110A1-2228-D008E000-xxxxxxxx>\n" + " - stores a StarFive product ID into the local EEPROM copy\n"; +#else + ""; +#endif + +U_BOOT_CMD( + mac, 3, 1, do_mac, + "display and program the board revision and MAC address in EEPROM", + booti_help_text); + +#endif /* CONFIG_SPL_BUILD */

On Sat, Sep 30, 2023 at 02:01:45PM +0200, Heinrich Schuchardt wrote:
The different implementations of the mac command have board or vendor specific sub-commands.
Add the command definition specific to the VisionFive 2 board.
Don't call cmd_usage() directly but return CMD_RET_USAGE instead.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

If the data version field of the EEPROM is not supported, provide a hexdump of the data.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- board/starfive/visionfive2/visionfive2-i2c-eeprom.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c index 8d99249279..329fbf6644 100644 --- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c +++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c @@ -190,6 +190,7 @@ static void show_eeprom(void) pbuf.eeprom.atom4.data.mac1_addr[4], pbuf.eeprom.atom4.data.mac1_addr[5]); } else { printf("Custom data v%d is not Supported\n", pbuf.eeprom.atom4.data.version); + dump_raw_eeprom(); } printf("--------EEPROM INFO--------\n\n"); }

On Sat, Sep 30, 2023 at 02:01:46PM +0200, Heinrich Schuchardt wrote:
If the data version field of the EEPROM is not supported, provide a hexdump of the data.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

Add a sub-command to print a hexdump of the EEPROM content.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- board/starfive/visionfive2/visionfive2-i2c-eeprom.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c index 329fbf6644..710044a235 100644 --- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c +++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c @@ -428,6 +428,9 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 0; } else if (!strcmp(cmd, "write_eeprom")) { return prog_eeprom(STARFIVE_EEPROM_HATS_SIZE_MAX); + } else if (!strcmp(cmd, "raw")) { + dump_raw_eeprom(); + return 0; }
if (argc != 3) @@ -550,6 +553,8 @@ static char booti_help_text[] = " - save memory data structure to the EEPROM\n" "mac initialize\n" " - initialize the in-memory EEPROM copy with default data\n" + "mac raw\n" + " - hexdump memory data structure\n" "mac mac0_address xx:xx:xx:xx:xx:xx\n" " - stores a MAC0 address into the local EEPROM copy\n" "mac mac1_address xx:xx:xx:xx:xx:xx\n"

On Sat, Sep 30, 2023 at 02:01:47PM +0200, Heinrich Schuchardt wrote:
Add a sub-command to print a hexdump of the EEPROM content.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Applied to u-boot/master, thanks!

On 9/30/23 14:01, Heinrich Schuchardt wrote:
There are three implementations of the 'mac' command:
- Freescale (NXP)
- SiFive Unmatched
- StarFive VisionFive 2
They all use different sets of sub-commands and hence should display a different long text help.
This series moves the command definition to the three implementations.
The following fixes are added for the StarFive implementation:
- Provide a hexdump if the data format is unknown.
- Provide a raw sub-command to force a hexdump.
I have tested the series on the Unmatched and VisionFive 2 boards but lack access to NXP hardware. So these patches need to be tested by one of the NXP maintainers.
Best regards
Heinrich
Heinrich Schuchardt (6): cmd: move mac command freescale: fix long help handling in mac command eeprom: SiFive Unmatched: re-implement mac command eeprom: starfive: re-implement mac command eeprom: starfive: raw dump if unsupported data version eeprom: starfive: add 'mac raw' command
board/freescale/common/sys_eeprom.c | 30 +++++++- .../unmatched/hifive-platform-i2c-eeprom.c | 30 +++++++- .../visionfive2/visionfive2-i2c-eeprom.c | 68 ++++++++++++------- cmd/Makefile | 1 - cmd/mac.c | 33 --------- 5 files changed, 98 insertions(+), 64 deletions(-) delete mode 100644 cmd/mac.c
participants (2)
-
Heinrich Schuchardt
-
Tom Rini