summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2012-06-22 18:18:17 +0800
committerChe-Liang Chiou <clchiou@chromium.org>2012-09-05 18:13:14 -0700
commit6515d550791a246fe0ba884687b6a361b915b7d3 (patch)
tree2cfa70861657f6ec15377e5d24915e19d1b8107b
parent5427c393a19df7bfe203fd22c240b037da2937ff (diff)
downloadchrome-ec-6515d550791a246fe0ba884687b6a361b915b7d3.tar.gz
stm32: Store VbNvContext in backup registers
This would improve boot speed when compared to storing in eMMC because initialing eMMC is slow. So far other platforms do not have this need because CMOS is quite efficient; thus it is left unimplemented in lm4. Signed-off-by: Che-Liang Chiou <clchiou@chromium.org> BRANCH=snow BUG=chrome-os-partner:10660,13094 TEST=On Snow, see VbNvContext is preserved across power cycles (you have to patch U-Boot to test this) Original-Change-Id: If5072c678b87bc47a3a82a1dff2afa3896304f36 Reviewed-on: https://gerrit.chromium.org/gerrit/31832 Tested-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Ready: Che-Liang Chiou <clchiou@chromium.org> (cherry picked from commit 8a9471e5ef305a2aea81e6cb62a17d6966865b6b) Change-Id: Ia09a8977f7053a20c97a3832bf60f81f2e11e271 Reviewed-on: https://gerrit.chromium.org/gerrit/32341 Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Che-Liang Chiou <clchiou@chromium.org>
-rw-r--r--chip/lm4/system.c10
-rw-r--r--chip/stm32/system.c43
-rw-r--r--common/system_common.c26
-rw-r--r--include/ec_commands.h18
-rw-r--r--include/system.h10
5 files changed, 107 insertions, 0 deletions
diff --git a/chip/lm4/system.c b/chip/lm4/system.c
index 4d7a36972e..082d5661bc 100644
--- a/chip/lm4/system.c
+++ b/chip/lm4/system.c
@@ -310,6 +310,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 8c6d1a2d2c..3b56ec5198 100644
--- a/common/system_common.c
+++ b/common/system_common.c
@@ -801,6 +801,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 2b4a8ba5aa..8ec35b915e 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -547,6 +547,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 cd42de01f7..65b802e775 100644
--- a/include/system.h
+++ b/include/system.h
@@ -172,6 +172,16 @@ const char *system_get_chip_vendor(void);
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);
+
/* TODO: request sleep. How do we want to handle transitioning
* to/from low-power states? */