]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.c
IntelFrameworkModulePkg: Fix typos in comments
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / SectionExtractionDxe / SectionExtraction.c
index 86bf2be6322096c7b23c87d47c622902e30a9582..cacac486bbfece03bbeb098566e4930f68da0cd3 100644 (file)
@@ -27,7 +27,7 @@
   3) A support protocol is not found, and the data is not available to be read\r
      without it.  This results in EFI_PROTOCOL_ERROR.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, 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
@@ -45,6 +45,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiLib.h>\r
 #include <Protocol/Decompress.h>\r
 #include <Protocol/GuidedSectionExtraction.h>\r
 #include <Protocol/SectionExtraction.h>\r
@@ -148,7 +149,7 @@ OpenSectionStream (
   @param Buffer                Double indirection to buffer.  If *Buffer is non-null on\r
                                input, then the buffer is caller allocated.  If\r
                                *Buffer is NULL, then the buffer is callee allocated.\r
-                               In either case, the requried buffer size is returned\r
+                               In either case, the required buffer size is returned\r
                                in *BufferSize.\r
   @param BufferSize            On input, indicates the size of *Buffer if *Buffer is\r
                                non-null on input.  On output, indicates the required\r
@@ -539,6 +540,53 @@ CreateProtocolNotifyEvent (
   return Event;\r
 }\r
 \r
+/**\r
+  Verify the Guided Section GUID by checking if there is the Guided Section GUID configuration table recorded the GUID itself.\r
+\r
+  @param GuidedSectionGuid          The Guided Section GUID.\r
+  @param GuidedSectionExtraction    A pointer to the pointer to the supported Guided Section Extraction Protocol\r
+                                    for the Guided Section.\r
+\r
+  @return TRUE      The GuidedSectionGuid could be identified, and the pointer to\r
+                    the Guided Section Extraction Protocol will be returned to *GuidedSectionExtraction.\r
+  @return FALSE     The GuidedSectionGuid could not be identified, or \r
+                    the Guided Section Extraction Protocol has not been installed yet.\r
+\r
+**/\r
+BOOLEAN\r
+VerifyGuidedSectionGuid (\r
+  IN  EFI_GUID                                  *GuidedSectionGuid,\r
+  OUT EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL    **GuidedSectionExtraction\r
+  )\r
+{\r
+  EFI_GUID              *GuidRecorded;\r
+  VOID                  *Interface;\r
+  EFI_STATUS            Status;\r
+\r
+  //\r
+  // Check if there is the Guided Section GUID configuration table recorded the GUID itself.\r
+  //\r
+  Status = EfiGetSystemConfigurationTable (GuidedSectionGuid, (VOID **) &GuidRecorded);\r
+  if (Status == EFI_SUCCESS) {\r
+    if (CompareGuid (GuidRecorded, GuidedSectionGuid)) {\r
+      //\r
+      // Found the recorded GuidedSectionGuid.\r
+      //\r
+      Status = gBS->LocateProtocol (GuidedSectionGuid, NULL, (VOID **) &Interface);\r
+      if (!EFI_ERROR (Status) && Interface != NULL) {\r
+        //\r
+        // Found the supported Guided Section Extraction Porotocol for the Guided Section.\r
+        //\r
+        *GuidedSectionExtraction = (EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *) Interface;\r
+        return TRUE;\r
+      }\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   RPN callback function.  \r
   1. Initialize the section stream when the GUIDED_SECTION_EXTRACTION_PROTOCOL is installed.\r
@@ -579,10 +627,10 @@ NotifyGuidedExtraction (
       (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);\r
     ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);\r
     \r
-    Status = gBS->LocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
-    ASSERT_EFI_ERROR (Status);\r
+    if (!VerifyGuidedSectionGuid (Context->ChildNode->EncapsulationGuid, &GuidedExtraction)) {\r
+      return;\r
+    }\r
 \r
-    \r
     Status = GuidedExtraction->ExtractSection (\r
                                  GuidedExtraction,\r
                                  GuidedHeader,\r
@@ -842,8 +890,7 @@ CreateChildNode (
         Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;\r
         GuidedSectionAttributes = GuidedHeader->Attributes;\r
       }\r
-      Status = gBS->LocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);\r
-      if (!EFI_ERROR (Status)) {\r
+      if (VerifyGuidedSectionGuid (Node->EncapsulationGuid, &GuidedExtraction)) {\r
         //\r
         // NewStreamBuffer is always allocated by ExtractSection... No caller\r
         // allocation here.\r
@@ -1187,7 +1234,7 @@ FindStreamNode (
   @param Buffer                Double indirection to buffer.  If *Buffer is non-null on\r
                                input, then the buffer is caller allocated.  If\r
                                *Buffer is NULL, then the buffer is callee allocated.\r
-                               In either case, the requried buffer size is returned\r
+                               In either case, the required buffer size is returned\r
                                in *BufferSize.\r
   @param BufferSize            On input, indicates the size of *Buffer if *Buffer is\r
                                non-null on input.  On output, indicates the required\r
@@ -1243,6 +1290,7 @@ GetSection (
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   Instance = SectionInstance + 1;\r
+  ChildStreamNode = NULL;\r
   \r
   //\r
   // Locate target stream\r