[Skiboot] [PATCH v2 3/7] core/init: recheck nvram on fast reboot

Oliver O'Halloran oohall at gmail.com
Wed Aug 17 15:32:50 AEST 2016


If the previously running OS modifies the NVRAM it may be left in an
invalid state. To prevent errors we need to re-validate the nvram format
in the fast-reboot path.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/init.c     |  5 ++++-
 core/nvram.c    | 32 +++++++++++++++++++++++---------
 include/nvram.h |  1 +
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/core/init.c b/core/init.c
index 86bcdea9ee75..28e9401106c6 100644
--- a/core/init.c
+++ b/core/init.c
@@ -44,6 +44,7 @@
 #include <ipmi.h>
 #include <sensor.h>
 #include <xive.h>
+#include <nvram.h>
 
 enum proc_gen proc_gen;
 
@@ -436,7 +437,9 @@ void __noreturn load_and_boot_kernel(bool is_reboot)
 
 		/* Wait for FW VPD data read to complete */
 		fsp_code_update_wait_vpd(true);
-	}
+	} else
+		nvram_reinit();
+
 	fsp_console_select_stdout();
 
 	/*
diff --git a/core/nvram.c b/core/nvram.c
index 9e860d983768..19eb7255ac7b 100644
--- a/core/nvram.c
+++ b/core/nvram.c
@@ -51,6 +51,28 @@ static int64_t opal_write_nvram(uint64_t buffer, uint64_t size, uint64_t offset)
 }
 opal_call(OPAL_WRITE_NVRAM, opal_write_nvram, 3);
 
+static void nvram_validate(void)
+{
+	/* Check and maybe format nvram */
+	if (nvram_check(nvram_image, nvram_size)) {
+		if (nvram_format(nvram_image, nvram_size))
+			prerror("NVRAM: Failed to format NVRAM!\n");
+
+		/* Write the whole thing back */
+		if (platform.nvram_write)
+			platform.nvram_write(0, nvram_image, nvram_size);
+	}
+}
+
+void nvram_reinit(void)
+{
+	/* It's possible we failed to load nvram at boot. */
+	if (!nvram_ready)
+		nvram_init();
+	else
+		nvram_validate();
+}
+
 void nvram_read_complete(bool success)
 {
 	struct dt_node *np;
@@ -62,15 +84,7 @@ void nvram_read_complete(bool success)
 		return;
 	}
 
-	/* Check and maybe format nvram */
-	if (nvram_check(nvram_image, nvram_size)) {
-		if (nvram_format(nvram_image, nvram_size))
-			prerror("NVRAM: Failed to format NVRAM!\n");
-
-		/* Write the whole thing back */
-		if (platform.nvram_write)
-			platform.nvram_write(0, nvram_image, nvram_size);
-	}
+	nvram_validate();
 
 	/* Add nvram node */
 	np = dt_new(opal_node, "nvram");
diff --git a/include/nvram.h b/include/nvram.h
index ce33d2fc2d80..c90c5712a2f7 100644
--- a/include/nvram.h
+++ b/include/nvram.h
@@ -19,5 +19,6 @@
 
 int nvram_format(void *nvram_image, uint32_t nvram_size);
 int nvram_check(void *nvram_image, uint32_t nvram_size);
+void nvram_reinit(void);
 
 #endif /* __NVRAM_H */
-- 
2.5.5



More information about the Skiboot mailing list