]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bloblist: add API for applying blobs with specified tag
authorRaymond Mao <raymond.mao@linaro.org>
Fri, 18 Jul 2025 14:16:17 +0000 (07:16 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 27 Apr 2026 15:42:36 +0000 (09:42 -0600)
Add an API to search for the blobs with specified tag and use the
hook function to apply the blob data.
Add a helper function to return the inline header size as according
to recent spec[1] updates, the actual data can be following an inline
header instead of following the TE header immediately.

[1] Firmware Handoff spec:
https://github.com/FirmwareHandoff/firmware_handoff

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Tested-by: Michal Simek <michal.simek@amd.com>
common/bloblist.c
include/bloblist.h

index 550c0c78ffc1f5b8eaeccc0bf4146a1588aadd71..2b5026e00da681a5249ac80a715b8d521c5c7a3c 100644 (file)
@@ -235,6 +235,19 @@ static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
        return 0;
 }
 
+static int bloblist_get_blob_data_offset(uint tag)
+{
+       switch (tag) {
+       case BLOBLISTT_FDT_OVERLAY:
+               return sizeof(struct dto_blob_hdr);
+       /*
+        * return the data offset if it is not following the blob
+        * header immediately.
+        */
+       }
+       return 0;
+}
+
 void *bloblist_find(uint tag, int size)
 {
        void *blob = NULL;
@@ -261,6 +274,44 @@ 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, int size))
+{
+       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);
+                       int dat_off = bloblist_get_blob_data_offset(tag);
+
+                       blob += dat_off;
+                       ret = func(&blob, rec->size - dat_off);
+                       if (ret) {
+                               log_err("Failed to apply blob with tag %d\n",
+                                       tag);
+                               return ret;
+                       }
+
+                       rec = rec_from_blob(blob - dat_off);
+                       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;
index c2d3065a43c4be44bcc0144dee2bb22fad24da19..e67b2a76358d1aecd6ef89f041ad207f1a1774f5 100644 (file)
@@ -73,6 +73,7 @@
 #define __BLOBLIST_H
 
 #include <mapmem.h>
+#include <linux/errno.h>
 
 enum {
        BLOBLIST_VERSION        = 1,
@@ -279,6 +280,26 @@ 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, int size));
+#else
+static inline int bloblist_apply_blobs(uint tag,
+                                      int (*func)(void **data, int size))
+{
+       return -EPERM;
+}
+#endif
+
 /**
  * bloblist_find() - Find a blob
  *