U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
To: <u-boot@lists.denx.de>
Cc: Christoph Niedermaier <cniedermaier@dh-electronics.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Marek Vasut <marex@denx.de>, Michal Simek <michal.simek@amd.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Rasmus Villemoes <ravi@prevas.dk>, Simon Glass <sjg@chromium.org>,
	Tom Rini <trini@konsulko.com>,
	Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
Subject: [PATCH V3 3/3] cmd: env: select: Add output for available environment targets
Date: Fri, 9 May 2025 21:00:43 +0200	[thread overview]
Message-ID: <20250509190043.28641-4-cniedermaier@dh-electronics.com> (raw)
In-Reply-To: <20250509190043.28641-1-cniedermaier@dh-electronics.com>

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: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Michal Simek <michal.simek@amd.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Rasmus Villemoes <ravi@prevas.dk>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
---
V2: - Showing available environment targets by parameter "-l"
    - Showing env usage message if env select is called without a target
V3: - Convert the parsing of arguments to getopt()
---
 cmd/nvedit.c  | 18 +++++++++++++++++-
 env/env.c     | 16 ++++++++++++++++
 include/env.h |  7 +++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index e5e89b51e0a..10fd93d4a45 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -504,6 +504,22 @@ 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[])
 {
+	struct getopt_state gs;
+	int opt;
+
+	if (!argv[1])
+		return CMD_RET_USAGE;
+
+	getopt_init_state(&gs);
+	while ((opt = getopt(&gs, argc, argv, "l")) > 0) {
+		switch (opt) {
+		case 'l': /* list */
+			return env_select_print_list() ? 1 : 0;
+		default:
+			return CMD_RET_USAGE;
+		}
+	}
+
 	return env_select(argv[1]) ? 1 : 0;
 }
 #endif
@@ -1180,7 +1196,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 dbaeedc3c3b..f94976d4271 100644
--- a/env/env.c
+++ b/env/env.c
@@ -350,6 +350,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


  parent reply	other threads:[~2025-05-09 19:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 19:00 [PATCH V3 0/3] cmd: env: select: Add output for available environment targets Christoph Niedermaier
2025-05-09 19:00 ` [PATCH V3 1/3] cmd: nvedit: Convert the parsing of arguments to getopt() Christoph Niedermaier
2025-05-09 19:00 ` [PATCH V3 2/3] test: cmd: nvedit: Add basic unit tests Christoph Niedermaier
2025-06-03 20:12   ` Tom Rini
2025-06-06 21:40     ` Christoph Niedermaier
2025-05-09 19:00 ` Christoph Niedermaier [this message]
2025-05-12  7:37 ` [PATCH V3 0/3] cmd: env: select: Add output for available environment targets Andy Shevchenko
2025-05-12  8:22   ` Christoph Niedermaier
2025-05-12  8:38     ` Andy Shevchenko
2025-05-12 15:15       ` Christoph Niedermaier
2025-05-12 18:25         ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250509190043.28641-4-cniedermaier@dh-electronics.com \
    --to=cniedermaier@dh-electronics.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ansuelsmth@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=joe.hershberger@ni.com \
    --cc=marex@denx.de \
    --cc=michal.simek@amd.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=ravi@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=venkatesh.abbarapu@amd.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox