]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/FvbRuntimeService/FWBlockService.c
Update the copyright notice format
[mirror_edk2.git] / DuetPkg / FvbRuntimeService / FWBlockService.c
index e4dab6339e9a7ccf90f78237357719bba53151e4..e0ddbd53121bf59a6685b93666db166dd9bfa2be 100644 (file)
@@ -1,6 +1,6 @@
 /**@file\r
-Copyright (c) 2007, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2007 - 2009, 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
@@ -61,9 +61,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {
     FvbProtocolWrite,\r
     FvbProtocolEraseBlocks,\r
     NULL\r
-  },\r
-  {\r
-    FvbExtendProtocolEraseCustomBlockRange\r
   }\r
 };\r
 \r
@@ -86,11 +83,11 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS  Status;\r
-  EFI_FILE    *File;\r
-  UINTN       FileOffset;\r
-  UINTN       BufferForFile;\r
-  UINTN       Length;\r
+  EFI_STATUS          Status;\r
+  EFI_FILE_PROTOCOL   *File;\r
+  UINTN               FileOffset;\r
+  UINTN               BufferForFile;\r
+  UINTN               Length;\r
 \r
   Status = EFI_SUCCESS;\r
   CopyMem ((VOID *) Address, Buffer, *NumBytes);\r
@@ -134,11 +131,11 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS  Status;\r
-  EFI_FILE    *File;\r
-  UINTN       FileOffset;\r
-  UINTN       BufferForFile;\r
-  UINTN       Length;\r
+  EFI_STATUS           Status;\r
+  EFI_FILE_PROTOCOL    *File;\r
+  UINTN                FileOffset;\r
+  UINTN                BufferForFile;\r
+  UINTN                Length;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -305,7 +302,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
@@ -477,10 +474,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
@@ -561,12 +558,12 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_FVB_ATTRIBUTES  Attributes;\r
-  UINTN               LbaAddress;\r
-  UINTN               LbaLength;\r
-  EFI_FW_VOL_INSTANCE *FwhInstance;\r
-  EFI_STATUS          Status;\r
-  EFI_STATUS          ReturnStatus;\r
+  EFI_FVB_ATTRIBUTES_2  Attributes;\r
+  UINTN                 LbaAddress;\r
+  UINTN                 LbaLength;\r
+  EFI_FW_VOL_INSTANCE   *FwhInstance;\r
+  EFI_STATUS            Status;\r
+  EFI_STATUS            ReturnStatus;\r
 \r
   //\r
   // Find the right instance of the FVB private data\r
@@ -658,11 +655,11 @@ Returns:
 --*/\r
 {\r
 \r
-  EFI_FVB_ATTRIBUTES  Attributes;\r
-  UINTN               LbaAddress;\r
-  EFI_FW_VOL_INSTANCE *FwhInstance;\r
-  UINTN               LbaLength;\r
-  EFI_STATUS          Status;\r
+  EFI_FVB_ATTRIBUTES_2  Attributes;\r
+  UINTN                 LbaAddress;\r
+  EFI_FW_VOL_INSTANCE   *FwhInstance;\r
+  UINTN                 LbaLength;\r
+  EFI_STATUS            Status;\r
 \r
   //\r
   // Find the right instance of the FVB private data\r
@@ -700,103 +697,10 @@ Returns:
           );\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 OUT EFI_FVB_ATTRIBUTES_2             *Attributes,\r
   IN ESAL_FWB_GLOBAL                      *Global,\r
   IN BOOLEAN                              Virtual\r
   )\r
@@ -809,7 +713,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
@@ -826,13 +730,13 @@ 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
 \r
   //\r
   // Find the right instance of the FVB private data\r
@@ -840,7 +744,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_CAPABILITIES;\r
   OldStatus     = OldAttributes & EFI_FVB2_STATUS;\r
