UEFI Spec HTTP Boot Device Path, after retrieving the boot resource
information, the BootURI device path node will be updated to include
the BootURI information. It means the device path on the child handle
will be updated after the LoadFile() service is called.

To handle this case, DxeCore LoadImage() service is updated as the below:
1) Get Device handle based on Device Path
2) Call LoadFile() service (GetFileBufferByFilePath() API) to get Load File 
Buffer.
3) Retrieve DevicePath from Device handle

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming....@intel.com>
---
 MdeModulePkg/Core/Dxe/Image/Image.c | 61 +++++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 20 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c 
b/MdeModulePkg/Core/Dxe/Image/Image.c
index ea6b2c6..5355940 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -1053,12 +1053,15 @@ CoreLoadImageCommon (
   EFI_STATUS                 SecurityStatus;
   EFI_HANDLE                 DeviceHandle;
   UINT32                     AuthenticationStatus;
   EFI_DEVICE_PATH_PROTOCOL   *OriginalFilePath;
   EFI_DEVICE_PATH_PROTOCOL   *HandleFilePath;
+  EFI_DEVICE_PATH_PROTOCOL   *InputFilePath;
+  EFI_DEVICE_PATH_PROTOCOL   *Node;
   UINTN                      FilePathSize;
   BOOLEAN                    ImageIsFromFv;
+  BOOLEAN                    ImageIsFromLoadFile;
 
   SecurityStatus = EFI_SUCCESS;
 
   ASSERT (gEfiCurrentTpl < TPL_NOTIFY);
   ParentImage = NULL;
@@ -1077,15 +1080,17 @@ CoreLoadImageCommon (
   }
 
   ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
   FHand.Signature  = IMAGE_FILE_HANDLE_SIGNATURE;
   OriginalFilePath = FilePath;
+  InputFilePath    = FilePath;
   HandleFilePath   = FilePath;
   DeviceHandle     = NULL;
   Status           = EFI_SUCCESS;
   AuthenticationStatus = 0;
-  ImageIsFromFv    = FALSE;
+  ImageIsFromFv        = FALSE;
+  ImageIsFromLoadFile  = FALSE;
 
   //
   // If the caller passed a copy of the file, then just use it
   //
   if (SourceBuffer != NULL) {
@@ -1102,10 +1107,37 @@ CoreLoadImageCommon (
     }
   } else {
     if (FilePath == NULL) {
       return EFI_INVALID_PARAMETER;
     }
+
+    //
+    // Try to get the image device handle by checking the match protocol.
+    //
+    Node   = NULL;
+    Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, 
&HandleFilePath, &DeviceHandle);
+    if (!EFI_ERROR (Status)) {
+      ImageIsFromFv = TRUE;
+    } else {
+      HandleFilePath = FilePath;
+      Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, 
&HandleFilePath, &DeviceHandle);
+      if (EFI_ERROR (Status)) {
+        if (!BootPolicy) {
+          HandleFilePath = FilePath;
+          Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, 
&HandleFilePath, &DeviceHandle);
+        }
+        if (EFI_ERROR (Status)) {
+          HandleFilePath = FilePath;
+          Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, 
&HandleFilePath, &DeviceHandle);
+          if (!EFI_ERROR (Status)) {
+            ImageIsFromLoadFile = TRUE;
+            Node = HandleFilePath;
+          }
+        }
+      }
+    }
+
     //
     // Get the source file buffer by its device path.
     //
     FHand.Source = GetFileBufferByFilePath (
                       BootPolicy, 
@@ -1114,30 +1146,16 @@ CoreLoadImageCommon (
                       &AuthenticationStatus
                       );
     if (FHand.Source == NULL) {
       Status = EFI_NOT_FOUND;
     } else {
-      //
-      // Try to get the image device handle by checking the match protocol.
-      //
       FHand.FreeBuffer = TRUE;
-      Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, 
&HandleFilePath, &DeviceHandle);
-      if (!EFI_ERROR (Status)) {
-        ImageIsFromFv = TRUE;
-      } else {
-        HandleFilePath = FilePath;
-        Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, 
&HandleFilePath, &DeviceHandle);
-        if (EFI_ERROR (Status)) {
-          if (!BootPolicy) {
-            HandleFilePath = FilePath;
-            Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, 
&HandleFilePath, &DeviceHandle);
-          }
-          if (EFI_ERROR (Status)) {
-            HandleFilePath = FilePath;
-            Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, 
&HandleFilePath, &DeviceHandle);
-          }
-        }
+      if (ImageIsFromLoadFile) {
+        //
+        // LoadFile () may cause the device path of the Handle be updated.
+        //
+        OriginalFilePath = AppendDevicePath (DevicePathFromHandle 
(DeviceHandle), Node);
       }
     }
   }
 
   if (EFI_ERROR (Status)) {
@@ -1335,10 +1353,13 @@ Done:
   // If we allocated the Source buffer, free it
   //
   if (FHand.FreeBuffer) {
     CoreFreePool (FHand.Source);
   }
+  if (OriginalFilePath != InputFilePath) {
+    CoreFreePool (OriginalFilePath);
+  }
 
   //
   // There was an error.  If there's an Image structure, free it
   //
   if (EFI_ERROR (Status)) {
-- 
1.9.5.msysgit.0


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to