]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
Move sure FvImage buffer at its alignment when install FVB protocol on it.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Dispatcher / Dispatcher.c
index 0529d36d7944d0db7574b12da16c14daf67dc4b3..d348c82a9e318c2fd46aa9195b0b98644dfa6c6f 100644 (file)
@@ -1,21 +1,5 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-Module Name:\r
-\r
-  Dispatcher.c\r
-\r
-Abstract:\r
-\r
-  Tiano DXE Dispatcher.\r
+/**@file\r
+  DXE Dispatcher.\r
 \r
   Step #1 - When a FV protocol is added to the system every driver in the FV\r
             is added to the mDiscoveredList. The SOR, Before, and After Depex are \r
@@ -42,7 +26,16 @@ Abstract:
   Depex - Dependency Expresion.\r
   SOR   - Schedule On Request - Don't schedule if this bit is set.\r
 \r
---*/\r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+All rights reserved. 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
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
 \r
 #include <DxeMain.h>\r
 \r
@@ -490,9 +483,15 @@ Returns:
       \r
       CoreReleaseDispatcherLock ();\r
 \r
-      CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_BEGIN, DriverEntry->ImageHandle);\r
+      CoreReportProgressCodeSpecific (\r
+        FixedPcdGet32(PcdStatusCodeValueDxeDriverBegin), \r
+        DriverEntry->ImageHandle\r
+        );\r
       Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r
-      CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END, DriverEntry->ImageHandle);\r
+      CoreReportProgressCodeSpecific (\r
+        FixedPcdGet32(PcdStatusCodeValueDxeDriverEnd), \r
+        DriverEntry->ImageHandle\r
+        );\r
 \r
       ReturnStatus = EFI_SUCCESS;\r
     }\r
@@ -860,14 +859,20 @@ Returns:
   EFI_SECTION_TYPE                    SectionType;\r
   UINT32                              AuthenticationStatus;\r
   VOID                                *Buffer;\r
+  VOID                                *AlignedBuffer;\r
   UINTN                               BufferSize;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FvHeader;\r
+  UINT32                              FvAlignment;  \r
 \r
   //\r
   // Read the first (and only the first) firmware volume section\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
@@ -879,22 +884,50 @@ Returns:
                 );\r
   if (!EFI_ERROR (Status)) {\r
     //\r
-    // Produce a FVB protocol for the file\r
+    // FvImage should be at its required alignment.\r
+    //\r
+    FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
+    FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
     //\r
-    Status = ProduceFVBProtocolOnBuffer (\r
-              (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer,\r
-              (UINT64)BufferSize,\r
-              FvHandle,\r
-              NULL\r
-              );\r
+    // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
+    // \r
+    if (FvAlignment < 8) {\r
+      FvAlignment = 8;\r
+    }\r
+    \r
+    AlignedBuffer = AllocateAlignedPool ((UINTN) BufferSize, (UINTN) FvAlignment);\r
+    if (AlignedBuffer == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      //\r
+      // Move FvImage into the aligned buffer and release the original buffer.\r
+      //\r
+      CopyMem (AlignedBuffer, Buffer, BufferSize);\r
+      CoreFreePool (Buffer);\r
+      Buffer = NULL;\r
+      //\r
+      // Produce a FVB protocol for the file\r
+      //\r
+      Status = ProduceFVBProtocolOnBuffer (\r
+                (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r
+                (UINT64)BufferSize,\r
+                FvHandle,\r
+                NULL\r
+                );\r
+    }\r
   }\r
 \r
-  if (EFI_ERROR (Status) && (Buffer != NULL)) {    \r
-  //\r
-  // ReadSection or Produce FVB failed, Free data buffer\r
-  //\r
-  CoreFreePool (Buffer); \r
-\r
+  if (EFI_ERROR (Status)) {    \r
+    //\r
+    // ReadSection or Produce FVB failed, Free data buffer\r
+    //\r
+    if (Buffer != NULL) {\r
+      CoreFreePool (Buffer); \r
+    }\r
+    \r
+    if (AlignedBuffer != NULL) {\r
+      FreeAlignedPool (AlignedBuffer);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1084,7 +1117,6 @@ Returns:
             if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r
               continue;\r
             }\r
-            \r
             //\r
             // Found a firmware volume image. Produce a firmware volume block\r
             // protocol for it so it gets dispatched from. This is usually a \r