@@ -983,7 +887,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
@@ -1010,7 +914,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
@@ -1223,56 +1127,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
@@ -1380,13 +1235,13 @@ GetFvbHeader (
   TRY_ASSIGN (Offset,      FlashMapEntry->Offset);\r
 \r
   DEBUG ((\r
-    EFI_D_ERROR\r
+    EFI_D_INFO\r
     "FlashMap HOB: BaseAddress = 0x%x, Length = 0x%x, ActuralLength = 0x%x, Offset = 0x%x\n", \r
     (UINTN) FlashMapSubEntry->Base, (UINTN) FlashMapSubEntry->Length, \r
     (UINTN) FlashMapEntry->ActuralSize, (UINTN) FlashMapEntry->Offset\r
   ));\r
   DEBUG ((\r
-    EFI_D_ERROR,\r
+    EFI_D_INFO,\r
     "FlashMap HOB: VolumeId = 0x%lx, MappedFile = %s\n",\r
     (UINTN) FlashMapEntry->VolumeId, (UINTN) FlashMapEntry->FilePath\r
   ));\r
@@ -1405,7 +1260,6 @@ GetFvbHeader (
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
 VOID\r
 EFIAPI\r
 OnSimpleFileSystemInstall (\r
@@ -1418,7 +1272,7 @@ OnSimpleFileSystemInstall (
   EFI_HANDLE                Handle;\r
   UINTN                     Instance;\r
   EFI_DEVICE_PATH_PROTOCOL  *Device;\r
-  EFI_FILE                  *File;\r
+  EFI_FILE_PROTOCOL         *File;\r
   EFI_FW_VOL_INSTANCE       *FwhInstance;\r
   while (TRUE) {\r
     HandleSize = sizeof (EFI_HANDLE);\r
@@ -1501,7 +1355,6 @@ OnSimpleFileSystemInstall (
   }\r
 }\r
 \r
-STATIC\r
 VOID\r
 FvbInstallSfsNotify (\r
   VOID\r
@@ -1511,7 +1364,7 @@ FvbInstallSfsNotify (
   EFI_EVENT  Event;\r
 \r
   Status = gBS->CreateEvent (\r
-                  EFI_EVENT_NOTIFY_SIGNAL,\r
+                  EVT_NOTIFY_SIGNAL,\r
                   TPL_CALLBACK,\r
                   OnSimpleFileSystemInstall,\r
                   NULL,\r
@@ -1548,7 +1401,6 @@ Returns:
   EFI_STATUS                          Status;\r
   EFI_FW_VOL_INSTANCE                 *FwhInstance;\r
   EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
-  VOID                                *HobList;\r
   EFI_PEI_HOB_POINTERS                FirmwareVolumeHobList;\r
   UINT32                              BufferSize;\r
   EFI_FV_BLOCK_MAP_ENTRY              *PtrBlockMapEntry;\r
@@ -1569,12 +1421,6 @@ Returns:
   UINTN                               HeaderLength;\r
   BOOLEAN                             InstallSfsNotify;\r
 \r
-  Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);\r
-  //\r
-  // No FV HOBs found\r
-  //\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   HeaderLength     = 0;\r
   InstallSfsNotify = FALSE;\r
 \r
@@ -1644,7 +1490,7 @@ Returns:
     if (!FwVolHeader) {\r
       continue;\r
     }\r
-\r
+    \r
     CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength);\r
     FwVolHeader                       = &(FwhInstance->VolumeHeader);\r
 \r
@@ -1665,11 +1511,12 @@ Returns:
       FwhInstance->MappedFile[0]        = L'\0';\r
     }\r
     \r
-\r
+    DEBUG ((EFI_D_INFO, "FirmVolume Found! BaseAddress=0x%lx, VolumeId=0x%x, MappedFile=%s, Size=0x%x\n",\r
+           (UINTN) BaseAddress, VolumeId, MappedFile, ActuralSize));\r
     //\r
     // We may expose readonly FVB in future.\r
     //\r
-    FwhInstance->WriteEnabled         = TRUE;\r
+    FwhInstance->WriteEnabled         = TRUE; // Ken: Why enable write?\r
     EfiInitializeLock (&(FwhInstance->FvbDevLock), TPL_HIGH_LEVEL);\r
 \r
     LbaAddress  = (UINTN) FwhInstance->FvBase[0];\r
@@ -1760,7 +1607,7 @@ 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
@@ -1785,19 +1632,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