From b2142963ef7391229dbe5021d72bbb209f53a8dd Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Sat, 9 Nov 2019 15:28:22 +0100 Subject: ARM: zynq: use getopt in zynq_mkimage Makes extending the command line much easier. Signed-off-by: Lucas Stach Signed-off-by: Sascha Hauer --- 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 e162aafae3..cc0cf6d2df 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 a096b834d1..905d6fc69a 100644 --- a/scripts/zynq_mkimage.c +++ b/scripts/zynq_mkimage.c @@ -14,33 +14,58 @@ #include #include +#include #include #include #include #include +static char *prgname; + static void usage(char *name) { - printf("Usage: %s barebox-flash-image \n", name); + fprintf(stderr, "usage: %s [OPTIONS]\n\n" + "-f input image file\n" + "-o 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"); -- cgit v1.2.3