sysvar: unprotect/protect flash before/after recovery.
Change-Id: I7e8ed3e593d2bae7bc2bac1e6d3de6a45f606fd6
diff --git a/common/cmd_sysvar.c b/common/cmd_sysvar.c
index 46a3bcd..ea0a477 100644
--- a/common/cmd_sysvar.c
+++ b/common/cmd_sysvar.c
@@ -72,6 +72,15 @@
/* check crc32 and wc32 (write count) */
if (check_var(buf, SYSVAR_LOAD_MODE) == SYSVAR_SUCCESS) {
+#ifdef CONFIG_SPI_FLASH_PROTECTION
+ printf("SV: Unprotecting flash\n");
+ ret = spi_flash_protect(sf_dev, 0);
+ if (ret) {
+ printf("## Error: failed to unprotect flash\n");
+ goto recovery_err;
+ }
+#endif
+
/* erase SPI flash */
ret = spi_flash_erase(sf_dev, sysvar_offset[j], buf->data_len);
if (ret) {
@@ -92,6 +101,13 @@
goto recovery_err;
}
+#ifdef CONFIG_SPI_FLASH_PROTECTION
+ printf("SV: Protecting flash\n");
+ ret = spi_flash_protect(sf_dev, 1);
+ if (ret)
+ printf("## Error: failed to protect flash\n");
+#endif
+
buf->loaded = true;
print_msg("Data recovery was completed", SYSVAR_MESSAGE);
return 0;