]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Apply GetFileBufferByFilePath API of DxeServicesLib to replace local CoreOpenImageFil...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Nov 2009 01:08:36 +0000 (01:08 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Nov 2009 01:08:36 +0000 (01:08 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9487 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/Core/Dxe/DxeMain.inf
MdeModulePkg/Core/Dxe/Image/Image.c
MdeModulePkg/Core/Dxe/Image/Image.h
MdeModulePkg/Core/Dxe/Image/ImageFile.c [deleted file]

index c0d644fda73106cec767b936dd416178fd16ec24..1c496bd8bdbb61cf8f907fd10d26244eb94f04b6 100644 (file)
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by DxeCore module.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation. <BR>\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
@@ -79,6 +79,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/TimerLib.h>\r
+#include <Library/DxeServicesLib.h>\r
 \r
 //\r
 // attributes for reserved memory before it is promoted to system memory\r
index 1cec93fadc7e7c104befd60de7c5f6502540c086..a7191b87e192aa3bb1d2f42440fc2c502b57928a 100644 (file)
@@ -2,7 +2,7 @@
 #  This is core module in DXE phase. It provides an implementation of DXE Core that is\r
 #  compliant with DXE CIS.  \r
 #  \r
-#  Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+#  Copyright (c) 2006 - 2009, Intel Corporation. <BR>\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
@@ -32,7 +32,6 @@
 [Sources.common]\r
   DxeMain.h\r
   SectionExtraction/CoreSectionExtraction.c\r
-  Image/ImageFile.c\r
   Image/Image.c\r
   Image/Image.h\r
   Misc/DebugImageInfo.c\r
@@ -89,6 +88,7 @@
   DevicePathLib\r
   ReportStatusCodeLib\r
   TimerLib\r
+  DxeServicesLib\r
 \r
 [Guids]\r
   gEfiEventMemoryMapChangeGuid                  ## CONSUMES ## Event\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueBootServiceExit\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverBegin\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverEnd\r
-\r
index 5b15a1edb7a6aa15dbe98489f0fd6bb5e1218cb2..077d2a02991d62ad14024a7bca12e0df158b713d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Core image handling services to load and unload PeImage.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation. <BR>\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
@@ -155,6 +155,49 @@ CoreInitializeImageServices (
            );\r
 }\r
 \r
+/**\r
+  Read image file (specified by UserHandle) into user specified buffer with specified offset\r
+  and length.\r
+\r
+  @param  UserHandle             Image file handle\r
+  @param  Offset                 Offset to the source file\r
+  @param  ReadSize               For input, pointer of size to read; For output,\r
+                                 pointer of size actually read.\r
+  @param  Buffer                 Buffer to write into\r
+\r
+  @retval EFI_SUCCESS            Successfully read the specified part of file\r
+                                 into buffer.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreReadImageFile (\r
+  IN     VOID    *UserHandle,\r
+  IN     UINTN   Offset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  UINTN               EndPosition;\r
+  IMAGE_FILE_HANDLE  *FHand;\r
+\r
+  FHand = (IMAGE_FILE_HANDLE  *)UserHandle;\r
+  ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE);\r
+\r
+  //\r
+  // Move data from our local copy of the file\r
+  //\r
+  EndPosition = Offset + *ReadSize;\r
+  if (EndPosition > FHand->SourceSize) {\r
+    *ReadSize = (UINT32)(FHand->SourceSize - Offset);\r
+  }\r
+  if (Offset >= FHand->SourceSize) {\r
+      *ReadSize = 0;\r
+  }\r
+\r
+  CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Loads, relocates, and invokes a PE/COFF image\r
@@ -766,19 +809,63 @@ CoreLoadImageCommon (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //\r
-  // Get simple read access to the source file\r
-  //\r
+  ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));\r
+  FHand.Signature  = IMAGE_FILE_HANDLE_SIGNATURE;\r
   OriginalFilePath = FilePath;\r
-  Status = CoreOpenImageFile (\r
-             BootPolicy,\r
-             SourceBuffer,\r
-             SourceSize,\r
-             &FilePath,\r
-             &DeviceHandle,\r
-             &FHand,\r
-             &AuthenticationStatus\r
-             );\r
+  HandleFilePath   = FilePath;\r
+  DeviceHandle     = NULL;\r
+  Status           = EFI_SUCCESS;\r
+  AuthenticationStatus = 0;\r
+  //\r
+  // If the caller passed a copy of the file, then just use it\r
+  //\r
+  if (SourceBuffer != NULL) {\r
+    FHand.Source     = SourceBuffer;\r
+    FHand.SourceSize = SourceSize;\r
+    CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+    if (SourceSize > 0) {\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      Status = EFI_LOAD_ERROR;\r
+    }\r
+  } else {\r
+    if (FilePath == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Get the source file buffer by its device path.\r
+    //\r
+    FHand.Source = GetFileBufferByFilePath (\r
+                      BootPolicy, \r
+                      FilePath,\r
+                      &FHand.SourceSize,\r
+                      &AuthenticationStatus\r
+                      );\r
+    if (FHand.Source == NULL) {\r
+      Status = EFI_LOAD_ERROR;\r
+    } else {\r
+      //\r
+      // Try to get the image device handle by checking the match protocol.\r
+      //\r
+      FHand.FreeBuffer = TRUE;\r
+      Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+      if (EFI_ERROR (Status)) {\r
+        HandleFilePath = FilePath;\r
+        Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+        if (EFI_ERROR (Status)) {\r
+          if (!BootPolicy) {\r
+            HandleFilePath = FilePath;\r
+            Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+          }\r
+          if (EFI_ERROR (Status)) {\r
+            HandleFilePath = FilePath;\r
+            Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
   if (Status == EFI_ALREADY_STARTED) {\r
     Image = NULL;\r
     goto Done;\r
index 54f71c3820364c90e50f66d4d79aa3a70481ef1b..4adade5a5342533540413905b392fbc6c7991275 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Data structure and functions to load and unload PeImage.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation. <BR>\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
@@ -89,67 +89,6 @@ typedef struct {
   UINTN               SourceSize;\r
 } IMAGE_FILE_HANDLE;\r
 \r
-\r
-/**\r
-  Opens a file for (simple) reading.  The simple read abstraction\r
-  will access the file either from a memory copy, from a file\r
-  system interface, or from the load file interface.\r
-\r
-  @param  BootPolicy             Policy for Open Image File.\r
-  @param  SourceBuffer           Pointer to the memory location containing copy\r
-                                 of the image to be loaded.\r
-  @param  SourceSize             The size in bytes of SourceBuffer.\r
-  @param  FilePath               The specific file path from which the image is\r
-                                 loaded\r
-  @param  DeviceHandle           Pointer to the return device handle.\r
-  @param  ImageFileHandle        Pointer to the image file handle.\r
-  @param  AuthenticationStatus   Pointer to a caller-allocated UINT32 in which\r
-                                 the authentication status is returned.\r
-\r
-  @retval EFI_SUCCESS            Image file successfully opened.\r
-  @retval EFI_LOAD_ERROR         If the caller passed a copy of the file, and\r
-                                 SourceSize is 0.\r
-  @retval EFI_INVALID_PARAMETER  File path is not valid.\r
-  @retval EFI_NOT_FOUND          File not found.\r
-\r
-**/\r
-EFI_STATUS\r
-CoreOpenImageFile (\r
-  IN BOOLEAN                        BootPolicy,\r
-  IN VOID                           *SourceBuffer   OPTIONAL,\r
-  IN UINTN                          SourceSize,\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL   **FilePath,\r
-  OUT EFI_HANDLE                    *DeviceHandle,\r
-  IN IMAGE_FILE_HANDLE              *ImageFileHandle,\r
-  OUT UINT32                        *AuthenticationStatus\r
-  );\r
-\r
-\r
-\r
-/**\r
-  Read image file (specified by UserHandle) into user specified buffer with specified offset\r
-  and length.\r
-\r
-  @param  UserHandle             Image file handle\r
-  @param  Offset                 Offset to the source file\r
-  @param  ReadSize               For input, pointer of size to read; For output,\r
-                                 pointer of size actually read.\r
-  @param  Buffer                 Buffer to write into\r
-\r
-  @retval EFI_SUCCESS            Successfully read the specified part of file\r
-                                 into buffer.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreReadImageFile (\r
-  IN     VOID    *UserHandle,\r
-  IN     UINTN   Offset,\r
-  IN OUT UINTN   *ReadSize,\r
-  OUT    VOID    *Buffer\r
-  );\r
-\r
-\r
 /**\r
   Loads an EFI image into memory and returns a handle to the image with extended parameters.\r
 \r
diff --git a/MdeModulePkg/Core/Dxe/Image/ImageFile.c b/MdeModulePkg/Core/Dxe/Image/ImageFile.c
deleted file mode 100644 (file)
index 9c6729a..0000000
+++ /dev/null
@@ -1,478 +0,0 @@
-/** @file\r
-  Handle services to image file.\r
-\r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\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
-#include "Image.h"\r
-\r
-/**\r
-  Search a handle to a device on a specified device path that supports a specified protocol,\r
-  interface of that protocol on that handle is another output.\r
-\r
-\r
-\r
-  @param  Protocol               The protocol to search for\r
-  @param  FilePath               The specified device path\r
-  @param  Interface              Interface of the protocol on the handle\r
-  @param  Handle                 The handle to the device on the specified device\r
-                                 path that supports the protocol.\r
-\r
-  @return Status code.\r
-\r
-**/\r
-EFI_STATUS\r
-CoreDevicePathToInterface (\r
-  IN EFI_GUID                     *Protocol,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
-  OUT VOID                        **Interface,\r
-  OUT EFI_HANDLE                  *Handle\r
-  )\r
-{\r
-  EFI_STATUS                      Status;\r
-\r
-  Status = CoreLocateDevicePath (Protocol, FilePath, Handle);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = CoreHandleProtocol (*Handle, Protocol, Interface);\r
-  }\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Opens a file for (simple) reading.  The simple read abstraction\r
-  will access the file either from a memory copy, from a file\r
-  system interface, or from the load file interface.\r
-\r
-  @param  BootPolicy             Policy for Open Image File.\r
-  @param  SourceBuffer           Pointer to the memory location containing copy\r
-                                 of the image to be loaded.\r
-  @param  SourceSize             The size in bytes of SourceBuffer.\r
-  @param  FilePath               The specific file path from which the image is\r
-                                 loaded\r
-  @param  DeviceHandle           Pointer to the return device handle.\r
-  @param  ImageFileHandle        Pointer to the image file handle.\r
-  @param  AuthenticationStatus   Pointer to a caller-allocated UINT32 in which\r
-                                 the authentication status is returned.\r
-\r
-  @retval EFI_SUCCESS            Image file successfully opened.\r
-  @retval EFI_LOAD_ERROR         If the caller passed a copy of the file, and\r
-                                 SourceSize is 0.\r
-  @retval EFI_INVALID_PARAMETER  File path is not valid.\r
-  @retval EFI_NOT_FOUND          File not found.\r
-\r
-**/\r
-EFI_STATUS\r
-CoreOpenImageFile (\r
-  IN BOOLEAN                        BootPolicy,\r
-  IN VOID                           *SourceBuffer   OPTIONAL,\r
-  IN UINTN                          SourceSize,\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL   **FilePath,\r
-  OUT EFI_HANDLE                    *DeviceHandle,\r
-  IN IMAGE_FILE_HANDLE              *ImageFileHandle,\r
-  OUT UINT32                        *AuthenticationStatus\r
-  )\r
-{\r
-  EFI_STATUS                        Status;\r
-  EFI_DEVICE_PATH_PROTOCOL          *TempFilePath;\r
-  FILEPATH_DEVICE_PATH              *FilePathNode;\r
-  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FwVolFilePathNode;\r
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Volume;\r
-  EFI_FILE_HANDLE                   FileHandle;\r
-  EFI_FILE_HANDLE                   LastHandle;\r
-  EFI_LOAD_FILE_PROTOCOL            *LoadFile;\r
-  EFI_LOAD_FILE2_PROTOCOL           *LoadFile2;\r
-  EFI_FIRMWARE_VOLUME2_PROTOCOL     *FwVol;\r
-  EFI_SECTION_TYPE                  SectionType;\r
-  UINT8                             *Pe32Buffer;\r
-  UINTN                             Pe32BufferSize;\r
-  EFI_FV_FILETYPE                   Type;\r
-  EFI_FV_FILE_ATTRIBUTES            Attrib;\r
-  EFI_FILE_INFO                     *FileInfo;\r
-  UINTN                             FileInfoSize;\r
-  EFI_GUID                          *NameGuid;\r
-  FILEPATH_DEVICE_PATH              *OriginalFilePathNode;\r
-\r
-  OriginalFilePathNode = NULL;\r
-  *AuthenticationStatus = 0;\r
-  ZeroMem (ImageFileHandle, sizeof (IMAGE_FILE_HANDLE));\r
-  ImageFileHandle->Signature = IMAGE_FILE_HANDLE_SIGNATURE;\r
-\r
-  //\r
-  // If the caller passed a copy of the file, then just use it\r
-  //\r
-  if (SourceBuffer != NULL) {\r
-    ImageFileHandle->Source     = SourceBuffer;\r
-    ImageFileHandle->SourceSize = SourceSize;\r
-    *DeviceHandle               = NULL;\r
-    CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, FilePath, DeviceHandle);\r
-    if (SourceSize > 0) {\r
-      Status = EFI_SUCCESS;\r
-    } else {\r
-      Status = EFI_LOAD_ERROR;\r
-    }\r
-    goto Done;\r
-  }\r
-\r
-  //\r
-  // Make sure FilePath is valid\r
-  //\r
-  if (*FilePath == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  //\r
-  // Check to see if it's in a Firmware Volume\r
-  //\r
-  FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) *FilePath;\r
-  Status = CoreDevicePathToInterface (\r
-            &gEfiFirmwareVolume2ProtocolGuid,\r
-            (EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode,\r
-            (VOID*)&FwVol,\r
-            DeviceHandle\r
-            );\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // For FwVol File system there is only a single file name that is a GUID.\r
-    //\r
-    NameGuid = EfiGetNameGuidFromFwVolDevicePathNode (FwVolFilePathNode);\r
-    if (NameGuid != NULL) {\r
-\r
-      SectionType = EFI_SECTION_PE32;\r
-      Pe32Buffer  = NULL;\r
-      Status = FwVol->ReadSection (\r
-                        FwVol,\r
-                        NameGuid,\r
-                        SectionType,\r
-                        0,\r
-                        (VOID **)&Pe32Buffer,\r
-                        &Pe32BufferSize,\r
-                        AuthenticationStatus\r
-                        );\r
-      if (EFI_ERROR (Status)) {\r
-        //\r
-        // Try a raw file, since a PE32 SECTION does not exist\r
-        //\r
-        if (Pe32Buffer != NULL) {\r
-          CoreFreePool (Pe32Buffer);\r
-          *AuthenticationStatus = 0;\r
-        }\r
-        Pe32Buffer = NULL;\r
-        Status = FwVol->ReadFile (\r
-                          FwVol,\r
-                          NameGuid,\r
-                          (VOID **)&Pe32Buffer,\r
-                          &Pe32BufferSize,\r
-                          &Type,\r
-                          &Attrib,\r
-                          AuthenticationStatus\r
-                          );\r
-      }\r
-\r
-      if (!EFI_ERROR (Status)) {\r
-        //\r
-        // One of the reads passed so we are done\r
-        //\r
-        ImageFileHandle->Source = Pe32Buffer;\r
-        ImageFileHandle->SourceSize = Pe32BufferSize;\r
-        ImageFileHandle->FreeBuffer = TRUE;\r
-        goto Done;\r
-      }\r
-    }\r
-  }\r
-\r
-  //\r
-  // Attempt to access the file via a file system interface\r
-  //\r
-  FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath;\r
-  Status = CoreDevicePathToInterface (\r
-            &gEfiSimpleFileSystemProtocolGuid,\r
-            (EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode,\r
-            (VOID*)&Volume,\r
-            DeviceHandle\r
-            );\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Open the Volume to get the File System handle\r
-    //\r
-    Status = Volume->OpenVolume (Volume, &FileHandle);\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Duplicate the device path to avoid the access to unaligned device path node.\r
-      // Because the device path consists of one or more FILE PATH MEDIA DEVICE PATH\r
-      // nodes, It assures the fields in device path nodes are 2 byte aligned.\r
-      //\r
-      FilePathNode = (FILEPATH_DEVICE_PATH *)DuplicateDevicePath((EFI_DEVICE_PATH_PROTOCOL *)(UINTN)FilePathNode);\r
-      if (FilePathNode == NULL) {\r
-        FileHandle->Close (FileHandle);\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-      } else {\r
-        OriginalFilePathNode = FilePathNode;\r
-        //\r
-        // Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the\r
-        // directory information and filename can be seperate. The goal is to inch\r
-        // our way down each device path node and close the previous node\r
-        //\r
-        while (!IsDevicePathEnd (&FilePathNode->Header)) {\r
-          if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r
-              DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {\r
-            Status = EFI_UNSUPPORTED;\r
-          }\r
-\r
-          if (EFI_ERROR (Status)) {\r
-            //\r
-            // Exit loop on Error\r
-            //\r
-            break;\r
-          }\r
-\r
-          LastHandle = FileHandle;\r
-          FileHandle = NULL;\r
-\r
-          Status = LastHandle->Open (\r
-                                LastHandle,\r
-                                &FileHandle,\r
-                                FilePathNode->PathName,\r
-                                EFI_FILE_MODE_READ,\r
-                                0\r
-                                );\r
-\r
-          //\r
-          // Close the previous node\r
-          //\r
-          LastHandle->Close (LastHandle);\r
-\r
-          FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);\r
-        }\r
-        //\r
-        // Free the allocated memory pool\r
-        //\r
-        CoreFreePool(OriginalFilePathNode);\r
-      }\r
-\r
-      if (!EFI_ERROR (Status)) {\r
-        //\r
-        // We have found the file. Now we need to read it. Before we can read the file we need to\r
-        // figure out how big the file is.\r
-        //\r
-        FileInfo = NULL;\r
-        FileInfoSize = 0;\r
-        Status = FileHandle->GetInfo (\r
-                              FileHandle,\r
-                              &gEfiFileInfoGuid,\r
-                              &FileInfoSize,\r
-                              FileInfo\r
-                              );\r
-        if (Status == EFI_BUFFER_TOO_SMALL) {\r
-          FileInfo = AllocatePool (FileInfoSize);\r
-          if (FileInfo != NULL) {\r
-            Status = FileHandle->GetInfo (\r
-                                  FileHandle,\r
-                                  &gEfiFileInfoGuid,\r
-                                  &FileInfoSize,\r
-                                  FileInfo\r
-                                  );\r
-          } else {\r
-            Status = EFI_OUT_OF_RESOURCES;\r
-            goto Done;\r
-          }\r
-        }\r
-        \r
-        if (!EFI_ERROR (Status)) {\r
-          //\r
-          // Allocate space for the file\r
-          //\r
-          ASSERT (FileInfo != NULL);\r
-          ImageFileHandle->Source = AllocatePool ((UINTN)FileInfo->FileSize);\r
-          if (ImageFileHandle->Source != NULL) {\r
-            //\r
-            // Read the file into the buffer we allocated\r
-            //\r
-            ImageFileHandle->SourceSize = (UINTN) FileInfo->FileSize;\r
-            ImageFileHandle->FreeBuffer = TRUE;\r
-            Status = FileHandle->Read (FileHandle, &ImageFileHandle->SourceSize, ImageFileHandle->Source);\r
-\r
-            //\r
-            // Close the file since we are done\r
-            //\r
-            FileHandle->Close (FileHandle);\r
-            CoreFreePool (FileInfo);\r
-          } else {\r
-            Status = EFI_OUT_OF_RESOURCES;\r
-          }\r
-\r
-          goto Done;\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  //\r
-  // Try LoadFile2 style\r
-  //\r
-  if (!BootPolicy) {\r
-    TempFilePath = *FilePath;\r
-    Status = CoreDevicePathToInterface (\r
-               &gEfiLoadFile2ProtocolGuid,\r
-               &TempFilePath,\r
-               (VOID*)&LoadFile2,\r
-               DeviceHandle\r
-               );\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Call LoadFile2 with the correct buffer size\r
-      //    \r
-      ASSERT (ImageFileHandle->SourceSize == 0);\r
-      ASSERT (ImageFileHandle->Source == NULL);\r
-      \r
-      Status = LoadFile2->LoadFile (\r
-                           LoadFile2,\r
-                           TempFilePath,\r
-                           BootPolicy,\r
-                           &ImageFileHandle->SourceSize,\r
-                           ImageFileHandle->Source\r
-                           );\r
-      if (Status == EFI_BUFFER_TOO_SMALL) {\r
-        ImageFileHandle->Source = AllocatePool (ImageFileHandle->SourceSize);\r
-        if (ImageFileHandle->Source == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        } else {\r
-          Status = LoadFile2->LoadFile (\r
-                               LoadFile2,\r
-                               TempFilePath,\r
-                               BootPolicy,\r
-                               &ImageFileHandle->SourceSize,\r
-                               ImageFileHandle->Source\r
-                               );\r
-        }\r
-      }\r
-\r
-      if (!EFI_ERROR (Status)) {\r
-        ImageFileHandle->FreeBuffer = TRUE;\r
-        goto Done;\r
-      }\r
-    }\r
-  }\r
-\r
-  //\r
-  // Try LoadFile style\r
-  //\r
-\r
-  TempFilePath = *FilePath;\r
-  Status = CoreDevicePathToInterface (\r
-             &gEfiLoadFileProtocolGuid,\r
-             &TempFilePath,\r
-             (VOID*) &LoadFile,\r
-             DeviceHandle\r
-             );\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // Call LoadFile with the correct buffer size\r
-    //\r
-    ASSERT (ImageFileHandle->SourceSize == 0);\r
-    ASSERT (ImageFileHandle->Source == NULL);\r
-    Status = LoadFile->LoadFile (\r
-                         LoadFile,\r
-                         TempFilePath,\r
-                         BootPolicy,\r
-                         &ImageFileHandle->SourceSize,\r
-                         ImageFileHandle->Source\r
-                         );\r
-    if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      ImageFileHandle->Source = AllocatePool (ImageFileHandle->SourceSize);\r
-      if (ImageFileHandle->Source == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-      } else {\r
-        Status = LoadFile->LoadFile (\r
-                             LoadFile,\r
-                             TempFilePath,\r
-                             BootPolicy,\r
-                             &ImageFileHandle->SourceSize,\r
-                             ImageFileHandle->Source\r
-                             );\r
-      }\r
-    }\r
-\r
-    if (!EFI_ERROR (Status)) {\r
-      ImageFileHandle->FreeBuffer = TRUE;\r
-      goto Done;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Nothing else to try\r
-  //\r
-  DEBUG ((DEBUG_LOAD|DEBUG_WARN, "CoreOpenImageFile: Device did not support a known load protocol\n"));\r
-  Status = EFI_NOT_FOUND;\r
-\r
-Done:\r
-  //\r
-  // If the file was not accessed, clean up\r
-  //\r
-  if (EFI_ERROR (Status)) {\r
-    if (ImageFileHandle->FreeBuffer) {\r
-      //\r
-      // Free the source buffer if we allocated it\r
-      //\r
-      CoreFreePool (ImageFileHandle->Source);\r
-    }\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-\r
-/**\r
-  Read image file (specified by UserHandle) into user specified buffer with specified offset\r
-  and length.\r
-\r
-  @param  UserHandle             Image file handle\r
-  @param  Offset                 Offset to the source file\r
-  @param  ReadSize               For input, pointer of size to read; For output,\r
-                                 pointer of size actually read.\r
-  @param  Buffer                 Buffer to write into\r
-\r
-  @retval EFI_SUCCESS            Successfully read the specified part of file\r
-                                 into buffer.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreReadImageFile (\r
-  IN     VOID    *UserHandle,\r
-  IN     UINTN   Offset,\r
-  IN OUT UINTN   *ReadSize,\r
-  OUT    VOID    *Buffer\r
-  )\r
-{\r
-  UINTN               EndPosition;\r
-  IMAGE_FILE_HANDLE  *FHand;\r
-\r
-  FHand = (IMAGE_FILE_HANDLE  *)UserHandle;\r
-  ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE);\r
-\r
-  //\r
-  // Move data from our local copy of the file\r
-  //\r
-  EndPosition = Offset + *ReadSize;\r
-  if (EndPosition > FHand->SourceSize) {\r
-    *ReadSize = (UINT32)(FHand->SourceSize - Offset);\r
-  }\r
-  if (Offset >= FHand->SourceSize) {\r
-      *ReadSize = 0;\r
-  }\r
-\r
-  CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);\r
-  return EFI_SUCCESS;\r
-}\r
-\r