]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/FvbServicesRuntimeDxe/FWBlockService.c
retire gEfiFirmwareVolumeDispatcherProtocolGuid as its original design is used to...
[mirror_edk2.git] / Nt32Pkg / FvbServicesRuntimeDxe / FWBlockService.c
index c2245f48c9918f5ee3b1903878310edd62933947..e021734d5fa0425c6ff8b6f0fc9431938460d618 100644 (file)
@@ -1,4 +1,4 @@
-/*++\r
+/**@file\r
 \r
 Copyright (c) 2006 - 2007, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -17,7 +17,7 @@ Abstract:
 \r
 Revision History\r
 \r
---*/\r
+**/\r
 \r
 //\r
 // The package level header files this module uses\r
@@ -45,6 +45,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
@@ -240,7 +241,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 +412,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 +497,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 +574,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
@@ -646,11 +647,15 @@ Returns:
   EFI_LBA Index;\r
   UINTN   LbaSize;\r
   UINTN   ScratchLbaSizeData;\r
+  EFI_STATUS Status;\r
 \r
   //\r
   // First LBA\r
   //\r
-  FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+  Status = FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Use the scratch space as the intermediate buffer to transfer data\r
@@ -668,7 +673,10 @@ Returns:
   // 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
+    Status = FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
   }\r
   //\r
   // Middle LBAs\r
@@ -682,30 +690,37 @@ Returns:
   // Last LBAs, the same as first LBAs\r
   //\r
   if (LastLba > StartLba) {\r
-    FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+    Status = FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\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
+  ScratchLbaSizeData = LbaSize - (OffsetLastLba + 1);\r
+  \r
+  if (ScratchLbaSizeData > 0) {\r
+    Status = FvbWriteBlock (\r
+              Instance,\r
+              LastLba,\r
+              (OffsetLastLba + 1),\r
+              &ScratchLbaSizeData,\r
+              Global->FvbScratchSpace[Virtual] + OffsetLastLba + 1,\r
+              Global,\r
+              Virtual\r
+              );\r
+  }\r
 \r
-  return FvbWriteBlock (\r
-          Instance,\r
-          LastLba,\r
-          (OffsetLastLba + 1),\r
-          &ScratchLbaSizeData,\r
-          Global->FvbScratchSpace[Virtual],\r
-          Global,\r
-          Virtual\r
-          );\r
+  return Status;\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 +731,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 +748,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 +763,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 +774,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 +929,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 +956,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
@@ -1047,10 +1081,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 +1122,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
@@ -1188,7 +1222,6 @@ Returns:
           );\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 ValidateFvHeader (\r
   EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader\r
@@ -1230,7 +1263,7 @@ Returns:
   Ptr           = (UINT16 *) FwVolHeader;\r
   Checksum      = 0;\r
   while (HeaderLength > 0) {\r
-    Checksum = Checksum + (*Ptr);\r
+    Checksum = (UINT16)(Checksum + (*Ptr));\r
     HeaderLength--;\r
     Ptr++;\r
   }\r
@@ -1452,14 +1485,14 @@ Returns:
                       NULL\r
                       );\r
       ASSERT_EFI_ERROR (Status);\r
-    } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) {\r
+    } else if (IsDevicePathEnd (TempFwbDevicePath)) {\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