Revision: 13732
          http://edk2.svn.sourceforge.net/edk2/?rev=13732&view=rev
Author:   lzeng14
Date:     2012-09-14 06:54:35 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
Fix the issue that FTW driver fail to reclaim WorkSpace.

Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
Reviewed-by: Hengyan Tao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c
    
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
    trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
    trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c    
    2012-09-14 02:59:35 UTC (rev 13731)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.c    
    2012-09-14 06:54:35 UTC (rev 13732)
@@ -3,7 +3,7 @@
   These are the common Fault Tolerant Write (FTW) functions that are shared 
   by DXE FTW driver and SMM FTW driver.
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD 
License         
 which accompanies this distribution.  The full text of the license may be 
found at        
@@ -193,9 +193,12 @@
   EFI_FAULT_TOLERANT_WRITE_HEADER *Header;
   EFI_FAULT_TOLERANT_WRITE_RECORD *Record;
   UINTN                           Offset;
+  EFI_LBA                         WorkSpaceLbaOffset;
 
   FtwDevice = FTW_CONTEXT_FROM_THIS (This);
 
+  WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
+
   //
   // Spare Complete but Destination not complete,
   // Recover the target block with the spare block.
@@ -215,7 +218,7 @@
     Offset = (UINT8 *) Record - FtwDevice->FtwWorkSpace;
     Status = FtwUpdateFvState (
               FtwDevice->FtwBackupFvb,
-              FtwDevice->FtwWorkSpaceLba,
+              FtwDevice->FtwSpareLba + WorkSpaceLbaOffset,
               FtwDevice->FtwWorkSpaceBase + Offset,
               SPARE_COMPLETED
               );

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c 
    2012-09-14 02:59:35 UTC (rev 13731)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c 
    2012-09-14 06:54:35 UTC (rev 13732)
@@ -209,6 +209,8 @@
   *NumberHandles = BufferSize / sizeof(EFI_HANDLE);
   if (EFI_ERROR(Status)) {
     *NumberHandles = 0;
+    FreePool (*Buffer);
+    *Buffer = NULL;
   }
 
   return Status;

Modified: trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
===================================================================
--- trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c   
2012-09-14 02:59:35 UTC (rev 13731)
+++ trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c   
2012-09-14 06:54:35 UTC (rev 13732)
@@ -572,6 +572,9 @@
   if (Buffer == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
+
+  WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
+
   //
   // To guarantee that the WorkingBlockValid is set on spare block
   //
@@ -581,7 +584,7 @@
   //
   FtwUpdateFvState (
     FtwDevice->FtwBackupFvb,
-    FtwDevice->FtwWorkSpaceLba,
+    FtwDevice->FtwSpareLba + WorkSpaceLbaOffset,
     FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
     WORKING_BLOCK_VALID
     );
@@ -608,7 +611,6 @@
   //
   // Clear the CRC and STATE, copy data from spare to working block.
   //
-  WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
   WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (Buffer + 
(UINTN) WorkSpaceLbaOffset * FtwDevice->BlockSize + 
FtwDevice->FtwWorkSpaceBase);
   InitWorkSpaceHeader (WorkingBlockHeader);
   WorkingBlockHeader->WorkingBlockValid   = FTW_ERASE_POLARITY;

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c    
    2012-09-14 02:59:35 UTC (rev 13731)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c    
    2012-09-14 06:54:35 UTC (rev 13732)
@@ -2,7 +2,7 @@
 
    Internal functions to operate Working Block Space.
 
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD 
License         
 which accompanies this distribution.  The full text of the license may be 
found at        
@@ -22,8 +22,8 @@
 
   @param WorkingHeader   Pointer of working block header
 
-  @retval  EFI_SUCCESS    The function completed successfully
-  @retval  EFI_ABORTED    The function could not complete successfully.
+  @retval TRUE          The work space is valid.
+  @retval FALSE         The work space is invalid.
 
 **/
 BOOLEAN
@@ -166,8 +166,6 @@
 {
   EFI_STATUS                      Status;
   UINTN                           Length;
-  UINTN                           Offset;
-  EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader;
 
   //
   // Initialize WorkSpace as FTW_ERASED_BYTE
@@ -200,14 +198,7 @@
             FtwDevice->FtwWorkSpaceSize,
             &FtwDevice->FtwLastWriteHeader
             );
-
-  FtwHeader = FtwDevice->FtwLastWriteHeader;
-  Offset    = (UINTN) (UINT8 *) FtwHeader - (UINTN) FtwDevice->FtwWorkSpace;
-
-  //
-  // if the Header is out of the workspace limit, call reclaim.
-  //
-  if (EFI_ERROR (Status) && (Offset >= FtwDevice->FtwWorkSpaceSize)) {
+  if (EFI_ERROR (Status)) {
     //
     // reclaim work space in working block.
     //
@@ -236,6 +227,9 @@
               FtwDevice->FtwWorkSpaceSize,
               &FtwDevice->FtwLastWriteHeader
               );
+    if (EFI_ERROR (Status)) {
+      return EFI_ABORTED;
+    }
   }
   //
   // Refresh the FtwLastWriteRecord
@@ -278,9 +272,12 @@
   EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingBlockHeader;
   UINTN                                   Index;
   UINT8                                   *Ptr;
+  EFI_LBA                                 WorkSpaceLbaOffset;
 
   DEBUG ((EFI_D_ERROR, "Ftw: start to reclaim work space\n"));
 
+  WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
+
   //
   // Read all original data from working block to a memory buffer
   //
@@ -311,7 +308,7 @@
   // Clean up the workspace, remove all the completed records.
   //
   Ptr = TempBuffer +
-        ((UINTN) (FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba)) * 
FtwDevice->BlockSize + 
+        (UINTN) WorkSpaceLbaOffset * FtwDevice->BlockSize +
         FtwDevice->FtwWorkSpaceBase;
 
   //
@@ -358,10 +355,17 @@
     &FtwDevice->FtwLastWriteHeader
     );
 
+  FtwGetLastWriteRecord (
+    FtwDevice->FtwLastWriteHeader,
+    &FtwDevice->FtwLastWriteRecord
+    );
+
   //
   // Set the WorkingBlockValid and WorkingBlockInvalid as INVALID
   //
-  WorkingBlockHeader                      = 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (TempBuffer + 
FtwDevice->FtwWorkSpaceBase);
+  WorkingBlockHeader                      = 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (TempBuffer +
+                                            (UINTN) WorkSpaceLbaOffset * 
FtwDevice->BlockSize +
+                                            FtwDevice->FtwWorkSpaceBase);
   WorkingBlockHeader->WorkingBlockValid   = FTW_INVALID_STATE;
   WorkingBlockHeader->WorkingBlockInvalid = FTW_INVALID_STATE;
 
@@ -426,7 +430,7 @@
   //
   Status = FtwUpdateFvState (
             FtwDevice->FtwBackupFvb,
-            FtwDevice->FtwWorkSpaceLba,
+            FtwDevice->FtwSpareLba + WorkSpaceLbaOffset,
             FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
             WORKING_BLOCK_VALID
             );

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to