[PATCH 1/1] starfive: fix return code of `mac write_eeprom`
E Shattow
e at freeshell.de
Mon Aug 11 05:16:04 CEST 2025
On 8/9/25 01:21, Heinrich Schuchardt wrote:
> When writing the EEPROM fails, the command usage help text is displayed
> after the error message. We should only display the error message instead.
>
> If writing the EEPROM fails, return CMD_RET_FAILURE (1) instead of
> CMD_RET_USAGE (-1).
>
> Fixes: aea1bd95b61e ("eeprom: starfive: Enable ID EEPROM configuration")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> board/starfive/visionfive2/visionfive2-i2c-eeprom.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
> index 010e386e64d..17a44020bcf 100644
> --- a/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
> +++ b/board/starfive/visionfive2/visionfive2-i2c-eeprom.c
> @@ -275,7 +275,7 @@ static int prog_eeprom(unsigned int size)
>
> if (is_match_magic()) {
> printf("MAGIC ERROR, Please check the data@%p.\n", pbuf.buf);
> - return -1;
> + return CMD_RET_FAILURE;
> }
>
> ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
> @@ -285,7 +285,7 @@ static int prog_eeprom(unsigned int size)
> if (ret) {
> printf("Get i2c bus:%d addr:%d fail.\n", CONFIG_SYS_EEPROM_BUS_NUM,
> CONFIG_SYS_I2C_EEPROM_ADDR);
> - return ret;
> + return CMD_RET_FAILURE;
> }
>
> for (i = 0, p = (u8 *)pbuf.buf; i < size; ) {
> @@ -314,11 +314,11 @@ static int prog_eeprom(unsigned int size)
> if (ret) {
> has_been_read = -1;
> printf("Programming failed.\n");
> - return -1;
> + return CMD_RET_FAILURE;
> }
>
> printf("Programming passed.\n");
> - return 0;
> + return CMD_RET_SUCCESS;
> }
>
> /**
This patch is a good start, but I think maybe more is needed? Quoting
the notes I wrote for myself last year:
"
mac command:
if data did not change then "Programming passed." is printed regardless
of write protect state but no action was taken and no usage help is
printed. 'mac' still outputs in-memory info.
when data was changed the command shows "Programming failed." or
"Programming passed." followed by usage help and 'mac' command shows no
output until 'mac read_eeprom'.
Suggested:
If data did not change at time of 'mac eeprom_write' then it should
still try to write so the message pass/fail will be correct.
The usage info following 'mac write_eeprom' is a bug, should not be printed.
prog_eeprom return values inconsistent with command.h
prog_eeprom returns -1 which overlaps with CMD_RET_USAGE
should be 1 for failure
show_eeprom()
Print a message "No valid data. Please do mac read_eeprom".
Maybe "Read nnn bytes from EEPROM" and "Displaying local copy of EEPROM
from memory" to be more clear.
"
Acked-by: E Shattow <e at freeshell.de>
More information about the U-Boot
mailing list