aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2016-12-03 04:18:55 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-12-03 04:18:55 +0000
commita8882eec97bc0ef26214a1ccdd54df5db7720297 (patch)
treea3d9f3307350d4d0f3c26b68c29f8f06914ec9c0
parent9dacaf8face476e9354278504472b9cd6da90569 (diff)
parent630e2e46ea030380846bc1a096767fc3623eb258 (diff)
downloadtpm2-a8882eec97bc0ef26214a1ccdd54df5db7720297.tar.gz
Introduce NVRAM storage format versioning am: 889c3dda30 am: 06c8e853bb
am: 630e2e46ea Change-Id: Ib35cc66f14c576c24ab4ee2aedfbded38cfa124d
-rw-r--r--Implementation.h2
-rw-r--r--NV.c45
2 files changed, 46 insertions, 1 deletions
diff --git a/Implementation.h b/Implementation.h
index 2019a8f..92d9ecf 100644
--- a/Implementation.h
+++ b/Implementation.h
@@ -264,6 +264,8 @@
#ifdef EMBEDDED_MODE
// This must be matched by the package using this library!
#define NV_MEMORY_SIZE 16076
+// Versioning NV storage format will allow to smoothly migrate NVRAM contents.
+#define NV_FORMAT_VERSION 1
#else
#define NV_MEMORY_SIZE 16384
#endif
diff --git a/NV.c b/NV.c
index e5a9cae..f714c91 100644
--- a/NV.c
+++ b/NV.c
@@ -780,6 +780,48 @@ NvFindHandle(
pAssert(addr == 0);
return addr;
}
+
+//
+// NvCheckAndMigrateIfNeeded()
+//
+// Supported only in EMBEDDED_MODE.
+//
+// Check if the NVRAM storage format changed, and if so - reinitialize the
+// NVRAM. No content migration yet, hopefully it will come one day.
+//
+// Note that the NV_FIRMWARE_V1 and NV_FIRMWARE_V2 values not used to store
+// TPM versoion when in embedded mode are used for NVRAM format version
+// instead.
+//
+//
+static void
+NvCheckAndMigrateIfNeeded(void)
+{
+#ifdef EMBEDDED_MODE
+ UINT32 nv_vers1;
+ UINT32 nv_vers2;
+
+ NvReadReserved(NV_FIRMWARE_V1, &nv_vers1);
+ NvReadReserved(NV_FIRMWARE_V2, &nv_vers2);
+
+ if ((nv_vers1 == ~nv_vers2) && (nv_vers1 == NV_FORMAT_VERSION))
+ return; // All is well.
+
+ // This will reinitialize NVRAM to empty. Migration code will come here
+ // later.
+ NvInit();
+
+ nv_vers1 = NV_FORMAT_VERSION;
+ nv_vers2 = ~NV_FORMAT_VERSION;
+
+ NvWriteReserved(NV_FIRMWARE_V1, &nv_vers1);
+ NvWriteReserved(NV_FIRMWARE_V2, &nv_vers2);
+
+ NvCommit();
+#endif
+}
+
+
//
//
// NvPowerOn()
@@ -804,7 +846,8 @@ NvPowerOn(
{
if((nvError = _plat__NVEnable(0)) < 0)
FAIL(FATAL_ERROR_NV_UNRECOVERABLE);
- NvInitStatic();
+ NvInitStatic();
+ NvCheckAndMigrateIfNeeded();
}
return nvError == 0;
}