diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-02-15 11:28:47 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-02-22 20:02:58 +0000 |
commit | 0746bc3366c1263d69c1a8d3ddee8e9ff274b0f5 (patch) | |
tree | bab43f781dc1e0b8957045fc42c949a57e9d856e /util/cbi-util.c | |
parent | b36899058e52830a48bdaabfbadfe777dc03672f (diff) | |
download | chrome-ec-0746bc3366c1263d69c1a8d3ddee8e9ff274b0f5.tar.gz |
CBI: Update cbi-util printing format
This patch makes cbi-util print the tag and the size of each field.
It also fixes help message and adds indendation for readability.
BUG=b:70294260
BRANCH=none
TEST=Run the command as follows:
$ cbi-util --show /tmp/cbi.bin
CBI blob: /tmp/cbi2.bin
TOTAL_SIZE: 18
CBI_VERSION: 0
Data Field: name: value (hex, tag, size)
BOARD_VERSION: 514 (0x202, 0, 2)
OEM_ID: 2 (0x2, 1, 1)
SKU_ID: 3 (0x3, 2, 1)
Data validated successfully
Change-Id: I5f0fde4690c29c0ee58c798e8cc35bac3ed1b6f8
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/926781
Reviewed-by: Randall Spangler <rspangler@chromium.org>
(cherry picked from commit f483d46b01992dfbaf274aaef4e382ca0091e407)
Reviewed-on: https://chromium-review.googlesource.com/932521
Diffstat (limited to 'util/cbi-util.c')
-rw-r--r-- | util/cbi-util.c | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/util/cbi-util.c b/util/cbi-util.c index 33f6203f56..c104e54eae 100644 --- a/util/cbi-util.c +++ b/util/cbi-util.c @@ -5,6 +5,7 @@ * Cros Board Info utility */ +#include <compile_time_macros.h> #include <errno.h> #include <dirent.h> #include <getopt.h> @@ -65,6 +66,14 @@ static const struct option long_opts[] = { {NULL, 0, 0, 0} }; +static const char *field_name[] = { + /* Same order as enum cbi_data_tag */ + "BOARD_VERSION", + "OEM_ID", + "SKU_ID", +}; +BUILD_ASSERT(ARRAY_SIZE(field_name) == CBI_TAG_COUNT); + static int write_file(const char *filename, const char *buf, int size) { FILE *f; @@ -200,12 +209,38 @@ static struct cbi_data *find_tag(const uint8_t *cbi, enum cbi_data_tag tag) 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); + const char *name = d->tag < CBI_TAG_COUNT ? field_name[d->tag] : "???"; + + if (!d) + return; + + switch (d->size) { + case 1: + v = *(uint8_t *)d->value; + break; + case 2: + v = *(uint16_t *)d->value; + break; + case 4: + v = *(uint32_t *)d->value; + break; + default: + printf(" %s: Integer of size %d not supported\n", + name, d->size); + return; + } + printf(" %s: %u (0x%x, %u, %u)\n", name, v, v, d->tag, d->size); +} + static int do_show(const char *cbi_filename, int show_all) { uint8_t *buf; uint32_t size; struct cbi_header *h; - struct cbi_data *d; if (!cbi_filename) { fprintf(stderr, "Missing arguments\n"); @@ -233,18 +268,10 @@ static int do_show(const char *cbi_filename, int show_all) printf(" TOTAL_SIZE: %u\n", h->total_size); printf(" CBI_VERSION: %u\n", h->version); - d = find_tag(buf, CBI_TAG_BOARD_VERSION); - if (d) - printf(" BOARD_VERSION: %u (0x%x)\n", - *(uint16_t *)d->value, *(uint16_t *)d->value); - d = find_tag(buf, CBI_TAG_OEM_ID); - if (d) - printf(" OEM_ID: %u (0x%x)\n", - *(uint8_t *)d->value, *(uint8_t *)d->value); - d = find_tag(buf, CBI_TAG_SKU_ID); - if (d) - printf(" SKU_ID: %u (0x%x)\n", - *(uint8_t *)d->value, *(uint8_t *)d->value); + printf(" Data Field: name: value (hex, tag, size)\n"); + print_integer(buf, CBI_TAG_BOARD_VERSION); + print_integer(buf, CBI_TAG_OEM_ID); + print_integer(buf, CBI_TAG_SKU_ID); printf("Data validated successfully\n"); return 0; @@ -253,7 +280,7 @@ static int do_show(const char *cbi_filename, int show_all) /* Print help and return error */ static void print_help(int argc, char *argv[]) { - printf("\nUsage: cbi %s <--create|--show>\n" + printf("\nUsage: %s <--create|--show>\n" "\n" "Utility for managing Cros Board Info (CBIs).\n" "\n" |