From 3b44f30597e6ff86ddd8fd9e77ea278b935b15ea Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Thu, 22 Sep 2016 17:20:54 -0700 Subject: [PATCH] bdb: Add functions to get attributes of BDB components These APIs return size and offsets of BDB components. They help code look more descriptive. BUG=none BRANCH=none TEST=make runtests Change-Id: I29326e249d9f2b88d5716f878f8415703f63360c Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/388813 Reviewed-by: Randall Spangler --- firmware/bdb/bdb.c | 23 ++++++++++++++++++++++- firmware/bdb/bdb.h | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/firmware/bdb/bdb.c b/firmware/bdb/bdb.c index 4ebf793616..707e3b0cff 100644 --- a/firmware/bdb/bdb.c +++ b/firmware/bdb/bdb.c @@ -5,7 +5,8 @@ * Boot descriptor block firmware functions */ -#include +#include "2sysincludes.h" +#include "2common.h" #include "2sha.h" #include "bdb.h" @@ -196,6 +197,11 @@ const struct bdb_header *bdb_get_header(const void *buf) return buf; } +uint32_t bdb_size_of(const void *buf) +{ + return bdb_get_header(buf)->bdb_size; +} + const struct bdb_key *bdb_get_bdbkey(const void *buf) { const struct bdb_header *h = bdb_get_header(buf); @@ -223,6 +229,11 @@ const struct bdb_key *bdb_get_datakey(const void *buf) return (const struct bdb_key *)(b8 + h->oem_area_0_size); } +ptrdiff_t bdb_offset_of_datakey(const void *buf) +{ + return vb2_offset_of(buf, bdb_get_datakey(buf)); +} + const struct bdb_sig *bdb_get_header_sig(const void *buf) { const struct bdb_header *h = bdb_get_header(buf); @@ -232,6 +243,11 @@ const struct bdb_sig *bdb_get_header_sig(const void *buf) return (const struct bdb_sig *)(b8 + h->signed_size); } +ptrdiff_t bdb_offset_of_header_sig(const void *buf) +{ + return vb2_offset_of(buf, bdb_get_header_sig(buf)); +} + const struct bdb_data *bdb_get_data(const void *buf) { const struct bdb_sig *s = bdb_get_header_sig(buf); @@ -241,6 +257,11 @@ const struct bdb_data *bdb_get_data(const void *buf) return (const struct bdb_data *)(b8 + s->struct_size); } +ptrdiff_t bdb_offset_of_data(const void *buf) +{ + return vb2_offset_of(buf, bdb_get_data(buf)); +} + const void *bdb_get_oem_area_1(const void *buf) { const struct bdb_data *p = bdb_get_data(buf); diff --git a/firmware/bdb/bdb.h b/firmware/bdb/bdb.h index ebe3b41490..5506db2555 100644 --- a/firmware/bdb/bdb.h +++ b/firmware/bdb/bdb.h @@ -9,6 +9,8 @@ #define VBOOT_REFERENCE_BDB_H_ #include +#include + #include "bdb_struct.h" /*****************************************************************************/ @@ -153,6 +155,24 @@ const void *bdb_get_oem_area_1(const void *buf); const struct bdb_hash *bdb_get_hash(const void *buf, enum bdb_data_type type); const struct bdb_sig *bdb_get_data_sig(const void *buf); +/** + * Functions to calculate size of BDB components + * + * @param buf Pointer to BDB buffer + * @return Size of the component + */ +uint32_t bdb_size_of(const void *buf); + +/** + * Functions to calculate offset of BDB components + * + * @param buf Pointer to BDB buffer + * @return Offset of the component + */ +ptrdiff_t bdb_offset_of_datakey(const void *buf); +ptrdiff_t bdb_offset_of_header_sig(const void *buf); +ptrdiff_t bdb_offset_of_data(const void *buf); + /*****************************************************************************/ /* Functions probably provided by the caller */