Revision: 14232
          http://edk2.svn.sourceforge.net/edk2/?rev=14232&view=rev
Author:   vanjeff
Date:     2013-04-01 07:43:46 +0000 (Mon, 01 Apr 2013)
Log Message:
-----------
Sync patches r14005, r14011, r14012, r14021, r14022 and r14043 from main trunk.
1. Reclaim work space when the remaining space size is even not enough to 
contain one header + one record.
2. Check status before reporting error status code.
3. Initialize a local work space header to be used by IsValidWorkSpace() and 
InitWorkSpaceHeader() to avoid executing code(gBS->CalculateCrc32 ()) outside 
SMRAM while inside SMM.
4. MdeMdeModulePkg/Xhci: Fix a wrong conditional judgment which bring assertion 
with 1.0 hub.
5. MdeMdeModulePkg/Ehci: Add logic to dispatch OHCI driver first if the 
companion controller is OHCI.
6. Fix the bug that the device claiming too much resource cannot be rejected by 
the PciBus driver.

Revision Links:
--------------
    http://edk2.svn.sourceforge.net/edk2/?rev=14005&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14011&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14012&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14021&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14022&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14043&view=rev

Modified Paths:
--------------
    branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
    branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
    branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
    branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
    branches/UDK2010.SR1/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
    
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
    branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
    
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c

Modified: branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c    2013-04-01 
06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c    2013-04-01 
07:43:46 UTC (rev 14232)
@@ -6,9 +6,10 @@
   Control, Bulk, Interrupt and Isochronous requests to Usb2.0 device.
 
   Note that EhciDxe driver is enhanced to guarantee that the EHCI controller 
get attached
-  to the EHCI controller before the UHCI driver attaches to the companion UHCI 
controller. 
-  This way avoids the control transfer on a shared port between EHCI and 
companion host
-  controller when UHCI gets attached earlier than EHCI and a USB 2.0 device 
inserts.
+  to the EHCI controller before a UHCI or OHCI driver attaches to the 
companion UHCI or 
+  OHCI controller.  This way avoids the control transfer on a shared port 
between EHCI 
+  and companion host controller when UHCI or OHCI gets attached earlier than 
EHCI and a 
+  USB 2.0 device inserts.
 
 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
@@ -1403,7 +1404,7 @@
   // Test whether the controller belongs to Ehci type
   //
   if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || 
(UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB)
-      || ((UsbClassCReg.ProgInterface != PCI_IF_EHCI) && 
(UsbClassCReg.ProgInterface !=PCI_IF_UHCI))) {
+      || ((UsbClassCReg.ProgInterface != PCI_IF_EHCI) && 
(UsbClassCReg.ProgInterface != PCI_IF_UHCI) && (UsbClassCReg.ProgInterface != 
PCI_IF_OHCI))) {
 
     Status = EFI_UNSUPPORTED;
   }
@@ -1690,10 +1691,10 @@
   EFI_HANDLE              *HandleBuffer;
   UINTN                   NumberOfHandles;
   UINTN                   Index;
-  UINTN                   UhciSegmentNumber;
-  UINTN                   UhciBusNumber;
-  UINTN                   UhciDeviceNumber;
-  UINTN                   UhciFunctionNumber;
+  UINTN                   CompanionSegmentNumber;
+  UINTN                   CompanionBusNumber;
+  UINTN                   CompanionDeviceNumber;
+  UINTN                   CompanionFunctionNumber;
   UINTN                   EhciSegmentNumber;
   UINTN                   EhciBusNumber;
   UINTN                   EhciDeviceNumber;
@@ -1783,19 +1784,19 @@
     goto CLOSE_PCIIO;
   }
   //
-  // determine if the device is UHCI host controller or not. If yes, then find 
out the 
+  // Determine if the device is UHCI or OHCI host controller or not. If yes, 
then find out the 
   // companion usb ehci host controller and force EHCI driver get attached to 
it before
-  // UHCI driver attaches to UHCI host controller.
+  // UHCI or OHCI driver attaches to UHCI or OHCI host controller.
   //
