]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Move the Fv updating of PeiCore's internal structure PrivateData out of the implement...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index 813eff59b8a81ee6c53949ca3a2ca4e02545f0a5..453b72f75a097c4526ab74761f45a1809476dc2d 100644 (file)
@@ -309,7 +309,23 @@ PeiInitializeFv (
            (UINTN)BfvHeader->FvLength,\r
            &FvHandle\r
            );\r
-                        \r
+\r
+  //\r
+  // Update internal PEI_CORE_FV array.\r
+  //\r
+  PrivateData->Fv[PrivateData->FvCount].FvHeader = BfvHeader;\r
+  PrivateData->Fv[PrivateData->FvCount].FvPpi    = FvPpi;\r
+  PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
+  DEBUG ((\r
+    EFI_D_INFO, \r
+    "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
+    (UINT32) PrivateData->FvCount, \r
+    (VOID *) BfvHeader, \r
+    BfvHeader->FvLength,\r
+    FvHandle\r
+    ));    \r
+  PrivateData->FvCount ++;\r
+                            \r
   //\r
   // Post a call-back for the FvInfoPPI services to expose\r
   // additional Fvs to PeiCore.\r
@@ -346,6 +362,8 @@ FirmwareVolmeInfoPpiNotifyCallback (
   EFI_STATUS                            Status;\r
   EFI_PEI_FV_HANDLE                     FvHandle;\r
   UINTN                                 FvIndex;\r
+  EFI_PEI_FILE_HANDLE                   FileHandle;\r
+  VOID                                  *DepexData;\r
   \r
   Status       = EFI_SUCCESS;\r
   PrivateData  = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
@@ -373,10 +391,67 @@ FirmwareVolmeInfoPpiNotifyCallback (
     //\r
     Status = FvPpi->ProcessVolume (FvPpi, FvInfoPpi->FvInfo, FvInfoPpi->FvInfoSize, &FvHandle);\r
     if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!"));\r
+      DEBUG ((EFI_D_ERROR, "Fail to process new found FV, FV may be corrupted!\n"));\r
       return Status;\r
     }\r
-    DEBUG ((EFI_D_INFO, "Found and process new FV %p, all fv's count is %d\n", FvHandle, PrivateData->FvCount));\r
+\r
+    //\r
+    // Check whether the FV has already been processed.\r
+    //\r
+    for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r
+      if (PrivateData->Fv[FvIndex].FvHandle == FvHandle) {\r
+        DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!\n", FvInfoPpi->FvInfo));\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Update internal PEI_CORE_FV array.\r
+    //\r
+    PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) FvInfoPpi->FvInfo;\r
+    PrivateData->Fv[PrivateData->FvCount].FvPpi    = FvPpi;\r
+    PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
+    DEBUG ((\r
+      EFI_D_INFO, \r
+      "The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
+      (UINT32) PrivateData->FvCount, \r
+      (VOID *) FvInfoPpi->FvInfo, \r
+      FvInfoPpi->FvInfoSize,\r
+      FvHandle\r
+      ));    \r
+    PrivateData->FvCount ++;\r
+\r
+    //\r
+    // Scan and process the new discoveried FV for EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE \r
+    //\r
+    FileHandle = NULL;\r
+    do {\r
+      Status = FvPpi->FindFileByType (\r
+                        FvPpi,\r
+                        EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r
+                        FvHandle,\r
+                        &FileHandle\r
+                       );\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = FvPpi->FindSectionByType (\r
+                          FvPpi,\r
+                          EFI_SECTION_PEI_DEPEX,\r
+                          FileHandle,\r
+                          (VOID**)&DepexData\r
+                          );\r
+        if (!EFI_ERROR (Status)) {\r
+          if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r
+            //\r
+            // Dependency is not satisfied.\r
+            //\r
+            continue;\r
+          }\r
+        }\r
+        \r
+        DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
+        ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
+      }\r
+    } while (FileHandle != NULL);\r
   } else {\r
     DEBUG ((EFI_D_ERROR, "Fail to process FV %p because no corresponding EFI_FIRMWARE_VOLUME_PPI is found!\n", FvInfoPpi->FvInfo));\r
     \r
@@ -924,14 +999,12 @@ PeiFfs2FvPpiProcessVolume (
   )\r
 {\r
   EFI_STATUS          Status;\r
-  PEI_CORE_INSTANCE   *PrivateData;\r
-  EFI_PEI_FILE_HANDLE FileHandle;\r
-  VOID                *DepexData;\r
-  EFI_PEI_SERVICES    **PeiServices;\r
-  UINTN               FvIndex;\r
   \r
-  PeiServices = (EFI_PEI_SERVICES**) GetPeiServicesTablePointer ();\r
-  PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
+  ASSERT (FvHandle != NULL);\r
+  \r
+  if (Buffer == NULL) {\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
   \r
   //\r
   // The build-in EFI_PEI_FIRMWARE_VOLUME_PPI for FFS2 support memory-mapped\r
@@ -948,61 +1021,6 @@ PeiFfs2FvPpiProcessVolume (
     return EFI_VOLUME_CORRUPTED;\r
   }\r
 \r
-  //\r
-  // Check whether the FV has already been processed.\r
-  //\r
-  for (FvIndex = 0; FvIndex < PrivateData->FvCount; FvIndex ++) {\r
-    if (PrivateData->Fv[FvIndex].FvHandle == *FvHandle) {\r
-      DEBUG ((EFI_D_INFO, "The Fv %p has already been processed!", Buffer));\r
-      return EFI_SUCCESS;\r
-    }\r
-  }\r
-  \r
-  //\r
-  // Update internal PEI_CORE_FV array.\r
-  //\r
-  PrivateData->Fv[PrivateData->FvCount].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) Buffer;\r
-  PrivateData->Fv[PrivateData->FvCount].FvPpi    = (EFI_PEI_FIRMWARE_VOLUME_PPI*) This;\r
-  PrivateData->Fv[PrivateData->FvCount].FvHandle = *FvHandle;\r
-  \r
-  DEBUG ((EFI_D_INFO, \r
-          "The %dth FV start address is 0x%11p and size is 0x%08x\n", \r
-          (UINT32) PrivateData->FvCount, \r
-          (VOID *) Buffer, \r
-          BufferSize\r
-          ));\r
-  PrivateData->FvCount ++;\r
-  \r
-  FileHandle = NULL;\r
-  \r
-  do {\r
-    Status = This->FindFileByType (\r
-                     This,\r
-                     EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,\r
-                     *FvHandle,\r
-                     &FileHandle\r
-                     );\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = This->FindSectionByType (\r
-                       This,\r
-                       EFI_SECTION_PEI_DEPEX,\r
-                       FileHandle,\r
-                       (VOID**)&DepexData\r
-                       );\r
-      if (!EFI_ERROR (Status)) {\r
-        if (!PeimDispatchReadiness (PeiServices, DepexData)) {\r
-          //\r
-          // Dependency is not satisfied.\r
-          //\r
-          continue;\r
-        }\r
-      }\r
-      \r
-      DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p", FileHandle, PrivateData->FvCount - 1, *FvHandle));\r
-      ProcessFvFile (&PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
-    }\r
-  } while (FileHandle != NULL);\r
-\r
   return EFI_SUCCESS;\r
 }  \r
 \r