[PATCH 5/6] bloblist: add API for applying blobs with specified tag

Raymond Mao raymond.mao at linaro.org
Wed Jun 18 16:59:27 CEST 2025


Add an API to search for the blobs with specified tag and use the
hook function to apply the blob data.

Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
---
 common/bloblist.c  | 36 ++++++++++++++++++++++++++++++++++++
 include/bloblist.h | 19 +++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/common/bloblist.c b/common/bloblist.c
index ae5273785eb..47ba6913cfd 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -261,6 +261,42 @@ void *bloblist_get_blob(uint tag, int *sizep)
 	return (void *)rec + rec_hdr_size(rec);
 }
 
+int bloblist_apply_blobs(uint tag, int (*func)(void **data))
+{
+	struct bloblist_hdr *hdr = gd->bloblist;
+	struct bloblist_rec *rec;
+
+	if (!func || !hdr)
+		return -ENOENT;
+
+	foreach_rec(rec, hdr) {
+		/* Apply all blobs with the specified tag */
+		if (rec_tag(rec) == tag) {
+			int ret;
+			int tag = rec_tag(rec);
+			void *blob = (void *)rec + rec_hdr_size(rec);
+
+			ret = func(&blob);
+			if (ret) {
+				log_err("Failed to apply blob with tag %d\n",
+					tag);
+				return ret;
+			}
+
+			rec = rec_from_blob(blob);
+			if (rec <= 0) {
+				log_err("Blob corrupted\n");
+				return -ENOENT;
+			}
+
+			/* Mark applied blob record as void */
+			void_blob(rec);
+		}
+	}
+
+	return 0;
+}
+
 void *bloblist_add(uint tag, int size, int align_log2)
 {
 	struct bloblist_rec *rec;
diff --git a/include/bloblist.h b/include/bloblist.h
index 0aaeb9ef7f1..62e4c5b220f 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -270,6 +270,25 @@ static inline void *bloblist_get_blob(uint tag, int *sizep)
 }
 #endif
 
+#if CONFIG_IS_ENABLED(BLOBLIST)
+/**
+ * bloblist_apply_blobs() - Apply the data of blobs by tag
+ *
+ * Scan the bloblist, find the blobs with the matching tag and apply the data
+ * of blobs
+ *
+ * @tag:	Tag to search for (enum bloblist_tag_t)
+ * @func:	Function to apply the data of blobs
+ * Return: 0 if OK, otherwise error.
+ */
+int bloblist_apply_blobs(uint tag, int (*func)(void **data));
+#else
+static inline int bloblist_apply_blobs(uint tag, int (*func)(void **data))
+{
+	return -EPERM;
+}
+#endif
+
 /**
  * bloblist_find() - Find a blob
  *
-- 
2.25.1



More information about the U-Boot mailing list