Merge "fiptool: return zero status on help and help <command>" into integration

This commit is contained in:
joanna.farley 2020-07-16 14:02:16 +00:00 committed by TrustedFirmware Code Review
commit 5ac9281388
2 changed files with 38 additions and 38 deletions

View File

@ -24,17 +24,17 @@
#define OPT_ALIGN 2 #define OPT_ALIGN 2
static int info_cmd(int argc, char *argv[]); static int info_cmd(int argc, char *argv[]);
static void info_usage(void); static void info_usage(int);
static int create_cmd(int argc, char *argv[]); static int create_cmd(int argc, char *argv[]);
static void create_usage(void); static void create_usage(int);
static int update_cmd(int argc, char *argv[]); static int update_cmd(int argc, char *argv[]);
static void update_usage(void); static void update_usage(int);
static int unpack_cmd(int argc, char *argv[]); static int unpack_cmd(int argc, char *argv[]);
static void unpack_usage(void); static void unpack_usage(int);
static int remove_cmd(int argc, char *argv[]); static int remove_cmd(int argc, char *argv[]);
static void remove_usage(void); static void remove_usage(int);
static int version_cmd(int argc, char *argv[]); static int version_cmd(int argc, char *argv[]);
static void version_usage(void); static void version_usage(int);
static int help_cmd(int argc, char *argv[]); static int help_cmd(int argc, char *argv[]);
static void usage(void); static void usage(void);
@ -448,7 +448,7 @@ static int info_cmd(int argc, char *argv[])
fip_toc_header_t toc_header; fip_toc_header_t toc_header;
if (argc != 2) if (argc != 2)
info_usage(); info_usage(EXIT_FAILURE);
argc--, argv++; argc--, argv++;
parse_fip(argv[0], &toc_header); parse_fip(argv[0], &toc_header);
@ -487,10 +487,10 @@ static int info_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void info_usage(void) static void info_usage(int exit_status)
{ {
printf("fiptool info FIP_FILENAME\n"); printf("fiptool info FIP_FILENAME\n");
exit(1); exit(exit_status);
} }
static int pack_images(const char *filename, uint64_t toc_flags, unsigned long align) static int pack_images(const char *filename, uint64_t toc_flags, unsigned long align)
@ -669,7 +669,7 @@ static int create_cmd(int argc, char *argv[])
unsigned long align = 1; unsigned long align = 1;
if (argc < 2) if (argc < 2)
create_usage(); create_usage(EXIT_FAILURE);
opts = fill_common_opts(opts, &nr_opts, required_argument); opts = fill_common_opts(opts, &nr_opts, required_argument);
opts = add_opt(opts, &nr_opts, "plat-toc-flags", required_argument, opts = add_opt(opts, &nr_opts, "plat-toc-flags", required_argument,
@ -710,7 +710,7 @@ static int create_cmd(int argc, char *argv[])
if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
filename[0] == '\0') filename[0] == '\0')
create_usage(); create_usage(EXIT_FAILURE);
desc = lookup_image_desc_from_uuid(&uuid); desc = lookup_image_desc_from_uuid(&uuid);
if (desc == NULL) { if (desc == NULL) {
@ -722,7 +722,7 @@ static int create_cmd(int argc, char *argv[])
break; break;
} }
default: default:
create_usage(); create_usage(EXIT_FAILURE);
} }
} }
argc -= optind; argc -= optind;
@ -730,7 +730,7 @@ static int create_cmd(int argc, char *argv[])
free(opts); free(opts);
if (argc == 0) if (argc == 0)
create_usage(); create_usage(EXIT_SUCCESS);
update_fip(); update_fip();
@ -738,7 +738,7 @@ static int create_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void create_usage(void) static void create_usage(int exit_status)
{ {
toc_entry_t *toc_entry = toc_entries; toc_entry_t *toc_entry = toc_entries;
@ -753,7 +753,7 @@ static void create_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++) for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name, printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name,
toc_entry->name); toc_entry->name);
exit(1); exit(exit_status);
} }
static int update_cmd(int argc, char *argv[]) static int update_cmd(int argc, char *argv[])
@ -767,7 +767,7 @@ static int update_cmd(int argc, char *argv[])
int pflag = 0; int pflag = 0;
if (argc < 2) if (argc < 2)
update_usage(); update_usage(EXIT_FAILURE);
opts = fill_common_opts(opts, &nr_opts, required_argument); opts = fill_common_opts(opts, &nr_opts, required_argument);
opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN);
@ -807,7 +807,7 @@ static int update_cmd(int argc, char *argv[])
if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
filename[0] == '\0') filename[0] == '\0')
update_usage(); update_usage(EXIT_FAILURE);
desc = lookup_image_desc_from_uuid(&uuid); desc = lookup_image_desc_from_uuid(&uuid);
if (desc == NULL) { if (desc == NULL) {
@ -825,7 +825,7 @@ static int update_cmd(int argc, char *argv[])
snprintf(outfile, sizeof(outfile), "%s", optarg); snprintf(outfile, sizeof(outfile), "%s", optarg);
break; break;
default: default:
update_usage(); update_usage(EXIT_FAILURE);
} }
} }
argc -= optind; argc -= optind;
@ -833,7 +833,7 @@ static int update_cmd(int argc, char *argv[])
free(opts); free(opts);
if (argc == 0) if (argc == 0)
update_usage(); update_usage(EXIT_SUCCESS);
if (outfile[0] == '\0') if (outfile[0] == '\0')
snprintf(outfile, sizeof(outfile), "%s", argv[0]); snprintf(outfile, sizeof(outfile), "%s", argv[0]);
@ -851,7 +851,7 @@ static int update_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void update_usage(void) static void update_usage(int exit_status)
{ {
toc_entry_t *toc_entry = toc_entries; toc_entry_t *toc_entry = toc_entries;
@ -867,7 +867,7 @@ static void update_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++) for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name, printf(" --%-16s FILENAME\t%s\n", toc_entry->cmdline_name,
toc_entry->name); toc_entry->name);
exit(1); exit(exit_status);
} }
static int unpack_cmd(int argc, char *argv[]) static int unpack_cmd(int argc, char *argv[])
@ -880,7 +880,7 @@ static int unpack_cmd(int argc, char *argv[])
int unpack_all = 1; int unpack_all = 1;
if (argc < 2) if (argc < 2)
unpack_usage(); unpack_usage(EXIT_FAILURE);
opts = fill_common_opts(opts, &nr_opts, required_argument); opts = fill_common_opts(opts, &nr_opts, required_argument);
opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b');
@ -915,7 +915,7 @@ static int unpack_cmd(int argc, char *argv[])
if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 || if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
filename[0] == '\0') filename[0] == '\0')
unpack_usage(); unpack_usage(EXIT_FAILURE);
desc = lookup_image_desc_from_uuid(&uuid); desc = lookup_image_desc_from_uuid(&uuid);
if (desc == NULL) { if (desc == NULL) {
@ -934,7 +934,7 @@ static int unpack_cmd(int argc, char *argv[])
snprintf(outdir, sizeof(outdir), "%s", optarg); snprintf(outdir, sizeof(outdir), "%s", optarg);
break; break;
default: default:
unpack_usage(); unpack_usage(EXIT_FAILURE);
} }
} }
argc -= optind; argc -= optind;
@ -942,7 +942,7 @@ static int unpack_cmd(int argc, char *argv[])
free(opts); free(opts);
if (argc == 0) if (argc == 0)
unpack_usage(); unpack_usage(EXIT_SUCCESS);
parse_fip(argv[0], NULL); parse_fip(argv[0], NULL);
@ -986,7 +986,7 @@ static int unpack_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void unpack_usage(void) static void unpack_usage(int exit_status)
{ {
toc_entry_t *toc_entry = toc_entries; toc_entry_t *toc_entry = toc_entries;
@ -1003,7 +1003,7 @@ static void unpack_usage(void)
toc_entry->name); toc_entry->name);
printf("\n"); printf("\n");
printf("If no options are provided, all images will be unpacked.\n"); printf("If no options are provided, all images will be unpacked.\n");
exit(1); exit(exit_status);
} }
static int remove_cmd(int argc, char *argv[]) static int remove_cmd(int argc, char *argv[])
@ -1017,7 +1017,7 @@ static int remove_cmd(int argc, char *argv[])
int fflag = 0; int fflag = 0;
if (argc < 2) if (argc < 2)
remove_usage(); remove_usage(EXIT_FAILURE);
opts = fill_common_opts(opts, &nr_opts, no_argument); opts = fill_common_opts(opts, &nr_opts, no_argument);
opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN);
@ -1053,7 +1053,7 @@ static int remove_cmd(int argc, char *argv[])
filename, sizeof(filename)); filename, sizeof(filename));
if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0) if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0)
remove_usage(); remove_usage(EXIT_FAILURE);
desc = lookup_image_desc_from_uuid(&uuid); desc = lookup_image_desc_from_uuid(&uuid);
if (desc == NULL) { if (desc == NULL) {
@ -1071,7 +1071,7 @@ static int remove_cmd(int argc, char *argv[])
snprintf(outfile, sizeof(outfile), "%s", optarg); snprintf(outfile, sizeof(outfile), "%s", optarg);
break; break;
default: default:
remove_usage(); remove_usage(EXIT_FAILURE);
} }
} }
argc -= optind; argc -= optind;
@ -1079,7 +1079,7 @@ static int remove_cmd(int argc, char *argv[])
free(opts); free(opts);
if (argc == 0) if (argc == 0)
remove_usage(); remove_usage(EXIT_SUCCESS);
if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag)
log_errx("File %s already exists, use --force to overwrite it", log_errx("File %s already exists, use --force to overwrite it",
@ -1110,7 +1110,7 @@ static int remove_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void remove_usage(void) static void remove_usage(int exit_status)
{ {
toc_entry_t *toc_entry = toc_entries; toc_entry_t *toc_entry = toc_entries;
@ -1126,7 +1126,7 @@ static void remove_usage(void)
for (; toc_entry->cmdline_name != NULL; toc_entry++) for (; toc_entry->cmdline_name != NULL; toc_entry++)
printf(" --%-16s\t%s\n", toc_entry->cmdline_name, printf(" --%-16s\t%s\n", toc_entry->cmdline_name,
toc_entry->name); toc_entry->name);
exit(1); exit(exit_status);
} }
static int version_cmd(int argc, char *argv[]) static int version_cmd(int argc, char *argv[])
@ -1140,10 +1140,10 @@ static int version_cmd(int argc, char *argv[])
return 0; return 0;
} }
static void version_usage(void) static void version_usage(int exit_status)
{ {
printf("fiptool version\n"); printf("fiptool version\n");
exit(1); exit(exit_status);
} }
static int help_cmd(int argc, char *argv[]) static int help_cmd(int argc, char *argv[])
@ -1157,7 +1157,7 @@ static int help_cmd(int argc, char *argv[])
for (i = 0; i < NELEM(cmds); i++) { for (i = 0; i < NELEM(cmds); i++) {
if (strcmp(cmds[i].name, argv[0]) == 0 && if (strcmp(cmds[i].name, argv[0]) == 0 &&
cmds[i].usage != NULL) cmds[i].usage != NULL)
cmds[i].usage(); cmds[i].usage(EXIT_SUCCESS);
} }
if (i == NELEM(cmds)) if (i == NELEM(cmds))
printf("No help for subcommand '%s'\n", argv[0]); printf("No help for subcommand '%s'\n", argv[0]);
@ -1178,7 +1178,7 @@ static void usage(void)
printf(" remove\tRemove images from FIP.\n"); printf(" remove\tRemove images from FIP.\n");
printf(" version\tShow fiptool version.\n"); printf(" version\tShow fiptool version.\n");
printf(" help\t\tShow help for given command.\n"); printf(" help\t\tShow help for given command.\n");
exit(1); exit(EXIT_SUCCESS);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -48,7 +48,7 @@ typedef struct image {
typedef struct cmd { typedef struct cmd {
char *name; char *name;
int (*handler)(int, char **); int (*handler)(int, char **);
void (*usage)(void); void (*usage)(int);
} cmd_t; } cmd_t;
#endif /* FIPTOOL_H */ #endif /* FIPTOOL_H */