Maximilian Brune has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/73487 )
Change subject: util/ifdtool: Add option to create FMAP template ......................................................................
util/ifdtool: Add option to create FMAP template
Signed-off-by: Maximilian Brune maximilian.brune@9elements.com Change-Id: I82cb252fff456773af69943e188480a4998736fd --- M util/ifdtool/ifdtool.c 1 file changed, 79 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/87/73487/1
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index b44d1f4..6dd08f8 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -995,6 +995,57 @@ } }
+static void create_fmap_template(char *image, int size, const char *layout_fname) +{ + const frba_t *frba = find_frba(image, size); + if (!frba) + exit(EXIT_FAILURE); + + int layout_fd = open(layout_fname, O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (layout_fd == -1) { + perror("Could not open file"); + exit(EXIT_FAILURE); + } + + char *lbuf = "FLASH@##ROM_BASE## ##ROM_SIZE## {\n" \ + "\tBIOS@##BIOS_BASE## ##BIOS_SIZE## {\n" \ + "\t\t##CONSOLE_ENTRY##\n" \ + "\t\t##MRC_CACHE_ENTRY##\n" \ + "\t\t##SMMSTORE_ENTRY##\n" \ + "\t\t##SPD_CACHE_ENTRY##\n" \ + "\t\t##VPD_ENTRY##\n" \ + "\t\tFMAP@##FMAP_BASE## ##FMAP_SIZE##\n" \ + "\t\tCOREBOOT(CBFS)@##CBFS_BASE## ##CBFS_SIZE##\n" \ + "\t}\n"; + if (write(layout_fd, lbuf, strlen(lbuf)) < 0) { + perror("Could not write to file"); + exit(EXIT_FAILURE); + } + + for (unsigned int i = 0; i < max_regions; i++) { + region_t region = get_region(frba, i); + /* is region invalid? */ + if (region.size < 1) + continue; + + char buf[LAYOUT_LINELEN]; + snprintf(buf, LAYOUT_LINELEN, "\t%s@0x%X 0x%X\n", region_names[i].fmapname, region.base, region.size); + if (write(layout_fd, buf, strlen(buf)) < 0) { + perror("Could not write to file"); + exit(EXIT_FAILURE); + } + } + + if (write(layout_fd, "}", 1) < 0 ) { + perror("Could not write to file"); + exit(EXIT_FAILURE); + } + + close(layout_fd); + printf("Wrote layout to %s\n", layout_fname); +} + static void write_regions(char *image, int size) { unsigned int i; @@ -1690,6 +1741,7 @@ printf("\n" " -d | --dump: dump intel firmware descriptor\n" " -f | --layout <filename> dump regions into a flashrom layout file\n" + " -F | --fmap-layout <filename> dump IFD regions into a fmap layout template (.fmd) file\n" " -t | --validate Validate that the firmware descriptor layout matches the fmap layout\n" " -x | --extract: extract intel fd modules\n" " -i | --inject <region>:<module> inject file <module> into region <region>\n" @@ -1736,7 +1788,7 @@ int mode_dump = 0, mode_extract = 0, mode_inject = 0, mode_spifreq = 0; int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0, mode_validate = 0; int mode_layout = 0, mode_newlayout = 0, mode_density = 0, mode_setstrap = 0; - int mode_read = 0, mode_altmedisable = 0, altmedisable = 0; + int mode_read = 0, mode_altmedisable = 0, altmedisable = 0, mode_fmap_template = 0; char *region_type_string = NULL, *region_fname = NULL; const char *layout_fname = NULL; char *new_filename = NULL; @@ -1749,6 +1801,7 @@ static const struct option long_options[] = { {"dump", 0, NULL, 'd'}, {"layout", 1, NULL, 'f'}, + {"fmap-template", 1, NULL, 'F'}, {"extract", 0, NULL, 'x'}, {"inject", 1, NULL, 'i'}, {"newlayout", 1, NULL, 'n'}, @@ -1770,7 +1823,7 @@ {0, 0, 0, 0} };
- while ((opt = getopt_long(argc, argv, "S:V:df:D:C:M:xi:n:O:s:p:elruvth?", + while ((opt = getopt_long(argc, argv, "S:V:df:F:D:C:M:xi:n:O:s:p:elruvth?", long_options, &option_index)) != EOF) { switch (opt) { case 'd': @@ -1792,6 +1845,15 @@ exit(EXIT_FAILURE); } break; + case 'F': + mode_fmap_template = 1; + layout_fname = strdup(optarg); + if (!layout_fname) { + fprintf(stderr, "No layout file specified\n"); + fprintf(stderr, "run '%s -h' for usage\n", argv[0]); + exit(EXIT_FAILURE); + } + break; case 'x': mode_extract = 1; break; @@ -2014,7 +2076,7 @@ } }
- if ((mode_dump + mode_layout + mode_extract + mode_inject + + if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject + mode_setstrap + mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked | mode_locked) + mode_altmedisable + mode_validate) > 1) { fprintf(stderr, "You may not specify more than one mode.\n\n"); @@ -2022,7 +2084,7 @@ exit(EXIT_FAILURE); }
- if ((mode_dump + mode_layout + mode_extract + mode_inject + + if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject + mode_setstrap + mode_newlayout + mode_spifreq + mode_em100 + mode_locked + mode_unlocked + mode_density + mode_altmedisable + mode_validate) == 0) { fprintf(stderr, "You need to specify a mode.\n\n"); @@ -2087,6 +2149,9 @@ if (mode_layout) dump_flashrom_layout(image, size, layout_fname);
+ if (mode_fmap_template) + create_fmap_template(image, size, layout_fname); + if (mode_extract) write_regions(image, size);