diff mbox series

[v1,03/43] binman: Add way to locate an entry in memory

Message ID 20200615035738.248710-4-sjg@chromium.org
State Accepted
Commit 8f9877df95ae0068ce14a962bd72c22026c1d2e8
Headers show
Series x86: Programmatic generation of ACPI tables (Part C) | expand

Commit Message

Simon Glass June 15, 2020, 3:56 a.m. UTC
Add support for accessing an entry's contents in memory-mapped SPI flash.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 include/binman.h | 22 ++++++++++++++++++++++
 lib/binman.c     | 23 +++++++++++++++++++++++
 2 files changed, 45 insertions(+)
diff mbox series

Patch

diff --git a/include/binman.h b/include/binman.h
index baf49f7876..e0b92075e2 100644
--- a/include/binman.h
+++ b/include/binman.h
@@ -9,6 +9,8 @@ 
 #ifndef _BINMAN_H_
 #define _BINMAN_H_
 
+#include <dm/ofnode.h>
+
 /**
  *struct binman_entry - information about a binman entry
  *
@@ -20,6 +22,18 @@  struct binman_entry {
 	u32 size;
 };
 
+/**
+ * binman_entry_map() - Look up the address of an entry in memory
+ *
+ * @parent: Parent binman node
+ * @name: Name of entry
+ * @bufp: Returns a pointer to the entry
+ * @sizep: Returns the size of the entry
+ * @return 0 on success, -EPERM if the ROM offset is not set, -ENOENT if the
+ *	entry cannot be found, other error code other error
+ */
+int binman_entry_map(ofnode parent, const char *name, void **bufp, int *sizep);
+
 /**
  * binman_set_rom_offset() - Set the ROM memory-map offset
  *
@@ -41,6 +55,14 @@  void binman_set_rom_offset(int rom_offset);
  */
 int binman_entry_find(const char *name, struct binman_entry *entry);
 
+/**
+ * binman_section_find_node() - Find a binman node
+ *
+ * @name: Name of node to look for
+ * @return Node that was found, ofnode_null() if not found
+ */
+ofnode binman_section_find_node(const char *name);
+
 /**
  * binman_init() - Set up the binman symbol information
  *
diff --git a/lib/binman.c b/lib/binman.c
index 79d01230dd..ba4d82963d 100644
--- a/lib/binman.c
+++ b/lib/binman.c
@@ -11,6 +11,7 @@ 
 #include <dm.h>
 #include <log.h>
 #include <malloc.h>
+#include <mapmem.h>
 
 /**
  * struct binman_info - Information needed by the binman library
@@ -54,6 +55,28 @@  int binman_entry_find(const char *name, struct binman_entry *entry)
 	return binman_entry_find_(binman->image, name, entry);
 }
 
+int binman_entry_map(ofnode parent, const char *name, void **bufp, int *sizep)
+{
+	struct binman_entry entry;
+	int ret;
+
+	if (binman->rom_offset == ROM_OFFSET_NONE)
+		return -EPERM;
+	ret = binman_entry_find_(parent, name, &entry);
+	if (ret)
+		return log_msg_ret("entry", ret);
+	if (sizep)
+		*sizep = entry.size;
+	*bufp = map_sysmem(entry.image_pos + binman->rom_offset, entry.size);
+
+	return 0;
+}
+
+ofnode binman_section_find_node(const char *name)
+{
+	return ofnode_find_subnode(binman->image, name);
+}
+
 void binman_set_rom_offset(int rom_offset)
 {
 	binman->rom_offset = rom_offset;