summaryrefslogtreecommitdiffstats
path: root/scripts
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 /scripts
parentd74176dee9b7d36258c5c69fe63dcbf4d795d6ff (diff)
downloadbarebox-b2142963ef7391229dbe5021d72bbb209f53a8dd.tar.gz
barebox-b2142963ef7391229dbe5021d72bbb209f53a8dd.tar.xz
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/zynq_mkimage.c43
1 files changed, 34 insertions, 9 deletions
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 <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");