[PATCH V2] cmd: env: select: Add output for available evironment targets

Christoph Niedermaier cniedermaier at dh-electronics.com
Wed Mar 26 17:02:54 CET 2025


From: Marek Vasut <marex at denx.de>
Sent: Friday, March 21, 2025 8:23 PM
> On 3/21/25 7:43 PM, Christoph Niedermaier wrote:
>> Add parameter "-l" for printing available environment targets. The
>> active target is marked with an asterisk. This is done by adding
>> the function env_select_print_list().
>>
>> If "env select" is called without a target parameter the result is
>> "Select Environment on <NULL>: driver not found". Replace this not
>> so useful output by showing the env usage message instead.
>>
>> Signed-off-by: Christoph Niedermaier <cniedermaier at dh-electronics.com>
>> ---
>> Cc: Marek Vasut <marex at denx.de>
>> Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>
>> Cc: Joe Hershberger <joe.hershberger at ni.com>
>> Cc: Tom Rini <trini at konsulko.com>
>> ---
>> V2: - Showing available environment targets by parameter "-l"
>>      - Showing env usage message if env select is called without a target
>> ---
>>   cmd/nvedit.c  | 19 ++++++++++++++++++-
>>   env/env.c     | 16 ++++++++++++++++
>>   include/env.h |  7 +++++++
>>   3 files changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
>> index 1f259801293..de64094db4d 100644
>> --- a/cmd/nvedit.c
>> +++ b/cmd/nvedit.c
>> @@ -499,6 +499,23 @@ static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc,
>>   static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc,
>>   			 char *const argv[])
>>   {
>> +	if (!argv[1])
>> +		return CMD_RET_USAGE;
>> +
>> +	while (argc > 1 && **(argv + 1) == '-') {
> Two higher level things:
> 
> - Can you first convert cmd/nvedit.h to use include/getopt.h and then
>    use getopt() here too ? This hand rolled arg parsing is repulsive,
>    the multiple ad-hoc copies of that are even worse.

I will try.

> - Please write a test for this, see test/cmd/ , maybe Simon can help
>    with details of this ... ?

I will try.


Regards
Christoph


More information about the U-Boot mailing list