* [PATCH V2] cmd: env: select: Add output for available evironment targets
@ 2025-03-21 18:43 Christoph Niedermaier
2025-03-21 19:22 ` Marek Vasut
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Niedermaier @ 2025-03-21 18:43 UTC (permalink / raw)
To: u-boot
Cc: Christoph Niedermaier, Marek Vasut, Patrick Delaunay,
Joe Hershberger, Tom Rini
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@dh-electronics.com>
---
Cc: Marek Vasut <marex@denx.de>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Tom Rini <trini@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) == '-') {
+ char *arg = *++argv;
+
+ --argc;
+ while (*++arg) {
+ switch (*arg) {
+ case 'l': /* list */
+ return env_select_print_list() ? 1 : 0;
+ default:
+ return CMD_RET_USAGE;
+ }
+ }
+ }
+
return env_select(argv[1]) ? 1 : 0;
}
#endif
@@ -1189,7 +1206,7 @@ U_BOOT_LONGHELP(env,
"env load - load environment\n"
#endif
#if defined(CONFIG_CMD_NVEDIT_SELECT)
- "env select [target] - select environment target\n"
+ "env select [-l] [target] - list/select environment target(s)\n"
#endif
#if defined(CONFIG_CMD_NVEDIT_EFI)
"env set -e [-nv][-bs][-rt][-at][-a][-i addr:size][-v] name [arg ...]\n"
diff --git a/env/env.c b/env/env.c
index bcc189e14db..c73b53a2c62 100644
--- a/env/env.c
+++ b/env/env.c
@@ -347,6 +347,22 @@ int env_init(void)
return ret;
}
+int env_select_print_list(void)
+{
+ struct env_driver *drv;
+ int prio;
+
+ printf("Available Environment targets:\n");
+ for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); prio++) {
+ if (gd->env_load_prio == prio)
+ printf("* ");
+ else
+ printf(" ");
+ printf("%s\n", drv->name);
+ }
+ return 0;
+}
+
int env_select(const char *name)
{
struct env_driver *drv;
diff --git a/include/env.h b/include/env.h
index 01c3eeae7e2..4553c7bc109 100644
--- a/include/env.h
+++ b/include/env.h
@@ -286,6 +286,13 @@ int env_save(void);
*/
int env_erase(void);
+/**
+ * env_select_print_list() - Print available environment targets
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int env_select_print_list(void);
+
/**
* env_select() - Select the environment storage
*
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH V2] cmd: env: select: Add output for available evironment targets
2025-03-21 18:43 [PATCH V2] cmd: env: select: Add output for available evironment targets Christoph Niedermaier
@ 2025-03-21 19:22 ` Marek Vasut
2025-03-26 16:02 ` Christoph Niedermaier
0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2025-03-21 19:22 UTC (permalink / raw)
To: Christoph Niedermaier, u-boot, Simon Glass
Cc: Patrick Delaunay, Joe Hershberger, Tom Rini
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@dh-electronics.com>
> ---
> Cc: Marek Vasut <marex@denx.de>
> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Tom Rini <trini@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.
- Please write a test for this, see test/cmd/ , maybe Simon can help
with details of this ... ?
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: [PATCH V2] cmd: env: select: Add output for available evironment targets
2025-03-21 19:22 ` Marek Vasut
@ 2025-03-26 16:02 ` Christoph Niedermaier
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Niedermaier @ 2025-03-26 16:02 UTC (permalink / raw)
To: Marek Vasut, u-boot@lists.denx.de
Cc: Patrick Delaunay, Joe Hershberger, Tom Rini, Simon Glass
From: Marek Vasut <marex@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@dh-electronics.com>
>> ---
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> Cc: Joe Hershberger <joe.hershberger@ni.com>
>> Cc: Tom Rini <trini@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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-26 16:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21 18:43 [PATCH V2] cmd: env: select: Add output for available evironment targets Christoph Niedermaier
2025-03-21 19:22 ` Marek Vasut
2025-03-26 16:02 ` Christoph Niedermaier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox