sysvar: unprotect/protect flash before/after save.
Change-Id: I9eb9d2abb27281e4abb0ea1d6bb9ea46a495c1d7
diff --git a/common/cmd_sysvar.c b/common/cmd_sysvar.c
index a5dac7f..46a3bcd 100644
--- a/common/cmd_sysvar.c
+++ b/common/cmd_sysvar.c
@@ -137,6 +137,15 @@
static int data_save(struct sysvar_buf *buf, int *idx) {
int i, j, ret;
+#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");
+ return 1;
+ }
+#endif
+
/* save the system variables */
for (j = 0; j < 2; j++) {
i = idx[j];
@@ -163,6 +172,16 @@
return 1;
}
}
+
+#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");
+ return 1;
+ }
+#endif
+
return 0;
}