From 546c606b5f0d4a3b8af54a17f5c729e670061fdc Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Thu, 22 Feb 2018 09:25:50 -0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/932001 --- util/build.mk | 2 +- util/cbi-util.c | 38 ++++---------------------------------- 2 files changed, 5 insertions(+), 35 deletions(-) (limited to 'util') 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) -- cgit v1.2.1