diff options
author | Thejaswani Puta thejaswani.putta@intel.com <thejaswani.putta@intel.corp-partner.google.com> | 2021-01-20 15:22:01 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-10 00:33:49 +0000 |
commit | 48ce00b56ce350cbec0e67b1b489aaa145c2b3a4 (patch) | |
tree | f9fda4095887e1d43dbde7744c4174386e5be575 /util | |
parent | 2875dd8dd9920954f8c40621e9453d3b2e4bfc82 (diff) | |
download | chrome-ec-48ce00b56ce350cbec0e67b1b489aaa145c2b3a4.tar.gz |
CBI: Add rework_id field
This field will be used to describe all the reworks performed on
a board which includes the mandatory, optional and feature reworks.
Also modified existing command handlers under ectool and cbi-util tool
to support 64 bit length data.
BUG: b:170385859
TEST: ./cbi-util create --file ~/cbi_image --board_version 1
--oem_id 2 --sku_id 255 --dram_part_num "01654329efghac"
--model_id 15 --rework_id 123456789123456712 --size 256
CBI image is created successfully
TEST: ./cbi-util show --file ~/cbi_image
CBI image: /home/thejaswani/cbi_image
TOTAL_SIZE: 47
Data Field: name: value (hex, tag, size)
BOARD_VERSION: 1 (0x1, 0, 1)
OEM_ID: 2 (0x2, 1, 1)
SKU_ID: 255 (0xff, 2, 1)
MODEL_ID: 15 (0xf, 5, 1)
REWORK_ID: 123456789123456712 (0x1b69b4bacd05ec8, 9, 8)
DRAM_PART_NUM: 01654329efghac (3, 15)
Data validated successfully
TEST: hexdump -C ~/cbi_image
00000000 43 42 49 1e 00 00 2f 00 00 01 01 01 01 02 02 01 |CBI.../.........|
00000010 ff 05 01 0f 09 08 c8 5e d0 ac 4b 9b b6 01 03 0f |.......^..K.....|
00000020 30 31 36 35 34 33 32 39 65 66 67 68 61 63 00 ff |01654329efghac..|
00000030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00000100
TEST:
localhost ~ # ectool cbi set 9 98765432 8
localhost ~ # ectool cbi get 9
As uint: 98765432 (0x5e30a78)
As binary: 78 0a e3 05 00 00 00 00
localhost ~ # ectool cbi set 9 123456789123456712 8
localhost ~ # ectool cbi get 9
As uint: 123456789123456712 (0x1b69b4bacd05ec8)
As binary: c8 5e d0 ac 4b 9b b6 01
localhost ~ # ectool cbi set 9 1234 2
localhost ~ # ectool cbi get 9
As uint: 1234 (0x4d2)
As binary: d2 04
TEST:
> cbi(from EC Console)
2021-01-19 20:59:56 [80.979692 CBI Reading board info]
2021-01-19 20:59:56 CBI_VERSION: 0x0000
2021-01-19 20:59:56 TOTAL_SIZE: 54
2021-01-19 20:59:56 BOARD_VERSION: 1 (0x1)
2021-01-19 20:59:56 OEM_ID: (Error 1)
2021-01-19 20:59:56 MODEL_ID: (Error 1)
2021-01-19 20:59:56 SKU_ID: 655361 (0xa0001)
2021-01-19 20:59:56 FW_CONFIG: 199683 (0x30c03)
2021-01-19 20:59:56 PCB_SUPPLIER: (Error 1)
2021-01-19 20:59:56 SSFC: (Error 1)
2021-01-19 20:59:56 REWORK_ID: 1234 (0x4d2)
2021-01-19 20:59:56 43 42 49 8c 00 00 36 00 00 01 01 02 04 01 00 0a |CBI...6.........|
2021-01-19 20:59:56 00 06 04 03 0c 03 00 03 19 4d 54 35 33 45 35 31 |.........MT53E51|
2021-01-19 20:59:56 32 4d 36 34 44 34 4e 57 2d 30 34 36 20 57 54 3a |2M64D4NW-046 WT:|
2021-01-19 20:59:56 45 00 09 02 d2 04 ff ff ff ff ff 7f ff ff ff ff |E...............|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2020-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
2021-01-19 20:59:56 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
Change-Id: Ic8163ceaec55c429c9836f9a1e75d0de31ea072b
Signed-off-by: Thejaswani Puta <thejaswani.putta@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2641127
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Thejaswani Putta <thejaswani.putta@intel.corp-partner.google.com>
Tested-by: Thejaswani Putta <thejaswani.putta@intel.corp-partner.google.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/cbi-util.c | 71 | ||||
-rw-r--r-- | util/ectool.c | 40 |
2 files changed, 93 insertions, 18 deletions
diff --git a/util/cbi-util.c b/util/cbi-util.c index 54782f8bad..51d229d901 100644 --- a/util/cbi-util.c +++ b/util/cbi-util.c @@ -40,6 +40,7 @@ enum { OPT_FW_CONFIG, OPT_PCB_SUPPLIER, OPT_SSFC, + OPT_REWORK_ID, OPT_SIZE, OPT_ERASE_BYTE, OPT_SHOW_ALL, @@ -57,6 +58,7 @@ static const struct option opts_create[] = { {"fw_config", 1, 0, OPT_FW_CONFIG}, {"pcb_supplier", 1, 0, OPT_PCB_SUPPLIER}, {"ssfc", 1, 0, OPT_SSFC}, + {"rework_id", 1, 0, OPT_REWORK_ID}, {"size", 1, 0, OPT_SIZE}, {"erase_byte", 1, 0, OPT_ERASE_BYTE}, {NULL, 0, 0, 0} @@ -79,6 +81,7 @@ static const char *field_name[] = { "FW_CONFIG", "PCB_SUPPLIER", "SSFC", + "REWORK_ID", }; BUILD_ASSERT(ARRAY_SIZE(field_name) == CBI_TAG_COUNT); @@ -101,9 +104,11 @@ const char help_create[] = " --fw_config <value> Firmware configuration bit-field\n" " --pcb_supplier <value> PCB supplier\n" " --ssfc <value> Second Source Factory Cache bit-field\n" + " --rework_id <lvalue> REWORK_ID\n" "\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> must be a positive integer <= 0XFFFFFFFF, <lvalue> must be a\n" + " positive integer <= 0xFFFFFFFFFFFFFFFF and field size can be\n" + " optionally specified by <value:size> notation: e.g. 0xabcd:4.\n" "<size> must be a positive integer <= 0XFFFF.\n" "<string> is a string\n" "\n"; @@ -124,6 +129,11 @@ struct integer_field { int size; }; +struct long_integer_field { + uint64_t val; + int size; +}; + static void print_help_create(void) { printf(help_create, cmd_name); @@ -250,6 +260,48 @@ static int parse_integer_field(const char *arg, struct integer_field *f) return 0; } +static int parse_uint64_field(const char *arg, struct long_integer_field *f) +{ + uint64_t val; + char *e; + char *ch; + + val = strtoul(arg, &e, 0); + /* strtoul sets an errno for invalid input. If the value read is out of + * range of representable values by an unsigned long int, the function + * returns ULONG_MAX or ULONG_MIN and the errno is set to ERANGE. + */ + if (errno == ERANGE || !*arg || (e && *e && *e != ':')) { + fprintf(stderr, "Invalid integer value\n"); + return -1; + } + f->val = val; + + ch = strchr(arg, ':'); + if (ch) { + ch++; + val = strtoul(ch, &e, 0); + if (val < 1 || 8 < val || !*ch || (e && *e)) { + fprintf(stderr, "Invalid size suffix\n"); + return -1; + } + f->size = val; + } else { + if (f->val < UINT32_MAX) + f->size = estimate_field_size(f->val); + else + f->size = 8; /* assign default long int size */ + } + + if (f->size < 8 && (f->val > (1ull << f->size * 8))) { + fprintf(stderr, "Value (0x%lx) exceeds field size (%d)\n", + f->val, f->size); + return -1; + } + + return 0; +} + static int cmd_create(int argc, char **argv) { uint8_t *cbi; @@ -261,6 +313,7 @@ static int cmd_create(int argc, char **argv) struct integer_field fw_config; struct integer_field pcb_supplier; struct integer_field ssfc; + struct long_integer_field rework; const char *dram_part_num; const char *oem_name; } bi; @@ -341,6 +394,10 @@ static int cmd_create(int argc, char **argv) if (parse_integer_field(optarg, &bi.ssfc)) return -1; break; + case OPT_REWORK_ID: + if (parse_uint64_field(optarg, &bi.rework)) + return -1; + break; } } @@ -372,6 +429,7 @@ static int cmd_create(int argc, char **argv) p = cbi_set_data(p, CBI_TAG_PCB_SUPPLIER, &bi.pcb_supplier.val, bi.pcb_supplier.size); p = cbi_set_data(p, CBI_TAG_SSFC, &bi.ssfc.val, bi.ssfc.size); + p = cbi_set_data(p, CBI_TAG_REWORK_ID, &bi.rework.val, bi.rework.size); p = cbi_set_string(p, CBI_TAG_DRAM_PART_NUM, bi.dram_part_num); p = cbi_set_string(p, CBI_TAG_OEM_NAME, bi.oem_name); @@ -407,7 +465,8 @@ static void print_string(const uint8_t *buf, enum cbi_data_tag tag) static void print_integer(const uint8_t *buf, enum cbi_data_tag tag) { - uint32_t v; + uint64_t v; + struct cbi_data *d = cbi_find_tag(buf, tag); const char *name; @@ -426,12 +485,15 @@ static void print_integer(const uint8_t *buf, enum cbi_data_tag tag) case 4: v = *(uint32_t *)d->value; break; + case 8: + v = *(uint64_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); + printf(" %s: %lu (0x%lx, %u, %u)\n", name, v, v, d->tag, d->size); } static int cmd_show(int argc, char **argv) @@ -500,6 +562,7 @@ static int cmd_show(int argc, char **argv) print_integer(buf, CBI_TAG_FW_CONFIG); print_integer(buf, CBI_TAG_PCB_SUPPLIER); print_integer(buf, CBI_TAG_SSFC); + print_integer(buf, CBI_TAG_REWORK_ID); print_string(buf, CBI_TAG_DRAM_PART_NUM); print_string(buf, CBI_TAG_OEM_NAME); diff --git a/util/ectool.c b/util/ectool.c index a5d156129d..cabe13adb5 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -8106,6 +8106,7 @@ static void cmd_cbi_help(char *cmd) " 6: FW_CONFIG\n" " 7: PCB_VENDOR\n" " 8: SSFC\n" + " 9: REWORK_ID\n" " <size> is the size of the data in byte. It should be zero for\n" " string types.\n" " <value/string> is an integer or a string to be set\n" @@ -8171,16 +8172,12 @@ static int cmd_cbi(int argc, char *argv[]) printf("%.*s", rv, (const char *)ec_inbuf); } else { const uint8_t * const buffer = ec_inbuf; + uint64_t int_value = 0; + for(i = 0; i < rv; i++) + int_value |= (uint64_t)buffer[i] << (i * 8); - if (rv <= sizeof(uint32_t)) { - uint32_t int_value = 0; - - for (i = 0; i < rv; i++) - int_value |= buffer[i] << (i * 8); - - printf("As uint: %u (0x%x)\n", int_value, - int_value); - } + printf("As uint: %lu (0x%lx)\n", int_value, + int_value); printf("As binary:"); for (i = 0; i < rv; i++) { if (i % 32 == 31) @@ -8194,8 +8191,9 @@ static int cmd_cbi(int argc, char *argv[]) struct ec_params_set_cbi *p = (struct ec_params_set_cbi *)ec_outbuf; void *val_ptr; - uint32_t val; + uint64_t val = 0; uint8_t size; + uint8_t bad_size = 0; if (argc < 5) { fprintf(stderr, "Invalid number of params\n"); cmd_cbi_help(argv[0]); @@ -8208,17 +8206,31 @@ static int cmd_cbi(int argc, char *argv[]) val_ptr = argv[3]; size = strlen(val_ptr) + 1; } else { - val = strtol(argv[3], &e, 0); - if (e && *e) { + val = strtoul(argv[3], &e, 0); + /* strtoul sets an errno for invalid input. If the value + * read is out of range of representable values by an + * unsigned long int, the function returns ULONG_MAX + * or ULONG_MIN and the errno is set to ERANGE. + */ + if ((e && *e) || errno == ERANGE) { fprintf(stderr, "Bad value\n"); return -1; } size = strtol(argv[4], &e, 0); - if ((e && *e) || size < 1 || 4 < size || - val >= (1ull << size*8)) { + if (tag == CBI_TAG_REWORK_ID) { + if ((e && *e) || size < 1 || size > 8 || + (size < 8 && val >= (1ull << size*8))) + bad_size = 1; + } else { + if ((e && *e) || size < 1 || 4 < size || + val >= (1ull << size*8)) + bad_size = 1; + } + if (bad_size == 1) { fprintf(stderr, "Bad size: %d\n", size); return -1; } + val_ptr = &val; } |