]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
MdeModulePkg DxeCore: Handle multiple FV images in one FV file
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Dispatcher / Dispatcher.c
index 4c6ca761a6054b7b2605ffd1a4e7ddb7c61accab..2f6286944fe52591e9fc8b85e14d408ad9329808 100644 (file)
@@ -26,7 +26,7 @@
   Depex - Dependency Expresion.\r
   SOR   - Schedule On Request - Don't schedule if this bit is set.\r
 \r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -184,14 +184,13 @@ CoreAddToDriverList (
   );\r
 \r
 /**\r
-  Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r
+  Get Fv image(s) from the FV through file name, and produce FVB protocol for every Fv image(s).\r
 \r
   @param  Fv                    The FIRMWARE_VOLUME protocol installed on the FV.\r
   @param  FvHandle              The handle which FVB protocol installed on.\r
-  @param  DriverName            The driver guid specified.\r
+  @param  FileName              The file name guid specified.\r
 \r
   @retval EFI_OUT_OF_RESOURCES  No enough memory or other resource.\r
-  @retval EFI_VOLUME_CORRUPTED  Corrupted volume.\r
   @retval EFI_SUCCESS           Function successfully returned.\r
 \r
 **/\r
@@ -199,7 +198,7 @@ EFI_STATUS
 CoreProcessFvImageFile (\r
   IN  EFI_FIRMWARE_VOLUME2_PROTOCOL   *Fv,\r
   IN  EFI_HANDLE                      FvHandle,\r
-  IN  EFI_GUID                        *DriverName\r
+  IN  EFI_GUID                        *FileName\r
   );\r
 \r
 \r
@@ -335,13 +334,13 @@ CoreSchedule (
       CoreReleaseDispatcherLock ();\r
 \r
       DEBUG ((DEBUG_DISPATCH, "Schedule FFS(%g) - EFI_SUCCESS\n", DriverName));\r
-      \r
+\r
       return EFI_SUCCESS;\r
     }\r
   }\r
-  \r
+\r
   DEBUG ((DEBUG_DISPATCH, "Schedule FFS(%g) - EFI_NOT_FOUND\n", DriverName));\r
