util/ifdtool: Add option to create FMAP template

On systems that do not provide their own *.fmd (Flashmap) file, we
fall back to a default flashmap file. That file however does not contain
the blobs (ME, GBE ...), that are usually placed below the BIOS Flashmap.
It can therefore easily happen that the placement of the blobs collides
with the placement of the BIOS region (e.g. if CBFS_SIZE is big enough).
The fmaptool can't catch that, since it does not know of the blobs
placement.

This patch basically maps the regions described in the IFD (Intel
Firmware Descriptor) to the default Flashmap.

Test: Build and see that build/fmap.fmd contains all blobs now (on intel
systems that are supported by the ifdtool)

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I82cb252fff456773af69943e188480a4998736fd
Reviewed-on: https://review.coreboot.org/c/coreboot/+/73487
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Lean Sheng Tan <sheng.tan@9elements.com>
diff --git a/Makefile.inc b/Makefile.inc
index ba4f6fa..d2d3f88 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -934,11 +934,22 @@
 		$(call sort-files,$(call placed-files-in-region,$(region))), \
 		$(call cbfs-add-cmd,$(file),$(region),$(CONFIG_UPDATE_IMAGE))))
 
+# If no FMD file (Flashmap) is supplied by mainboard, fall back to a default
 ifeq ($(CONFIG_FMDFILE),)
-# For a description of the flash layout described by these variables, check
-# the $(DEFAULT_FLASHMAP) .fmd files.
+
 ifeq ($(CONFIG_ARCH_X86),y)
+
 DEFAULT_FLASHMAP:=$(top)/util/cbfstool/default-x86.fmd
+# check if IFD_CHIPSET is set and if yes generate a FMAP template from IFD descriptor
+ifneq ($(CONFIG_IFD_CHIPSET),)
+ifeq ($(CONFIG_HAVE_IFD_BIN),y)
+DEFAULT_FLASHMAP:=$(obj)/fmap-template.fmd
+$(DEFAULT_FLASHMAP): $(call strip_quotes,$(CONFIG_IFD_BIN_PATH)) $(IFDTOOL)
+	echo "    IFDTOOL    -p $(CONFIG_IFD_CHIPSET) -F $@ $<"
+	$(IFDTOOL) -p $(CONFIG_IFD_CHIPSET) -F $@ $<
+endif # ifeq($(CONFIG_HAVE_IFD_BIN),y)
+endif # ifneq($(CONFIG_IFD_CHIPSET),)
+
 # entire flash
 FMAP_ROM_ADDR := $(call int-subtract, 0x100000000 $(CONFIG_ROM_SIZE))
 FMAP_ROM_SIZE := $(CONFIG_ROM_SIZE)