summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/g/flash.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/chip/g/flash.c b/chip/g/flash.c
index f9ce5d580e..ab00745be9 100644
--- a/chip/g/flash.c
+++ b/chip/g/flash.c
@@ -467,3 +467,64 @@ void flash_close_ro_window(void)
{
GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, WR_EN, 0);
}
+
+#ifdef CR50_DEV
+
+static int command_erase_flash_info(int argc, char **argv)
+{
+ uint32_t *preserved_manufacture_state;
+ const size_t manuf_word_count = FLASH_INFO_MANUFACTURE_STATE_SIZE /
+ sizeof(uint32_t);
+ int i;
+ int rv = EC_ERROR_BUSY;
+
+ if (shared_mem_acquire(FLASH_INFO_MANUFACTURE_STATE_SIZE,
+ (char **)&preserved_manufacture_state) !=
+ EC_SUCCESS) {
+ ccprintf("Failed to allocate memory for manufacture state!\n");
+ return rv;
+ }
+
+ /* Read the entire info1. */
+ p = (uint32_t *)info1;
+ for (i = 0; i < (sizeof(*info1) / sizeof(*p)); i++) {
+ if (flash_physical_info_read_word(i * sizeof(*p), p + i) !=
+ EC_SUCCESS) {
+ ccprintf("Failed to read word %d!\n", i);
+ goto exit;
+ }
+ }
+
+ mutex_lock(&flash_mtx);
+
+ flash_info_write_enable();
+
+ rv = do_flash_op(OP_ERASE_BLOCK, 1, 0, 512);
+
+ mutex_unlock(&flash_mtx);
+
+ if (rv != EC_SUCCESS) {
+ ccprintf("Failed to erase info space!\n");
+ goto exit;
+ }
+
+ if (flash_info_physical_write
+ (FLASH_INFO_MANUFACTURE_STATE_OFFSET,
+ FLASH_INFO_MANUFACTURE_STATE_SIZE,
+ (char *)preserved_manufacture_state) != EC_SUCCESS) {
+ ccprintf("Failed to restore manufacture state!\n");
+ goto exit;
+ }
+
+ rv = EC_SUCCESS;
+ exit:
+ always_memset(preserved_manufacture_state, 0,
+ FLASH_INFO_MANUFACTURE_STATE_SIZE);
+ shared_mem_release(preserved_manufacture_state);
+ flash_info_write_disable();
+ return rv;
+}
+DECLARE_CONSOLE_COMMAND(eraseflashinfo, command_erase_flash_info,
+ "",
+ "Erase INFO1 flash space");
+#endif