-  \r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -418,7 +417,7 @@ CoreDispatcher (
   EFI_CORE_DRIVER_ENTRY           *DriverEntry;\r
   BOOLEAN                         ReadyToRun;\r
   EFI_EVENT                       DxeDispatchEvent;\r
-  \r
+\r
   PERF_FUNCTION_BEGIN ();\r
 \r
   if (gDispatcherRunning) {\r
@@ -512,10 +511,10 @@ CoreDispatcher (
 \r
       CoreReleaseDispatcherLock ();\r
 \r
\r
+\r
       if (DriverEntry->IsFvImage) {\r
         //\r
-        // Produce a firmware volume block protocol for FvImage so it gets dispatched from. \r
+        // Produce a firmware volume block protocol for FvImage so it gets dispatched from.\r
         //\r
         Status = CoreProcessFvImageFile (DriverEntry->Fv, DriverEntry->FvHandle, &DriverEntry->FileName);\r
       } else {\r
@@ -526,9 +525,9 @@ CoreDispatcher (
           sizeof (DriverEntry->ImageHandle)\r
           );\r
         ASSERT (DriverEntry->ImageHandle != NULL);\r
-  \r
+\r
         Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r
-  \r
+\r
         REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
           EFI_PROGRESS_CODE,\r
           (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END),\r
@@ -692,17 +691,17 @@ FvHasBeenProcessed (
 \r
 /**\r
   Remember that Fv protocol on FvHandle has had it's drivers placed on the\r
-  mDiscoveredList. This fucntion adds entries on the mFvHandleList if new \r
+  mDiscoveredList. This fucntion adds entries on the mFvHandleList if new\r
   entry is different from one in mFvHandleList by checking FvImage Guid.\r
   Items are never removed/freed from the mFvHandleList.\r
 \r
   @param  FvHandle              The handle of a FV that has been processed\r
 \r
   @return A point to new added FvHandle entry. If FvHandle with the same FvImage guid\r
-          has been added, NULL will return. \r
+          has been added, NULL will return.\r
 \r
 **/\r
-KNOWN_HANDLE * \r
+KNOWN_HANDLE *\r
 FvIsBeingProcesssed (\r
   IN  EFI_HANDLE    FvHandle\r
   )\r
@@ -1004,14 +1003,13 @@ GetFvUsedSize (
 }\r
 \r
 /**\r
-  Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r
+  Get Fv image(s) from the FV through file name, and produce FVB protocol for every Fv image(s).\r
 \r
   @param  Fv                    The FIRMWARE_VOLUME protocol installed on the FV.\r
   @param  FvHandle              The handle which FVB protocol installed on.\r
-  @param  DriverName            The driver guid specified.\r
+  @param  FileName              The file name guid specified.\r
 \r
   @retval EFI_OUT_OF_RESOURCES  No enough memory or other resource.\r
-  @retval EFI_VOLUME_CORRUPTED  Corrupted volume.\r
   @retval EFI_SUCCESS           Function successfully returned.\r
 \r
 **/\r
@@ -1019,7 +1017,7 @@ EFI_STATUS
 CoreProcessFvImageFile (\r
   IN  EFI_FIRMWARE_VOLUME2_PROTOCOL   *Fv,\r
   IN  EFI_HANDLE                      FvHandle,\r
-  IN  EFI_GUID                        *DriverName\r
+  IN  EFI_GUID                        *FileName\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
@@ -1033,141 +1031,158 @@ CoreProcessFvImageFile (
   EFI_DEVICE_PATH_PROTOCOL            *FvFileDevicePath;\r
   UINT32                              FvUsedSize;\r
   UINT8                               EraseByte;\r
+  UINTN                               Index;\r
 \r
   //\r
-  // Read the first (and only the first) firmware volume section\r
+  // Read firmware volume section(s)\r
   //\r
   SectionType   = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;\r
-  FvHeader      = NULL;\r
-  FvAlignment   = 0;\r
-  Buffer        = NULL;\r
-  BufferSize    = 0;\r
-  AlignedBuffer = NULL;\r
-  Status = Fv->ReadSection (\r
-                 Fv,\r
-                 DriverName,\r
-                 SectionType,\r
-                 0,\r
-                 &Buffer,\r
-                 &BufferSize,\r
-                 &AuthenticationStatus\r
-                 );\r
-  if (!EFI_ERROR (Status)) {\r
-     //\r
-    // Evaluate the authentication status of the Firmware Volume through\r
-    // Security Architectural Protocol\r
-    //\r
-    if (gSecurity != NULL) {\r
-      FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r
-      Status = gSecurity->FileAuthenticationState (\r
-                            gSecurity,\r
-                            AuthenticationStatus,\r
-                            FvFileDevicePath\r
-                            );\r
-      if (FvFileDevicePath != NULL) {\r
-        FreePool (FvFileDevicePath);\r
-      }\r
 \r
-      if (Status != EFI_SUCCESS) {\r
-        //\r
-        // Security check failed. The firmware volume should not be used for any purpose.\r
-        //\r
-        if (Buffer != NULL) {\r
-          FreePool (Buffer);\r
+  Index = 0;\r
+  do {\r
+    FvHeader      = NULL;\r
+    FvAlignment   = 0;\r
+    Buffer        = NULL;\r
+    BufferSize    = 0;\r
+    AlignedBuffer = NULL;\r
+    Status = Fv->ReadSection (\r
+                   Fv,\r
+                   FileName,\r
+                   SectionType,\r
+                   Index,\r
+                   &Buffer,\r
+                   &BufferSize,\r
+                   &AuthenticationStatus\r
+                   );\r
+    if (!EFI_ERROR (Status)) {\r
+       //\r
+      // Evaluate the authentication status of the Firmware Volume through\r
+      // Security Architectural Protocol\r
+      //\r
+      if (gSecurity != NULL) {\r
+        FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, FileName);\r
+        Status = gSecurity->FileAuthenticationState (\r
+                              gSecurity,\r
+                              AuthenticationStatus,\r
+                              FvFileDevicePath\r
+                              );\r
+        if (FvFileDevicePath != NULL) {\r
+          FreePool (FvFileDevicePath);\r
+        }\r
+\r
+        if (Status != EFI_SUCCESS) {\r
+          //\r
+          // Security check failed. The firmware volume should not be used for any purpose.\r
+          //\r
+          if (Buffer != NULL) {\r
+            FreePool (Buffer);\r
+          }\r
+          break;\r
         }\r
-        return Status;\r
       }\r
-    }\r
 \r
-    //\r
-    // FvImage should be at its required alignment.\r
-    //\r
-    FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
-    //\r
-    // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
-    // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
-    // its initial linked location and maintain its alignment.\r
-    //\r
-    if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
       //\r
-      // Get FvHeader alignment\r
+      // FvImage should be at its required alignment.\r
       //\r
-      FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
       //\r
-      // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
+      // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume\r
+      // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from\r
+      // its initial linked location and maintain its alignment.\r
       //\r
-      if (FvAlignment < 8) {\r
-        FvAlignment = 8;\r
-      }\r
+      if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {\r
+        //\r
+        // Get FvHeader alignment\r
+        //\r
+        FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
+        //\r
+        // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.\r
+        //\r
+        if (FvAlignment < 8) {\r
+          FvAlignment = 8;\r
+        }\r
 \r
-      DEBUG ((\r
-        DEBUG_INFO,\r
-        "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
-        __FUNCTION__,\r
-        FvHeader,\r
-        FvAlignment\r
-        ));\r
+        DEBUG ((\r
+          DEBUG_INFO,\r
+          "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
+          __FUNCTION__,\r
+          FvHeader,\r
+          FvAlignment\r
+          ));\r
 \r
-      //\r
-      // Check FvImage alignment.\r
-      //\r
-      if ((UINTN) FvHeader % FvAlignment != 0) {\r
         //\r
-        // Allocate the aligned buffer for the FvImage.\r
+        // Check FvImage alignment.\r
         //\r
-        AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r
-        if (AlignedBuffer == NULL) {\r
-          FreePool (Buffer);\r
-          return EFI_OUT_OF_RESOURCES;\r
-        } else {\r
+        if ((UINTN) FvHeader % FvAlignment != 0) {\r
           //\r
-          // Move FvImage into the aligned buffer and release the original buffer.\r
+          // Allocate the aligned buffer for the FvImage.\r
           //\r
-          if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
+          AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r
+          if (AlignedBuffer == NULL) {\r
+            FreePool (Buffer);\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+            break;\r
+          } else {\r
             //\r
-            // Copy the used bytes and fill the rest with the erase value.\r
+            // Move FvImage into the aligned buffer and release the original buffer.\r
             //\r
-            CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize);\r
-            SetMem (\r
-              (UINT8 *) AlignedBuffer + FvUsedSize,\r
-              (UINTN) (BufferSize - FvUsedSize),\r
-              EraseByte\r
-              );\r
-          } else {\r
-            CopyMem (AlignedBuffer, Buffer, BufferSize);\r
+            if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
+              //\r
+              // Copy the used bytes and fill the rest with the erase value.\r
+              //\r
+              CopyMem (AlignedBuffer, FvHeader, (UINTN) FvUsedSize);\r
+              SetMem (\r
+                (UINT8 *) AlignedBuffer + FvUsedSize,\r
+                (UINTN) (BufferSize - FvUsedSize),\r
+                EraseByte\r
+                );\r
+            } else {\r
+              CopyMem (AlignedBuffer, Buffer, BufferSize);\r
+            }\r
+            FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;\r
+            FreePool (Buffer);\r
+            Buffer = NULL;\r
           }\r
-          FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer;\r
-          CoreFreePool (Buffer);\r
-          Buffer = NULL;\r
         }\r
       }\r
+      //\r
+      // Produce a FVB protocol for the file\r
+      //\r
+      Status = ProduceFVBProtocolOnBuffer (\r
+                (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+                (UINT64)BufferSize,\r
+                FvHandle,\r
+                AuthenticationStatus,\r
+                NULL\r
+                );\r
     }\r
-    //\r
-    // Produce a FVB protocol for the file\r
-    //\r
-    Status = ProduceFVBProtocolOnBuffer (\r
-              (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
-              (UINT64)BufferSize,\r
-              FvHandle,\r
-              AuthenticationStatus,\r
-              NULL\r
-              );\r
-  }\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // ReadSection or Produce FVB failed, Free data buffer\r
-    //\r
-    if (Buffer != NULL) {\r
-      FreePool (Buffer);\r
-    }\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // ReadSection or Produce FVB failed, Free data buffer\r
+      //\r
+      if (Buffer != NULL) {\r
+        FreePool (Buffer);\r
+      }\r
 \r
-    if (AlignedBuffer != NULL) {\r
-      FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+      if (AlignedBuffer != NULL) {\r
+        FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+      }\r
+\r
+      break;\r
+    } else {\r
+      Index++;\r
     }\r
-  }\r
+  } while (TRUE);\r
 \r
-  return Status;\r
+  if (Index > 0) {\r
+    //\r
+    // At least one FvImage has been processed successfully.\r
+    //\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return Status;\r
+  }\r
 }\r
 \r
 \r
@@ -1247,7 +1262,7 @@ CoreFwVolEventProtocolNotify (
     KnownHandle = FvIsBeingProcesssed (FvHandle);\r
     if (KnownHandle == NULL) {\r
       //\r
-      // The FV with the same FV name guid has already been processed. \r
+      // The FV with the same FV name guid has already been processed.\r
       // So lets skip it!\r
       //\r
       continue;\r
@@ -1337,7 +1352,7 @@ CoreFwVolEventProtocolNotify (
             if (!EFI_ERROR (Status)) {\r
               //\r
               // If SMM depex section is found, this FV image is invalid to be supported.\r
-              // ASSERT FALSE to report this FV image.  \r
+              // ASSERT FALSE to report this FV image.\r
               //\r
               FreePool (DepexBuffer);\r
               ASSERT (FALSE);\r
@@ -1359,7 +1374,7 @@ CoreFwVolEventProtocolNotify (
                            );\r
             if (EFI_ERROR (Status)) {\r
               //\r
-              // If no depex section, produce a firmware volume block protocol for it so it gets dispatched from. \r
+              // If no depex section, produce a firmware volume block protocol for it so it gets dispatched from.\r
               //\r
               CoreProcessFvImageFile (Fv, FvHandle, &NameGuid);\r
             } else {\r