aboutsummaryrefslogtreecommitdiff
path: root/src/vendorcode/google/chromeos/vbnv_cmos.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vendorcode/google/chromeos/vbnv_cmos.c')
-rw-r--r--src/vendorcode/google/chromeos/vbnv_cmos.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/vendorcode/google/chromeos/vbnv_cmos.c b/src/vendorcode/google/chromeos/vbnv_cmos.c
index e0d7ba1ea3..22acefa517 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