summaryrefslogtreecommitdiff
path: root/util/ectool.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/ectool.c')
-rw-r--r--util/ectool.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/util/ectool.c b/util/ectool.c
index a706ec12e8..6661e51936 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -6231,11 +6231,13 @@ static void cmd_cbi_help(char *cmd)
{
fprintf(stderr,
" Usage: %s get <type> [get_flag]\n"
- " Usage: %s set <type> value [set_flag]\n"
+ " Usage: %s set <type> <value> <size> [set_flag]\n"
" <type> is one of:\n"
" 0: BOARD_VERSION\n"
" 1: OEM_ID\n"
" 2: SKU_ID\n"
+ " <size> is the size of the data"
+ " <value> is integer to be set. No raw data support yet."
" [get_flag] is combination of:\n"
" 01b: Invalidate cache and reload data from EEPROM\n"
" [set_flag] is combination of:\n"
@@ -6250,7 +6252,7 @@ static void cmd_cbi_help(char *cmd)
*/
static int cmd_cbi(int argc, char *argv[])
{
- enum cbi_data_type type;
+ enum cbi_data_tag tag;
char *e;
int rv;
@@ -6260,17 +6262,18 @@ static int cmd_cbi(int argc, char *argv[])
return -1;
}
- /* Type */
- type = strtol(argv[2], &e, 0);
+ /* Tag */
+ tag = strtol(argv[2], &e, 0);
if (e && *e) {
- fprintf(stderr, "Bad type\n");
+ fprintf(stderr, "Bad tag\n");
return -1;
}
if (!strcasecmp(argv[1], "get")) {
struct ec_params_get_cbi p;
- uint32_t r;
- p.type = type;
+ uint8_t *r;
+ int i;
+ p.tag = tag;
if (argc > 3) {
p.flag = strtol(argv[3], &e, 0);
if (e && *e) {
@@ -6279,45 +6282,60 @@ static int cmd_cbi(int argc, char *argv[])
}
}
rv = ec_command(EC_CMD_GET_CROS_BOARD_INFO, 0, &p, sizeof(p),
- &r, sizeof(r));
+ ec_inbuf, ec_max_insize);
if (rv < 0) {
fprintf(stderr, "Error code: %d\n", rv);
return rv;
}
- if (type < CBI_FIRST_STRING_PARAM) { /* integer fields */
- if (rv < sizeof(uint32_t)) {
- fprintf(stderr, "Invalid size: %d\n", rv);
- return -1;
- }
- printf("%u (0x%x)\n", r, r);
- } else {
- fprintf(stderr, "Invalid type: %x\n", type);
+ if (rv < sizeof(uint8_t)) {
+ fprintf(stderr, "Invalid size: %d\n", rv);
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]);
+ }
+ printf("\n");
return 0;
} else if (!strcasecmp(argv[1], "set")) {
- struct ec_params_set_cbi p;
- if (argc < 4) {
+ struct ec_params_set_cbi *p =
+ (struct ec_params_set_cbi *)ec_outbuf;
+ uint32_t val;
+ uint8_t size;
+ if (argc < 5) {
fprintf(stderr, "Invalid number of params\n");
cmd_cbi_help(argv[0]);
return -1;
}
- memset(&p, 0, sizeof(p));
- p.type = type;
- p.data = strtol(argv[3], &e, 0);
+ 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 (argc > 4) {
- p.flag = strtol(argv[4], &e, 0);
+ size = strtol(argv[4], &e, 0);
+ if ((e && *e) || val >= (1 << size*8)) {
+ fprintf(stderr, "Bad size\n");
+ return -1;
+ }
+ /* Little endian */
+ memcpy(p->data, &val, size);
+ p->size = size;
+ if (argc > 5) {
+ p->flag = strtol(argv[5], &e, 0);
if (e && *e) {
fprintf(stderr, "Bad flag\n");
return -1;
}
}
- rv = ec_command(EC_CMD_SET_CROS_BOARD_INFO, 0, &p, sizeof(p),
- NULL, 0);
+ rv = ec_command(EC_CMD_SET_CROS_BOARD_INFO, 0,
+ p, sizeof(*p) + size, NULL, 0);
if (rv < 0) {
if (rv == -EC_RES_ACCESS_DENIED - EECRESULT)
fprintf(stderr, "Write failed. WP enabled?\n");