Re: [edk2] [PATCH] MdeModulePkg Variable: Handle ftw driver executes prior to variable driver

2015-12-29 Thread Gao, Liming
Reviewed-by: Liming Gao 

-Original Message-
From: Zeng, Star 
Sent: Monday, December 28, 2015 1:39 PM
To: edk2-devel@lists.01.org
Cc: Gao, Liming
Subject: [PATCH] MdeModulePkg Variable: Handle ftw driver executes prior to 
variable driver

Variable driver uses gEdkiiFaultTolerantWriteGuid hob and copies  data to 
NvStorageData if hob exists.
But if ftw driver executes prior to variable driver then spare block is erased.

So the patch is to enhance the code to do not check FTW last write data hob if 
FTW protocol has been installed.

Cc: Liming Gao 
Reported-by: Baraneedharan Anbazhagan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng 
Reviewed-by: Baraneedharan Anbazhagan 
---
 .../Universal/Variable/RuntimeDxe/Variable.c   | 52 +-
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c 
b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 9d89d39..3136745 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -3626,6 +3626,8 @@ InitNonVolatileVariableStore (
   UINT32HwErrStorageSize;
   UINT32MaxUserNvVariableSpaceSize;
   UINT32BoottimeReservedNvVariableSpaceSize;
+  EFI_STATUSStatus;
+  VOID  *FtwProtocol;
 
   mVariableModuleGlobal->FvbInstance = NULL;
 
@@ -3648,30 +3650,36 @@ InitNonVolatileVariableStore (
   //
   CopyMem (NvStorageData, (UINT8 *) (UINTN) NvStorageBase, NvStorageSize);
 
+  Status = GetFtwProtocol ((VOID **)&FtwProtocol);
   //
-  // Check the FTW last write data hob.
+  // If FTW protocol has been installed, no need to check FTW last write data 
hob.
   //
-  GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
-  if (GuidHob != NULL) {
-FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) 
GET_GUID_HOB_DATA (GuidHob);
-if (FtwLastWriteData->TargetAddress == NvStorageBase) {
-  DEBUG ((EFI_D_INFO, "Variable: NV storage is backed up in spare block: 
0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
-  //
-  // Copy the backed up NV storage data to the memory buffer from spare 
block.
-  //
-  CopyMem (NvStorageData, (UINT8 *) (UINTN) 
(FtwLastWriteData->SpareAddress), NvStorageSize);
-} else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
-   (FtwLastWriteData->TargetAddress < (NvStorageBase + 
NvStorageSize))) {
-  //
-  // Flash NV storage from the Offset is backed up in spare block.
-  //
-  BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - 
NvStorageBase);
-  BackUpSize = NvStorageSize - BackUpOffset;
-  DEBUG ((EFI_D_INFO, "Variable: High partial NV storage from offset: %x 
is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) 
FtwLastWriteData->SpareAddress));
-  //
-  // Copy the partial backed up NV storage data to the memory buffer from 
spare block.
-  //
-  CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) 
FtwLastWriteData->SpareAddress, BackUpSize);
+  if (EFI_ERROR (Status)) {
+//
+// Check the FTW last write data hob.
+//
+GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
+if (GuidHob != NULL) {
+  FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) 
GET_GUID_HOB_DATA (GuidHob);
+  if (FtwLastWriteData->TargetAddress == NvStorageBase) {
+DEBUG ((EFI_D_INFO, "Variable: NV storage is backed up in spare block: 
0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
+//
+// Copy the backed up NV storage data to the memory buffer from spare 
block.
+//
+CopyMem (NvStorageData, (UINT8 *) (UINTN) 
(FtwLastWriteData->SpareAddress), NvStorageSize);
+  } else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
+ (FtwLastWriteData->TargetAddress < (NvStorageBase + 
NvStorageSize))) {
+//
+// Flash NV storage from the Offset is backed up in spare block.
+//
+BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - 
NvStorageBase);
+BackUpSize = NvStorageSize - BackUpOffset;
+DEBUG ((EFI_D_INFO, "Variable: High partial NV storage from offset: %x 
is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) 
FtwLastWriteData->SpareAddress));
+//
+// Copy the partial backed up NV storage data to the memory buffer 
from spare block.
+//
+CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) 
FtwLastWriteData->SpareAddress, BackUpSize);
+  }
 }
   }
 
