diff options
author | Simon Glass <sjg@chromium.org> | 2023-12-27 13:07:06 -0800 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2023-12-31 07:21:02 -0700 |
commit | f9ef9fb033d5ea29d0a72349fea9d0e55a528d36 (patch) | |
tree | 0e8b7b49a970e479a8d0eb542301a368697a0f10 | |
parent | 997dac6edebe5b82f4d6f9b90753f0af6e9d04f0 (diff) | |
download | u-boot-f9ef9fb033d5ea29d0a72349fea9d0e55a528d36.zip u-boot-f9ef9fb033d5ea29d0a72349fea9d0e55a528d36.tar.gz u-boot-f9ef9fb033d5ea29d0a72349fea9d0e55a528d36.tar.bz2 |
bloblist: Handle alignment with a void entry
Rather than setting the alignment using the header size, add an entirely
new entry to cover the gap left by the alignment.
Signed-off-by: Simon Glass <sjg@chromium.org>
Co-developed-by: Raymond Mao <raymond.mao@linaro.org>
Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
-rw-r--r-- | common/bloblist.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/common/bloblist.c b/common/bloblist.c index 705d9c6..73dbbc0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -142,7 +142,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, { struct bloblist_hdr *hdr = gd->bloblist; struct bloblist_rec *rec; - int data_start, new_alloced; + int data_start, aligned_start, new_alloced; if (!align_log2) align_log2 = BLOBLIST_ALIGN_LOG2; @@ -151,10 +151,25 @@ static int bloblist_addrec(uint tag, int size, int align_log2, data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec); /* Align the address and then calculate the offset from ->alloced */ - data_start = ALIGN(data_start, 1U << align_log2) - map_to_sysmem(hdr); + aligned_start = ALIGN(data_start, 1U << align_log2) - data_start; + + /* If we need to create a dummy record, create it */ + if (aligned_start) { + int void_size = aligned_start - sizeof(*rec); + struct bloblist_rec *vrec; + int ret; + + ret = bloblist_addrec(BLOBLISTT_VOID, void_size, 0, &vrec); + if (ret) + return log_msg_ret("void", ret); + + /* start the record after that */ + data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*vrec); + } /* Calculate the new allocated total */ - new_alloced = data_start + ALIGN(size, 1U << align_log2); + new_alloced = data_start - map_to_sysmem(hdr) + + ALIGN(size, 1U << align_log2); if (new_alloced > hdr->size) { log_err("Failed to allocate %x bytes size=%x, need size=%x\n", @@ -164,7 +179,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, rec = (void *)hdr + hdr->alloced; rec->tag = tag; - rec->hdr_size = data_start - hdr->alloced; + rec->hdr_size = sizeof(struct bloblist_rec); rec->size = size; /* Zero the record data */ |