scripts/omap_signGP: add getopt
Instead of using positional arguments add proper getopt support. This also adds a help text. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
41dd510b5c
commit
0b342aca51
|
@ -142,8 +142,7 @@ KBUILD_IMAGE := barebox.s5p
|
||||||
endif
|
endif
|
||||||
|
|
||||||
quiet_cmd_mlo ?= IFT $@
|
quiet_cmd_mlo ?= IFT $@
|
||||||
cmd_mlo ?= scripts/omap_signGP $< $(TEXT_BASE) 1; \
|
cmd_mlo ?= scripts/omap_signGP -o MLO -l $(TEXT_BASE) -c $<
|
||||||
test -e $<.ift && mv $<.ift MLO
|
|
||||||
|
|
||||||
MLO: $(KBUILD_BINARY)
|
MLO: $(KBUILD_BINARY)
|
||||||
$(call if_changed,mlo)
|
$(call if_changed,mlo)
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
|
||||||
#undef CH_WITH_CHRAM
|
#undef CH_WITH_CHRAM
|
||||||
|
@ -233,6 +234,18 @@ static struct ch_chsettings_nochram config_header
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void usage(const char *prgname)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"usage: %s [OPTIONS] <infile>\n"
|
||||||
|
"\n"
|
||||||
|
"Options:\n"
|
||||||
|
"-o <outfile> output to <outfile>\n"
|
||||||
|
"-l <loadaddr> specify load address\n"
|
||||||
|
"-c Add config header\n"
|
||||||
|
"-h This help\n"
|
||||||
|
, prgname);
|
||||||
|
}
|
||||||
|
|
||||||
#define err(...) do { int save_errno = errno; \
|
#define err(...) do { int save_errno = errno; \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
@ -243,29 +256,43 @@ static struct ch_chsettings_nochram config_header
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char ifname[FILENAME_MAX], ofname[FILENAME_MAX], ch;
|
char *ifname, *ofname = NULL, ch;
|
||||||
FILE *ifile, *ofile;
|
FILE *ifile, *ofile;
|
||||||
unsigned long loadaddr, len;
|
unsigned long loadaddr = ~0, len;
|
||||||
struct stat sinfo;
|
struct stat sinfo;
|
||||||
int ch_add = 0;
|
int ch_add = 0;
|
||||||
|
int opt;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "o:hl:c")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'h':
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(0);
|
||||||
|
case 'o':
|
||||||
|
ofname = optarg;
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
loadaddr = strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
ch_add = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Default to x-load.bin and 0x40200800. */
|
if (loadaddr == ~0) {
|
||||||
strcpy(ifname, "x-load.bin");
|
fprintf(stderr, "no loadaddr given\n");
|
||||||
loadaddr = 0x40200800;
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if ((argc == 2) || (argc == 3) || (argc == 4))
|
if (optind == argc || !ofname) {
|
||||||
strcpy(ifname, argv[1]);
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if ((argc == 3) || (argc == 4))
|
ifname = argv[optind];
|
||||||
loadaddr = strtoul(argv[2], NULL, 16);
|
|
||||||
|
|
||||||
if (argc == 4)
|
|
||||||
ch_add = strtoul(argv[3], NULL, 16);
|
|
||||||
|
|
||||||
/* Form the output file name. */
|
|
||||||
strcpy(ofname, ifname);
|
|
||||||
strcat(ofname, ".ift");
|
|
||||||
|
|
||||||
/* Open the input file. */
|
/* Open the input file. */
|
||||||
ifile = fopen(ifname, "rb");
|
ifile = fopen(ifname, "rb");
|
||||||
|
|
Loading…
Reference in New Issue