[PATCH 17/17] binman: Allow reading entries from a subnode

Simon Glass sjg at chromium.org
Thu Jan 14 04:29:57 CET 2021


Some images may have multiple copies of the same thing, e.g. two versions
of the read/write U-Boots. It is necessary to read data from one or other
of these under selection of the verified-boot logic. Add a function to
select the subnode to use.

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

 include/binman.h | 14 ++++++++++++++
 lib/binman.c     | 18 ++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/binman.h b/include/binman.h
index 8b89a9666d5..5958dfb4485 100644
--- a/include/binman.h
+++ b/include/binman.h
@@ -70,6 +70,20 @@ int binman_entry_find(const char *name, struct binman_entry *entry);
  */
 ofnode binman_section_find_node(const char *name);
 
+/**
+ * binman_select_subnode() - Select a subnode to use to find entries
+ *
+ * Normally binman selects the top-level node for future entry requests, such as
+ * binman_entry_find(). This function allows a subnode to be chosen instead.
+ *
+ * @name: Name of subnode, typically a section. This must be in the top-level
+ *	binman node
+ * @return 0 if OK, -EINVAL if there is no /binman node, -ECHILD if multiple
+ *	images are being used but the first image is not available, -ENOENT if
+ *	the requested subnode cannot be found
+ */
+int binman_select_subnode(const char *name);
+
 /**
  * binman_init() - Set up the binman symbol information
  *
diff --git a/lib/binman.c b/lib/binman.c
index b6d9dff5b7c..f415df30545 100644
--- a/lib/binman.c
+++ b/lib/binman.c
@@ -116,6 +116,24 @@ int binman_get_rom_offset(void)
 	return binman->rom_offset;
 }
 
+int binman_select_subnode(const char *name)
+{
+	ofnode node;
+	int ret;
+
+	ret = find_image_node(&node);
+	if (ret)
+		return log_msg_ret("main", -ENOENT);
+	node = ofnode_find_subnode(node, name);
+	if (!ofnode_valid(node))
+		return log_msg_ret("node", -ENOENT);
+	binman->image = node;
+	log_debug("binman: Selected image subnode '%s'\n",
+		  ofnode_get_name(binman->image));
+
+	return 0;
+}
+
 int binman_init(void)
 {
 	int ret;
-- 
2.30.0.284.gd98b1dd5eaa7-goog



More information about the U-Boot mailing list