]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
Add missing status code in several modules.
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / DxeLoad.c
index e6836596d8c2a8b83af42e56304f327dd5ba1517..89d3a6fcffec662cac5bea835e9e7f37c316d0a4 100644 (file)
@@ -2,7 +2,7 @@
   Last PEIM.\r
   Responsibility of this module is to load the DXE Core from a Firmware Volume.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, 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
@@ -124,6 +124,53 @@ PeimInitializeDxeIpl (
   return Status;\r
 }\r
 \r
+/**\r
+   Validate variable data for the MemoryTypeInformation. \r
+\r
+   @param MemoryData       Variable data.\r
+   @param MemoryDataSize   Variable data length.\r
+\r
+   @return TRUE            The variable data is valid.\r
+   @return FALSE           The variable data is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+ValidateMemoryTypeInfoVariable (\r
+  IN EFI_MEMORY_TYPE_INFORMATION      *MemoryData,\r
+  IN UINTN                            MemoryDataSize\r
+  )\r
+{\r
+  UINTN                       Count;\r
+  UINTN                       Index;\r
+\r
+  // Check the input parameter.\r
+  if (MemoryData == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Get Count\r
+  Count = MemoryDataSize / sizeof (*MemoryData);\r
+\r
+  // Check Size\r
+  if (Count * sizeof(*MemoryData) != MemoryDataSize) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check last entry type filed.\r
+  if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check the type filed.\r
+  for (Index = 0; Index < Count - 1; Index++) {\r
+    if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
 /**\r
    Main entry point to last PEIM. \r
 \r
@@ -174,25 +221,49 @@ DxeLoadCore (
                NULL,\r
                (VOID **) &S3Resume\r
                );\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Report Status code that S3Resume PPI can not be found\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+        (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND)\r
+        );\r
+    }\r
     ASSERT_EFI_ERROR (Status);\r
     \r
     Status = S3Resume->S3RestoreConfig2 (S3Resume);\r
     ASSERT_EFI_ERROR (Status);\r
   } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_BEGIN));\r
     Status = PeiServicesLocatePpi (\r
                &gEfiPeiRecoveryModulePpiGuid,\r
                0,\r
                NULL,\r
                (VOID **) &PeiRecovery\r
                );\r
+    //\r
+    // Report Status code the failure of locating Recovery PPI \r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+      (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND)\r
+      );    \r
     ASSERT_EFI_ERROR (Status);\r
-    \r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_LOAD));\r
     Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r
+      //\r
+      // Report Status code that S3Resume PPI can not be found\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+        (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_NO_RECOVERY_CAPSULE)\r
+        );\r
       CpuDeadLoop ();\r
     }\r
-\r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_START));\r
     //\r
     // Now should have a HOB with the DXE core\r
     //\r
@@ -214,7 +285,7 @@ DxeLoadCore (
                          &DataSize,\r
                          &MemoryData\r
                          );\r
-    if (!EFI_ERROR (Status)) {\r
+    if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r
       //\r
       // Build the GUID'd HOB for DXE\r
       //\r
@@ -515,21 +586,32 @@ Decompress (
   UINT8                           *ScratchBuffer;\r
   UINT32                          DstBufferSize;\r
   UINT32                          ScratchBufferSize;\r
-  EFI_COMMON_SECTION_HEADER       *Section;\r
-  UINT32                          SectionLength;\r
+  VOID                            *CompressionSource;\r
+  UINT32                          CompressionSourceSize;\r
+  UINT32                          UncompressedLength;\r
+  UINT8                           CompressionType;\r
 \r
   if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {\r
     ASSERT (FALSE);\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Section = (EFI_COMMON_SECTION_HEADER *) CompressionSection;\r
-  SectionLength = *(UINT32 *) (Section->Size) & 0x00ffffff;\r
+  if (IS_SECTION2 (CompressionSection)) {\r
+    CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));\r
+    CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));\r
+    UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->UncompressedLength;\r
+    CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->CompressionType;\r
+  } else {\r
+    CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION));\r
+    CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));\r
+    UncompressedLength = CompressionSection->UncompressedLength;\r
+    CompressionType = CompressionSection->CompressionType;\r
+  }\r
   \r
   //\r
   // This is a compression set, expand it\r
   //\r
-  switch (CompressionSection->CompressionType) {\r
+  switch (CompressionType) {\r
   case EFI_STANDARD_COMPRESSION:\r
     if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {\r
       //\r
@@ -537,8 +619,8 @@ Decompress (
       // For compressed data, decompress them to destination buffer.\r
       //\r
       Status = UefiDecompressGetInfo (\r
-                 (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                 SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                 CompressionSource,\r
+                 CompressionSourceSize,\r
                  &DstBufferSize,\r
                  &ScratchBufferSize\r
                  );\r
@@ -572,7 +654,7 @@ Decompress (
       // Call decompress function\r
       //\r
       Status = UefiDecompress (\r
-                  (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
+                  CompressionSource,\r
                   DstBuffer,\r
                   ScratchBuffer\r
                   );\r
@@ -597,7 +679,7 @@ Decompress (
     //\r
     // Allocate destination buffer\r
     //\r
-    DstBufferSize = CompressionSection->UncompressedLength;\r
+    DstBufferSize = UncompressedLength;\r
     DstBuffer     = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r
     if (DstBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -610,7 +692,7 @@ Decompress (
     //\r
     // stream is not actually compressed, just encapsulated.  So just copy it.\r
     //\r
-    CopyMem (DstBuffer, CompressionSection + 1, DstBufferSize);\r
+    CopyMem (DstBuffer, CompressionSource, DstBufferSize);\r
     break;\r
 \r
   default:\r