From patchwork Thu Dec 10 12:40:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1414101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mork.no Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=N/HH45B/; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=ZNjXeQLr; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsD8l6W9rz9sW1 for ; Thu, 10 Dec 2020 23:42:47 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=jWlqDNSRqtl9uEjbyz3WWutOFgO8ZiLhIVt1/NNqdXE=; b=N/HH45B/Ux/BsYWXO2q4CLSakI cPfvI28SgaTO6lpB8Nb0c8PWA2hPZYCA4JFZuav9wz/FA4UQnCAmIoGNWpWgCALkvEswndGxqP7Sh 3JQ5k674R97c9TvIonIHcK4RvhrqSwtIXzpf1hRGgVJ4Lh9NXqdZ9cEw92jwux7MEpp7B0vHyI1fX tkYjCTEj8zdfUIIdj0MHD42szqAr2ezJ7nXDOXQCnFZihD8wGERlDi/9LCz1xum0y0EK6C401zWMu m8X3Y6jcXVaLINLZIX31K9/U2CRfVF9qE6IhW3QXghD+zxfufTFgKkqGaooqZainzk8ytu2xgJlzc hP50q6JQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knLFT-0001UG-E9; Thu, 10 Dec 2020 12:40:43 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knLFP-0001SW-CJ for openwrt-devel@lists.openwrt.org; Thu, 10 Dec 2020 12:40:40 +0000 Received: from canardo.mork.no (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by canardo.mork.no (8.15.2/8.15.2) with ESMTPS id 0BACeYIh027027 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Thu, 10 Dec 2020 13:40:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1607604035; bh=8pt2Wg6Mx/nb7QuUMAzI9tdzBpHdrX+1bX6SzAjCGFo=; h=From:To:Cc:Subject:Date:Message-Id:From; b=ZNjXeQLrIpW+VN91l9sTHUXVNp1Z6y6vQwpAmSf/z+gy6uxnlugcR0c/LLiB3uEUI 30jlBqDoUqGeakMwoP7E3sJZoLZaUbtCVVBkaIBj+/Jmhu8S/R0L0rJdVJ91MVFL/b +JQ6KW2HeADyOptdV7fKtWdhOn4aY8dzuGYMuaZo= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 0BACeYFl027026; Thu, 10 Dec 2020 13:40:34 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] uboot-envtools: add support for multiple config partitions Date: Thu, 10 Dec 2020 13:40:27 +0100 Message-Id: <20201210124028.26979-1-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on canardo.mork.no X-Virus-Scanned: clamav-milter 0.102.4 at canardo X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201210_074039_859594_A37C8CBA X-CRM114-Status: GOOD ( 12.34 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2001:4641:0:0:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Most (all?) of the realtek devices have two u-boot config partitions with a different set of variables in each. The U-Boot shell provides two sets of apps to manipulate these: printenv- print environment variables printsys- printsys - print system information variables saveenv - save environment variables to persistent storage savesys - savesys - save system information variables to persistent storage setenv - set environment variables setsys - setsys - set system information variables Add support for multiple ubootenv configuration types, allowing more than one configuration file. Section names are not suitable for naming the different configurations since each file can be the result of multiple sections in case of backup partitions. Signed-off-by: Bjørn Mork --- package/boot/uboot-envtools/Makefile | 1 + package/boot/uboot-envtools/files/realtek | 8 +++- .../uboot-envtools/files/uboot-envtools.sh | 38 ++++++++++++------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/package/boot/uboot-envtools/Makefile b/package/boot/uboot-envtools/Makefile index 590e38d8831a..601627011d56 100644 --- a/package/boot/uboot-envtools/Makefile +++ b/package/boot/uboot-envtools/Makefile @@ -61,6 +61,7 @@ MAKE_FLAGS += \ define Package/uboot-envtools/conffiles /etc/config/ubootenv /etc/fw_env.config +/etc/fw_sys.config endef define Package/uboot-envtools/install diff --git a/package/boot/uboot-envtools/files/realtek b/package/boot/uboot-envtools/files/realtek index cce0628ffcbb..b64bb23b0747 100644 --- a/package/boot/uboot-envtools/files/realtek +++ b/package/boot/uboot-envtools/files/realtek @@ -15,15 +15,21 @@ zyxel,gs1900-10hp) idx="$(find_mtd_index u-boot-env)" [ -n "$idx" ] && \ ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x400" "0x10000" + idx="$(find_mtd_index u-boot-env2)" + [ -n "$idx" ] && \ + ubootenv_add_uci_sys_config "/dev/mtd$idx" "0x0" "0x1000" "0x10000" ;; *) idx="$(find_mtd_index u-boot-env)" [ -n "$idx" ] && \ ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000" + idx="$(find_mtd_index u-boot-env2)" + [ -n "$idx" ] && \ + ubootenv_add_uci_sys_config "/dev/mtd$idx" "0x0" "0x1000" "0x10000" ;; esac config_load ubootenv -config_foreach ubootenv_add_app_config ubootenv +config_foreach ubootenv_add_app_config exit 0 diff --git a/package/boot/uboot-envtools/files/uboot-envtools.sh b/package/boot/uboot-envtools/files/uboot-envtools.sh index 9218bc4e3912..980c9962b17c 100644 --- a/package/boot/uboot-envtools/files/uboot-envtools.sh +++ b/package/boot/uboot-envtools/files/uboot-envtools.sh @@ -3,34 +3,44 @@ # Copyright (C) 2011-2012 OpenWrt.org # -ubootenv_add_uci_config() { - local dev=$1 - local offset=$2 - local envsize=$3 - local secsize=$4 - local numsec=$5 +_ubootenv_add_uci_config() { + local cfgtype=$1 + local dev=$2 + local offset=$3 + local envsize=$4 + local secsize=$5 + local numsec=$6 uci batch <>/etc/fw_env.config + grep -q "^[[:space:]]*${dev}[[:space:]]*${offset}" "/etc/fw_${cfgtype#uboot}.config" || echo "$dev $offset $envsize $secsize $numsec" >>"/etc/fw_${cfgtype#uboot}.config" } - From patchwork Thu Dec 10 12:40:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1414100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mork.no Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=jvABAmCI; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=ARzEcxLO; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsD8q2Cyfz9sWL for ; Thu, 10 Dec 2020 23:42:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y+HdIceYO8f56yiL/fQUKQJlaHQEInyiKZtw9J/Rv24=; b=jvABAmCIPFpqQhX/7dVLngiNz /AgF7EephswYDsLrEKYdDnaB1z9kehb1OFvXkyK69nDKlbDvcGEpBYJguusYklrKj15ocKxdGy7hi iEgWRBn9/k9MI/rU4WkiW0dJ3hIOMVTeCLy44j1bSlasbWxLbtrgrrzenyhBl3SzZr5PXJg/1Kg3c BcmhiFaV8ptyCN20JchFJZYFZESD9m+T2LDfxjbu/b2b2nzOLeR5nsLeV9ih8Puz6yWHciXG+h+Wz kRn17DIJ29tk4Tc08fXk3GJTGS5mjQTKEIxmh164dVBhfJ42XZpyj+ESCI5XAgaByOHueOa6Yvrcc uQDa13yxg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knLFX-0001Vf-D6; Thu, 10 Dec 2020 12:40:47 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knLFR-0001Ta-PE for openwrt-devel@lists.openwrt.org; Thu, 10 Dec 2020 12:40:43 +0000 Received: from canardo.mork.no (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by canardo.mork.no (8.15.2/8.15.2) with ESMTPS id 0BACee3r027042 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Thu, 10 Dec 2020 13:40:40 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1607604040; bh=qU1TL6TS87ndppiPZjuIYiO2uIWZpFNJQ+cayqy2hYs=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=ARzEcxLOgzuAzTOkQ0gfeYWcI8GimdH31CtIpdL41cCuyKe+RzYgkIeNprmtKFuVe y/E7W7ugIIvOvh/UnCh5WDm0hvzTJURWzIvB9VWBgoex7+yckC8rj8JZXpFCHfZuZG W7tBNYeW0sjJCt3sHdVOLI34LCmnaXkDAhDYsGg4= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 0BACeeYM027041; Thu, 10 Dec 2020 13:40:40 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/2] uboot-envtools: support alternate default config Date: Thu, 10 Dec 2020 13:40:28 +0100 Message-Id: <20201210124028.26979-2-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201210124028.26979-1-bjorn@mork.no> References: <20201210124028.26979-1-bjorn@mork.no> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on canardo.mork.no X-Virus-Scanned: clamav-milter 0.102.4 at canardo X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201210_074042_111780_3EFD4978 X-CRM114-Status: GOOD ( 21.88 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2001:4641:0:0:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Now that we can create an alternate configuration file, add support for selecting it by using the alternate application names `fw_printsys' or `fw_setsys'. Signed-off-by: Bjørn Mork --- package/boot/uboot-envtools/Makefile | 2 + .../002-support-alternate-config.patch | 91 ++++++++++ .../patches/003-fix-usage-text.patch | 167 ++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 package/boot/uboot-envtools/patches/002-support-alternate-config.patch create mode 100644 package/boot/uboot-envtools/patches/003-fix-usage-text.patch diff --git a/package/boot/uboot-envtools/Makefile b/package/boot/uboot-envtools/Makefile index 601627011d56..e7ecfefec73a 100644 --- a/package/boot/uboot-envtools/Makefile +++ b/package/boot/uboot-envtools/Makefile @@ -68,6 +68,8 @@ define Package/uboot-envtools/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/tools/env/fw_printenv $(1)/usr/sbin $(LN) fw_printenv $(1)/usr/sbin/fw_setenv + $(LN) fw_printenv $(1)/usr/sbin/fw_printsys + $(LN) fw_printenv $(1)/usr/sbin/fw_setsys $(INSTALL_DIR) $(1)/lib $(INSTALL_DATA) ./files/uboot-envtools.sh $(1)/lib $(INSTALL_DIR) $(1)/etc/uci-defaults diff --git a/package/boot/uboot-envtools/patches/002-support-alternate-config.patch b/package/boot/uboot-envtools/patches/002-support-alternate-config.patch new file mode 100644 index 000000000000..aa341545a03c --- /dev/null +++ b/package/boot/uboot-envtools/patches/002-support-alternate-config.patch @@ -0,0 +1,91 @@ +From e5255e1ca3af000adb5ff686ea5c5b5b60fb7d9d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= +Date: Thu, 10 Dec 2020 12:32:21 +0100 +Subject: [PATCH 1/2] tools: env: add support for alternate config file +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some devices use two distinct environment partitions for +different variable sets. Add basic support for choosing +between two configuration files based on application name. + +Signed-off-by: Bjørn Mork +--- + tools/env/fw_env_main.c | 28 +++++++++++++++++++++++++--- + tools/env/fw_env_private.h | 4 +++- + 2 files changed, 28 insertions(+), 4 deletions(-) + +diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c +index 1d193bd437d8..d67c2ed407e3 100644 +--- a/tools/env/fw_env_main.c ++++ b/tools/env/fw_env_main.c +@@ -42,6 +42,12 @@ + #define CMD_SETENV "fw_setenv" + static int do_printenv; + ++#ifdef CONFIG_SYSFILE ++#define CMD_PRINTSYS "fw_printsys" ++#define CMD_SETSYS "fw_setsys" ++static int do_sys; ++#endif ++ + static struct option long_options[] = { + {"config", required_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, +@@ -117,7 +123,7 @@ static void parse_common_args(int argc, char *argv[]) + int c; + + #ifdef CONFIG_FILE +- env_opts.config_file = CONFIG_FILE; ++ env_opts.config_file = do_sys ? CONFIG_SYSFILE : CONFIG_FILE; + #endif + + while ((c = getopt_long(argc, argv, ":a:c:l:h:v", long_options, NULL)) != +@@ -219,10 +225,26 @@ int main(int argc, char *argv[]) + do_printenv = 1; + } else if (strcmp(_cmdname, CMD_SETENV) == 0) { + do_printenv = 0; ++#ifdef CONFIG_SYSFILE ++ } else if (strcmp(_cmdname, CMD_PRINTSYS) == 0) { ++ do_printenv = 1; ++ do_sys = 1; ++ } else if (strcmp(_cmdname, CMD_SETSYS) == 0) { ++ do_printenv = 0; ++ do_sys = 1; ++#endif + } else { + fprintf(stderr, +- "Identity crisis - may be called as `%s' or as `%s' but not as `%s'\n", +- CMD_PRINTENV, CMD_SETENV, _cmdname); ++ "Identity crisis - may be called as `%s'," ++#ifdef CONFIG_SYSFILE ++ "`%s', `%s'," ++#endif ++ " or as `%s' but not as `%s'\n", ++ CMD_PRINTENV, CMD_SETENV, ++#ifdef CONFIG_SYSFILE ++ CMD_PRINTSYS, CMD_SETSYS, ++#endif ++ _cmdname); + exit(EXIT_FAILURE); + } + +diff --git a/tools/env/fw_env_private.h b/tools/env/fw_env_private.h +index 86be16dabc62..35b9bfc70aee 100644 +--- a/tools/env/fw_env_private.h ++++ b/tools/env/fw_env_private.h +@@ -23,7 +23,9 @@ + */ + #define CONFIG_FILE "/etc/fw_env.config" + +-#ifndef CONFIG_FILE ++#ifdef CONFIG_FILE ++#define CONFIG_SYSFILE "/etc/fw_sys.config" ++#else + #define HAVE_REDUND /* For systems with 2 env sectors */ + #define DEVICE1_NAME "/dev/mtd1" + #define DEVICE2_NAME "/dev/mtd2" +-- +2.29.2 + diff --git a/package/boot/uboot-envtools/patches/003-fix-usage-text.patch b/package/boot/uboot-envtools/patches/003-fix-usage-text.patch new file mode 100644 index 000000000000..220239ac2150 --- /dev/null +++ b/package/boot/uboot-envtools/patches/003-fix-usage-text.patch @@ -0,0 +1,167 @@ +From 2b3239c16749a175b189971a25025872774d690e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= +Date: Thu, 10 Dec 2020 12:54:53 +0100 +Subject: [PATCH 2/2] tools: env: fix usage text for alternate cmd names +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Bjørn Mork +--- + tools/env/fw_env_main.c | 65 ++++++++++++++++++++++------------------- + 1 file changed, 35 insertions(+), 30 deletions(-) + +diff --git a/tools/env/fw_env_main.c b/tools/env/fw_env_main.c +index d67c2ed407e3..034db42813e2 100644 +--- a/tools/env/fw_env_main.c ++++ b/tools/env/fw_env_main.c +@@ -66,41 +66,46 @@ static int noheader; + /* getenv options */ + static char *script_file; + +-void usage_printenv(void) ++void usage_common(const char *prog) + { +- ++#ifdef CONFIG_FILE ++ const char *cfgfile = do_sys ? CONFIG_SYSFILE : CONFIG_FILE; ++#endif + fprintf(stderr, +- "Usage: fw_printenv [OPTIONS]... [VARIABLE]...\n" +- "Print variables from U-Boot environment\n" ++ "Usage: %s [OPTIONS]... [VARIABLE]...\n" ++ "%s variables from U-Boot environment\n" + "\n" + " -h, --help print this help.\n" + " -v, --version display version\n" + #ifdef CONFIG_FILE +- " -c, --config configuration file, default:" CONFIG_FILE "\n" ++ " -c, --config configuration file, default:%s\n" ++#endif ++ " -l, --lock lock node, default:/var/lock\n", ++ prog, do_printenv ? "Print" : "Modify" ++#ifdef CONFIG_FILE ++ , cfgfile + #endif ++ ); ++} ++ ++void usage_printenv(const char *prog) ++{ ++ usage_common(prog); ++ fprintf(stderr, + " -n, --noheader do not repeat variable name in output\n" +- " -l, --lock lock node, default:/var/lock\n" + "\n"); + } + +-void usage_env_set(void) ++void usage_env_set(const char *prog) + { ++ usage_common(prog); + fprintf(stderr, +- "Usage: fw_setenv [OPTIONS]... [VARIABLE]...\n" +- "Modify variables in U-Boot environment\n" +- "\n" +- " -h, --help print this help.\n" +- " -v, --version display version\n" +-#ifdef CONFIG_FILE +- " -c, --config configuration file, default:" CONFIG_FILE "\n" +-#endif +- " -l, --lock lock node, default:/var/lock\n" + " -s, --script batch mode to minimize writes\n" + "\n" + "Examples:\n" +- " fw_setenv foo bar set variable foo equal bar\n" +- " fw_setenv foo clear variable foo\n" +- " fw_setenv --script file run batch script\n" ++ " %s foo bar set variable foo equal bar\n" ++ " %s foo clear variable foo\n" ++ " %s --script file run batch script\n" + "\n" + "Script Syntax:\n" + " key [space] value\n" +@@ -115,10 +120,10 @@ void usage_env_set(void) + " kernel_addr 400000\n" + " foo empty empty empty empty empty empty\n" + " bar\n" +- "\n"); ++ "\n", prog, prog, prog); + } + +-static void parse_common_args(int argc, char *argv[]) ++static void parse_common_args(char *prog, int argc, char *argv[]) + { + int c; + +@@ -138,7 +143,7 @@ static void parse_common_args(int argc, char *argv[]) + env_opts.lockname = optarg; + break; + case 'h': +- do_printenv ? usage_printenv() : usage_env_set(); ++ do_printenv ? usage_printenv(prog) : usage_env_set(prog); + exit(EXIT_SUCCESS); + break; + case 'v': +@@ -156,11 +161,11 @@ static void parse_common_args(int argc, char *argv[]) + optind = 1; + } + +-int parse_printenv_args(int argc, char *argv[]) ++int parse_printenv_args(char *prog, int argc, char *argv[]) + { + int c; + +- parse_common_args(argc, argv); ++ parse_common_args(prog, argc, argv); + + while ((c = getopt_long(argc, argv, "a:c:ns:l:h:v", long_options, NULL)) + != EOF) { +@@ -175,7 +180,7 @@ int parse_printenv_args(int argc, char *argv[]) + /* ignore common options */ + break; + default: /* '?' */ +- usage_printenv(); ++ usage_printenv(prog); + exit(EXIT_FAILURE); + break; + } +@@ -183,11 +188,11 @@ int parse_printenv_args(int argc, char *argv[]) + return 0; + } + +-int parse_setenv_args(int argc, char *argv[]) ++int parse_setenv_args(char *prog, int argc, char *argv[]) + { + int c; + +- parse_common_args(argc, argv); ++ parse_common_args(prog, argc, argv); + + while ((c = getopt_long(argc, argv, "a:c:ns:l:h:v", long_options, NULL)) + != EOF) { +@@ -202,7 +207,7 @@ int parse_setenv_args(int argc, char *argv[]) + /* ignore common options */ + break; + default: /* '?' */ +- usage_env_set(); ++ usage_env_set(prog); + exit(EXIT_FAILURE); + break; + } +@@ -249,10 +254,10 @@ int main(int argc, char *argv[]) + } + + if (do_printenv) { +- if (parse_printenv_args(argc, argv)) ++ if (parse_printenv_args(_cmdname, argc, argv)) + exit(EXIT_FAILURE); + } else { +- if (parse_setenv_args(argc, argv)) ++ if (parse_setenv_args(_cmdname, argc, argv)) + exit(EXIT_FAILURE); + } + +-- +2.29.2 +