summaryrefslogtreecommitdiff
path: root/util/cbfstool/fmaptool.c
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@chromium.org>2016-01-20 15:29:30 +0100
committerPatrick Georgi <pgeorgi@google.com>2016-01-21 16:11:44 +0100
commitc3771b0f8f66942a617299e013b24ac2d6cfa8a1 (patch)
tree15df0815da2817a635537a20b1ce020a79a8ce50 /util/cbfstool/fmaptool.c
parent6966759edb84f5158f3daad4098a18d11f699cf7 (diff)
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>
Diffstat (limited to 'util/cbfstool/fmaptool.c')
-rw-r--r--util/cbfstool/fmaptool.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/util/cbfstool/fmaptool.c b/util/cbfstool/fmaptool.c
index c8397073f2..c3b4a673a1 100644
--- a/util/cbfstool/fmaptool.c
+++ b/util/cbfstool/fmaptool.c
@@ -45,7 +45,7 @@ static void usage(const char *invoked_as)
stderr);
fputs("\nUSAGE:\n", 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);
fputs("\nMANDATORY ARGUMENTS:\n", stderr);
fprintf(stderr,
@@ -56,6 +56,8 @@ static void usage(const char *invoked_as)
fprintf(stderr,
"-h\tAlso produce a C header defining %s to the FMAP section's flash offset.\n",
HEADER_FMAP_OFFSET);
+ fprintf(stderr,
+ "-R\tAlso produce a text file listing the CBFS regions, comma separated.\n");
fputs("\nOUTPUT:\n", stderr);
fputs("A successful invocation prints a summary of work done to standard error, and a comma-separated list\n",
stderr);
@@ -63,7 +65,7 @@ static void usage(const char *invoked_as)
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();
assert(cbfs_it);
@@ -73,11 +75,11 @@ static void list_cbfs_section_names(void)
const char *cur_name =
cbfs_sections_iterator_deref(cbfs_it)->name;
if (cbfs_sections_iterator_advance(&cbfs_it) && subsequent)
- putchar(',');
- fputs(cur_name, stdout);
+ fputc(',', out);
+ fputs(cur_name, out);
subsequent = true;
}
- putchar('\n');
+ fputc('\n', out);
}
static bool write_header(const char *out_fname,
@@ -123,15 +125,19 @@ int main(int argc, char **argv)
// Optional
const char *header_filename;
- } args = {NULL, NULL, NULL};
+ const char *region_filename;
+ } args = {NULL};
bool show_usage = false;
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) {
case 'h':
args.header_filename = optarg;
break;
+ case 'R':
+ args.region_filename = optarg;
+ break;
case ':':
fprintf(stderr, "-%c: Expected an accompanying value\n",
optopt);
@@ -233,7 +239,15 @@ int main(int argc, char **argv)
args.fmap_filename,
args.header_filename ? " (and generated header)" : "");
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);
return FMAPTOOL_EXIT_SUCCESS;