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>
This commit is contained in:
Daisuke Nojiri
2016-09-22 17:20:54 -07:00
committed by chrome-bot
parent 626e0b034d
commit 3b44f30597
2 changed files with 42 additions and 1 deletions

View File

@@ -5,7 +5,8 @@
* Boot descriptor block firmware functions * Boot descriptor block firmware functions
*/ */
#include <string.h> #include "2sysincludes.h"
#include "2common.h"
#include "2sha.h" #include "2sha.h"
#include "bdb.h" #include "bdb.h"
@@ -196,6 +197,11 @@ const struct bdb_header *bdb_get_header(const void *buf)
return 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_key *bdb_get_bdbkey(const void *buf)
{ {
const struct bdb_header *h = bdb_get_header(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); 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_sig *bdb_get_header_sig(const void *buf)
{ {
const struct bdb_header *h = bdb_get_header(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); 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_data *bdb_get_data(const void *buf)
{ {
const struct bdb_sig *s = bdb_get_header_sig(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); 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 void *bdb_get_oem_area_1(const void *buf)
{ {
const struct bdb_data *p = bdb_get_data(buf); const struct bdb_data *p = bdb_get_data(buf);

View File

@@ -9,6 +9,8 @@
#define VBOOT_REFERENCE_BDB_H_ #define VBOOT_REFERENCE_BDB_H_
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
#include "bdb_struct.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_hash *bdb_get_hash(const void *buf, enum bdb_data_type type);
const struct bdb_sig *bdb_get_data_sig(const void *buf); 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 */ /* Functions probably provided by the caller */