]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / Nt32Pkg / FvbServicesRuntimeDxe / FWBlockService.c
index c2245f48c9918f5ee3b1903878310edd62933947..67d88c650c264d140cc00abbb4a93d955233a947 100644 (file)
@@ -1,7 +1,7 @@
-/*++\r
+/**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -17,7 +17,7 @@ Abstract:
 \r
 Revision History\r
 \r
---*/\r
+**/\r
 \r
 //\r
 // The package level header files this module uses\r
@@ -28,9 +28,7 @@ Revision History
 // The protocols, PPI and GUID defintions for this module\r
 //\r
 #include <Guid/EventGroup.h>\r
-#include <Protocol/FvbExtension.h>\r
 #include <Protocol/FirmwareVolumeBlock.h>\r
-#include <Guid/AlternateFvBlock.h>\r
 #include <Protocol/DevicePath.h>\r
 //\r
 // The Library classes this module consumes\r
@@ -45,6 +43,7 @@ Revision History
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
 \r
 #include "FWBlockService.h"\r
 \r
@@ -52,31 +51,55 @@ Revision History
 \r
 ESAL_FWB_GLOBAL         *mFvbModuleGlobal;\r
 \r
-EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {\r
-  FVB_DEVICE_SIGNATURE,\r
+FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {\r
   {\r
     {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_MEMMAP_DP,\r
       {\r
-        HARDWARE_DEVICE_PATH,\r
-        HW_MEMMAP_DP,\r
-        {\r
-          sizeof (MEMMAP_DEVICE_PATH),\r
-          0\r
-        }\r
-      },\r
-      EfiMemoryMappedIO,\r
-      0,\r
-      0,\r
+        (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r
+        (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8)\r
+      }\r
     },\r
+    EfiMemoryMappedIO,\r
+    (EFI_PHYSICAL_ADDRESS) 0,\r
+    (EFI_PHYSICAL_ADDRESS) 0,\r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      END_DEVICE_PATH_LENGTH,\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {\r
+  {\r
     {\r
-      END_DEVICE_PATH_TYPE,\r
-      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      MEDIA_DEVICE_PATH,\r
+      MEDIA_PIWG_FW_VOL_DP,\r
       {\r
-        sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
-        0\r
+        (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)),\r
+        (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8)\r
       }\r
-    }\r
+    },\r
+    { 0 }\r
   },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      END_DEVICE_PATH_LENGTH,\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {\r
+  FVB_DEVICE_SIGNATURE,\r
+  NULL,\r
   0,\r
   {\r
     FvbProtocolGetAttributes,\r
@@ -87,9 +110,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {
     FvbProtocolWrite,\r
     FvbProtocolEraseBlocks,\r
     NULL\r
-  },\r
-  {\r
-    FvbExtendProtocolEraseCustomBlockRange\r
   }\r
 };\r
 \r
@@ -240,7 +260,7 @@ Returns:
 EFI_STATUS\r
 FvbGetVolumeAttributes (\r
   IN UINTN                                Instance,\r
-  OUT EFI_FVB_ATTRIBUTES                  *Attributes,\r
+  OUT EFI_FVB_ATTRIBUTES_2                *Attributes,\r
   IN ESAL_FWB_GLOBAL                      *Global,\r
   IN BOOLEAN                              Virtual\r
   )\r
@@ -411,10 +431,10 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_FVB_ATTRIBUTES  Attributes;\r
-  UINTN               LbaAddress;\r
-  UINTN               LbaLength;\r
-  EFI_STATUS          Status;\r
+  EFI_FVB_ATTRIBUTES_2  Attributes;\r
+  UINTN                 LbaAddress;\r
+  UINTN                 LbaLength;\r
+  EFI_STATUS            Status;\r
 \r
   //\r
   // Check for invalid conditions\r
@@ -496,10 +516,10 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_FVB_ATTRIBUTES  Attributes;\r
-  UINTN               LbaAddress;\r
-  UINTN               LbaLength;\r
-  EFI_STATUS          Status;\r
+  EFI_FVB_ATTRIBUTES_2  Attributes;\r
+  UINTN                 LbaAddress;\r
+  UINTN                 LbaLength;\r
+  EFI_STATUS            Status;\r
 \r
   //\r
   // Check for invalid conditions\r
@@ -573,11 +593,11 @@ Returns:
 --*/\r
 {\r
 \r
-  EFI_FVB_ATTRIBUTES  Attributes;\r
-  UINTN               LbaAddress;\r
-  UINTN               LbaLength;\r
-  EFI_STATUS          Status;\r
-  UINT8               Data;\r
+  EFI_FVB_ATTRIBUTES_2  Attributes;\r
+  UINTN                 LbaAddress;\r
+  UINTN                 LbaLength;\r
+  EFI_STATUS            Status;\r
+  UINT8                 Data;\r
 \r
   //\r
   // Check if the FV is write enabled\r
@@ -607,105 +627,12 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_STATUS\r
-FvbEraseCustomBlockRange (\r
-  IN UINTN                                Instance,\r
-  IN EFI_LBA                              StartLba,\r
-  IN UINTN                                OffsetStartLba,\r
-  IN EFI_LBA                              LastLba,\r
-  IN UINTN                                OffsetLastLba,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Erases and initializes a specified range of a firmware volume\r
-\r
-Arguments:\r
-  Instance              - The FV instance to be erased\r
-  StartLba              - The starting logical block index to be erased\r
-  OffsetStartLba        - Offset into the starting block at which to\r
-                          begin erasing\r
-  LastLba               - The last logical block index to be erased\r
-  OffsetStartLba        - Offset into the last block at which to end erasing\r
-  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
-                          instance data\r
-  Virtual               - Whether CPU is in virtual or physical mode\r
-\r
-Returns:\r
-  EFI_SUCCESS           - The firmware volume was erased successfully\r
-  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
-  EFI_DEVICE_ERROR      - The block device is not functioning correctly and\r
-                          could not be written. Firmware device may have been\r
-                          partially erased\r
-  EFI_INVALID_PARAMETER - Instance not found\r
-\r
---*/\r
-{\r
-  EFI_LBA Index;\r
-  UINTN   LbaSize;\r
-  UINTN   ScratchLbaSizeData;\r
-\r
-  //\r
-  // First LBA\r
-  //\r
-  FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);\r
-\r
-  //\r
-  // Use the scratch space as the intermediate buffer to transfer data\r
-  // Back up the first LBA in scratch space.\r
-  //\r
-  FvbReadBlock (Instance, StartLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
-\r
-  //\r
-  // erase now\r
-  //\r
-  FvbEraseBlock (Instance, StartLba, Global, Virtual);\r
-  ScratchLbaSizeData = OffsetStartLba;\r
-\r
-  //\r
-  // write the data back to the first block\r
-  //\r
-  if (ScratchLbaSizeData > 0) {\r
-    FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
-  }\r
-  //\r
-  // Middle LBAs\r
-  //\r
-  if (LastLba > (StartLba + 1)) {\r
-    for (Index = (StartLba + 1); Index <= (LastLba - 1); Index++) {\r
-      FvbEraseBlock (Instance, Index, Global, Virtual);\r
-    }\r
-  }\r
-  //\r
-  // Last LBAs, the same as first LBAs\r
-  //\r
-  if (LastLba > StartLba) {\r
-    FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);\r
-    FvbReadBlock (Instance, LastLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
-    FvbEraseBlock (Instance, LastLba, Global, Virtual);\r
-  }\r
-\r
-  ScratchLbaSizeData = LbaSize - (OffsetStartLba + 1);\r
-\r
-  return FvbWriteBlock (\r
-          Instance,\r
-          LastLba,\r
-          (OffsetLastLba + 1),\r
-          &ScratchLbaSizeData,\r
-          Global->FvbScratchSpace[Virtual],\r
-          Global,\r
-          Virtual\r
-          );\r
-}\r
-\r
 EFI_STATUS\r
 FvbSetVolumeAttributes (\r
-  IN UINTN                                Instance,\r
-  IN OUT EFI_FVB_ATTRIBUTES               *Attributes,\r
-  IN ESAL_FWB_GLOBAL                      *Global,\r
-  IN BOOLEAN                              Virtual\r
+  IN UINTN                                  Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES_2               *Attributes,\r
+  IN ESAL_FWB_GLOBAL                        *Global,\r
+  IN BOOLEAN                                Virtual\r
   )\r
 /*++\r
 \r
@@ -716,7 +643,7 @@ Routine Description:
 Arguments:\r
   Instance              - The FV instance whose attributes is going to be\r
                           modified\r
-  Attributes            - On input, it is a pointer to EFI_FVB_ATTRIBUTES\r
+  Attributes            - On input, it is a pointer to EFI_FVB_ATTRIBUTES_2\r
                           containing the desired firmware volume settings.\r
                           On successful return, it contains the new settings\r
                           of the firmware volume\r
@@ -733,13 +660,14 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_FW_VOL_INSTANCE *FwhInstance;\r
-  EFI_FVB_ATTRIBUTES  OldAttributes;\r
-  EFI_FVB_ATTRIBUTES  *AttribPtr;\r
-  UINT32              Capabilities;\r
-  UINT32              OldStatus;\r
-  UINT32              NewStatus;\r
-  EFI_STATUS          Status;\r
+  EFI_FW_VOL_INSTANCE   *FwhInstance;\r
+  EFI_FVB_ATTRIBUTES_2  OldAttributes;\r
+  EFI_FVB_ATTRIBUTES_2  *AttribPtr;\r
+  UINT32                Capabilities;\r
+  UINT32                OldStatus;\r
+  UINT32                NewStatus;\r
+  EFI_STATUS            Status;\r
+  EFI_FVB_ATTRIBUTES_2  UnchangedAttributes;\r
 \r
   //\r
   // Find the right instance of the FVB private data\r
@@ -747,7 +675,7 @@ Returns:
   Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  AttribPtr     = (EFI_FVB_ATTRIBUTES *) &(FwhInstance->VolumeHeader.Attributes);\r
+  AttribPtr     = (EFI_FVB_ATTRIBUTES_2 *) &(FwhInstance->VolumeHeader.Attributes);\r
   OldAttributes = *AttribPtr;\r
   Capabilities  = OldAttributes & (EFI_FVB2_READ_DISABLED_CAP | \\r
                                    EFI_FVB2_READ_ENABLED_CAP | \\r
@@ -758,6 +686,24 @@ Returns:
   OldStatus     = OldAttributes & EFI_FVB2_STATUS;\r
   NewStatus     = *Attributes & EFI_FVB2_STATUS;\r
 \r
+  UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP  | \\r
+                        EFI_FVB2_READ_ENABLED_CAP   | \\r
+                        EFI_FVB2_WRITE_DISABLED_CAP | \\r
+                        EFI_FVB2_WRITE_ENABLED_CAP  | \\r
+                        EFI_FVB2_LOCK_CAP           | \\r
+                        EFI_FVB2_STICKY_WRITE       | \\r
+                        EFI_FVB2_MEMORY_MAPPED      | \\r
+                        EFI_FVB2_ERASE_POLARITY     | \\r
+                        EFI_FVB2_READ_LOCK_CAP      | \\r
+                        EFI_FVB2_WRITE_LOCK_CAP     | \\r
+                        EFI_FVB2_ALIGNMENT;\r
+\r
+  //\r
+  // Some attributes of FV is read only can *not* be set\r
+  //\r
+  if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
   //\r
   // If firmware volume is locked, no status bit can be updated\r
   //\r
@@ -895,7 +841,7 @@ EFI_STATUS
 EFIAPI\r
 FvbProtocolGetAttributes (\r
   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
-  OUT EFI_FVB_ATTRIBUTES                          *Attributes\r
+  OUT EFI_FVB_ATTRIBUTES_2                              *Attributes\r
   )\r
 /*++\r
 \r
@@ -922,7 +868,7 @@ EFI_STATUS
 EFIAPI\r
 FvbProtocolSetAttributes (\r
   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
-  IN OUT EFI_FVB_ATTRIBUTES                       *Attributes\r
+  IN OUT EFI_FVB_ATTRIBUTES_2                           *Attributes\r
   )\r
 /*++\r
 \r
@@ -1004,14 +950,10 @@ Returns:
     //\r
     // Check input parameters\r
     //\r
-    if (NumOfLba == 0) {\r
+    if (NumOfLba == 0 || (StartingLba + NumOfLba) > NumOfBlocks) {\r
       VA_END (args);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-\r
-    if ((StartingLba + NumOfLba) > NumOfBlocks) {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
   } while (1);\r
 \r
   VA_END (args);\r
@@ -1047,10 +989,10 @@ EFI_STATUS
 EFIAPI\r
 FvbProtocolWrite (\r
   IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
-  IN CONST EFI_LBA                                      Lba,\r
-  IN CONST UINTN                                        Offset,\r
-  IN OUT UINTN                                    *NumBytes,\r
-  IN CONST UINT8                                        *Buffer\r
+  IN       EFI_LBA                                      Lba,\r
+  IN       UINTN                                        Offset,\r
+  IN OUT   UINTN                                    *NumBytes,\r
+  IN       UINT8                                        *Buffer\r
   )\r
 /*++\r
 \r
@@ -1088,7 +1030,7 @@ Returns:
 \r
   FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
 \r
-  return FvbWriteBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
+  return FvbWriteBlock (FvbDevice->Instance, (EFI_LBA)Lba, (UINTN)Offset, NumBytes, (UINT8 *)Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
 }\r
 \r
 EFI_STATUS\r
@@ -1139,56 +1081,7 @@ Returns:
 \r
   return FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
 }\r
-//\r
-// FVB Extension Protocols\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-FvbExtendProtocolEraseCustomBlockRange (\r
-  IN EFI_FVB_EXTENSION_PROTOCOL           *This,\r
-  IN EFI_LBA                              StartLba,\r
-  IN UINTN                                OffsetStartLba,\r
-  IN EFI_LBA                              LastLba,\r
-  IN UINTN                                OffsetLastLba\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Erases and initializes a specified range of a firmware volume\r
-\r
-Arguments:\r
-  This                  - Calling context\r
-  StartLba              - The starting logical block index to be erased\r
-  OffsetStartLba        - Offset into the starting block at which to\r
-                          begin erasing\r
-  LastLba               - The last logical block index to be erased\r
-  OffsetStartLba        - Offset into the last block at which to end erasing\r
 \r
-Returns:\r
-  EFI_SUCCESS           - The firmware volume was erased successfully\r
-  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
-  EFI_DEVICE_ERROR      - The block device is not functioning correctly and\r
-                          could not be written. Firmware device may have been\r
-                          partially erased\r
-\r
---*/\r
-{\r
-  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
-\r
-  FvbDevice = FVB_EXTEND_DEVICE_FROM_THIS (This);\r
-\r
-  return FvbEraseCustomBlockRange (\r
-          FvbDevice->Instance,\r
-          StartLba,\r
-          OffsetStartLba,\r
-          LastLba,\r
-          OffsetLastLba,\r
-          mFvbModuleGlobal,\r
-          EfiGoneVirtual ()\r
-          );\r
-}\r
-\r
-STATIC\r
 EFI_STATUS\r
 ValidateFvHeader (\r
   EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader\r
@@ -1207,10 +1100,6 @@ Returns:
 \r
 --*/\r
 {\r
-  UINT16  *Ptr;\r
-  UINT16  HeaderLength;\r
-  UINT16  Checksum;\r
-\r
   //\r
   // Verify the header revision, header signature, length\r
   // Length of FvBlock cannot be 2**64-1\r
@@ -1223,19 +1112,11 @@ Returns:
       ) {\r
     return EFI_NOT_FOUND;\r
   }\r
+  \r
   //\r
   // Verify the header checksum\r
   //\r
-  HeaderLength  = (UINT16) (FwVolHeader->HeaderLength / 2);\r
-  Ptr           = (UINT16 *) FwVolHeader;\r
-  Checksum      = 0;\r
-  while (HeaderLength > 0) {\r
-    Checksum = Checksum + (*Ptr);\r
-    HeaderLength--;\r
-    Ptr++;\r
-  }\r
-\r
-  if (Checksum != 0) {\r
+  if (CalculateCheckSum16 ((UINT16 *) FwVolHeader, FwVolHeader->HeaderLength) != 0) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -1269,15 +1150,13 @@ Returns:
   EFI_HANDLE                          FwbHandle;\r
   EFI_FW_VOL_BLOCK_DEVICE             *FvbDevice;\r
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
-  EFI_DEVICE_PATH_PROTOCOL            *TempFwbDevicePath;\r
-  FV_DEVICE_PATH                      TempFvbDevicePathData;\r
   UINT32                              MaxLbaSize;\r
   EFI_PHYSICAL_ADDRESS                BaseAddress;\r
   UINT64                              Length;\r
   UINTN                               NumOfBlocks;\r
   EFI_PEI_HOB_POINTERS                FvHob;\r
 \r
-   //\r
+  //\r
   // Get the DXE services table\r
   //\r
   DxeServices = gDS;\r
@@ -1388,7 +1267,7 @@ Returns:
         FwVolHeader->HeaderLength\r
         );\r
     }\r
-\r
+    \r
     FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
     FwhInstance->FvBase[FVB_VIRTUAL]  = (UINTN) BaseAddress;\r
 \r
@@ -1400,9 +1279,7 @@ Returns:
 \r
     for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
       //\r
-      // Get the maximum size of a block. The size will be used to allocate\r
-      // buffer for Scratch space, the intermediate buffer for FVB extension\r
-      // protocol\r
+      // Get the maximum size of a block.\r
       //\r
       if (MaxLbaSize < PtrBlockMapEntry->Length) {\r
         MaxLbaSize = PtrBlockMapEntry->Length;\r
@@ -1425,19 +1302,29 @@ Returns:
 \r
     FvbDevice->Instance = mFvbModuleGlobal->NumFv;\r
     mFvbModuleGlobal->NumFv++;\r
-\r
+    \r
+    \r
     //\r
     // Set up the devicepath\r
     //\r
-    FvbDevice->DevicePath.MemMapDevPath.StartingAddress = BaseAddress;\r
-    FvbDevice->DevicePath.MemMapDevPath.EndingAddress   = BaseAddress + (FwVolHeader->FvLength - 1);\r
-\r
+    if (FwVolHeader->ExtHeaderOffset == 0) {\r
+        //\r
+        // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH\r
+        //\r
+      FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);\r
+      ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;\r
+      ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress   = BaseAddress + FwVolHeader->FvLength - 1;\r
+    } else {\r
+      FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);\r
+      CopyGuid (\r
+        &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName, \r
+        (GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)\r
+        );\r
+    }\r
     //\r
     // Find a handle with a matching device path that has supports FW Block protocol\r
     //\r
-    TempFwbDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &TempFvbDevicePathData;\r
-    CopyMem (TempFwbDevicePath, &FvbDevice->DevicePath, sizeof (FV_DEVICE_PATH));\r
-    Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &TempFwbDevicePath, &FwbHandle);\r
+    Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &FvbDevice->DevicePath, &FwbHandle);\r
     if (EFI_ERROR (Status)) {\r
       //\r
       // LocateDevicePath fails so install a new interface and device path\r
@@ -1452,14 +1339,14 @@ Returns:
                       NULL\r
                       );\r
       ASSERT_EFI_ERROR (Status);\r
-    } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) {\r
+    } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
       //\r
       // Device allready exists, so reinstall the FVB protocol\r
       //\r
       Status = gBS->HandleProtocol (\r
                       FwbHandle,\r
                       &gEfiFirmwareVolumeBlockProtocolGuid,\r
-                      &OldFwbInterface\r
+                      (VOID**)&OldFwbInterface\r
                       );\r
       ASSERT_EFI_ERROR (Status);\r
 \r
@@ -1477,19 +1364,6 @@ Returns:
       //\r
       ASSERT (FALSE);\r
     }\r
-    //\r
-    // Install FVB Extension Protocol on the same handle\r
-    //\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &FwbHandle,\r
-                    &gEfiFvbExtensionProtocolGuid,\r
-                    &FvbDevice->FvbExtension,\r
-                    &gEfiAlternateFvBlockGuid,\r
-                    NULL,\r
-                    NULL\r
-                    );\r
-\r
-    ASSERT_EFI_ERROR (Status);\r
 \r
     FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
       (\r
@@ -1500,13 +1374,5 @@ Returns:
     FvHob.Raw = GET_NEXT_HOB (FvHob);\r
   }\r
 \r
-  //\r
-  // Allocate for scratch space, an intermediate buffer for FVB extention\r
-  //\r
-  mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL] = AllocateRuntimePool (MaxLbaSize);\r
-  ASSERT (mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL] != NULL);\r
-\r
-  mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL] = mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL];\r
-\r
   return EFI_SUCCESS;\r
 }\r