summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-09-22 17:20:54 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-01 00:01:12 -0700
commit3b44f30597e6ff86ddd8fd9e77ea278b935b15ea (patch)
tree54cffc93c4a2531026c61da1163c7e3fbcc8588d
parent626e0b034db4c3c395cc5eb716d8725b4f030fe0 (diff)
downloadvboot-3b44f30597e6ff86ddd8fd9e77ea278b935b15ea.tar.gz
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 <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/388813 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--firmware/bdb/bdb.c23
-rw-r--r--firmware/bdb/bdb.h20
2 files changed, 42 insertions, 1 deletions
diff --git a/firmware/bdb/bdb.c b/firmware/bdb/bdb.c
index 4ebf7936..707e3b0c 100644
--- a/firmware/bdb/bdb.c
+++ b/firmware/bdb/bdb.c
@@ -5,7 +5,8 @@
* Boot descriptor block firmware functions
*/
-#include <string.h>
+#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 ebe3b414..5506db25 100644
--- a/firmware/bdb/bdb.h
+++ b/firmware/bdb/bdb.h
@@ -9,6 +9,8 @@
#define VBOOT_REFERENCE_BDB_H_
#include <stdlib.h>
+#include <stddef.h>
+
#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 */