Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAE07C83029 for ; Mon, 30 Jun 2025 15:19:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4915682E35; Mon, 30 Jun 2025 17:18:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=dh-electronics.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=dh-electronics.com header.i=@dh-electronics.com header.b="C4VI0V4n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A67E882E9A; Mon, 30 Jun 2025 17:18:57 +0200 (CEST) Received: from mx2.securetransport.de (mx2.securetransport.de [IPv6:2a03:4000:13:6c7::1]) by phobos.denx.de (Postfix) with ESMTP id 354AE8003E for ; Mon, 30 Jun 2025 17:18:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=dh-electronics.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=cniedermaier@dh-electronics.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dh-electronics.com; s=dhelectronicscom; t=1751296469; bh=YBR/t+mGCEITfW3LMmGwYgSJs8U7fElrVMHrTl3hXOk=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=C4VI0V4niPLkWGPYEI1GdiPdgfOrTXwq/WrJEn4Fi8BQJWmm47seuMVxetWcwAVZT Xgbs/oeqTTht4bAILeDMoC+j50xWM5HYjXXcOOcMuke/POfqASjismnZEibKIMKsVE 3exKwzWoRFvdD5fhxfC545l6wd7//F02AwaiQxhyb+NEt1gwh7ToIkFRx7E+c6fhuj iKEk+9932GpAcAkVV1vjAiCgg6g86RXoOJC2g9n54iH0mL0Lz99LBgDUCfL03zZlDk ebDPLgUUNguCu1BEFfZsPf57hyJsigGOuGoc4XT2Jz8jTMjBaINXVBQSlPmK6j0OR8 UNij6ux6R9i0A== From: Christoph Niedermaier To: CC: Christoph Niedermaier , Andy Shevchenko , Christian Marangi , Heinrich Schuchardt , "Ilias Apalodimas" , Jerome Forissier , Joe Hershberger , Marek Vasut , Michal Simek , "Patrick Delaunay" , Rasmus Villemoes , Simon Glass , Tom Rini , "Venkatesh Yadav Abbarapu" Subject: [PATCH V4 3/3] cmd: env: select: Add output for available environment targets Date: Mon, 30 Jun 2025 17:12:32 +0200 Message-ID: <20250630151232.39100-4-cniedermaier@dh-electronics.com> X-klartext: yes In-Reply-To: <20250630151232.39100-1-cniedermaier@dh-electronics.com> References: <20250630151232.39100-1-cniedermaier@dh-electronics.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 : driver not found". Replace this not so useful output by showing the env usage message instead. Signed-off-by: Christoph Niedermaier --- Cc: Andy Shevchenko Cc: Christian Marangi Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Jerome Forissier Cc: Joe Hershberger Cc: Marek Vasut Cc: Michal Simek Cc: Patrick Delaunay Cc: Rasmus Villemoes Cc: Simon Glass Cc: Tom Rini Cc: Venkatesh Yadav Abbarapu --- 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() V4: - No changes --- 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 945db536bf2..604ce71f269 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