diff options
author | Scott <scollyer@chromium.org> | 2016-07-21 19:17:16 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-22 13:36:06 -0700 |
commit | 1dc78318ba55ca30285570e2254d182fa4cb693a (patch) | |
tree | 0bafce521e13fd01a087d6bbb726e8628fb1e0e2 /test | |
parent | c765bed2ca2479f6490b6171aacf6e7d67cb58d3 (diff) | |
download | chrome-ec-1dc78318ba55ca30285570e2254d182fa4cb693a.tar.gz |
Cr50: NvMem: Modified nvmem_init to handle 2 corrupt partitions
During initialization the NvMem module looks for either a valid
partition or that the NvMem area is fully erased. If neither of
these two conditions were found, then it was only returning an
error code and logging a message to the console.
This CL modifies nvmem_init() so that if the error case as described
above is detected, then it will call nvmem_setup() which will
create two valid partitions. In addition, the setup function
erases all of the existing data in the NvMem space.
Enhanced the unit test that deals with both partitions being
corrupted so that it verifies the version numbers are correct
and that all user buffer data is set to 0xff.
BUG=chrome-os-partner:55536
BRANCH=None
TEST=Manual
Executed make runtests TEST_LIST_HOST=nvmem and verifed that all
tests passed.
Change-Id: Ib932e02f15bd1aad7811032a12d826c76476e53f
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/362448
Commit-Ready: Vadim Bendebury <vbendeb@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/nvmem.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/test/nvmem.c b/test/nvmem.c index d3bc0b99e1..b9dd76c8cf 100644 --- a/test/nvmem.c +++ b/test/nvmem.c @@ -169,23 +169,58 @@ static int test_corrupt_nvmem(void) { uint32_t offset; int n; + int ret; + struct nvmem_tag *p_part; + uint8_t *p_data; /* * The purpose of this test is to check nvmem_init() in the case when no * vailid partition exists (not fully erased and no valid sha). In this - * case, NvMem can't be initialized and should return an error to the - * calling function. + * case, the initialization function will call setup() to create two new + * valid partitions. */ - /* Overwrite tags of each parition */ - memset(write_buffer, 0, 8); + /* Overwrite each partition will all 0s */ + memset(write_buffer, 0, NVMEM_PARTITION_SIZE); for (n = 0; n < NVMEM_NUM_PARTITIONS; n++) { offset = NVMEM_PARTITION_SIZE * n; - flash_physical_write(CONFIG_FLASH_NVMEM_OFFSET + offset, 8, + flash_physical_write(CONFIG_FLASH_NVMEM_OFFSET + offset, + NVMEM_PARTITION_SIZE, (const char *)write_buffer); } - /* In this case nvmem_init is expected to fail */ - return !nvmem_init(); + /* + * The initialization function will look for a valid partition and if + * none is found, then will call nvmem_setup() which will erase the + * paritions and setup new tags. + */ + ret = nvmem_init(); + if (ret) + return ret; + /* Fill buffer with 0xffs */ + memset(write_buffer, 0xff, NVMEM_PARTITION_SIZE); + /* + * nvmem_setup() will write put version 1 into partition 1 since the + * commit() function toggles the active partition. Check here that + * partition 0 has a version number of 1 and that all of the user buffer + * data has been erased. + */ + p_part = (struct nvmem_tag *)CONFIG_FLASH_NVMEM_BASE; + TEST_ASSERT(p_part->version == 1); + p_data = (uint8_t *)p_part + sizeof(struct nvmem_tag); + /* Verify that partition 0 is fully erased */ + TEST_ASSERT_ARRAY_EQ(write_buffer, p_data, NVMEM_PARTITION_SIZE - + sizeof(struct nvmem_tag)); + + /* Run the same test for partition 1 which should have version 0 */ + p_part = (struct nvmem_tag *)(CONFIG_FLASH_NVMEM_BASE + + NVMEM_PARTITION_SIZE); + TEST_ASSERT(p_part->version == 0); + p_data = (uint8_t *)p_part + sizeof(struct nvmem_tag); + ccprintf("Partition Version = %d\n", p_part->version); + /* Verify that partition 1 is fully erased */ + TEST_ASSERT_ARRAY_EQ(write_buffer, p_data, NVMEM_PARTITION_SIZE - + sizeof(struct nvmem_tag)); + return ret; } static int test_write_read_sequence(void) |