summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2016-05-31 12:48:15 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-05-31 19:38:20 -0700
commitd9f0c13447ebcf37bd2123edd1878c00975bb590 (patch)
treea1b93c198bcaddac06f8730043cd60b405114100
parent723f703fd42beb0f074d3c63f23a576decb0def2 (diff)
downloadchrome-ec-d9f0c13447ebcf37bd2123edd1878c00975bb590.tar.gz
nvmem: provide a function to wipe out nvmem contents
It is important to be able to wipe out the non-volatile memory for various reasons. This patch adds this ability for both when NV memory is kept in SRAM and in flash. Also a minor clean up to eliminate some code duplication and to have normal flow messages printed out with time stamps. BRANCH=none BUG=chrome-os-partner:44745 TEST=just makeall at this time. Change-Id: I59c1909669aeaa9e8ffb3d8ef81b02fa0facb6ab Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/348291 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--board/cr50/tpm2/NVMem.c15
-rw-r--r--board/cr50/tpm2/memory.h3
-rw-r--r--common/nvmem.c4
3 files changed, 15 insertions, 7 deletions
diff --git a/board/cr50/tpm2/NVMem.c b/board/cr50/tpm2/NVMem.c
index 7dad3d5d3d..695debe26c 100644
--- a/board/cr50/tpm2/NVMem.c
+++ b/board/cr50/tpm2/NVMem.c
@@ -65,14 +65,10 @@ int _plat__NVEnable(void *platParameter)
*/
s_NV_recoverable = nvmem_get_error_state() != 0;
s_NV_unrecoverable = s_NV_recoverable;
+#endif
if (s_NV_unrecoverable)
return -1;
return s_NV_recoverable;
-#else
- if (s_NV_unrecoverable)
- return -1;
- return s_NV_recoverable;
-#endif
}
void _plat__NVDisable(void)
@@ -217,3 +213,12 @@ void _plat__ClearNvAvail(void)
s_NvIsAvailable = FALSE;
return;
}
+
+void wipe_nvram(void)
+{
+#ifdef CONFIG_FLASH_NVMEM
+ nvmem_setup(0);
+#else
+ memset(s_NV, 0xff, sizeof(s_NV));
+#endif
+}
diff --git a/board/cr50/tpm2/memory.h b/board/cr50/tpm2/memory.h
index de9729313d..fc79db2778 100644
--- a/board/cr50/tpm2/memory.h
+++ b/board/cr50/tpm2/memory.h
@@ -6,6 +6,7 @@
#ifndef __EC_BOARD_CR50_TPM2_MEMORY_H
#define __EC_BOARD_CR50_TPM2_MEMORY_H
-/* An empty file to meet expectations of the tpm2 library. */
+/* A function to reinitialize the TPM NVram. */
+void wipe_nvram(void);
#endif /* __EC_BOARD_CR50_TPM2_MEMORY_H */
diff --git a/common/nvmem.c b/common/nvmem.c
index 63ea1581f5..c4a373291a 100644
--- a/common/nvmem.c
+++ b/common/nvmem.c
@@ -12,6 +12,7 @@
#include "util.h"
#define CPRINTF(format, args...) cprintf(CC_COMMAND, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_COMMAND, format, ## args)
#define NVMEM_ACQUIRE_CACHE_SLEEP_MS 25
#define NVMEM_ACQUIRE_CACHE_MAX_ATTEMPTS (250 / NVMEM_ACQUIRE_CACHE_SLEEP_MS)
@@ -273,7 +274,7 @@ int nvmem_setup(uint8_t starting_version)
int part;
int ret;
- CPRINTF("Configuring NVMEM FLash Partition\n");
+ CPRINTS("Configuring NVMEM FLash Partition");
/*
* Initialize NVmem partition. This function will only be called
* if during nvmem_init() fails which implies that NvMem is not fully
@@ -334,6 +335,7 @@ int nvmem_init(void)
return ret;
}
+ CPRINTS("Active NVram partition set to %d", nvmem_act_partition);
return EC_SUCCESS;
}