fmaptool: emit list of CBFS regions on request

The CBFS flag in fmd files isn't stored in the fmap, so allow storing it
out of band using the -R option.

Change-Id: I342772878d7f8ce350de1a32dc7b2a5b07d6617d
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: https://review.coreboot.org/13058
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Patrick Georgi 2016-01-20 15:29:30 +01:00 committed by Patrick Georgi
parent 6966759edb
commit c3771b0f8f
1 changed files with 22 additions and 8 deletions

View File

@ -45,7 +45,7 @@ static void usage(const char *invoked_as)
stderr); stderr);
fputs("\nUSAGE:\n", stderr); fputs("\nUSAGE:\n", stderr);
fprintf(stderr, fprintf(stderr,
"\t%s [-h <header output file>] <fmd input file> <binary output file>\n", "\t%s [-h <header output file>] [-R <region output file>] <fmd input file> <binary output file>\n",
invoked_as); invoked_as);
fputs("\nMANDATORY ARGUMENTS:\n", stderr); fputs("\nMANDATORY ARGUMENTS:\n", stderr);
fprintf(stderr, fprintf(stderr,
@ -56,6 +56,8 @@ static void usage(const char *invoked_as)
fprintf(stderr, fprintf(stderr,
"-h\tAlso produce a C header defining %s to the FMAP section's flash offset.\n", "-h\tAlso produce a C header defining %s to the FMAP section's flash offset.\n",
HEADER_FMAP_OFFSET); HEADER_FMAP_OFFSET);
fprintf(stderr,
"-R\tAlso produce a text file listing the CBFS regions, comma separated.\n");
fputs("\nOUTPUT:\n", stderr); fputs("\nOUTPUT:\n", stderr);
fputs("A successful invocation prints a summary of work done to standard error, and a comma-separated list\n", fputs("A successful invocation prints a summary of work done to standard error, and a comma-separated list\n",
stderr); stderr);
@ -63,7 +65,7 @@ static void usage(const char *invoked_as)
stderr); stderr);
} }
static void list_cbfs_section_names(void) static void list_cbfs_section_names(FILE *out)
{ {
cbfs_section_iterator_t cbfs_it = cbfs_sections_iterator(); cbfs_section_iterator_t cbfs_it = cbfs_sections_iterator();
assert(cbfs_it); assert(cbfs_it);
@ -73,11 +75,11 @@ static void list_cbfs_section_names(void)
const char *cur_name = const char *cur_name =
cbfs_sections_iterator_deref(cbfs_it)->name; cbfs_sections_iterator_deref(cbfs_it)->name;
if (cbfs_sections_iterator_advance(&cbfs_it) && subsequent) if (cbfs_sections_iterator_advance(&cbfs_it) && subsequent)
putchar(','); fputc(',', out);
fputs(cur_name, stdout); fputs(cur_name, out);
subsequent = true; subsequent = true;
} }
putchar('\n'); fputc('\n', out);
} }
static bool write_header(const char *out_fname, static bool write_header(const char *out_fname,
@ -123,15 +125,19 @@ int main(int argc, char **argv)
// Optional // Optional
const char *header_filename; const char *header_filename;
} args = {NULL, NULL, NULL}; const char *region_filename;
} args = {NULL};
bool show_usage = false; bool show_usage = false;
int each_arg; int each_arg;
while (!show_usage && (each_arg = getopt(argc, argv, ":h:")) != -1) { while (!show_usage && (each_arg = getopt(argc, argv, ":h:R:")) != -1) {
switch (each_arg) { switch (each_arg) {
case 'h': case 'h':
args.header_filename = optarg; args.header_filename = optarg;
break; break;
case 'R':
args.region_filename = optarg;
break;
case ':': case ':':
fprintf(stderr, "-%c: Expected an accompanying value\n", fprintf(stderr, "-%c: Expected an accompanying value\n",
optopt); optopt);
@ -233,7 +239,15 @@ int main(int argc, char **argv)
args.fmap_filename, args.fmap_filename,
args.header_filename ? " (and generated header)" : ""); args.header_filename ? " (and generated header)" : "");
fputs("The sections containing CBFSes are: ", stderr); fputs("The sections containing CBFSes are: ", stderr);
list_cbfs_section_names(); list_cbfs_section_names(stdout);
if (args.region_filename) {
FILE *region_file = fopen(args.region_filename, "w");
if (region_file == NULL)
return FMAPTOOL_EXIT_FAILED_WRITING_OUTPUT;
list_cbfs_section_names(region_file);
fclose(region_file);
}
full_fmd_cleanup(&descriptor); full_fmd_cleanup(&descriptor);
return FMAPTOOL_EXIT_SUCCESS; return FMAPTOOL_EXIT_SUCCESS;