[coreboot-gerrit] Patch set updated for coreboot: fmap: Introduce new function to derive fmap name from offset/size

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Jul 9 18:41:33 CEST 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10865

-gerrit

commit add3cdb044ab4433252ab98f3fdb36238b7df6fb
Author: Patrick Georgi <pgeorgi at chromium.org>
Date:   Thu Jul 9 11:27:44 2015 +0200

    fmap: Introduce new function to derive fmap name from offset/size
    
    vboot passes around the offset and size of the region to use in later stages.
    To assign more meaning to this pair, provide a function that returns the
    fmap area name if there's a precise match (and an error otherwise).
    
    Change-Id: I5724b860271025c8cb8b390ecbd33352ea779660
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
---
 src/include/fmap.h |  5 +++++
 src/lib/fmap.c     | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/src/include/fmap.h b/src/include/fmap.h
index e575bbf..671e802 100644
--- a/src/include/fmap.h
+++ b/src/include/fmap.h
@@ -21,6 +21,7 @@
 #define _FMAP_H_
 
 #include <region.h>
+#include <fmap_serialized.h>
 
 /* Locate the named area in the fmap and fill in a region device representing
  * that area. The region is a sub-region of the readonly boot media. Return
@@ -32,4 +33,8 @@ int fmap_locate_area_as_rdev(const char *name, struct region_device *area);
  * < 0 on error. */
 int fmap_locate_area(const char *name, struct region *r);
 
+/* Find fmap area name by offset and size.
+ * Return 0 on success, < 0 on error. */
+int fmap_find_region_name(const struct region * const ar,
+	char name[FMAP_STRLEN]);
 #endif
diff --git a/src/lib/fmap.c b/src/lib/fmap.c
index 0f48cdc..f2087c3 100644
--- a/src/lib/fmap.c
+++ b/src/lib/fmap.c
@@ -117,3 +117,46 @@ int fmap_locate_area(const char *name, struct region *ar)
 
 	return -1;
 }
+
+int fmap_find_region_name(const struct region * const ar,
+	char name[FMAP_STRLEN])
+{
+	struct region_device fmrd;
+	size_t offset;
+
+	if (find_fmap_directory(&fmrd))
+		return -1;
+
+	/* Start reading the areas just after fmap header. */
+	offset = sizeof(struct fmap);
+
+	while (1) {
+		struct fmap_area *area;
+
+		area = rdev_mmap(&fmrd, offset, sizeof(*area));
+
+		if (area == NULL)
+			return -1;
+
+		if ((ar->offset != area->offset) ||
+		    (ar->size != area->size)) {
+			rdev_munmap(&fmrd, area);
+			offset += sizeof(struct fmap_area);
+			continue;
+		}
+
+		printk(BIOS_DEBUG, "FMAP: area (%zx, %zx) found, named %s\n",
+			ar->offset, ar->size, area->name);
+
+		memcpy(name, area->name, FMAP_STRLEN);
+
+		rdev_munmap(&fmrd, area);
+
+		return 0;
+	}
+
+	printk(BIOS_DEBUG, "FMAP: area (%zx, %zx) not found\n",
+		ar->offset, ar->size);
+
+	return -1;
+}



More information about the coreboot-gerrit mailing list