Commit 24fee61e authored by Juan Castillo's avatar Juan Castillo
Browse files

fip_create: miscellaneous improvements to source code

This patch introduces the following improvements:

  * Global variables in fip_create.c declared static.
  * Flags to signal the requested actions (do_dump, do_pack) made
    global.
  * The ToC is printed at the end of the main funcion, after the FIP
    has been created/updated, not in the parse_cmdline() function.
  * Short format added to the command line options (-d,--dump;
    -h,--help).
  * Help message updated.

Change-Id: I5f08273c76f1de45fe597e290bee4b60aa404df9
parent 85320724
...@@ -40,12 +40,15 @@ ...@@ -40,12 +40,15 @@
/* Values returned by getopt() as part of the command line parsing */ /* Values returned by getopt() as part of the command line parsing */
#define OPT_TOC_ENTRY 0 #define OPT_TOC_ENTRY 0
#define OPT_DUMP 1 #define OPT_DUMP 'd'
#define OPT_HELP 2 #define OPT_HELP 'h'
#define OPT_STR "dh"
file_info_t files[MAX_FILES]; static file_info_t files[MAX_FILES];
unsigned file_info_count = 0; static unsigned file_info_count;
uuid_t uuid_null = {0}; static uuid_t uuid_null = {0};
static int do_dump;
static int do_pack;
/* /*
* TODO: Add ability to specify and flag different file types. * TODO: Add ability to specify and flag different file types.
...@@ -118,12 +121,13 @@ static void print_usage(void) ...@@ -118,12 +121,13 @@ static void print_usage(void)
{ {
entry_lookup_list_t *entry = toc_entry_lookup_list; entry_lookup_list_t *entry = toc_entry_lookup_list;
printf("Usage: fip_create [options] FIP_FILENAME\n\n"); printf("\nThis tool is used to create a Firmware Image Package.\n\n");
printf("\tThis tool is used to create a Firmware Image Package.\n\n"); printf("Usage:\n");
printf("\tfip_create [options] FIP_FILENAME\n\n");
printf("Options:\n"); printf("Options:\n");
printf("\t--help: Print this help message and exit\n"); printf("\t-h,--help: Print this help message and exit\n");
printf("\t--dump: Print contents of FIP\n\n"); printf("\t-d,--dump: Print contents of FIP after update\n");
printf("\tComponents that can be added/updated:\n"); printf("Components that can be added/updated:\n");
for (; entry->command_line_name != NULL; entry++) { for (; entry->command_line_name != NULL; entry++) {
printf("\t--%s%s\t\t%s", printf("\t--%s%s\t\t%s",
entry->command_line_name, entry->command_line_name,
...@@ -131,6 +135,7 @@ static void print_usage(void) ...@@ -131,6 +135,7 @@ static void print_usage(void)
entry->name); entry->name);
printf("\n"); printf("\n");
} }
printf("\n");
} }
...@@ -528,7 +533,7 @@ static char *get_filename(int argc, char **argv, struct option *options) ...@@ -528,7 +533,7 @@ static char *get_filename(int argc, char **argv, struct option *options)
*/ */
optind = 1; optind = 1;
while (1) { while (1) {
c = getopt_long(argc, argv, "", options, NULL); c = getopt_long(argc, argv, OPT_STR, options, NULL);
if (c == -1) if (c == -1)
break; break;
...@@ -549,19 +554,17 @@ static char *get_filename(int argc, char **argv, struct option *options) ...@@ -549,19 +554,17 @@ static char *get_filename(int argc, char **argv, struct option *options)
/* Work through command-line options */ /* Work through command-line options */
static int parse_cmdline(int argc, char **argv, struct option *options, static int parse_cmdline(int argc, char **argv, struct option *options)
int *do_pack)
{ {
int c; int c;
int status = 0; int status = 0;
int option_index = 0; int option_index = 0;
entry_lookup_list_t *lookup_entry; entry_lookup_list_t *lookup_entry;
int do_dump = 0;
/* restart parse to process all options. starts at 1. */ /* restart parse to process all options. starts at 1. */
optind = 1; optind = 1;
while (1) { while (1) {
c = getopt_long(argc, argv, "", options, &option_index); c = getopt_long(argc, argv, OPT_STR, options, &option_index);
if (c == -1) if (c == -1)
break; break;
...@@ -578,7 +581,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options, ...@@ -578,7 +581,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options,
return status; return status;
} else { } else {
/* Update package */ /* Update package */
*do_pack = 1; do_pack = 1;
} }
} }
} }
...@@ -586,7 +589,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options, ...@@ -586,7 +589,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options,
case OPT_DUMP: case OPT_DUMP:
do_dump = 1; do_dump = 1;
continue; break;
case OPT_HELP: case OPT_HELP:
print_usage(); print_usage();
...@@ -598,12 +601,6 @@ static int parse_cmdline(int argc, char **argv, struct option *options, ...@@ -598,12 +601,6 @@ static int parse_cmdline(int argc, char **argv, struct option *options,
} }
} }
/* Do not dump toc if we have an error as it could hide the error */
if ((status == 0) && (do_dump)) {
dump_toc();
}
return status; return status;
} }
...@@ -613,7 +610,6 @@ int main(int argc, char **argv) ...@@ -613,7 +610,6 @@ int main(int argc, char **argv)
int i; int i;
int status; int status;
char *fip_filename; char *fip_filename;
int do_pack = 0;
/* Clear file list table. */ /* Clear file list table. */
memset(files, 0, sizeof(files)); memset(files, 0, sizeof(files));
...@@ -677,7 +673,7 @@ int main(int argc, char **argv) ...@@ -677,7 +673,7 @@ int main(int argc, char **argv)
} }
/* Work through provided program arguments and perform actions */ /* Work through provided program arguments and perform actions */
status = parse_cmdline(argc, argv, long_options, &do_pack); status = parse_cmdline(argc, argv, long_options);
if (status != 0) { if (status != 0) {
return status; return status;
}; };
...@@ -699,5 +695,10 @@ int main(int argc, char **argv) ...@@ -699,5 +695,10 @@ int main(int argc, char **argv)
} }
} }
/* Do not dump toc if we have an error as it could hide the error */
if ((status == 0) && (do_dump)) {
dump_toc();
}
return status; return status;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment