Skip to content

Commit

Permalink
Merge pull request #710 from dp-arm/dp/fiptool-usage
Browse files Browse the repository at this point in the history
fiptool: Invoke command specific usage function
  • Loading branch information
danh-arm committed Sep 19, 2016
2 parents 92455d8 + 85ee277 commit 8874924
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions tools/fiptool/fiptool.c
Expand Up @@ -373,7 +373,7 @@ static int info_cmd(int argc, char *argv[])
int i;

if (argc != 2)
usage();
info_usage();
argc--, argv++;

parse_fip(argv[0], &toc_header);
Expand Down Expand Up @@ -421,6 +421,7 @@ static int info_cmd(int argc, char *argv[])
static void info_usage(void)
{
printf("fiptool info FIP_FILENAME\n");
exit(1);
}

static int pack_images(char *filename, uint64_t toc_flags)
Expand Down Expand Up @@ -554,7 +555,7 @@ static int create_cmd(int argc, char *argv[])
int i;

if (argc < 2)
usage();
create_usage();

i = fill_common_opts(opts, required_argument);
add_opt(opts, i, "plat-toc-flags", required_argument,
Expand Down Expand Up @@ -583,14 +584,14 @@ static int create_cmd(int argc, char *argv[])
parse_plat_toc_flags(optarg, &toc_flags);
break;
default:
usage();
create_usage();
}
}
argc -= optind;
argv += optind;

if (argc == 0)
usage();
create_usage();

update_fip();

Expand All @@ -611,6 +612,7 @@ static void create_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name,
toc_entry->name);
exit(1);
}

static int update_cmd(int argc, char *argv[])
Expand All @@ -623,7 +625,7 @@ static int update_cmd(int argc, char *argv[])
int i;

if (argc < 2)
usage();
update_usage();

i = fill_common_opts(opts, required_argument);
add_opt(opts, i, "out", required_argument, 'o');
Expand Down Expand Up @@ -658,14 +660,14 @@ static int update_cmd(int argc, char *argv[])
snprintf(outfile, sizeof(outfile), "%s", optarg);
break;
default:
usage();
update_usage();
}
}
argc -= optind;
argv += optind;

if (argc == 0)
usage();
update_usage();

if (outfile[0] == '\0')
snprintf(outfile, sizeof(outfile), "%s", argv[0]);
Expand Down Expand Up @@ -698,6 +700,7 @@ static void update_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name,
toc_entry->name);
exit(1);
}

static int unpack_cmd(int argc, char *argv[])
Expand All @@ -710,7 +713,7 @@ static int unpack_cmd(int argc, char *argv[])
int i;

if (argc < 2)
usage();
unpack_usage();

i = fill_common_opts(opts, required_argument);
add_opt(opts, i, "force", no_argument, 'f');
Expand Down Expand Up @@ -740,14 +743,14 @@ static int unpack_cmd(int argc, char *argv[])
snprintf(outdir, sizeof(outdir), "%s", optarg);
break;
default:
usage();
unpack_usage();
}
}
argc -= optind;
argv += optind;

if (argc == 0)
usage();
unpack_usage();

parse_fip(argv[0], NULL);

Expand Down Expand Up @@ -822,6 +825,7 @@ static void unpack_usage(void)
toc_entry->name);
fputc('\n', stderr);
printf("If no options are provided, all images will be unpacked.\n");
exit(1);
}

static int remove_cmd(int argc, char *argv[])
Expand All @@ -834,7 +838,7 @@ static int remove_cmd(int argc, char *argv[])
int i;

if (argc < 2)
usage();
remove_usage();

i = fill_common_opts(opts, no_argument);
add_opt(opts, i, "force", no_argument, 'f');
Expand All @@ -860,14 +864,14 @@ static int remove_cmd(int argc, char *argv[])
snprintf(outfile, sizeof(outfile), "%s", optarg);
break;
default:
usage();
remove_usage();
}
}
argc -= optind;
argv += optind;

if (argc == 0)
usage();
remove_usage();

if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag)
log_errx("File %s already exists, use --force to overwrite it",
Expand Down Expand Up @@ -912,6 +916,7 @@ static void remove_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s\t%s\n", toc_entry->cmdline_name,
toc_entry->name);
exit(1);
}

static int version_cmd(int argc, char *argv[])
Expand All @@ -928,6 +933,7 @@ static int version_cmd(int argc, char *argv[])
static void version_usage(void)
{
printf("fiptool version\n");
exit(1);
}

static int help_cmd(int argc, char *argv[])
Expand All @@ -940,10 +946,8 @@ static int help_cmd(int argc, char *argv[])

for (i = 0; i < NELEM(cmds); i++) {
if (strcmp(cmds[i].name, argv[0]) == 0 &&
cmds[i].usage != NULL) {
cmds[i].usage != NULL)
cmds[i].usage();
break;
}
}
if (i == NELEM(cmds))
printf("No help for subcommand '%s'\n", argv[0]);
Expand Down

0 comments on commit 8874924

Please sign in to comment.