[PATCH 3/3] cmd: tlv_eeprom: enable 'dev' subcommand before 'read'

Stefan Roese sr at denx.de
Wed May 3 08:35:28 CEST 2023


On 4/29/23 11:15, Josua Mayer wrote:
> Move the handler for "tlv_eeprom dev X" command to the beginning of
> do_tlv_eeprom, to allow using it before issuing a "read" command for
> currently selected eeprom.
> 
> Also remove the check if eeprom exists, since that can only work after
> the first execution of read_eeprom triggered device lookup.
> Instead accept values up to the defined array size (MAX_TLV_DEVICES).
> 
> Signed-off-by: Josua Mayer <josua at solid-run.com>
> Cc: Stefan Roese <sr at denx.de>
> Cc: Baruch Siach <baruch at tkos.co.il>
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
>   cmd/tlv_eeprom.c | 26 ++++++++++++++++----------
>   1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c
> index 636c1fe32ef..79796394c5c 100644
> --- a/cmd/tlv_eeprom.c
> +++ b/cmd/tlv_eeprom.c
> @@ -450,6 +450,22 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>   	// "reset" will both be treated as "read".
>   	cmd = argv[1][0];
>   
> +	// select device
> +	if (cmd == 'd') {
> +		 /* 'dev' command */
> +		unsigned int devnum;
> +
> +		devnum = simple_strtoul(argv[2], NULL, 0);
> +		if (devnum >= MAX_TLV_DEVICES) {
> +			printf("Invalid device number\n");
> +			return 0;
> +		}
> +		current_dev = devnum;
> +		has_been_read = 0;
> +
> +		return 0;
> +	}
> +
>   	// Read the EEPROM contents
>   	if (cmd == 'r') {
>   		has_been_read = 0;
> @@ -508,16 +524,6 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>   		tlvinfo_delete_tlv(eeprom, tcode);
>   		if (argc == 4)
>   			tlvinfo_add_tlv(eeprom, tcode, argv[3]);
> -	} else if (cmd == 'd') { /* 'dev' command */
> -		unsigned int devnum;
> -
> -		devnum = simple_strtoul(argv[2], NULL, 0);
> -		if (devnum > MAX_TLV_DEVICES || !tlv_devices[devnum]) {
> -			printf("Invalid device number\n");
> -			return 0;
> -		}
> -		current_dev = devnum;
> -		has_been_read = 0;
>   	} else {
>   		return CMD_RET_USAGE;
>   	}

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list