[U-Boot] [PATCH 24/32] fdt: Add a function for reading a flash map entry
Simon Glass
sjg at chromium.org
Sun Nov 10 18:27:10 CET 2013
A flash map describes the layout of flash memory in terms of offsets and
sizes for each region. Add a function to read a flash map entry from the
device tree.
(Unfortunately I had to change this commit to also touch cros/ but it is
a very small change and can be removed for upstreaming.)
Signed-off-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou at chromium.org>
---
include/fdtdec.h | 18 ++++++++++++++++++
lib/fdtdec.c | 24 ++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 433d6a7..26661e6 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -529,4 +529,22 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
*/
int fdtdec_decode_region(const void *blob, int node,
const char *prop_name, void **ptrp, size_t *size);
+
+/* A flash map entry, containing an offset and length */
+struct fmap_entry {
+ uint32_t offset;
+ uint32_t length;
+};
+
+/**
+ * Read a flash entry from the fdt
+ *
+ * @param blob FDT blob
+ * @param node Offset of node to read
+ * @param name Name of node being read
+ * @param entry Place to put offset and size of this node
+ * @return 0 if ok, -ve on error
+ */
+int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
+ struct fmap_entry *entry);
#endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 207314f..ab93e0d 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -616,3 +616,27 @@ int fdtdec_decode_region(const void *blob, int node,
debug("%s: size=%zx\n", __func__, *size);
return 0;
}
+
+/**
+ * Read a flash entry from the fdt
+ *
+ * @param blob FDT blob
+ * @param node Offset of node to read
+ * @param name Name of node being read
+ * @param entry Place to put offset and size of this node
+ * @return 0 if ok, -ve on error
+ */
+int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
+ struct fmap_entry *entry)
+{
+ u32 reg[2];
+
+ if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
+ debug("Node '%s' has bad/missing 'reg' property\n", name);
+ return -FDT_ERR_NOTFOUND;
+ }
+ entry->offset = reg[0];
+ entry->length = reg[1];
+
+ return 0;
+}
--
1.8.4.1
More information about the U-Boot
mailing list