summaryrefslogtreecommitdiff
path: root/board/cr50/tpm2/NVMem.c
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2016-05-20 11:28:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-05-26 18:08:57 -0700
commit7184144012cdcfdede45efc3ad3b121ec16ddacf (patch)
treeae46cd084ce5270b68588c872b9fee379d267572 /board/cr50/tpm2/NVMem.c
parentdf35737d63811cd7ad9e4ce62406448fd709b431 (diff)
downloadchrome-ec-7184144012cdcfdede45efc3ad3b121ec16ddacf.tar.gz
Cr50: NvMem: Connected function stubs in /board/tpm2/NVMem.c
Used #define CONFIG_FLASH_NVMEM to have functions in /board/tpm2/NVMem.c utlitize on chip Nvmem functions. On chip NV Memory availability is tied to an internal nvmem error state which itself only depends on finding at least one valid partition. Added nvmem_is_different and nvmem_move functions which were needed to complete the tpm2 platform interface. In addition, added unit tests to support these two new functions. BUG=chrome-os-partner:44745 BRANCH=none TEST=manual make runtests TEST_LIST_HOST=nvmem and verify that all tests pass. Tested with tcg_test utility to test reads/writes using the command "build/test-tpm2/install/bin/compliance --ntpm localhost:9883 --select CPCTPM_TC2_3_33_07_01". Change-Id: I475fdd1331e28ede00f9b674c7bee1536fa9ea48 Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/346236 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'board/cr50/tpm2/NVMem.c')
-rw-r--r--board/cr50/tpm2/NVMem.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/board/cr50/tpm2/NVMem.c b/board/cr50/tpm2/NVMem.c
index 6ec0031454..7dad3d5d3d 100644
--- a/board/cr50/tpm2/NVMem.c
+++ b/board/cr50/tpm2/NVMem.c
@@ -15,9 +15,12 @@
#include "PlatformData.h"
#include "TpmError.h"
#include "assert.h"
+#include "nvmem.h"
/* Local state */
+#ifndef CONFIG_FLASH_NVMEM
static unsigned char s_NV[NV_MEMORY_SIZE];
+#endif
static BOOL s_NvIsAvailable;
static BOOL s_NV_unrecoverable;
static BOOL s_NV_recoverable;
@@ -52,9 +55,24 @@ int _plat__NVEnable(void *platParameter)
s_NV_unrecoverable = FALSE;
s_NV_recoverable = FALSE;
+#ifdef CONFIG_FLASH_NVMEM
+ /* TODO: Need to define what is recoverable and unrecoverable
+ * conditions with regards to NvMem module. For now, the only
+ * requirement is that at Cr50 board initialization time, the
+ * nvmem_init() function either detects a valid partition, or
+ * determines that NvMem is fully erased and configures a valid
+ * partition. Setting both variables TRUE if NvMem is not available
+ */
+ s_NV_recoverable = nvmem_get_error_state() != 0;
+ s_NV_unrecoverable = s_NV_recoverable;
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)
@@ -73,10 +91,23 @@ void _plat__NVDisable(void)
*/
int _plat__IsNvAvailable(void)
{
+
+#ifdef CONFIG_FLASH_NVMEM
+ int rv;
+ /*
+ * sNv_IsAvailable is a state variable that can be accesed by the
+ * simmulator to control access to NvMemory. This variable and
+ * the on chip NvMem area must be in the correct state for NvMem
+ * to be in 'NV is available' state.
+ */
+ rv = !s_NvIsAvailable || nvmem_get_error_state();
+ return rv;
+#else
if (!s_NvIsAvailable)
return 1;
return 0;
+#endif
}
/*
@@ -88,7 +119,11 @@ void _plat__NvMemoryRead(unsigned int startOffset,
{
assert(startOffset + size <= NV_MEMORY_SIZE);
/* Copy the data from the NV image */
+#ifdef CONFIG_FLASH_NVMEM
+ nvmem_read(startOffset, size, data, NVMEM_TPM);
+#else
memcpy(data, &s_NV[startOffset], size);
+#endif
return;
}
@@ -101,8 +136,12 @@ _plat__NvIsDifferent(unsigned int startOffset,
unsigned int size,
void *data)
{
+#ifdef CONFIG_FLASH_NVMEM
+ return (nvmem_is_different(startOffset, size, data, NVMEM_TPM) != 0);
+#else
/* Do we need a safe memcmp here? */
return (memcmp(&s_NV[startOffset], data, size) != 0);
+#endif
}
/*
@@ -116,7 +155,11 @@ void _plat__NvMemoryWrite(unsigned int startOffset,
{
assert(startOffset + size <= NV_MEMORY_SIZE);
/* Copy the data to the NV image */
+#ifdef CONFIG_FLASH_NVMEM
+ nvmem_write(startOffset, size, data, NVMEM_TPM);
+#else
memcpy(&s_NV[startOffset], data, size);
+#endif
}
/*
@@ -129,8 +172,12 @@ void _plat__NvMemoryMove(unsigned int sourceOffset,
{
assert(sourceOffset + size <= NV_MEMORY_SIZE);
assert(destOffset + size <= NV_MEMORY_SIZE);
+#ifdef CONFIG_FLASH_NVMEM
+ nvmem_move(sourceOffset, destOffset, size, NVMEM_TPM);
+#else
/* Move data in RAM */
memmove(&s_NV[destOffset], &s_NV[sourceOffset], size);
+#endif
return;
}
@@ -144,7 +191,11 @@ void _plat__NvMemoryMove(unsigned int sourceOffset,
*/
int _plat__NvCommit(void)
{
+#ifdef CONFIG_FLASH_NVMEM
+ return nvmem_commit();
+#else
return 0;
+#endif
}
/*