summaryrefslogtreecommitdiff
path: root/common/cbi.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-10-03 18:28:57 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-07 21:16:39 +0000
commitb29d0808e22d30c3e9ce85dd31457ab8ff28dd2c (patch)
treeed5984d796061918350904ba20568944bc4f16ca /common/cbi.c
parent1c62421d797d31f2cbc05a5cfe6b9f1219f5484a (diff)
downloadchrome-ec-b29d0808e22d30c3e9ce85dd31457ab8ff28dd2c.tar.gz
CBI: Add unit test
This patch adds unit tests for Cros Board Info APIs. BUG=b:163038871 BRANCH=none TEST=buildall Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I7b2fdb2c4f13da12f8c0dc2ab526332cbd46d849 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2339393
Diffstat (limited to 'common/cbi.c')
-rw-r--r--common/cbi.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/common/cbi.c b/common/cbi.c
index 5263407441..6918ad50dd 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -57,12 +57,12 @@ uint8_t *cbi_set_string(uint8_t *p, enum cbi_data_tag tag, const char *str)
return cbi_set_data(p, tag, str, strlen(str) + 1);
}
-struct cbi_data *cbi_find_tag(const void *cbi, enum cbi_data_tag tag)
+struct cbi_data *cbi_find_tag(const void *buf, enum cbi_data_tag tag)
{
struct cbi_data *d;
- const struct cbi_header *h = cbi;
+ const struct cbi_header *h = buf;
const uint8_t *p;
- for (p = h->data; p + sizeof(*d) < (uint8_t *)cbi + h->total_size;) {
+ for (p = h->data; p + sizeof(*d) < (uint8_t *)buf + h->total_size;) {
d = (struct cbi_data *)p;
if (d->tag == tag)
return d;
@@ -92,6 +92,26 @@ static int cached_read_result = EC_ERROR_CBI_CACHE_INVALID;
static uint8_t cbi[CBI_EEPROM_SIZE];
static struct cbi_header * const head = (struct cbi_header *)cbi;
+int cbi_create(void)
+{
+ struct cbi_header * const h = (struct cbi_header *)cbi;
+
+ memset(cbi, 0, sizeof(cbi));
+ memcpy(h->magic, cbi_magic, sizeof(cbi_magic));
+ h->total_size = sizeof(*h);
+ h->major_version = CBI_VERSION_MAJOR;
+ h->minor_version = CBI_VERSION_MINOR;
+ h->crc = cbi_crc8(h);
+ cached_read_result = EC_SUCCESS;
+
+ return EC_SUCCESS;
+}
+
+void cbi_invalidate_cache(void)
+{
+ cached_read_result = EC_ERROR_CBI_CACHE_INVALID;
+}
+
static int read_eeprom(uint8_t offset, uint8_t *in, int in_size)
{
return i2c_read_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM_FLAGS,
@@ -266,6 +286,11 @@ static int write_board_info(void)
return EC_SUCCESS;
}
+int cbi_write(void)
+{
+ return write_board_info();
+}
+
int cbi_get_board_version(uint32_t *ver)
{
uint8_t size = sizeof(*ver);