summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-11-16 15:22:09 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-11-29 12:11:03 -0800
commite9022668702c87c7403a0548a9236cc68b763df7 (patch)
tree3a3253c34a84eae37a9a1dbc652e73ca4fb87d20
parenta44c0c1e92b60a992c6b3add46016557d0343ed7 (diff)
downloadchrome-ec-e9022668702c87c7403a0548a9236cc68b763df7.tar.gz
CBI: Add MODEL_ID field
MODEL_ID is an optional field containing a numeric value identifying models. Model IDs are unique within each OEM and <OEM_ID, MODEL_ID> should form a unique ID within the family. $ cbi-util create --file ~/cbi_image --board_version 0 --oem_id 6 --sku_id 255 --dram_part_num "012345679abcdef" --model_id 127 --size 256 $ hexdump -C /tmp/cbi.bin 0000 43 42 49 fa 00 00 26 00 00 01 00 01 01 06 02 01 |CBI...&.........| 0010 ff 05 01 7f 03 10 30 31 32 33 34 35 36 37 39 61 |......012345679a| 0020 62 63 64 65 66 00 ff ff ff ff ff ff ff ff ff ff |bcdef...........| $ cbi-util show --file /tmp/cbi.bin CBI image: /tmp/cbi.bin TOTAL_SIZE: 38 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) MODEL_ID: 127 (0x7f, 5, 1) DRAM_PART_NUM: 012345679abcdef (3, 16) Data validated successfully localhost # ectool cbi set 5 127 1 localhost # ectool cbi get 5 As integer: 127 (0x7f) As binary: 7f > cbi [1289.860454 CBI Reading board info] CBI_VERSION: 0x0000 TOTAL_SIZE: 22 BOARD_VERSION: 513 (0x201) OEM_ID: 3 (0x3) MODEL_ID: 127 (0x7f) SKU_ID: 14951 (0x3a67) 43 42 49 b0 00 00 16 00 00 02 01 02 01 01 03 02 02 67 3a 05 01 7f ff ff ff ff ff ff ff ff ff ff Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b:119522898,b:120105950 BRANCH=none TEST=See above. Change-Id: Ifd6f3087f5422bcf4c36d3d981b262653d0c89dc Reviewed-on: https://chromium-review.googlesource.com/1341099 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--common/cbi.c7
-rw-r--r--include/cros_board_info.h1
-rw-r--r--include/ec_commands.h1
-rw-r--r--util/cbi-util.c23
-rw-r--r--util/ectool.c20
5 files changed, 39 insertions, 13 deletions
diff --git a/common/cbi.c b/common/cbi.c
index f37d6950b1..8ec4472b24 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -253,6 +253,12 @@ int cbi_get_oem_id(uint32_t *id)
return cbi_get_board_info(CBI_TAG_OEM_ID, (uint8_t *)id, &size);
}
+int cbi_get_model_id(uint32_t *id)
+{
+ uint8_t size = sizeof(*id);
+ return cbi_get_board_info(CBI_TAG_MODEL_ID, (uint8_t *)id, &size);
+}
+
static int hc_cbi_get(struct host_cmd_handler_args *args)
{
const struct __ec_align4 ec_params_get_cbi *p = args->params;
@@ -367,6 +373,7 @@ static void dump_cbi(void)
print_tag("BOARD_VERSION", cbi_get_board_version(&val), &val);
print_tag("OEM_ID", cbi_get_oem_id(&val), &val);
+ print_tag("MODEL_ID", cbi_get_model_id(&val), &val);
print_tag("SKU_ID", cbi_get_sku_id(&val), &val);
}
diff --git a/include/cros_board_info.h b/include/cros_board_info.h
index 23063d2766..8ed8737731 100644
--- a/include/cros_board_info.h
+++ b/include/cros_board_info.h
@@ -50,6 +50,7 @@ struct cbi_data {
int cbi_get_board_version(uint32_t *version);
int cbi_get_sku_id(uint32_t *sku_id);
int cbi_get_oem_id(uint32_t *oem_id);
+int cbi_get_model_id(uint32_t *id);
/**
* Primitive accessors
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 34d6bb7038..7e651ea214 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -4958,6 +4958,7 @@ enum cbi_data_tag {
CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
+ CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
CBI_TAG_COUNT,
};
diff --git a/util/cbi-util.c b/util/cbi-util.c
index cc4fda8ba5..2ea86b14cf 100644
--- a/util/cbi-util.c
+++ b/util/cbi-util.c
@@ -37,6 +37,7 @@ enum {
OPT_SKU_ID,
OPT_DRAM_PART_NUM,
OPT_OEM_NAME,
+ OPT_MODEL_ID,
OPT_SIZE,
OPT_ERASE_BYTE,
OPT_SHOW_ALL,
@@ -50,6 +51,7 @@ static const struct option opts_create[] = {
{"sku_id", 1, 0, OPT_SKU_ID},
{"dram_part_num", 1, 0, OPT_DRAM_PART_NUM},
{"oem_name", 1, 0, OPT_OEM_NAME},
+ {"model_id", 1, 0, OPT_MODEL_ID},
{"size", 1, 0, OPT_SIZE},
{"erase_byte", 1, 0, OPT_ERASE_BYTE},
{NULL, 0, 0, 0}
@@ -67,7 +69,8 @@ static const char *field_name[] = {
"OEM_ID",
"SKU_ID",
"DRAM_PART_NUM",
- "OEM_NAME"
+ "OEM_NAME",
+ "MODEL_ID",
};
BUILD_ASSERT(ARRAY_SIZE(field_name) == CBI_TAG_COUNT);
@@ -75,11 +78,11 @@ const char help_create[] =
"\n"
"'%s create [ARGS]' creates an EEPROM image file.\n"
"Required ARGS are:\n"
- " --file <file> Path to output file\n"
- " --board_version <value> Board version\n"
- " --oem_id <value> OEM ID\n"
- " --sku_id <value> SKU ID\n"
- " --size <size> Size of output file in bytes\n"
+ " --file <file> Path to output file\n"
+ " --board_version <value> Board version\n"
+ " --oem_id <value> OEM ID\n"
+ " --sku_id <value> SKU ID\n"
+ " --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"
"<size> must be a positive integer <= 0XFFFF.\n"
@@ -88,6 +91,7 @@ const char help_create[] =
" --oem_name <string> OEM NAME\n"
" --erase_byte <uint8> Byte used for empty space. Default:0xff\n"
" --format_version <uint16> Data format version\n"
+ " --model_id <value> Model ID\n"
"<string> is a string\n"
"\n";
@@ -240,6 +244,7 @@ static int cmd_create(int argc, char **argv)
struct integer_field ver;
struct integer_field oem;
struct integer_field sku;
+ struct integer_field model;
const char *dram_part_num;
const char *oem_name;
} bi;
@@ -305,6 +310,10 @@ static int cmd_create(int argc, char **argv)
case OPT_OEM_NAME:
bi.oem_name = optarg;
break;
+ case OPT_MODEL_ID:
+ if (parse_integer_field(optarg, &bi.model))
+ return -1;
+ break;
}
}
@@ -330,6 +339,7 @@ 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);
+ p = cbi_set_data(p, CBI_TAG_MODEL_ID, &bi.model.val, bi.model.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);
@@ -458,6 +468,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_integer(buf, CBI_TAG_MODEL_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 03b0ecca17..f918c0b7eb 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -6805,6 +6805,7 @@ static void cmd_cbi_help(char *cmd)
" 2: SKU_ID\n"
" 3: DRAM_PART_NUM (string)\n"
" 4: OEM_NAME (string)\n"
+ " 5: MODEL_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"
@@ -6815,6 +6816,11 @@ static void cmd_cbi_help(char *cmd)
" 10b: Set all fields to defaults first\n", cmd, cmd);
}
+static int cmd_cbi_is_string_field(enum cbi_data_tag tag)
+{
+ return tag == CBI_TAG_DRAM_PART_NUM || tag == CBI_TAG_OEM_NAME;
+}
+
/*
* Write value to CBI
*
@@ -6862,7 +6868,9 @@ static int cmd_cbi(int argc, char *argv[])
return -1;
}
r = ec_inbuf;
- if (tag != CBI_TAG_DRAM_PART_NUM && tag != CBI_TAG_OEM_NAME) {
+ if (cmd_cbi_is_string_field(tag)) {
+ printf("%.*s", rv, (const char *)r);
+ } else {
if (rv <= sizeof(uint32_t))
printf("As integer: %u (0x%x)\n", r[0], r[0]);
printf("As binary:");
@@ -6871,8 +6879,6 @@ static int cmd_cbi(int argc, char *argv[])
printf("\n");
printf(" %02x", r[i]);
}
- } else {
- printf("%.*s", rv, (const char *)r);
}
printf("\n");
return 0;
@@ -6890,7 +6896,10 @@ static int cmd_cbi(int argc, char *argv[])
memset(p, 0, ec_max_outsize);
p->tag = tag;
- if (tag != CBI_TAG_DRAM_PART_NUM && tag != CBI_TAG_OEM_NAME) {
+ if (cmd_cbi_is_string_field(tag)) {
+ val_ptr = argv[3];
+ size = strlen(val_ptr) + 1;
+ } else {
val = strtol(argv[3], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad value\n");
@@ -6903,9 +6912,6 @@ static int cmd_cbi(int argc, char *argv[])
return -1;
}
val_ptr = &val;
- } else {
- val_ptr = argv[3];
- size = strlen(val_ptr) + 1;
}
if (size > ec_max_outsize - sizeof(*p)) {