mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Johannes Zink <j.zink@pengutronix.de>
To: barebox@lists.infradead.org
Cc: patchwork-jzi@pengutronix.de, Johannes Zink <j.zink@pengutronix.de>
Subject: [PATCH v2 3/3] imx-usb-loader: add commandline option for displaying version number
Date: Fri,  5 May 2023 17:52:48 +0200	[thread overview]
Message-ID: <20230505155248.2261867-4-j.zink@pengutronix.de> (raw)
In-Reply-To: <20230505155248.2261867-1-j.zink@pengutronix.de>

For debugging purposes of the imx-usb-loader it can be helpful to
display the version number as a commandline option.

If built from outside the KBuild infrastructure, the version string
cannot be fetched from the generated utsrelease.h header the version
number needs to be defined by setting the UTS_VERSION macro. If the
macro is not set on an out-of-KBuild build, the version number "unknown"
is displayed.

Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
---
Changelog:

v1 -> v2: - fixed tool relying on KBuild-infrastructure-generated header
            file to allow build outside of a KBuild environment
	  - remove unneeded double exit() call when displaying the
	    version number

 scripts/imx/Makefile         |  2 +-
 scripts/imx/imx-usb-loader.c | 22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/scripts/imx/Makefile b/scripts/imx/Makefile
index dbfa82910a55..b3be3886d8eb 100644
--- a/scripts/imx/Makefile
+++ b/scripts/imx/Makefile
@@ -3,7 +3,7 @@
 hostprogs-always-$(CONFIG_ARCH_IMX_IMXIMAGE)	+= imx-image
 hostprogs-always-$(CONFIG_ARCH_IMX_USBLOADER)	+= imx-usb-loader
 
-HOSTCFLAGS_imx-usb-loader.o = `pkg-config --cflags libusb-1.0`
+HOSTCFLAGS_imx-usb-loader.o = `pkg-config --cflags libusb-1.0` -include $(objtree)/include/generated/utsrelease.h
 HOSTLDLIBS_imx-usb-loader  = `pkg-config --libs libusb-1.0`
 
 imx-usb-loader-target-userccflags += `$(CROSS_PKG_CONFIG) --cflags libusb-1.0`
diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index e49c0bea6ca4..5f9c7ff3a458 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -46,6 +46,10 @@
 #define FT_DCD	0xee
 #define FT_LOAD_ONLY	0x00
 
+#ifndef UTS_RELEASE
+#define UTS_RELEASE "unknown"
+#endif
+
 /*
  * comment from libusb:
  * As per the USB 3.0 specs, the current maximum limit for the depth is 7.
@@ -1526,9 +1530,15 @@ static void usage(const char *prgname)
 		"-p <devpath> Specify device path: <bus>-<port>[.<port>]...\n"
 		"-s           skip DCD included in image\n"
 		"-v           verbose (give multiple times to increase)\n"
+		"--version    display version number\n"
 		"-h           this help\n", prgname);
 }
 
+static void version(const char *prgname)
+{
+	fprintf(stderr, "%s %s\n", prgname, UTS_RELEASE);
+}
+
 int main(int argc, char *argv[])
 {
 	libusb_device **devs;
@@ -1544,10 +1554,20 @@ int main(int argc, char *argv[])
 	char *initfile = NULL;
 	char *devpath = NULL;
 	char *devtype = NULL;
+	int opt_version = 0;
+	struct option long_options[] = {
+		{"version", no_argument, &opt_version, 1},
+		{ }
+	};
 
 	w.do_dcd_once = 1;
 
-	while ((opt = getopt(argc, argv, "cvhd:i:p:s")) != -1) {
+	while ((opt = getopt_long(argc, argv, "cvhd:i:p:s", long_options, NULL)) != -1) {
+		if (opt_version) {
+			version(argv[0]);
+			exit(EXIT_SUCCESS);
+		}
+
 		switch (opt) {
 		case 'c':
 			verify = 1;
-- 
2.39.2




  parent reply	other threads:[~2023-05-05 15:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 15:52 [PATCH v2 0/3] Add displaying a version number in imx-usb-loader Johannes Zink
2023-05-05 15:52 ` [PATCH v2 1/3] imx-usb-loader: exit with success when displaying help on purpose Johannes Zink
2023-05-05 15:52 ` [PATCH v2 2/3] imx-usb-loader: use proper return code macros Johannes Zink
2023-05-05 15:52 ` Johannes Zink [this message]
2023-05-09  7:22 ` [PATCH v2 0/3] Add displaying a version number in imx-usb-loader Sascha Hauer

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=20230505155248.2261867-4-j.zink@pengutronix.de \
    --to=j.zink@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=patchwork-jzi@pengutronix.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