summaryrefslogtreecommitdiff
path: root/common/nvmem.c
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2016-07-21 19:17:16 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-07-22 13:36:06 -0700
commit1dc78318ba55ca30285570e2254d182fa4cb693a (patch)
tree0bafce521e13fd01a087d6bbb726e8628fb1e0e2 /common/nvmem.c
parentc765bed2ca2479f6490b6171aacf6e7d67cb58d3 (diff)
downloadchrome-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 'common/nvmem.c')
-rw-r--r--common/nvmem.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/common/nvmem.c b/common/nvmem.c
index 1c7d8d69dc..8cf88909c0 100644
--- a/common/nvmem.c
+++ b/common/nvmem.c
@@ -244,7 +244,7 @@ static int nvmem_find_partition(void)
return EC_SUCCESS;
if (nvmem_is_unitialized()) {
- CPRINTF("NvMem: No Valid Paritions and not fully erased!!\n");
+ CPRINTS("NvMem: No Valid Paritions!");
return EC_ERROR_UNKNOWN;
}
@@ -316,20 +316,18 @@ int nvmem_setup(uint8_t starting_version)
return EC_ERROR_TIMEOUT;
}
- /* Fill in tag info */
+ /* Fill entire partition to 0xFFs */
+ memset(cache.base_ptr, 0xff, NVMEM_PARTITION_SIZE);
+ /* Get pointer to start of partition */
p_part = (struct nvmem_partition *)cache.base_ptr;
/* Commit function will increment version number */
p_part->tag.version = starting_version + part - 1;
+ /* Compute sha for the partition */
nvmem_compute_sha(&cache.base_ptr[NVMEM_SHA_SIZE],
NVMEM_PARTITION_SIZE -
NVMEM_SHA_SIZE,
p_part->tag.sha,
NVMEM_SHA_SIZE);
- /*
- * TODO: Should erase parition area prior to this function being
- * called, or could write all user buffer data to 0xff here
- * before the commit() call.
- */
/* Partition is now ready, write it to flash. */
ret = nvmem_commit();
if (ret != EC_SUCCESS)
@@ -357,10 +355,16 @@ int nvmem_init(void)
ret = nvmem_find_partition();
if (ret != EC_SUCCESS) {
- /* Change error state to non-zero */
- nvmem_error_state = EC_ERROR_UNKNOWN;
- CPRINTF("%s:%d\n", __func__, __LINE__);
- return ret;
+ /* Write NvMem partitions to 0xff and setup new tags */
+ nvmem_setup(0);
+ /* Should find valid partiion now */
+ ret = nvmem_find_partition();
+ if (ret) {
+ /* Change error state to non-zero */
+ nvmem_error_state = EC_ERROR_UNKNOWN;
+ CPRINTF("%s:%d\n", __func__, __LINE__);
+ return ret;
+ }
}
CPRINTS("Active NVram partition set to %d", nvmem_act_partition);