diff options
| author | Raymond Mao <[email protected]> | 2025-07-18 07:16:17 -0700 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-04-27 09:42:36 -0600 |
| commit | 25baace94298bbe50a91f7b1b7470bf0eb5688fa (patch) | |
| tree | 6334be35c79838b2293170f8f2a2ae4671d014c9 /common | |
| parent | 63cc797a7e89a2543c9997a271ad8f02b04a6777 (diff) | |
bloblist: add API for applying blobs with specified tag
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 <[email protected]>
Reviewed-by: Tom Rini <[email protected]>
Tested-by: Michal Simek <[email protected]>
Diffstat (limited to 'common')
| -rw-r--r-- | common/bloblist.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/common/bloblist.c b/common/bloblist.c index 550c0c78ffc..2b5026e00da 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -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; |
