From d57c1286de8a2537d7ba2ff81b5b9a425f0eaecc Mon Sep 17 00:00:00 2001 From: Felix Held Date: Fri, 18 Sep 2020 19:01:16 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/45594 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Furquan Shaikh --- util/cbfstool/fmaptool.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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); -- cgit v1.2.3