mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
d173cf4d6c
commit
f483d46b01
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user