diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2019-02-28 20:11:28 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-05 09:21:44 -0700 |
commit | 171578b67f40355528cbb5f34b78e8e8ed83e335 (patch) | |
tree | 2303b74da9487ca2d046b93ad04212feff6164ac /common/pinweaver.c | |
parent | 1d6c7bb9773f76aa70ce65822fa001ff72892cd2 (diff) | |
download | chrome-ec-171578b67f40355528cbb5f34b78e8e8ed83e335.tar.gz |
cr50: complete support of the new NVMEM structure
This patch eliminates unnecessary legacy nvmem.c and nvmem_vars.c code
and brings the code base to the state where the new NVMEM layout is
fully functional.
BRANCH=cr50, cr50-mp
BUG=b:69907320, b:129710256
CQ-DEPEND=CL:1450278
TEST=the following tests pass:
- test cases in ./test/nvmem.c
- TCG suite (passes on par with the existing Cr50 code with the
reduced code footprint TPM2 library)
- Chrome OS device migrates from legacy to new implementation with
user account maintained.
- Chrome OS user account is maintained over AP and H1 reboots and
deep sleep cycles.
Change-Id: If4bc2dd125873a79dbe0e268eb32100a8b8b352d
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1496607
Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'common/pinweaver.c')
-rw-r--r-- | common/pinweaver.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/common/pinweaver.c b/common/pinweaver.c index 1777a4c28b..d65e1bad0c 100644 --- a/common/pinweaver.c +++ b/common/pinweaver.c @@ -656,6 +656,7 @@ static int load_log_data(struct pw_log_storage_t *log) { const struct tuple *ptr; const struct pw_log_storage_t *view; + int rv = EC_SUCCESS; ptr = getvar(PW_LOG_VAR0, sizeof(PW_LOG_VAR0) - 1); if (ptr == NULL) @@ -663,24 +664,21 @@ static int load_log_data(struct pw_log_storage_t *log) view = (void *)tuple_val(ptr); if (ptr->val_len != sizeof(struct pw_log_storage_t)) - return PW_ERR_NV_LENGTH_MISMATCH; - if (view->storage_version != PW_STORAGE_VERSION) - return PW_ERR_NV_VERSION_MISMATCH; + rv = PW_ERR_NV_LENGTH_MISMATCH; + else if (view->storage_version != PW_STORAGE_VERSION) + rv = PW_ERR_NV_VERSION_MISMATCH; + else + memcpy(log, view, ptr->val_len); - memcpy(log, view, ptr->val_len); - return EC_SUCCESS; + freevar(ptr); + + return rv; } int store_log_data(const struct pw_log_storage_t *log) { - int ret; - - ret = setvar(PW_LOG_VAR0, sizeof(PW_LOG_VAR0) - 1, (uint8_t *)log, - sizeof(struct pw_log_storage_t)); - if (ret != EC_SUCCESS) - return ret; - - return writevars(); + return setvar(PW_LOG_VAR0, sizeof(PW_LOG_VAR0) - 1, (uint8_t *)log, + sizeof(struct pw_log_storage_t)); } static int load_merkle_tree(struct merkle_tree_t *merkle_tree) @@ -695,15 +693,19 @@ static int load_merkle_tree(struct merkle_tree_t *merkle_tree) const struct pw_long_term_storage_t *tree; ptr = getvar(PW_TREE_VAR, sizeof(PW_TREE_VAR) - 1); - if (ptr == NULL) + if (!ptr) return PW_ERR_NV_EMPTY; tree = (void *)tuple_val(ptr); /* Add storage format updates here. */ - if (ptr->val_len != sizeof(*tree)) + if (ptr->val_len != sizeof(*tree)) { + freevar(ptr); return PW_ERR_NV_LENGTH_MISMATCH; - if (tree->storage_version != PW_STORAGE_VERSION) + } + if (tree->storage_version != PW_STORAGE_VERSION) { + freevar(ptr); return PW_ERR_NV_VERSION_MISMATCH; + } merkle_tree->bits_per_level = tree->bits_per_level; merkle_tree->height = tree->height; @@ -711,8 +713,10 @@ static int load_merkle_tree(struct merkle_tree_t *merkle_tree) tree->key_derivation_nonce, sizeof(tree->key_derivation_nonce)); ret = derive_keys(merkle_tree); - if (ret != EC_SUCCESS) + if (ret != EC_SUCCESS) { + freevar(ptr); return ret; + } } /* Handle the root hash. */ @@ -720,15 +724,19 @@ static int load_merkle_tree(struct merkle_tree_t *merkle_tree) struct pw_log_storage_t *log; ptr = getvar(PW_LOG_VAR0, sizeof(PW_LOG_VAR0) - 1); - if (ptr == NULL) + if (!ptr) return PW_ERR_NV_EMPTY; log = (void *)tuple_val(ptr); /* Add storage format updates here. */ - if (ptr->val_len != sizeof(struct pw_log_storage_t)) + if (ptr->val_len != sizeof(struct pw_log_storage_t)) { + freevar(ptr); return PW_ERR_NV_LENGTH_MISMATCH; - if (log->storage_version != PW_STORAGE_VERSION) + } + if (log->storage_version != PW_STORAGE_VERSION) { + freevar(ptr); return PW_ERR_NV_VERSION_MISMATCH; + } memcpy(merkle_tree->root, log->entries[0].root, sizeof(merkle_tree->root)); @@ -747,15 +755,15 @@ static int load_merkle_tree(struct merkle_tree_t *merkle_tree) ret = setvar(PW_LOG_VAR0, sizeof(PW_LOG_VAR0) - 1, (uint8_t *)log, sizeof(struct pw_log_storage_t)); - if (ret != EC_SUCCESS) - return ret; - ret = writevars(); - if (ret != EC_SUCCESS) + if (ret != EC_SUCCESS) { + freevar(ptr); return ret; + } } pw_restart_count = log->restart_count; } + freevar(ptr); cprints(CC_TASK, "PinWeaver: Loaded Tree. restart_count = %d", pw_restart_count); |