summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-02-22 09:25:50 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-23 03:36:35 -0800
commit546c606b5f0d4a3b8af54a17f5c729e670061fdc (patch)
treebb152d9c9e274976f0e3bc337e2042df6818f031 /util
parentd015bc937c0eecf1cb8f1b163874ea69c890dea4 (diff)
downloadchrome-ec-546c606b5f0d4a3b8af54a17f5c729e670061fdc.tar.gz
CBI: Share common code between host tool and firmware
This patch makes EC firmware and cbi-util share the common code. BUG=b:70294260 BRANCH=none TEST=Set fields using ectool. Verify the contents by cbi command. Verify cbi-util creates the same binary as before. Verify emerge ec-utils ec-devutils pass. Change-Id: If5e65e48dd03960e0adf23ef775f67aecf785d85 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/932001
Diffstat (limited to 'util')
-rw-r--r--util/build.mk2
-rw-r--r--util/cbi-util.c38
2 files changed, 5 insertions, 35 deletions
diff --git a/util/build.mk b/util/build.mk
index 7a1ab8b766..1879a0a2a5 100644
--- a/util/build.mk
+++ b/util/build.mk
@@ -57,7 +57,7 @@ $(out)/util/gen_touchpad_hash: BUILD_CFLAGS += $(OPENSSL_CFLAGS)
$(out)/util/gen_touchpad_hash: BUILD_LDFLAGS += $(OPENSSL_LDFLAGS)
endif # CONFIG_TOUCHPAD_VIRTUAL_OFF
-cbi-util-objs=../common/crc8.o
+cbi-util-objs=../common/crc8.o ../common/cbi.o
$(out)/util/export_taskinfo.so: $(out)/util/export_taskinfo_ro.o \
$(out)/util/export_taskinfo_rw.o
diff --git a/util/cbi-util.c b/util/cbi-util.c
index c104e54eae..5f8cddc128 100644
--- a/util/cbi-util.c
+++ b/util/cbi-util.c
@@ -137,22 +137,6 @@ static uint8_t *read_file(const char *filename, uint32_t *size_ptr)
return buf;
}
-static int cbi_crc8(const struct cbi_header *h)
-{
- return crc8((uint8_t *)&h->crc + 1,
- h->total_size - sizeof(h->magic) - sizeof(h->crc));
-}
-
-static uint8_t *set_data(uint8_t *p, enum cbi_data_tag tag, void *buf, int size)
-{
- struct cbi_data *d = (struct cbi_data *)p;
- d->tag = tag;
- d->size = size;
- memcpy(d->value, buf, size);
- p += sizeof(*d) + size;
- return p;
-}
-
/*
* Create a CBI blob
*/
@@ -176,10 +160,10 @@ static int do_create(const char *cbi_filename, uint32_t size, uint8_t erase,
h->major_version = CBI_VERSION_MAJOR;
h->minor_version = CBI_VERSION_MINOR;
p = h->data;
- p = set_data(p, CBI_TAG_BOARD_VERSION,
+ p = cbi_set_data(p, CBI_TAG_BOARD_VERSION,
&bi->version, sizeof(bi->version));
- p = set_data(p, CBI_TAG_OEM_ID, &bi->oem_id, sizeof(bi->oem_id));
- p = set_data(p, CBI_TAG_SKU_ID, &bi->sku_id, sizeof(bi->sku_id));
+ p = cbi_set_data(p, CBI_TAG_OEM_ID, &bi->oem_id, sizeof(bi->oem_id));
+ p = cbi_set_data(p, CBI_TAG_SKU_ID, &bi->sku_id, sizeof(bi->sku_id));
h->total_size = p - cbi;
h->crc = cbi_crc8(h);
@@ -195,24 +179,10 @@ static int do_create(const char *cbi_filename, uint32_t size, uint8_t erase,
return 0;
}
-static struct cbi_data *find_tag(const uint8_t *cbi, enum cbi_data_tag tag)
-{
- struct cbi_data *d;
- const struct cbi_header *h = (const struct cbi_header *)cbi;
- const uint8_t *p;
- for (p = h->data; p + sizeof(*d) < cbi + h->total_size;) {
- d = (struct cbi_data *)p;
- if (d->tag == tag)
- return d;
- p += sizeof(*d) + d->size;
- }
- return NULL;
-}
-
static void print_integer(const uint8_t *buf, enum cbi_data_tag tag)
{
uint32_t v;
- struct cbi_data *d = find_tag(buf, tag);
+ struct cbi_data *d = cbi_find_tag(buf, tag);
const char *name = d->tag < CBI_TAG_COUNT ? field_name[d->tag] : "???";
if (!d)