[coreboot-gerrit] Patch set updated for coreboot: c9e3a7f fmap: add region based fmap API

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Wed Apr 15 02:12:12 CEST 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9171

-gerrit

commit c9e3a7fd3357b3354be3a2953c2cd1722e310514
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Sun Mar 29 00:05:18 2015 -0500

    fmap: add region based fmap API
    
    Instead of being pointer based use the region infrastrucutre.
    Additionally, this removes the need for arch-specific compilation
    paths.
    
    Change-Id: I436533a4f4a272837794ee00c90280602745edac
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/Kconfig                            |   9 +++
 src/include/fmap.h                     |  35 ++++++++++
 src/lib/Makefile.inc                   |   4 ++
 src/lib/fmap.c                         | 121 +++++++++++++++++++++++++++++++++
 src/vendorcode/google/chromeos/Kconfig |   9 ---
 5 files changed, 169 insertions(+), 9 deletions(-)

diff --git a/src/Kconfig b/src/Kconfig
index 6cf3134..824e0d1 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -219,6 +219,15 @@ config CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM
 	 The relocated ramstage is saved in an area specified by the
 	 by the board and/or chipset.
 
+config FLASHMAP_OFFSET
+	hex "Flash Map Offset"
+	default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
+	default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
+	default CBFS_SIZE if !ARCH_X86
+	default 0
+	help
+	  Offset of flash map in firmware image
+
 choice
 	prompt "Bootblock behaviour"
 	default BOOTBLOCK_SIMPLE
diff --git a/src/include/fmap.h b/src/include/fmap.h
new file mode 100644
index 0000000..e575bbf
--- /dev/null
+++ b/src/include/fmap.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#ifndef _FMAP_H_
+#define _FMAP_H_
+
+#include <region.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
+ * 0 on success, < 0 on error. */
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area);
+
+/* Locate the named area in the fmap and fill in a region with the
+ * offset and size of that area within the boot media. Return 0 on success,
+ * < 0 on error. */
+int fmap_locate_area(const char *name, struct region *r);
+
+#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index f33f878..801589e 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -31,11 +31,13 @@ bootblock-y += memchr.c
 bootblock-y += memcmp.c
 bootblock-y += mem_pool.c
 bootblock-y += region.c
+bootblock-y += fmap.c
 
 verstage-y += prog_ops.c
 verstage-y += delay.c
 verstage-y += cbfs.c
 verstage-y += cbfs_boot_props.c
+verstage-y += fmap.c
 verstage-y += memcmp.c
 verstage-y += region.c
 verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
@@ -52,6 +54,7 @@ $(foreach arch,$(ARCH_SUPPORTED),\
 	    $(eval rmodules_$(arch)-y += memcmp.c) \
 	    $(eval rmodules_$(arch)-y += rmodule.ld))
 
+romstage-y += fmap.c
 romstage-$(CONFIG_I2C_TPM) += delay.c
 romstage-y += cbfs.c
 romstage-y += cbfs_boot_props.c
@@ -80,6 +83,7 @@ ramstage-y += hardwaremain.c
 ramstage-y += selfboot.c
 ramstage-y += coreboot_table.c
 ramstage-y += bootmem.c
+ramstage-y += fmap.c
 ramstage-y += memchr.c
 ramstage-y += memcmp.c
 ramstage-y += malloc.c
diff --git a/src/lib/fmap.c b/src/lib/fmap.c
new file mode 100644
index 0000000..c0cbca1
--- /dev/null
+++ b/src/lib/fmap.c
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2012-2015 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <boot_device.h>
+#include <console/console.h>
+#include <fmap.h>
+#include <fmap_serialized.h>
+#include <stddef.h>
+#include <string.h>
+
+/*
+ * See http://code.google.com/p/flashmap/ for more information on FMAP.
+ */
+
+static int find_fmap_directory(struct region_device *fmrd)
+{
+	const struct region_device *boot;
+	struct fmap *fmap;
+	size_t fmap_size;
+	size_t offset = CONFIG_FLASHMAP_OFFSET;
+
+	boot = boot_device_ro();
+
+	if (boot == NULL)
+		return -1;
+
+	fmap_size = sizeof(struct fmap);
+
+	fmap = rdev_mmap(boot, offset, fmap_size);
+
+	if (fmap == NULL)
+		return -1;
+
+	if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) {
+		printk(BIOS_DEBUG, "No FMAP found at %zx offset.\n", offset);
+		rdev_munmap(boot, fmap);
+		return -1;
+	}
+
+	printk(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %zx.\n",
+	       fmap->name, fmap->ver_major, fmap->ver_minor, offset);
+	printk(BIOS_DEBUG, "FMAP: base = %llx size = %x #areas = %d\n",
+	       (long long)fmap->base, fmap->size, fmap->nareas);
+
+	fmap_size += fmap->nareas * sizeof(struct fmap_area);
+
+	rdev_munmap(boot, fmap);
+
+	return rdev_chain(fmrd, boot, offset, fmap_size);
+}
+
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area)
+{
+	const struct region_device *boot;
+	struct region ar;
+
+	boot = boot_device_ro();
+
+	if (fmap_locate_area(name, &ar))
+		return -1;
+
+	return rdev_chain(area, boot, ar.offset, ar.size);
+}
+
+int fmap_locate_area(const char *name, struct region *ar)
+{
+	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 (strcmp((const char *)area->name, name)) {
+			rdev_munmap(&fmrd, area);
+			offset += sizeof(struct fmap_area);
+			continue;
+		}
+
+		printk(BIOS_DEBUG, "FMAP: area %s found\n", name);
+		printk(BIOS_DEBUG, "FMAP:   offset: %x\n", area->offset);
+		printk(BIOS_DEBUG, "FMAP:   size:   %d bytes\n", area->size);
+
+		ar->offset = area->offset;
+		ar->size = area->size;
+
+		rdev_munmap(&fmrd, area);
+
+		return 0;
+	}
+
+	printk(BIOS_DEBUG, "FMAP: area %s not found\n", name);
+
+	return -1;
+}
diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index fa382ae..6ab02ed 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -91,15 +91,6 @@ config CHROMEOS_RAMOOPS_RAM_SIZE
 	default 0x00100000
 	depends on CHROMEOS_RAMOOPS
 
-config FLASHMAP_OFFSET
-	hex "Flash Map Offset"
-	default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
-	default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
-	default CBFS_SIZE if !ARCH_X86
-	default 0
-	help
-	  Offset of flash map in firmware image
-
 config EC_SOFTWARE_SYNC
 	bool "Enable EC software sync"
 	default n



More information about the coreboot-gerrit mailing list