summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2019-02-28 20:11:28 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-04-05 09:21:44 -0700
commit171578b67f40355528cbb5f34b78e8e8ed83e335 (patch)
tree2303b74da9487ca2d046b93ad04212feff6164ac /board
parent1d6c7bb9773f76aa70ce65822fa001ff72892cd2 (diff)
downloadchrome-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 'board')
-rw-r--r--board/cr50/board.c2
-rw-r--r--board/cr50/board.h16
-rw-r--r--board/cr50/u2f.c15
3 files changed, 18 insertions, 15 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c
index 09a43901a4..e7482a9577 100644
--- a/board/cr50/board.c
+++ b/board/cr50/board.c
@@ -717,8 +717,6 @@ static void board_init(void)
init_runlevel(PERMISSION_MEDIUM);
/* Initialize NvMem partitions */
nvmem_init();
- /* Initialize the persistent storage. */
- initvars();
/*
* If this was a low power wake and not a rollback, restore the ccd
diff --git a/board/cr50/board.h b/board/cr50/board.h
index 2e75645138..f6f2f5c9de 100644
--- a/board/cr50/board.h
+++ b/board/cr50/board.h
@@ -62,12 +62,20 @@
#define CONFIG_FLASH_NVMEM_OFFSET_A (CFG_TOP_A_OFF + CONFIG_FLASH_NVCTR_SIZE)
#define CONFIG_FLASH_NVMEM_OFFSET_B (CFG_TOP_B_OFF + CONFIG_FLASH_NVCTR_SIZE)
/* Address of start of Nvmem area */
-#define CONFIG_FLASH_NVMEM_BASE_A (CONFIG_PROGRAM_MEMORY_BASE + \
- CONFIG_FLASH_NVMEM_OFFSET_A)
-#define CONFIG_FLASH_NVMEM_BASE_B (CONFIG_PROGRAM_MEMORY_BASE + \
- CONFIG_FLASH_NVMEM_OFFSET_B)
+#define CONFIG_FLASH_NVMEM_BASE_A \
+ (CONFIG_PROGRAM_MEMORY_BASE + CONFIG_FLASH_NVMEM_OFFSET_A)
+#define CONFIG_FLASH_NVMEM_BASE_B \
+ (CONFIG_PROGRAM_MEMORY_BASE + CONFIG_FLASH_NVMEM_OFFSET_B)
+#define CONFIG_FLASH_NEW_NVMEM_BASE_A \
+ (CONFIG_FLASH_NVMEM_BASE_A + CONFIG_FLASH_BANK_SIZE)
+#define CONFIG_FLASH_NEW_NVMEM_BASE_B \
+ (CONFIG_FLASH_NVMEM_BASE_B + CONFIG_FLASH_BANK_SIZE)
+
/* Size partition in NvMem */
#define NVMEM_PARTITION_SIZE (CFG_TOP_SIZE - CONFIG_FLASH_NVCTR_SIZE)
+#define NEW_NVMEM_PARTITION_SIZE (NVMEM_PARTITION_SIZE - CONFIG_FLASH_BANK_SIZE)
+#define NEW_NVMEM_TOTAL_PAGES \
+ (2 * NEW_NVMEM_PARTITION_SIZE / CONFIG_FLASH_BANK_SIZE)
/* Size in bytes of NvMem area */
#define CONFIG_FLASH_LOG
#define CONFIG_FLASH_NVMEM_SIZE (NVMEM_PARTITION_SIZE * NVMEM_NUM_PARTITIONS)
diff --git a/board/cr50/u2f.c b/board/cr50/u2f.c
index a858edfa58..320f026a6e 100644
--- a/board/cr50/u2f.c
+++ b/board/cr50/u2f.c
@@ -82,25 +82,22 @@ static int load_state(void)
/* create random salt */
if (!DCRYPTO_ladder_random(salt))
return 0;
- if (setvar(&k_salt, sizeof(k_salt),
- (const uint8_t *)salt, sizeof(salt)))
+ if (setvar(&k_salt, sizeof(k_salt), (const uint8_t *)salt,
+ sizeof(salt)))
return 0;
- /* really save the new variable to flash */
- writevars();
} else {
memcpy(salt, tuple_val(t_salt), sizeof(salt));
+ freevar(t_salt);
}
- if (read_tpm_nvmem_hidden(
- TPM_HIDDEN_U2F_KEK,
- sizeof(salt_kek), salt_kek) ==
- tpm_read_not_found) {
+ if (read_tpm_nvmem_hidden(TPM_HIDDEN_U2F_KEK, sizeof(salt_kek),
+ salt_kek) == tpm_read_not_found) {
/*
* Not found means that we have not used u2f before,
* or not used it with updated fw that resets kek seed
* on TPM clear.
*/
- if (t_salt) {
+ if (t_salt) { /* Note that memory has been freed already!. */
/*
* We have previously used u2f, and may have
* existing registrations; we don't want to