summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-02-13 10:57:26 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-02-23 01:19:07 -0800
commitd7303404a59a296fad9085db23fa18fe97f0f5c3 (patch)
tree5b20b0f8f182f60519509c68a46f2e63e27c2433 /test
parent3ce5e5d8b3ebdd9abf9d182082a81e29bd899d2b (diff)
downloadchrome-ec-d7303404a59a296fad9085db23fa18fe97f0f5c3.tar.gz
cr50: Make sure TPM wipe only clears TPM data.
Previously, wiping the TPM would wipe all of NvMem, however, it really should only clear the TPM's NvMem space. This commit adds a function to clear a given NvMem user's space and makes the TPM only clear its space. BUG=chrome-os-partner:61597 BRANCH=None TEST=Add code for using nvmem vars, create a test variable, add a user to snappy, unlock the console, verify that the user is no longer present on the system and the test nvmem var still exists. TEST=make -j buildall Change-Id: Ic98baa5166a1ef9ae76e910b1b9ab100300e947f Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/445803 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/nvmem.c72
1 files changed, 46 insertions, 26 deletions
diff --git a/test/nvmem.c b/test/nvmem.c
index b70c4732f4..d09bf8752a 100644
--- a/test/nvmem.c
+++ b/test/nvmem.c
@@ -175,41 +175,61 @@ static int test_configured_nvmem(void)
return nvmem_init();
}
-/* Verify that nvmem_setup indeed reinitializes the entire NVMEM. */
-static int test_nvmem_setup(void)
+/* Verify that nvmem_erase_user_data only erases the given user's data. */
+static int test_nvmem_erase_user_data(void)
{
uint32_t write_value;
uint32_t read_value;
+ int i;
nvmem_init();
- write_value = 1;
-
- /* Make sure both partitions have data in them. */
- nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_0);
- nvmem_commit();
- read_value = ~write_value;
- nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_0);
- TEST_ASSERT(read_value == write_value);
+ /* Make sure all partitions have data in them. */
+ for (i = 0; i < NVMEM_NUM_PARTITIONS; i++) {
+ write_value = i;
+ nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_0);
+ write_value = 2;
+ nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_1);
+ write_value = 3;
+ nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_2);
+ nvmem_commit();
+ }
- nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_0);
- nvmem_commit();
+ /* Check that the writes took place. */
read_value = ~write_value;
nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_0);
- TEST_ASSERT(read_value == write_value);
+ TEST_ASSERT(read_value == i-1);
+ nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_1);
+ TEST_ASSERT(read_value == 2);
+ nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_2);
+ TEST_ASSERT(read_value == 3);
- /* nvmem_setup() is supposed to erase both partitions. */
- nvmem_setup();
-
- nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_0);
- TEST_ASSERT(read_value == 0xffffffff);
-
- /* Switch active partition. */
- nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_0);
- nvmem_commit();
-
- nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_0);
- TEST_ASSERT(read_value != 0xffffffff);
+ /*
+ * nvmem_erase_user_data() is supposed to erase the user's data across
+ * all partitions.
+ */
+ nvmem_erase_user_data(NVMEM_USER_0);
+
+ for (i = 0; i < NVMEM_NUM_PARTITIONS; i++) {
+ /* Make sure USER 0's data is (still) gone. */
+ nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_0);
+ TEST_ASSERT(read_value == 0xffffffff);
+
+ /* Make sure the other users' data has been untouched. */
+ nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_1);
+ TEST_ASSERT(read_value == 2);
+
+ /*
+ * The active partition changes when the contents of the cache
+ * changes. Therefore, in order to examine all the paritions,
+ * we'll keep modifying one of the user's data.
+ */
+ nvmem_read(0, sizeof(read_value), &read_value, NVMEM_USER_2);
+ TEST_ASSERT(read_value == (3+i));
+ write_value = 4 + i;
+ nvmem_write(0, sizeof(write_value), &write_value, NVMEM_USER_2);
+ nvmem_commit();
+ }
return EC_SUCCESS;
}
@@ -689,7 +709,7 @@ void run_test(void)
RUN_TEST(test_move);
RUN_TEST(test_is_different);
RUN_TEST(test_lock);
- RUN_TEST(test_nvmem_setup);
+ RUN_TEST(test_nvmem_erase_user_data);
RUN_TEST(test_nvmem_save);
test_print_result();
}