From ead2428e915ba97185d35dfcfcf86feda5ff0059 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Wed, 17 Jan 2018 17:22:42 -0800 Subject: CBI: Allow get command to reload data from EEPROM This patch adds CBI_GET_RELOAD flag to EC_CMD_GET_CROS_BOARD_INFO command. When the flag is set, the command will be forced to read data from EEPROM even, ignoring the data cached by the previous read. This allows ectool to verify a write was successful without reboot. BUG=b:70294260 BRANCH=none TEST=ectool cbi set 0 0x1234 && ectool cbi get 0 1 Change-Id: I3e7ced5be56a74c605870a4c0622c0a2f47963bb Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/874155 Reviewed-by: Randall Spangler --- common/cbi.c | 3 +++ include/ec_commands.h | 11 ++++++++++- util/ectool.c | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/common/cbi.c b/common/cbi.c index bc21d901fa..c0cba85e4a 100644 --- a/common/cbi.c +++ b/common/cbi.c @@ -172,6 +172,9 @@ static int hc_cbi_get(struct host_cmd_handler_args *args) { const struct __ec_align4 ec_params_get_cbi *p = args->params; + if (p->flag & CBI_GET_RELOAD) + cached_read_result = EC_ERROR_CBI_CACHE_INVALID; + if (read_board_info()) return EC_RES_ERROR; diff --git a/include/ec_commands.h b/include/ec_commands.h index 705e54f2b1..e1573e85b9 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -4592,8 +4592,17 @@ enum cbi_data_type { CBI_DATA_COUNT, }; +/* + * Flags to control read operation + * + * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify + * write was successful without reboot. + */ +#define CBI_GET_RELOAD (1 << 0) + struct __ec_align4 ec_params_get_cbi { uint32_t type; /* enum cbi_data_type */ + uint32_t flag; /* CBI_GET_* */ }; /* @@ -4609,7 +4618,7 @@ struct __ec_align4 ec_params_get_cbi { struct __ec_align1 ec_params_set_cbi { uint32_t type; /* enum cbi_data_type */ - uint8_t flag; /* CBI_SET_* */ + uint32_t flag; /* CBI_SET_* */ uint32_t data; /* For numeric value */ uint8_t raw[]; /* For string and raw data */ }; diff --git a/util/ectool.c b/util/ectool.c index 4737ac91e3..97cfaa8262 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -6230,13 +6230,15 @@ int cmd_board_version(int argc, char *argv[]) static void cmd_cbi_help(char *cmd) { fprintf(stderr, - " Usage: %s get \n" - " Usage: %s set value [flag]\n" + " Usage: %s get [get_flag]\n" + " Usage: %s set value [set_flag]\n" " is one of:\n" " 0: BOARD_VERSION\n" " 1: OEM_ID\n" " 2: SKU_ID\n" - " [flag] is combination of:\n" + " [get_flag] is combination of:\n" + " 01b: Invalidate cache and reload data from EEPROM\n" + " [set_flag] is combination of:\n" " 01b: Skip write to EEPROM. Use for back-to-back writes\n" " 10b: Set all fields to defaults first\n", cmd, cmd); } @@ -6269,6 +6271,13 @@ static int cmd_cbi(int argc, char *argv[]) struct ec_params_get_cbi p; uint32_t r; p.type = type; + if (argc > 3) { + p.flag = strtol(argv[3], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad flag\n"); + return -1; + } + } rv = ec_command(EC_CMD_GET_CROS_BOARD_INFO, 0, &p, sizeof(p), &r, sizeof(r)); if (rv < 0) { -- cgit v1.2.1