-  if ((UsbClassCReg.ProgInterface == PCI_IF_UHCI) &&
+  if ((UsbClassCReg.ProgInterface == PCI_IF_UHCI || UsbClassCReg.ProgInterface 
== PCI_IF_OHCI) &&
        (UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) && 
        (UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB)) {
     Status = PciIo->GetLocation (
                     PciIo,
-                    &UhciSegmentNumber,
-                    &UhciBusNumber,
-                    &UhciDeviceNumber,
-                    &UhciFunctionNumber
+                    &CompanionSegmentNumber,
+                    &CompanionBusNumber,
+                    &CompanionDeviceNumber,
+                    &CompanionFunctionNumber
                     );
     if (EFI_ERROR (Status)) {
       goto CLOSE_PCIIO;
@@ -1853,7 +1854,7 @@
         // Currently, the judgment on the companion usb host controller is 
through the
         // same bus number, which may vary on different platform.
         //
-        if (EhciBusNumber == UhciBusNumber) {
+        if (EhciBusNumber == CompanionBusNumber) {
           gBS->CloseProtocol (
                     Controller,
                     &gEfiPciIoProtocolGuid,
@@ -2081,7 +2082,7 @@
 
   //
   // Disable routing of all ports to EHCI controller, so all ports are 
-  // routed back to the UHCI controller.
+  // routed back to the UHCI or OHCI controller.
   //
   EhcClearOpRegBit (Ehc, EHC_CONFIG_FLAG_OFFSET, CONFIGFLAG_ROUTE_EHC);
 

Modified: branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 
2013-04-01 06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 
2013-04-01 07:43:46 UTC (rev 14232)
@@ -1,7 +1,7 @@
 /** @file
   PCI eunmeration implementation on entire PCI bus system for PCI Bus module.
 
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, 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
@@ -1035,6 +1035,11 @@
     //
     Status = RejectPciDevice (PciResNode->PciDev);
     if (Status == EFI_SUCCESS) {
+      DEBUG ((
+        EFI_D_ERROR,
+        "PciBus: [%02x|%02x|%02x] was rejected due to resource confliction.\n",
+        PciResNode->PciDev->BusNumber, PciResNode->PciDev->DeviceNumber, 
PciResNode->PciDev->FunctionNumber
+        ));
 
       //
       // Raise the EFI_IOB_EC_RESOURCE_CONFLICT status code
@@ -1867,7 +1872,7 @@
                             );
   }
 
-  return EFI_SUCCESS;
+  return Status;
 }
 
 /**

Modified: branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c        
2013-04-01 06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c        
2013-04-01 07:43:46 UTC (rev 14232)
@@ -1,7 +1,7 @@
 /** @file
   Internal library implementation for PCI Bus module.
 
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, 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
@@ -568,6 +568,12 @@
                                 RootBridgeDev->Handle,
                                 AcpiConfig
                                 );
+        //
+        // If SubmitResources returns error, PciBus isn't able to start.
+        // It's a fatal error so assertion is added.
+        //
+        DEBUG ((EFI_D_INFO, "PciBus: HostBridge->SubmitResources() - %r\n", 
Status));
+        ASSERT_EFI_ERROR (Status);
       }
 
       //
@@ -598,6 +604,7 @@
     // Notify platform to start to program the resource
     //
     Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeAllocateResources);
+    DEBUG ((EFI_D_INFO, "PciBus: HostBridge->NotifyPhase(AllocateResources) - 
%r\n", Status));
     if (!FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) {
       //
       // If Hot Plug is not supported

Modified: branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c    2013-04-01 
06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c    2013-04-01 
07:43:46 UTC (rev 14232)
@@ -1009,17 +1009,15 @@
       if ((State & XHC_PORTSC_PS) >> 10 == 0) {
         PortStatus.PortStatus |= USB_PORT_STAT_SUPER_SPEED;
       }
-    } else if (DeviceSpeed == EFI_USB_SPEED_HIGH) {
+    } else {
       //
-      // For high speed hub, its bit9~10 presents the attached device speed.
+      // For high or full/low speed hub, its bit9~10 presents the attached 
device speed.
       //
       if (XHC_BIT_IS_SET (State, BIT9)) {
         PortStatus.PortStatus |= USB_PORT_STAT_LOW_SPEED;
       } else if (XHC_BIT_IS_SET (State, BIT10)) {
         PortStatus.PortStatus |= USB_PORT_STAT_HIGH_SPEED;
       }
-    } else {
-      ASSERT (0);
     }
 
     //

Modified: branches/UDK2010.SR1/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c 2013-04-01 
06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c 2013-04-01 
07:43:46 UTC (rev 14232)
@@ -241,20 +241,25 @@
                NULL,
                (VOID **) &PeiRecovery
                );
-    //
-    // Report Status code the failure of locating Recovery PPI 
-    //
-    REPORT_STATUS_CODE (
-      EFI_ERROR_CODE | EFI_ERROR_MAJOR,
-      (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND)
-      );    
-    ASSERT_EFI_ERROR (Status);
+
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "Locate Recovery PPI Failed.(Status = %r)\n", 
Status));
+      //
+      // Report Status code the failure of locating Recovery PPI 
+      //
+      REPORT_STATUS_CODE (
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,
+        (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND)
+        );
+      CpuDeadLoop ();
+    }
+
     REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | 
EFI_SW_PEI_PC_CAPSULE_LOAD));
     Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);
     if (EFI_ERROR (Status)) {
       DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", 
Status));
       //
-      // Report Status code that S3Resume PPI can not be found
+      // Report Status code that recovery image can not be found
       //
       REPORT_STATUS_CODE (
         EFI_ERROR_CODE | EFI_ERROR_MAJOR,

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
      2013-04-01 06:48:54 UTC (rev 14231)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
      2013-04-01 07:43:46 UTC (rev 14232)
@@ -3,7 +3,7 @@
   The internal header file includes the common header files, defines
   internal structure and functions used by FtwLite module.
 
-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        
@@ -20,6 +20,7 @@
 #include <PiDxe.h>
 
 #include <Guid/SystemNvDataGuid.h>
+#include <Guid/ZeroGuid.h>
 #include <Protocol/FaultTolerantWrite.h>
 #include <Protocol/FirmwareVolumeBlock.h>
 #include <Protocol/SwapAddressRange.h>
@@ -736,5 +737,16 @@
 InitFtwProtocol (
   IN OUT EFI_FTW_DEVICE               *FtwDevice
   );
+
+/**
+  Initialize a local work space header.
+
+  Since Signature and WriteQueueSize have been known, Crc can be calculated 
out,
+  then the work space header will be fixed.
+**/
+VOID
+InitializeLocalWorkSpaceHeader (
+  VOID
+  );
  
 #endif

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c 
2013-04-01 06:48:54 UTC (rev 14231)
+++ branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c 
2013-04-01 07:43:46 UTC (rev 14232)
@@ -1174,6 +1174,8 @@
   FtwDevice->FtwLastWriteHeader = NULL;
   FtwDevice->FtwLastWriteRecord = NULL;
 
+  InitializeLocalWorkSpaceHeader ();
+
   //
   // Refresh the working space data from working block
   //

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
      2013-04-01 06:48:54 UTC (rev 14231)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
      2013-04-01 07:43:46 UTC (rev 14232)
@@ -16,77 +16,90 @@
 
 #include "FaultTolerantWrite.h"
 
+EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBlockHeader = {ZERO_GUID, 0, 
0, 0, 0, {0, 0, 0}, 0};
+
 /**
-  Check to see if it is a valid work space.
+  Initialize a local work space header.
 
-
-  @param WorkingHeader   Pointer of working block header
-
-  @retval TRUE          The work space is valid.
-  @retval FALSE         The work space is invalid.
-
+  Since Signature and WriteQueueSize have been known, Crc can be calculated 
out,
+  then the work space header will be fixed.
 **/
-BOOLEAN
-IsValidWorkSpace (
-  IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+VOID
+InitializeLocalWorkSpaceHeader (
+  VOID
   )
 {
   EFI_STATUS                              Status;
-  EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER WorkingBlockHeader;
 
-  if (WorkingHeader == NULL) {
-    return FALSE;
-  }
-
-  if (WorkingHeader->WorkingBlockValid != FTW_VALID_STATE) {
-    DEBUG ((EFI_D_ERROR, "Ftw: Work block header valid bit check error\n"));
-    return FALSE;
-  }
   //
-  // Check signature with gEfiSystemNvDataFvGuid
+  // Check signature with gEfiSystemNvDataFvGuid.
   //
-  if (!CompareGuid (&gEfiSystemNvDataFvGuid, &WorkingHeader->Signature)) {
-    DEBUG ((EFI_D_ERROR, "Ftw: Work block header signature check error\n"));
-    return FALSE;
+  if (CompareGuid (&gEfiSystemNvDataFvGuid, &mWorkingBlockHeader.Signature)) {
+    //
+    // The local work space header has been initialized.
+    //
+    return;
   }
+
+  SetMem (
+    &mWorkingBlockHeader,
+    sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
+    FTW_ERASED_BYTE
+    );
+
   //
-  // Check the CRC of header
+  // Here using gEfiSystemNvDataFvGuid as the signature.
   //
   CopyMem (
-    &WorkingBlockHeader,
-    WorkingHeader,
-    sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)
+    &mWorkingBlockHeader.Signature,
+    &gEfiSystemNvDataFvGuid,
+    sizeof (EFI_GUID)
     );
+  mWorkingBlockHeader.WriteQueueSize = (UINT64) (PcdGet32 
(PcdFlashNvStorageFtwWorkingSize) - sizeof 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
 
   //
-  // Filter out the Crc and State fields
+  // Crc is calculated with all the fields except Crc and STATE, so leave them 
as FTW_ERASED_BYTE.
   //
-  SetMem (
-    &WorkingBlockHeader.Crc,
-    sizeof (UINT32),
-    FTW_ERASED_BYTE
-    );
-  WorkingBlockHeader.WorkingBlockValid    = FTW_ERASE_POLARITY;
-  WorkingBlockHeader.WorkingBlockInvalid  = FTW_ERASE_POLARITY;
 
   //
   // Calculate the Crc of woking block header
   //
   Status = gBS->CalculateCrc32 (
-                  (UINT8 *) &WorkingBlockHeader,
+                  &mWorkingBlockHeader,
                   sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
-                  &WorkingBlockHeader.Crc
+                  &mWorkingBlockHeader.Crc
                   );
-  if (EFI_ERROR (Status)) {
+  ASSERT_EFI_ERROR (Status);
+
+  mWorkingBlockHeader.WorkingBlockValid    = FTW_VALID_STATE;
+  mWorkingBlockHeader.WorkingBlockInvalid  = FTW_INVALID_STATE;
+}
+
+/**
+  Check to see if it is a valid work space.
+
+
+  @param WorkingHeader   Pointer of working block header
+
+  @retval TRUE          The work space is valid.
+  @retval FALSE         The work space is invalid.
+
+**/
+BOOLEAN
+IsValidWorkSpace (
+  IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
+  )
+{
+  if (WorkingHeader == NULL) {
     return FALSE;
   }
 
-  if (WorkingBlockHeader.Crc != WorkingHeader->Crc) {
-    DEBUG ((EFI_D_ERROR, "Ftw: Work block header CRC check error\n"));
-    return FALSE;
+  if (CompareMem (WorkingHeader, &mWorkingBlockHeader, sizeof 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER)) == 0) {
+    return TRUE;
   }
 
-  return TRUE;
+  DEBUG ((EFI_D_ERROR, "Ftw: Work block header check error\n"));
+  return FALSE;
 }
 
 /**
@@ -103,50 +116,12 @@
   IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
   )
 {
-  EFI_STATUS  Status;
-
   if (WorkingHeader == NULL) {
     return EFI_INVALID_PARAMETER;
   }
-  //
-  // Here using gEfiSystemNvDataFvGuid as the signature.
-  //
-  CopyMem (
-    &WorkingHeader->Signature,
-    &gEfiSystemNvDataFvGuid,
-    sizeof (EFI_GUID)
-    );
-  WorkingHeader->WriteQueueSize = (UINT64) (PcdGet32 
(PcdFlashNvStorageFtwWorkingSize) - sizeof 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
 
-  //
-  // Crc is calculated with all the fields except Crc and STATE
-  //
-  WorkingHeader->WorkingBlockValid    = FTW_ERASE_POLARITY;
-  WorkingHeader->WorkingBlockInvalid  = FTW_ERASE_POLARITY;
+  CopyMem (WorkingHeader, &mWorkingBlockHeader, sizeof 
(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
 
-  SetMem (
-    &WorkingHeader->Crc,
-    sizeof (UINT32),
-    FTW_ERASED_BYTE
-    );
-
-  //
-  // Calculate the CRC value
-  //
-  Status = gBS->CalculateCrc32 (
-                  (UINT8 *) WorkingHeader,
-                  sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER),
-                  &WorkingHeader->Crc
-                  );
-  if (EFI_ERROR (Status)) {
-    return EFI_ABORTED;
-  }
-  //
-  // Restore the WorkingBlockValid flag to VALID state
-  //
-  WorkingHeader->WorkingBlockValid    = FTW_VALID_STATE;
-  WorkingHeader->WorkingBlockInvalid  = FTW_INVALID_STATE;
-
   return EFI_SUCCESS;
 }
 
@@ -166,6 +141,7 @@
 {
   EFI_STATUS                      Status;
   UINTN                           Length;
+  UINTN                           RemainingSpaceSize;
 
   //
   // Initialize WorkSpace as FTW_ERASED_BYTE
@@ -198,7 +174,15 @@
             FtwDevice->FtwWorkSpaceSize,
             &FtwDevice->FtwLastWriteHeader
             );
-  if (EFI_ERROR (Status)) {
+  RemainingSpaceSize = FtwDevice->FtwWorkSpaceSize - ((UINTN) 
FtwDevice->FtwLastWriteHeader - (UINTN) FtwDevice->FtwWorkSpace);
+  DEBUG ((EFI_D_INFO, "Ftw: Remaining work space size - %x\n", 
RemainingSpaceSize));
+  //
+  // If FtwGetLastWriteHeader() returns error, or the remaining space size is 
even not enough to contain
+  // one EFI_FAULT_TOLERANT_WRITE_HEADER + one 
EFI_FAULT_TOLERANT_WRITE_RECORD(It will cause that the header
+  // pointed by FtwDevice->FtwLastWriteHeader or record pointed by 
FtwDevice->FtwLastWriteRecord may contain invalid data),
+  // it needs to reclaim work space.
+  //
+  if (EFI_ERROR (Status) || RemainingSpaceSize < sizeof 
(EFI_FAULT_TOLERANT_WRITE_HEADER) + sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD)) {
     //
     // reclaim work space in working block.
     //

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


------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to