diff options
author | Julius Werner <jwerner@chromium.org> | 2020-03-13 16:43:34 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2020-12-03 00:00:33 +0000 |
commit | d477565dbd6e9b6467f49c84a4f05047ffa22682 (patch) | |
tree | 864556875c6b3e15b5cb35193db29af542ae7e8e /src/commonlib/bsd/cbfs_private.c | |
parent | 9d0cc2aea918eced42dc3825c1ac94d0d4fbc380 (diff) |
cbfstool: Use cbfs_serialized.h and standard vboot helpers
This patch reduces some code duplication in cbfstool by switching it to
use the CBFS data structure definitions in commonlib rather than its own
private copy. In addition, replace a few custom helpers related to hash
algorithms with the official vboot APIs of the same purpose.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I22eae1bcd76d85fff17749617cfe4f1de55603f4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41117
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Diffstat (limited to 'src/commonlib/bsd/cbfs_private.c')
-rw-r--r-- | src/commonlib/bsd/cbfs_private.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/commonlib/bsd/cbfs_private.c b/src/commonlib/bsd/cbfs_private.c index 7814c4a727..527860db75 100644 --- a/src/commonlib/bsd/cbfs_private.c +++ b/src/commonlib/bsd/cbfs_private.c @@ -46,7 +46,7 @@ cb_err_t cbfs_walk(cbfs_dev_t dev, cb_err_t (*walker)(cbfs_dev_t dev, size_t off const uint32_t data_offset = be32toh(mdata.h.offset); const uint32_t data_length = be32toh(mdata.h.len); const uint32_t type = be32toh(mdata.h.type); - const bool empty = (type == CBFS_TYPE_DELETED || type == CBFS_TYPE_DELETED2); + const bool empty = (type == CBFS_TYPE_DELETED || type == CBFS_TYPE_NULL); DEBUG("Found CBFS header @%#zx (type %d, attr +%#x, data +%#x, length %#x)\n", offset, type, attr_offset, data_offset, data_length); @@ -75,7 +75,7 @@ cb_err_t cbfs_walk(cbfs_dev_t dev, cb_err_t (*walker)(cbfs_dev_t dev, size_t off if (cbfs_dev_read(dev, mdata.raw + sizeof(mdata.h), offset + sizeof(mdata.h), todo) != todo) return CB_CBFS_IO; - DEBUG("File name: '%s'\n", mdata.filename); + DEBUG("File name: '%s'\n", mdata.h.filename); if (do_hash && !empty && vb2_digest_extend(&dc, mdata.raw, data_offset)) return CB_ERR; @@ -134,10 +134,9 @@ static cb_err_t lookup_walker(cbfs_dev_t dev, size_t offset, const union cbfs_md size_t already_read, void *arg) { struct cbfs_lookup_args *args = arg; - /* Check if the name we're looking for could fit, then we can safely memcmp() it. */ - if (args->namesize > already_read - offsetof(union cbfs_mdata, filename) || - memcmp(args->name, mdata->filename, args->namesize) != 0) + if (args->namesize > already_read - offsetof(union cbfs_mdata, h.filename) || + memcmp(args->name, mdata->h.filename, args->namesize) != 0) return CB_CBFS_NOT_FOUND; LOG("Found '%s' @%#zx size %#x\n", args->name, offset, be32toh(mdata->h.len)); @@ -175,13 +174,13 @@ const void *cbfs_find_attr(const union cbfs_mdata *mdata, uint32_t attr_tag, siz if (offset + len > end) { ERROR("Attribute %s[%u] overflows end of metadata\n", - mdata->filename, tag); + mdata->h.filename, tag); return NULL; } if (tag == attr_tag) { if (size_check && len != size_check) { ERROR("Attribute %s[%u] size mismatch: %u != %zu\n", - mdata->filename, tag, len, size_check); + mdata->h.filename, tag, len, size_check); return NULL; } return attr; |