My fresh vm installation with OVMF firmware has problem that the OS boot
entry are not displayed by boot manager. It happens only when the EFI
System Partition are created from scratch, that is there's no NvVars in
it initially.

After some testing and debugging, the cause is modified BootOrder gets
overwritten by the loaded NvVars, which is using a stale dump created
from previous boot.

This patch fixes the problem for me by handing the initial case (ie NvVars
file not found) with loading NvVars immediately after it's been saved. Then
the system is flagged as NvVars loaded and would not attempt to restore it
in reboot which could always use stale dumps.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Michael Chang <mch...@suse.com>
---
 OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c 
b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c
index c89bb4a..fcbfcbb 100644
--- a/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c
+++ b/OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.c
@@ -36,12 +36,20 @@ ConnectNvVarsToFileSystem (
   )
 {
   EFI_STATUS Status;
+  BOOLEAN Initial = FALSE;
 
   //
   // We might fail to load the variable, since the file system initially
   // will not have the NvVars file.
   //
-  LoadNvVarsFromFs (FsHandle);
+  Status = LoadNvVarsFromFs (FsHandle);
+
+  //
+  // The NvVars file is initially not exist.
+  //
+  if (Status == EFI_NOT_FOUND) {
+    Initial = TRUE;
+  }
 
   //
   // We must be able to save the variables successfully to the file system
@@ -52,6 +60,15 @@ ConnectNvVarsToFileSystem (
     mNvVarsFileLibFsHandle = FsHandle;
   }
 
+  //
+  // In initial case we load the NvVars right after it's created. By doing
+  // this we can avoid the problem caused by loading saved NvVars in next
+  // (re)boot, which could contain stale data saved from previous boot. 
+  //
+  if (Initial) {
+    LoadNvVarsFromFs (FsHandle);
+  }
+
   return Status;
 }
 
-- 
1.8.1.4


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to