summaryrefslogtreecommitdiff
path: root/util/cbi-util.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2018-08-07 11:29:28 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-08-08 13:45:46 -0700
commit6ece66961c1ea17f7f6868c41cc553b794623bb4 (patch)
treee6467333360405fc8ece28346bedc4695abb80f9 /util/cbi-util.c
parentb80693e94e6e9aa0a382c39c20efba6f2c7403a9 (diff)
downloadchrome-ec-6ece66961c1ea17f7f6868c41cc553b794623bb4.tar.gz
Add DRAM part number support to CBI
Allow one to encode the DRAM part number in CBI. Both cbi-util and ectool are updated. $ cbi-util create --file ~/cbi_image --board_version 0 --oem_id 6 --sku_id 255 --dram_part_num "012345679abcdef" --size 256 CBI image is created successfully $ hexdump -C ~/cbi_image 00000000 43 42 49 47 00 00 23 00 00 01 00 01 01 06 02 01 |CBIG..#.........| 00000010 ff 03 10 30 31 32 33 34 35 36 37 39 61 62 63 64 |...012345679abcd| 00000020 65 66 00 ff ff ff ff ff ff ff ff ff ff ff ff ff |ef..............| 00000030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| * 00000100 $ cbi-util show --file ~/cbi_image CBI image: /home/adurbin/cbi_image TOTAL_SIZE: 35 Data Field: name: value (hex, tag, size) BOARD_VERSION: 0 (0x0, 0, 1) OEM_ID: 6 (0x6, 1, 1) SKU_ID: 255 (0xff, 2, 1) DRAM_PART_NUM: 012345679abcdef (3, 16) Data validated successfully localhost /tmp # ./ectool cbi set 0 0 1 2 localhost /tmp # ./ectool cbi set 1 6 1 1 localhost /tmp # ./ectool cbi set 2 255 1 1 localhost /tmp # ./ectool cbi set 3 H9HCNNNBPUMLHR 0 0 localhost /tmp # ./ectool cbi get 0 As integer: 0 (0x0) As binary: 00 localhost /tmp # ./ectool cbi get 1 As integer: 6 (0x6) As binary: 06 localhost /tmp # ./ectool cbi get 2 As integer: 255 (0xff) As binary: ff localhost /tmp # ./ectool cbi get 3 H9HCNNNBPUMLHR BUG=b:112203105 BRANCH=None TEST=Commands executed above. Change-Id: I2d519ad16a158db4e624d3a03912434d0e8fdd73 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1165622 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'util/cbi-util.c')
-rw-r--r--util/cbi-util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util/cbi-util.c b/util/cbi-util.c
index 23d9986348..f62db3d819 100644
--- a/util/cbi-util.c
+++ b/util/cbi-util.c
@@ -35,6 +35,7 @@ enum {
OPT_BOARD_VERSION,
OPT_OEM_ID,
OPT_SKU_ID,
+ OPT_DRAM_PART_NUM,
OPT_SIZE,
OPT_ERASE_BYTE,
OPT_SHOW_ALL,
@@ -46,6 +47,7 @@ static const struct option opts_create[] = {
{"board_version", 1, 0, OPT_BOARD_VERSION},
{"oem_id", 1, 0, OPT_OEM_ID},
{"sku_id", 1, 0, OPT_SKU_ID},
+ {"dram_part_num", 1, 0, OPT_DRAM_PART_NUM},
{"size", 1, 0, OPT_SIZE},
{"erase_byte", 1, 0, OPT_ERASE_BYTE},
{NULL, 0, 0, 0}
@@ -62,6 +64,7 @@ static const char *field_name[] = {
"BOARD_VERSION",
"OEM_ID",
"SKU_ID",
+ "DRAM_PART_NUM"
};
BUILD_ASSERT(ARRAY_SIZE(field_name) == CBI_TAG_COUNT);
@@ -76,8 +79,10 @@ const char help_create[] =
" --size <size> Size of output file in bytes\n"
"<value> must be a positive integer <= 0XFFFFFFFF and field size can\n"
"be optionally specified by <value:size> notation: e.g. 0xabcd:4.\n"
+ "<value> can be a string for DRAM PART NUM.\n"
"<size> must be a positive integer <= 0XFFFF.\n"
"Optional ARGS are:\n"
+ " --dram_part_num <value> DRAM PART NUM\n"
" --erase_byte <uint8> Byte used for empty space. Default:0xff\n"
" --format_version <uint16> Data format version\n"
"\n";
@@ -231,6 +236,7 @@ static int cmd_create(int argc, char **argv)
struct integer_field ver;
struct integer_field oem;
struct integer_field sku;
+ const char *dram_part_num;
} bi;
struct cbi_header *h;
int rv;
@@ -288,6 +294,9 @@ static int cmd_create(int argc, char **argv)
return -1;
set_mask |= ARGS_MASK_SKU_ID;
break;
+ case OPT_DRAM_PART_NUM:
+ bi.dram_part_num = optarg;
+ break;
}
}
@@ -313,6 +322,10 @@ static int cmd_create(int argc, char **argv)
p = cbi_set_data(p, CBI_TAG_BOARD_VERSION, &bi.ver.val, bi.ver.size);
p = cbi_set_data(p, CBI_TAG_OEM_ID, &bi.oem.val, bi.oem.size);
p = cbi_set_data(p, CBI_TAG_SKU_ID, &bi.sku.val, bi.sku.size);
+ if (bi.dram_part_num != NULL) {
+ p = cbi_set_data(p, CBI_TAG_DRAM_PART_NUM, bi.dram_part_num,
+ strlen(bi.dram_part_num) + 1);
+ }
h->total_size = p - cbi;
h->crc = cbi_crc8(h);
@@ -329,6 +342,20 @@ static int cmd_create(int argc, char **argv)
return 0;
}
+static void print_string(const uint8_t *buf, enum cbi_data_tag tag)
+{
+ struct cbi_data *d = cbi_find_tag(buf, tag);
+ const char *name;
+
+ if (!d)
+ return;
+
+ name = d->tag < CBI_TAG_COUNT ? field_name[d->tag] : "???";
+
+ printf(" %s: %.*s (%u, %u)\n", name, d->size, (const char *)d->value,
+ d->tag, d->size);
+}
+
static void print_integer(const uint8_t *buf, enum cbi_data_tag tag)
{
uint32_t v;
@@ -418,6 +445,7 @@ static int cmd_show(int argc, char **argv)
print_integer(buf, CBI_TAG_BOARD_VERSION);
print_integer(buf, CBI_TAG_OEM_ID);
print_integer(buf, CBI_TAG_SKU_ID);
+ print_string(buf, CBI_TAG_DRAM_PART_NUM);
free(buf);