diff options
-rw-r--r-- | chip/lm4/system.c | 10 | ||||
-rw-r--r-- | chip/stm32/system.c | 43 | ||||
-rw-r--r-- | common/system_common.c | 26 | ||||
-rw-r--r-- | include/ec_commands.h | 18 | ||||
-rw-r--r-- | include/system.h | 10 |
5 files changed, 107 insertions, 0 deletions
diff --git a/chip/lm4/system.c b/chip/lm4/system.c index 6046f15d4c..2c970ee125 100644 --- a/chip/lm4/system.c +++ b/chip/lm4/system.c @@ -396,6 +396,16 @@ const char *system_get_chip_name(void) } } +int system_get_vbnvcontext(uint8_t *block) +{ + return EC_ERROR_UNIMPLEMENTED; +} + +int system_set_vbnvcontext(const uint8_t *block) +{ + return EC_ERROR_UNIMPLEMENTED; +} + const char *system_get_chip_revision(void) { static char rev[3]; diff --git a/chip/stm32/system.c b/chip/stm32/system.c index f5f7dff73d..df10f6810a 100644 --- a/chip/stm32/system.c +++ b/chip/stm32/system.c @@ -19,6 +19,14 @@ enum bkpdata_index { BKPDATA_INDEX_SCRATCHPAD, /* General-purpose scratchpad */ BKPDATA_INDEX_SAVED_RESET_FLAGS,/* Saved reset flags */ + BKPDATA_INDEX_VBNV_CONTEXT0, + BKPDATA_INDEX_VBNV_CONTEXT1, + BKPDATA_INDEX_VBNV_CONTEXT2, + BKPDATA_INDEX_VBNV_CONTEXT3, + BKPDATA_INDEX_VBNV_CONTEXT4, + BKPDATA_INDEX_VBNV_CONTEXT5, + BKPDATA_INDEX_VBNV_CONTEXT6, + BKPDATA_INDEX_VBNV_CONTEXT7, }; @@ -217,6 +225,41 @@ const char *system_get_chip_revision(void) } +int system_get_vbnvcontext(uint8_t *block) +{ + enum bkpdata_index i; + uint16_t value; + + for (i = BKPDATA_INDEX_VBNV_CONTEXT0; + i <= BKPDATA_INDEX_VBNV_CONTEXT7; i++) { + value = bkpdata_read(i); + *block++ = (uint8_t)(value & 0xff); + *block++ = (uint8_t)(value >> 8); + } + + return EC_SUCCESS; +} + + +int system_set_vbnvcontext(const uint8_t *block) +{ + enum bkpdata_index i; + uint16_t value; + int err; + + for (i = BKPDATA_INDEX_VBNV_CONTEXT0; + i <= BKPDATA_INDEX_VBNV_CONTEXT7; i++) { + value = *block++; + value |= ((uint16_t)*block++) << 8; + err = bkpdata_write(i, value); + if (err) + return err; + } + + return EC_SUCCESS; +} + + /* TODO: crosbug.com/p/12036 */ int system_set_fake_wp(int val) { diff --git a/common/system_common.c b/common/system_common.c index 772d932748..e88a377b63 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -816,6 +816,32 @@ DECLARE_HOST_COMMAND(EC_CMD_GET_BOARD_VERSION, host_command_get_board_version, EC_VER_MASK(0)); +int host_command_vbnvcontext(struct host_cmd_handler_args *args) +{ + const struct ec_params_vbnvcontext *p = args->params; + struct ec_response_vbnvcontext *r; + + switch (p->op) { + case EC_VBNV_CONTEXT_OP_READ: + r = args->response; + if (system_get_vbnvcontext(r->block)) + return EC_RES_ERROR; + args->response_size = sizeof(*r); + break; + case EC_VBNV_CONTEXT_OP_WRITE: + if (system_set_vbnvcontext(p->block)) + return EC_RES_ERROR; + break; + default: + return EC_RES_ERROR; + } + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_VBNV_CONTEXT, + host_command_vbnvcontext, + EC_VER_MASK(EC_VER_VBNV_CONTEXT)); + int host_command_reboot(struct host_cmd_handler_args *args) { struct ec_params_reboot_ec p; diff --git a/include/ec_commands.h b/include/ec_commands.h index b74da5e4cd..f9ee74e86e 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -553,6 +553,24 @@ struct ec_response_flash_region_info { uint32_t size; } __packed; +/* Read/write VbNvContext */ +#define EC_CMD_VBNV_CONTEXT 0x17 +#define EC_VER_VBNV_CONTEXT 1 +#define EC_VBNV_BLOCK_SIZE 16 + +enum ec_vbnvcontext_op { + EC_VBNV_CONTEXT_OP_READ, + EC_VBNV_CONTEXT_OP_WRITE, +}; + +struct ec_params_vbnvcontext { + uint32_t op; + uint8_t block[EC_VBNV_BLOCK_SIZE]; +} __packed; + +struct ec_response_vbnvcontext { + uint8_t block[EC_VBNV_BLOCK_SIZE]; +} __packed; /*****************************************************************************/ /* PWM commands */ diff --git a/include/system.h b/include/system.h index f3d5b035d6..1385c4d006 100644 --- a/include/system.h +++ b/include/system.h @@ -173,6 +173,16 @@ const char *system_get_chip_name(void); const char *system_get_chip_revision(void); /** + * Get/Set VbNvContext in non-volatile storage. The block should be 16 bytes + * long, which is the current size of VbNvContext block. + * + * @param block Pointer to a buffer holding VbNvContext. + * @return 0 on success, !0 on error. + */ +int system_get_vbnvcontext(uint8_t *block); +int system_set_vbnvcontext(const uint8_t *block); + +/** * Put the EC in hibernate (lowest EC power state). * * @param seconds Number of seconds to hibernate. |