]> 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 9300f4dfe07d26a3cc0f35d16721298bb5538077..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
@@ -75,6 +76,11 @@ typedef struct {
   //\r
   UINTN                       EncapsulatedStreamHandle;\r
   EFI_GUID                    *EncapsulationGuid;\r
+  //\r
+  // If the section REQUIRES an extraction protocol, register for RPN \r
+  // when the required GUIDed extraction protocol becomes available.\r
+  //\r
+  EFI_EVENT                   Event;\r
 } FRAMEWORK_SECTION_CHILD_NODE;\r
 \r
 #define FRAMEWORK_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')\r
@@ -100,7 +106,6 @@ typedef struct {
   FRAMEWORK_SECTION_CHILD_NODE     *ChildNode;\r
   FRAMEWORK_SECTION_STREAM_NODE    *ParentStream;\r
   VOID                             *Registration;\r
-  EFI_EVENT                        Event;\r
 } RPN_EVENT_CONTEXT;\r
 \r
 /**\r
@@ -144,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
@@ -535,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
@@ -575,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
@@ -602,12 +654,13 @@ NotifyGuidedExtraction (
   }\r
 \r
   //\r
-  //  If above, the stream  did not close successfully, it indicates it's\r
-  //  alread been closed by someone, so just destroy the event and be done with\r
+  //  If above, the stream did not close successfully, it indicates it's\r
+  //  already been closed by someone, so just destroy the event and be done with\r
   //  it.\r
   //\r
   \r
   gBS->CloseEvent (Event);\r
+  Context->ChildNode->Event = NULL;\r
   FreePool (Context);\r
 }  \r
 \r
@@ -636,14 +689,14 @@ CreateGuidedExtractionRpnEvent (
   Context->ChildNode = ChildNode;\r
   Context->ParentStream = ParentStream;\r
  \r
-  Context->Event = CreateProtocolNotifyEvent (\r
-                    Context->ChildNode->EncapsulationGuid,\r
-                    TPL_NOTIFY,\r
-                    NotifyGuidedExtraction,\r
-                    Context,\r
-                    &Context->Registration,\r
-                    FALSE\r
-                    );\r
+  Context->ChildNode->Event = CreateProtocolNotifyEvent (\r
+                                Context->ChildNode->EncapsulationGuid,\r
+                                TPL_NOTIFY,\r
+                                NotifyGuidedExtraction,\r
+                                Context,\r
+                                &Context->Registration,\r
+                                FALSE\r
+                                );\r
 }\r
 \r
 /**\r
@@ -695,7 +748,7 @@ CreateChildNode (
   //\r
   // Allocate a new node\r
   //\r
-  *ChildNode = AllocatePool (sizeof (FRAMEWORK_SECTION_CHILD_NODE));\r
+  *ChildNode = AllocateZeroPool (sizeof (FRAMEWORK_SECTION_CHILD_NODE));\r
   Node = *ChildNode;\r
   if (Node == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -837,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
@@ -1045,6 +1097,7 @@ FindChildNode (
   CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));\r
 \r
   for (;;) {\r
+    ASSERT (CurrentChildNode != NULL);\r
     if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {\r
       //\r
       // The type matches, so check the instance count to see if it's the one we want\r
@@ -1061,7 +1114,6 @@ FindChildNode (
       }\r
     }\r
     \r
-    ASSERT (CurrentChildNode != NULL);\r
     if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {\r
       //\r
       // If the current node is an encapsulating node, recurse into it...\r
@@ -1182,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
@@ -1238,6 +1290,7 @@ GetSection (
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   Instance = SectionInstance + 1;\r
+  ChildStreamNode = NULL;\r
   \r
   //\r
   // Locate target stream\r
@@ -1339,6 +1392,11 @@ FreeChildNode (
     //\r
     CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);\r
   }\r
+\r
+  if (ChildNode->Event != NULL) {\r
+    gBS->CloseEvent (ChildNode->Event);\r
+  }\r
+\r
   //\r
   // Last, free the child node itself\r
   //\r