[PATCH1/2] mrc cache: Add MRC cache FMAP entry support.

Add code to retrieve the location of the MRC cache from the FMAP
device tree definition.

fdt_decode.c should be refactored (fmap_offset could be determined
just once and used throughout without passing it as a parameter), will
leave this for another day.

BUG=chrome-os-partner:5808
TEST=manual
  . see test description in the second patch commit message.

Change-Id: Ic4003d685609beb61d1dea324bd804a2838e471c
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/9961
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/include/chromeos/fdt_decode.h b/include/chromeos/fdt_decode.h
index 96def9a..b1c861f 100644
--- a/include/chromeos/fdt_decode.h
+++ b/include/chromeos/fdt_decode.h
@@ -43,4 +43,14 @@
 void *fdt_decode_chromeos_alloc_region(const void *blob,
 		const char *prop_name, size_t *size);
 
+/**
+ * Retrieve the MRC cache base address from the FMAP section of the device
+ * tree.
+ *
+ * @param blob		FDT blob
+ * @param fme		pointer to the return value (offset and length are
+ *			saved in the structure)
+ */
+int fdt_get_mrc_cache_base(const char *blob, struct fmap_entry *fme);
+
 #endif /* CHROMEOS_FDT_DECODE_H_ */
diff --git a/lib/chromeos/fdt_decode.c b/lib/chromeos/fdt_decode.c
index 5c93dcd..fbc44a3 100644
--- a/lib/chromeos/fdt_decode.c
+++ b/lib/chromeos/fdt_decode.c
@@ -105,6 +105,21 @@
 	return err;
 }
 
+int fdt_get_mrc_cache_base(const char *blob, struct fmap_entry *fme)
+{
+	int fmap_offset;
+
+	fmap_offset = fdt_node_offset_by_compatible(blob, -1,
+			"chromeos,flashmap");
+	if (fmap_offset < 0) {
+		VBDEBUG(PREFIX "%s: chromeos,flashmap node is missing\n",
+			__func__);
+		return fmap_offset;
+	}
+
+	return decode_fmap_entry(blob, fmap_offset, "rw", "mrc-cache", fme);
+}
+
 int fdt_decode_twostop_fmap(const void *blob, struct twostop_fmap *config)
 {
 	int fmap_offset;