From 5232cdd16bb2e1b15b281b0041c33c55bc9ca52d Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 12 Jan 2018 12:52:18 -0800 Subject: CBI: Add host command to get board info This patch adds host command to get board info from EEPROM. BUG=b:70294260 BRANCH=none TEST=Run ectool cbi get to get board version, OEM, SKU Change-Id: I41a84d3eea6da9d88fa8122db36dcd1df515842d Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/865161 Reviewed-by: Randall Spangler --- common/cbi.c | 29 ++++++++++++++++++++++ include/ec_commands.h | 21 ++++++++++++++++ util/ectool.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/common/cbi.c b/common/cbi.c index dce8475d81..b82d0375c2 100644 --- a/common/cbi.c +++ b/common/cbi.c @@ -9,6 +9,7 @@ #include "console.h" #include "crc8.h" #include "cros_board_info.h" +#include "host_command.h" #include "i2c.h" #include "util.h" @@ -125,3 +126,31 @@ int board_get_version(void) return -1; return version; } + +static int hc_cbi_get(struct host_cmd_handler_args *args) +{ + const struct __ec_align4 ec_params_get_cbi *p = args->params; + + if (read_board_info()) + return EC_RES_ERROR; + + switch (p->type) { + case CBI_DATA_BOARD_VERSION: + *(uint32_t *)args->response = bi.version; + break; + case CBI_DATA_OEM_ID: + *(uint32_t *)args->response = bi.oem_id; + break; + case CBI_DATA_SKU_ID: + *(uint32_t *)args->response = bi.sku_id; + break; + default: + return EC_RES_INVALID_PARAM; + } + args->response_size = sizeof(uint32_t); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_GET_CROS_BOARD_INFO, + hc_cbi_get, + EC_VER_MASK(0)); diff --git a/include/ec_commands.h b/include/ec_commands.h index 20c29a6f7e..23307354e1 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -4570,6 +4570,27 @@ struct __ec_align1 ec_params_efs_verify { uint8_t region; /* enum ec_flash_region */ }; +/* + * Retrieve info from Cros Board Info store. Response is based on the data + * type. Integers return a uint32. Strings return a string, using the response + * size to determine how big it is. + */ +#define EC_CMD_GET_CROS_BOARD_INFO 0x011F + +enum cbi_data_type { + /* integer types */ + CBI_DATA_BOARD_VERSION = 0, + CBI_DATA_OEM_ID = 1, + CBI_DATA_SKU_ID = 2, + /* string types */ + CBI_FIRST_STRING_PARAM = 0x1000, + CBI_DATA_COUNT, +}; + +struct __ec_align4 ec_params_get_cbi { + uint32_t type; /* enum cbi_data_type */ +}; + /*****************************************************************************/ /* The command range 0x200-0x2FF is reserved for Rotor. */ diff --git a/util/ectool.c b/util/ectool.c index c241b885c1..c694e83c56 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -59,6 +59,8 @@ const char help_str[] = " Read or write board-specific battery parameter\n" " boardversion\n" " Prints the board version\n" + " cbi\n" + " Get Cros Board Info\n" " chargecurrentlimit\n" " Set the maximum battery charging current\n" " chargecontrol\n" @@ -6225,6 +6227,69 @@ int cmd_board_version(int argc, char *argv[]) return rv; } +static void cmd_cbi_help(char *cmd) +{ + fprintf(stderr, + " Usage: %s get \n" + " is one of:\n" + " 0: BOARD_VERSION\n" + " 1: OEM_ID\n" + " 2: SKU_ID\n", cmd); +} + +/* + * Write value to CBI + * + * TODO: Support asynchronous write + */ +static int cmd_cbi(int argc, char *argv[]) +{ + enum cbi_data_type type; + char *e; + int rv; + + if (argc < 3) { + fprintf(stderr, "Invalid number of params\n"); + cmd_cbi_help(argv[0]); + return -1; + } + + /* Type */ + type = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad type\n"); + return -1; + } + + if (!strcasecmp(argv[1], "get")) { + struct ec_params_get_cbi p; + uint32_t r; + p.type = type; + rv = ec_command(EC_CMD_GET_CROS_BOARD_INFO, 0, &p, sizeof(p), + &r, sizeof(r)); + 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); + return -1; + } + return 0; + } + + fprintf(stderr, "Invalid sub command: %s\n", argv[1]); + cmd_cbi_help(argv[0]); + + return -1; +} + int cmd_chipinfo(int argc, char *argv[]) { struct ec_response_get_chip_info info; @@ -7363,6 +7428,7 @@ const struct command commands[] = { {"batterycutoff", cmd_battery_cut_off}, {"batteryparam", cmd_battery_vendor_param}, {"boardversion", cmd_board_version}, + {"cbi", cmd_cbi}, {"chargecurrentlimit", cmd_charge_current_limit}, {"chargecontrol", cmd_charge_control}, {"chargeoverride", cmd_charge_port_override}, -- cgit v1.2.1