diff options
author | Aaron Durbin <adurbin@chromium.org> | 2018-08-07 11:29:28 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-08 13:45:46 -0700 |
commit | 6ece66961c1ea17f7f6868c41cc553b794623bb4 (patch) | |
tree | e6467333360405fc8ece28346bedc4695abb80f9 /util | |
parent | b80693e94e6e9aa0a382c39c20efba6f2c7403a9 (diff) | |
download | chrome-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')
-rw-r--r-- | util/cbi-util.c | 28 | ||||
-rw-r--r-- | util/ectool.c | 53 |
2 files changed, 64 insertions, 17 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); diff --git a/util/ectool.c b/util/ectool.c index 669cd09499..2af028b3ca 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -6613,8 +6613,9 @@ static void cmd_cbi_help(char *cmd) " 0: BOARD_VERSION\n" " 1: OEM_ID\n" " 2: SKU_ID\n" + " 3: DRAM_PART_NUM\n" " <size> is the size of the data in byte\n" - " <value> is integer to be set. No raw data support yet.\n" + " <value> is integer to be set, string for DRAM_PART_NUM\n" " [get_flag] is combination of:\n" " 01b: Invalidate cache and reload data from EEPROM\n" " [set_flag] is combination of:\n" @@ -6669,19 +6670,24 @@ static int cmd_cbi(int argc, char *argv[]) return -1; } r = ec_inbuf; - if (rv <= sizeof(uint32_t)) - printf("As integer: %u (0x%x)\n", r[0], r[0]); - printf("As binary:"); - for (i = 0; i < rv; i++) { - if (i % 32 == 31) - printf("\n"); - printf(" %02x", r[i]); + if (tag != CBI_TAG_DRAM_PART_NUM) { + if (rv <= sizeof(uint32_t)) + printf("As integer: %u (0x%x)\n", r[0], r[0]); + printf("As binary:"); + for (i = 0; i < rv; i++) { + if (i % 32 == 31) + printf("\n"); + printf(" %02x", r[i]); + } + } else { + printf("%.*s", rv, (const char *)r); } printf("\n"); return 0; } else if (!strcasecmp(argv[1], "set")) { struct ec_params_set_cbi *p = (struct ec_params_set_cbi *)ec_outbuf; + void *val_ptr; uint32_t val; uint8_t size; if (argc < 5) { @@ -6691,19 +6697,32 @@ static int cmd_cbi(int argc, char *argv[]) } memset(p, 0, ec_max_outsize); p->tag = tag; - val = strtol(argv[3], &e, 0); - if (e && *e) { - fprintf(stderr, "Bad value\n"); - return -1; + + if (tag != CBI_TAG_DRAM_PART_NUM) { + val = strtol(argv[3], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad value\n"); + return -1; + } + size = strtol(argv[4], &e, 0); + if ((e && *e) || size < 1 || 4 < size || + val >= (1ull << size*8)) { + fprintf(stderr, "Bad size: %d\n", size); + return -1; + } + val_ptr = &val; + } else { + val_ptr = argv[3]; + size = strlen(val_ptr) + 1; } - size = strtol(argv[4], &e, 0); - if ((e && *e) || size < 1 || 4 < size || - val >= (1ull << size*8)) { - fprintf(stderr, "Bad size: %d\n", size); + + if (size > ec_max_outsize - sizeof(*p)) { + fprintf(stderr, "Size exceeds parameter buffer: %d\n", + size); return -1; } /* Little endian */ - memcpy(p->data, &val, size); + memcpy(p->data, val_ptr, size); p->size = size; if (argc > 5) { p->flag = strtol(argv[5], &e, 0); |