summaryrefslogtreecommitdiff
path: root/util/cbfstool
diff options
context:
space:
mode:
authorFelix Held <felix-coreboot@felixheld.de>2020-09-18 19:01:16 +0200
committerFelix Held <felix-coreboot@felixheld.de>2020-09-23 13:39:21 +0000
commitd57c1286de8a2537d7ba2ff81b5b9a425f0eaecc (patch)
tree6eb622598420180349a64dbf9230f6dc1abbd336 /util/cbfstool
parentc99bd4a6c991d7cd9d9cc3ffabb1a0a63e21c83f (diff)
util/cbfstool/fmaptool: generate defines for all fmap sections
Add defines for the start and size of the FMAP sections to the optionally generated header file. For the defines the name of the corresponding FMAP section is used without the full path, since every section name should be unique anyway as documented here: Documentation/lib/flashmap.md BUG=b:157068645 TEST=Generated header file contains expected defines. BRANCH=zork Change-Id: Ie31161cfd304b69a3cb4bb366bf365d979e77c64 Signed-off-by: Felix Held <felix-coreboot@felixheld.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/45594 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'util/cbfstool')
-rw-r--r--util/cbfstool/fmaptool.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/util/cbfstool/fmaptool.c b/util/cbfstool/fmaptool.c
index aace5aea33..9f5803d8ee 100644
--- a/util/cbfstool/fmaptool.c
+++ b/util/cbfstool/fmaptool.c
@@ -71,6 +71,29 @@ static void list_cbfs_section_names(FILE *out)
fputc('\n', out);
}
+static void write_header_fmap_sections(FILE *header, const struct flashmap_descriptor *root,
+ unsigned int offset)
+{
+ assert(root);
+ /*
+ * The offset may only be unknown for the root node in a system where the flash isn't
+ * memory-mapped.
+ */
+ if (!root->offset_known && offset != 0)
+ return;
+
+ const unsigned int current_offset = offset + (root->offset_known ? root->offset : 0);
+ fprintf(header, "#define FMAP_SECTION_%s_START %#x\n", root->name, current_offset);
+
+ if (!root->size_known)
+ return;
+
+ fprintf(header, "#define FMAP_SECTION_%s_SIZE %#x\n", root->name, root->size);
+
+ fmd_foreach_child(child, root)
+ write_header_fmap_sections(header, child, current_offset);
+}
+
static bool write_header(const char *out_fname,
const struct flashmap_descriptor *root,
const int fmap_size)
@@ -93,6 +116,9 @@ static bool write_header(const char *out_fname,
fprintf(header, "#define %s %#x\n", HEADER_FMAP_OFFSET, fmap_offset);
fprintf(header, "#define %s %#x\n\n", HEADER_FMAP_SIZE, fmap_size);
+ write_header_fmap_sections(header, root, 0);
+ fputs("\n", header);
+
fputs("#endif\n", header);
fclose(header);