summaryrefslogtreecommitdiff
path: root/common/cbi.c
diff options
context:
space:
mode:
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);