mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <dev@lynxeye.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 03/18] ARM: zynq: use getopt in zynq_mkimage
Date: Sat,  9 Nov 2019 15:28:22 +0100	[thread overview]
Message-ID: <20191109142837.82409-3-dev@lynxeye.de> (raw)
In-Reply-To: <20191109142837.82409-1-dev@lynxeye.de>

Makes extending the command line much easier.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 images/Makefile.zynq   |  4 +++-
 scripts/zynq_mkimage.c | 43 +++++++++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/images/Makefile.zynq b/images/Makefile.zynq
index e162aafae336..cc0cf6d2dfa0 100644
--- a/images/Makefile.zynq
+++ b/images/Makefile.zynq
@@ -2,7 +2,9 @@
 # barebox image generation Makefile for Xilinx Zynq images
 #
 quiet_cmd_zynq_image = ZYNQIMG  $@
-      cmd_zynq_image = $(objtree)/scripts/zynq_mkimage $(subst .zynqimg,,$@) $@
+      cmd_zynq_image = \
+         $(objtree)/scripts/zynq_mkimage -f $(subst .zynqimg,,$@) -o $@
+
 $(obj)/%.zynqimg: $(obj)/% FORCE
 	$(call if_changed,zynq_image)
 
diff --git a/scripts/zynq_mkimage.c b/scripts/zynq_mkimage.c
index a096b834d156..905d6fc69a54 100644
--- a/scripts/zynq_mkimage.c
+++ b/scripts/zynq_mkimage.c
@@ -14,33 +14,58 @@
 
 #include <endian.h>
 #include <errno.h>
+#include <getopt.h>
 #include <malloc.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 
+static char *prgname;
+
 static void usage(char *name)
 {
-	printf("Usage: %s barebox-flash-image <outfile>\n", name);
+	fprintf(stderr, "usage: %s [OPTIONS]\n\n"
+			"-f <input>   input image file\n"
+			"-o <output>  output file\n"
+			"-h           this help\n", prgname);
+		exit(1);
 }
 
 int main(int argc, char *argv[])
 {
 	FILE *ifile, *ofile;
 	unsigned int *buf;
-	const char *infile;
-	const char *outfile;
+	const char *infile = NULL, *outfile = NULL;
 	struct stat st;
-	unsigned int i;
-	unsigned long sum = 0;
+	unsigned int i,sum = 0;
+	int opt;
 
-	if (argc != 3) {
-		usage(argv[0]);
+	prgname = argv[0];
+
+	while ((opt = getopt(argc, argv, "f:ho:")) != -1) {
+		switch (opt) {
+		case 'f':
+			infile = optarg;
+			break;
+		case 'o':
+			outfile = optarg;
+			break;
+		case 'h':
+			usage(argv[0]);
+		default:
+			exit(1);
+		}
+	}
+
+	if (!infile) {
+		fprintf(stderr, "input file not given\n");
 		exit(1);
 	}
 
-	infile = argv[1];
-	outfile = argv[2];
+	if (!outfile) {
+		fprintf(stderr, "output file not given\n");
+		exit(1);
+	}
 
 	if (stat(infile, &st) == -1) {
 		perror("stat");
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-11-09 14:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-09 14:28 [PATCH v2 01/18] ARM: zynq: zedboard: enable MACB driver in defconfig Lucas Stach
2019-11-09 14:28 ` [PATCH v2 02/18] ARM: zynq: add trivial image build mechanism Lucas Stach
2019-11-09 14:28 ` Lucas Stach [this message]
2019-11-09 14:28 ` [PATCH v2 04/18] ARM: zynq: move header generation to zynq_mkimage Lucas Stach
2019-11-09 14:28 ` [PATCH v2 05/18] ARM: zynq: add size check in zynq_mkimage Lucas Stach
2019-11-09 14:28 ` [PATCH v2 06/18] ARM: zynq: zedboard: provide DTB Lucas Stach
2019-11-09 14:28 ` [PATCH v2 07/18] net: macb: handle more clocks Lucas Stach
2019-11-09 14:28 ` [PATCH v2 08/18] net: macb: add Zynq compatible Lucas Stach
2019-11-09 14:28 ` [PATCH v2 09/18] ARM: zynq: move clock controller driver to drivers/clk Lucas Stach
2019-11-09 14:28 ` [PATCH v2 10/18] clk: zynq: use base address of clock controller Lucas Stach
2019-11-09 14:28 ` [PATCH v2 11/18] clk: zynq: improve PLL enable handling Lucas Stach
2019-11-09 14:28 ` [PATCH v2 12/18] clk: zynq: fix up address from DT Lucas Stach
2019-11-09 14:28 ` [PATCH v2 13/18] clk: zynq: partially sync with Linux Lucas Stach
2019-11-09 14:28 ` [PATCH v2 14/18] ARM: zynq: switch to DT based probing Lucas Stach
2019-11-09 14:28 ` [PATCH v2 15/18] clk: zynq: remove clkdevs Lucas Stach
2019-11-09 14:28 ` [PATCH v2 16/18] ARM: zynq: switch to multi-image build Lucas Stach
2019-11-09 14:28 ` [PATCH v2 17/18] bootsource: add JTAG bootsource Lucas Stach
2019-11-09 14:28 ` [PATCH v2 18/18] ARM: zynq: add bootsource detection Lucas Stach
2019-11-11  8:16 ` [PATCH v2 01/18] ARM: zynq: zedboard: enable MACB driver in defconfig 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=20191109142837.82409-3-dev@lynxeye.de \
    --to=dev@lynxeye.de \
    --cc=barebox@lists.infradead.org \
    /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