-- 
1.9.5.msysgit.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH] MdeModulePkg Variable: Handle ftw driver executes prior to variable driver

2015-12-27 Thread Star Zeng
Variable driver uses gEdkiiFaultTolerantWriteGuid hob and copies  data to 
NvStorageData if hob exists.
But if ftw driver executes prior to variable driver then spare block is erased.

So the patch is to enhance the code to do not check FTW last write data hob if 
FTW protocol has been installed.

Cc: Liming Gao 
Reported-by: Baraneedharan Anbazhagan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng 
Reviewed-by: Baraneedharan Anbazhagan 
---
 .../Universal/Variable/RuntimeDxe/Variable.c   | 52 +-
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c 
b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 9d89d39..3136745 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -3626,6 +3626,8 @@ InitNonVolatileVariableStore (
   UINT32HwErrStorageSize;
   UINT32MaxUserNvVariableSpaceSize;
   UINT32BoottimeReservedNvVariableSpaceSize;
+  EFI_STATUSStatus;
+  VOID  *FtwProtocol;
 
   mVariableModuleGlobal->FvbInstance = NULL;
 
@@ -3648,30 +3650,36 @@ InitNonVolatileVariableStore (
   //
   CopyMem (NvStorageData, (UINT8 *) (UINTN) NvStorageBase, NvStorageSize);
 
+  Status = GetFtwProtocol ((VOID **)&FtwProtocol);
   //
-  // Check the FTW last write data hob.
+  // If FTW protocol has been installed, no need to check FTW last write data 
hob.
   //
-  GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
-  if (GuidHob != NULL) {
-FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) 
GET_GUID_HOB_DATA (GuidHob);
-if (FtwLastWriteData->TargetAddress == NvStorageBase) {
-  DEBUG ((EFI_D_INFO, "Variable: NV storage is backed up in spare block: 
0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
-  //
-  // Copy the backed up NV storage data to the memory buffer from spare 
block.
-  //
-  CopyMem (NvStorageData, (UINT8 *) (UINTN) 
(FtwLastWriteData->SpareAddress), NvStorageSize);
-} else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
-   (FtwLastWriteData->TargetAddress < (NvStorageBase + 
NvStorageSize))) {
-  //
-  // Flash NV storage from the Offset is backed up in spare block.
-  //
-  BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - 
NvStorageBase);
-  BackUpSize = NvStorageSize - BackUpOffset;
-  DEBUG ((EFI_D_INFO, "Variable: High partial NV storage from offset: %x 
is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) 
FtwLastWriteData->SpareAddress));
-  //
-  // Copy the partial backed up NV storage data to the memory buffer from 
spare block.
-  //
-  CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) 
FtwLastWriteData->SpareAddress, BackUpSize);
+  if (EFI_ERROR (Status)) {
+//
+// Check the FTW last write data hob.
+//
+GuidHob = GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid);
+if (GuidHob != NULL) {
+  FtwLastWriteData = (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) 
GET_GUID_HOB_DATA (GuidHob);
+  if (FtwLastWriteData->TargetAddress == NvStorageBase) {
+DEBUG ((EFI_D_INFO, "Variable: NV storage is backed up in spare block: 
0x%x\n", (UINTN) FtwLastWriteData->SpareAddress));
+//
+// Copy the backed up NV storage data to the memory buffer from spare 
block.
+//
+CopyMem (NvStorageData, (UINT8 *) (UINTN) 
(FtwLastWriteData->SpareAddress), NvStorageSize);
+  } else if ((FtwLastWriteData->TargetAddress > NvStorageBase) &&
+ (FtwLastWriteData->TargetAddress < (NvStorageBase + 
NvStorageSize))) {
+//
+// Flash NV storage from the Offset is backed up in spare block.
+//
+BackUpOffset = (UINT32) (FtwLastWriteData->TargetAddress - 
NvStorageBase);
+BackUpSize = NvStorageSize - BackUpOffset;
+DEBUG ((EFI_D_INFO, "Variable: High partial NV storage from offset: %x 
is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) 
FtwLastWriteData->SpareAddress));
+//
+// Copy the partial backed up NV storage data to the memory buffer 
from spare block.
+//
+CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) 
FtwLastWriteData->SpareAddress, BackUpSize);
+  }
 }
   }
 
-- 
1.9.5.msysgit.0

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel