[coreboot-gerrit] Patch set updated for coreboot: chromeos: Add option to back up VBNV CMOS into flash

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Tue Feb 9 14:02:57 CET 2016


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/13600

-gerrit

commit 24fb6c457d23b1d04404be6f8b2afed9e1038b79
Author: Duncan Laurie <dlaurie at chromium.org>
Date:   Tue Jan 26 16:30:36 2016 -0800

    chromeos: Add option to back up VBNV CMOS into flash
    
    This adds a new kconfig option that will back up the VBNV data
    from CMOS to flash, and restore it if the CMOS data is invalid
    during boot.
    
    This allows special flags to not get lost when power is lost,
    RTC reset is triggered, or CMOS is corrupted.
    
    BUG=chrome-os-partner:47915
    BRANCH=glados
    TEST=manually tested on chell:
    1-boot and run "enable_dev_usb_boot"
    2-reboot and check that it is enabled with crossystem
    3-run "mosys nvram clear"
    4-reboot and check that it is still enabled
    
    Change-Id: I38103d100117da34471734a6dd31eb7058735c12
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: 8a356e616c6885d5ae3b776691929675d48a28f9
    Original-Change-Id: I06e7ddff7b272e579c704914a0cf8cc14d6994e8
    Original-Signed-off-by: Duncan Laurie <dlaurie at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/324122
    Original-Reviewed-by: Aaron Durbin <adurbin at chromium.org>
---
 src/vendorcode/google/chromeos/Kconfig      |  8 ++++++++
 src/vendorcode/google/chromeos/Makefile.inc |  5 +++++
 src/vendorcode/google/chromeos/vbnv_cmos.c  | 31 +++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index 79d6918..4a889b1 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -50,6 +50,14 @@ config CHROMEOS_VBNV_CMOS
 	help
 	  VBNV is stored in CMOS
 
+config CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH
+	bool "Backup Vboot non-volatile storage from CMOS to flash."
+	default n
+	depends on CHROMEOS_VBNV_CMOS
+	help
+	  Vboot non-volatile storage data will be backed up from CMOS to flash
+	  and restored from flash if the CMOS is invalid due to power loss.
+
 config CHROMEOS_VBNV_EC
 	bool "Vboot non-volatile storage in EC."
 	default n
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index ee8b50d..7d62b5b 100644
--- a/src/vendorcode/google/chromeos/Makefile.inc
+++ b/src/vendorcode/google/chromeos/Makefile.inc
@@ -28,6 +28,11 @@ verstage-$(CONFIG_CHROMEOS_VBNV_CMOS) += vbnv_cmos.c
 romstage-$(CONFIG_CHROMEOS_VBNV_CMOS) += vbnv_cmos.c
 ramstage-$(CONFIG_CHROMEOS_VBNV_CMOS) += vbnv_cmos.c
 
+bootblock-$(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH) += vbnv_flash.c
+verstage-$(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH) += vbnv_flash.c
+romstage-$(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH) += vbnv_flash.c
+ramstage-$(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH) += vbnv_flash.c
+
 bootblock-$(CONFIG_CHROMEOS_VBNV_EC) += vbnv_ec.c
 verstage-$(CONFIG_CHROMEOS_VBNV_EC) += vbnv_ec.c
 romstage-$(CONFIG_CHROMEOS_VBNV_EC) += vbnv_ec.c
diff --git a/src/vendorcode/google/chromeos/vbnv_cmos.c b/src/vendorcode/google/chromeos/vbnv_cmos.c
index e0d7ba1..22acefa 100644
--- a/src/vendorcode/google/chromeos/vbnv_cmos.c
+++ b/src/vendorcode/google/chromeos/vbnv_cmos.c
@@ -13,6 +13,8 @@
  * GNU General Public License for more details.
  */
 
+#include <bootstate.h>
+#include <console/console.h>
 #include <types.h>
 #include <pc80/mc146818rtc.h>
 #include "vbnv.h"
@@ -24,6 +26,21 @@ void read_vbnv_cmos(uint8_t *vbnv_copy)
 
 	for (i = 0; i < VBNV_BLOCK_SIZE; i++)
 		vbnv_copy[i] = cmos_read(CONFIG_VBNV_OFFSET + 14 + i);
+
+	if (IS_ENABLED(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH)) {
+		if (verify_vbnv(vbnv_copy))
+			return;
+
+		printk(BIOS_INFO, "VBNV: CMOS invalid, restoring from flash\n");
+		read_vbnv_flash(vbnv_copy);
+
+		if (verify_vbnv(vbnv_copy)) {
+			save_vbnv_cmos(vbnv_copy);
+			printk(BIOS_INFO, "VBNV: Flash backup restored\n");
+		} else {
+			printk(BIOS_INFO, "VBNV: Restore from flash failed\n");
+		}
+	}
 }
 
 void save_vbnv_cmos(const uint8_t *vbnv_copy)
@@ -33,3 +50,17 @@ void save_vbnv_cmos(const uint8_t *vbnv_copy)
 	for (i = 0; i < VBNV_BLOCK_SIZE; i++)
 		cmos_write(vbnv_copy[i], CONFIG_VBNV_OFFSET + 14 + i);
 }
+
+#if IS_ENABLED(CONFIG_CHROMEOS_VBNV_CMOS_BACKUP_TO_FLASH)
+static void backup_vbnv_cmos(void *unused)
+{
+	uint8_t vbnv_cmos[VBNV_BLOCK_SIZE];
+
+	/* Read current VBNV from CMOS. */
+	read_vbnv_cmos(vbnv_cmos);
+
+	/* Save to flash, will only be saved if different. */
+	save_vbnv_flash(vbnv_cmos);
+}
+BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, backup_vbnv_cmos, NULL);
+#endif



More information about the coreboot-gerrit mailing list