summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucas Stach <dev@lynxeye.de>2019-11-09 15:28:22 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-11-11 09:15:55 +0100
commitb2142963ef7391229dbe5021d72bbb209f53a8dd (patch)
tree5e7eb21d6d962950b4acf644c7f21d841046df48
parentd74176dee9b7d36258c5c69fe63dcbf4d795d6ff (diff)
downloadbarebox-b2142963ef7391229dbe5021d72bbb209f53a8dd.tar.gz
ARM: zynq: use getopt in zynq_mkimage
Makes extending the command line much easier. Signed-off-by: Lucas Stach <dev@lynxeye.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--images/Makefile.zynq4
-rw-r--r--scripts/zynq_mkimage.c43
2 files changed, 37 insertions, 10 deletions
diff --git a/images/Makefile.zynq b/images/Makefile.zynq
index e162aaf..cc0cf6d 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 a096b83..905d6fc 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");