From 165b6cf5c1192439838df83158c92313451f7777 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Mon, 27 Jun 2016 16:19:09 -0700 Subject: vbnv: Do not silently reset cache in read_vbnv Currently, read_vbnv performs a reset of the vbnv cache if it is not valid. However, this information is not passed up to the vboot layer, thus resulting in missed write-back of vbnv cache to storage if vboot does not update the cache itself. Update read_vbnv to return a value depending upon whether it wants a write-back to be performed when save is called. Return value: 0 = No write-back required 1 = Write-back of VBNV cache is required. Change-Id: I239939d5f9731d89a9d53fe662321b93fc1ab113 Signed-off-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/15457 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/vendorcode/google/chromeos/vbnv.c | 15 +++++++++++---- src/vendorcode/google/chromeos/vbnv.h | 7 ++++++- src/vendorcode/google/chromeos/vboot2/vboot_logic.c | 8 ++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src/vendorcode/google/chromeos') diff --git a/src/vendorcode/google/chromeos/vbnv.c b/src/vendorcode/google/chromeos/vbnv.c index 92f03fbfe3..baccb2313d 100644 --- a/src/vendorcode/google/chromeos/vbnv.c +++ b/src/vendorcode/google/chromeos/vbnv.c @@ -85,8 +85,12 @@ int verify_vbnv(uint8_t *vbnv_copy) (crc8_vbnv(vbnv_copy, CRC_OFFSET) == vbnv_copy[CRC_OFFSET]); } -/* Read VBNV data from configured storage backend. */ -void read_vbnv(uint8_t *vbnv_copy) +/* + * Read VBNV data from configured storage backend. + * If VBNV verification fails, reset the vbnv copy. + * Returns 1 if write-back of vbnv copy is required. Else, returns 0. + */ +int read_vbnv(uint8_t *vbnv_copy) { if (IS_ENABLED(CONFIG_CHROMEOS_VBNV_CMOS)) read_vbnv_cmos(vbnv_copy); @@ -96,8 +100,11 @@ void read_vbnv(uint8_t *vbnv_copy) read_vbnv_flash(vbnv_copy); /* Check data for consistency */ - if (!verify_vbnv(vbnv_copy)) - reset_vbnv(vbnv_copy); + if (verify_vbnv(vbnv_copy)) + return 0; + + reset_vbnv(vbnv_copy); + return 1; } /* diff --git a/src/vendorcode/google/chromeos/vbnv.h b/src/vendorcode/google/chromeos/vbnv.h index 5d21cc8481..a66d687fe5 100644 --- a/src/vendorcode/google/chromeos/vbnv.h +++ b/src/vendorcode/google/chromeos/vbnv.h @@ -19,7 +19,12 @@ #include /* Generic functions */ -void read_vbnv(uint8_t *vbnv_copy); +/* + * Return value for read_vbnv: + * 1 = write-back of vbnv copy is required. + * 0 = otherwise + */ +int read_vbnv(uint8_t *vbnv_copy); void save_vbnv(const uint8_t *vbnv_copy); int verify_vbnv(uint8_t *vbnv_copy); int get_recovery_mode_from_vbnv(void); diff --git a/src/vendorcode/google/chromeos/vboot2/vboot_logic.c b/src/vendorcode/google/chromeos/vboot2/vboot_logic.c index a81a9c2892..116c9498d9 100644 --- a/src/vendorcode/google/chromeos/vboot2/vboot_logic.c +++ b/src/vendorcode/google/chromeos/vboot2/vboot_logic.c @@ -301,8 +301,12 @@ void verstage_main(void) /* Set up context and work buffer */ vb2_init_work_context(&ctx); - /* Read nvdata from a non-volatile storage */ - read_vbnv(ctx.nvdata); + /* + * Read nvdata from a non-volatile storage and mark data as changed + * if instructed. + */ + if (read_vbnv(ctx.nvdata)) + ctx.flags |= VB2_CONTEXT_NVDATA_CHANGED; /* Set S3 resume flag if vboot should behave differently when selecting * which slot to boot. This is only relevant to vboot if the platform -- cgit v1.2.3