MdeModulePkg: Update DxeCore to handle LoadFile DevicePath

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.gao@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17799 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Liming Gao 2015-07-02 04:28:21 +00:00 committed by lgao4
parent de6c0eff30
commit fa4470638a
1 changed files with 41 additions and 20 deletions

View File

@ -1055,8 +1055,11 @@ CoreLoadImageCommon (
UINT32 AuthenticationStatus; UINT32 AuthenticationStatus;
EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath; EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath;
EFI_DEVICE_PATH_PROTOCOL *HandleFilePath; EFI_DEVICE_PATH_PROTOCOL *HandleFilePath;
EFI_DEVICE_PATH_PROTOCOL *InputFilePath;
EFI_DEVICE_PATH_PROTOCOL *Node;
UINTN FilePathSize; UINTN FilePathSize;
BOOLEAN ImageIsFromFv; BOOLEAN ImageIsFromFv;
BOOLEAN ImageIsFromLoadFile;
SecurityStatus = EFI_SUCCESS; SecurityStatus = EFI_SUCCESS;
@ -1079,11 +1082,13 @@ CoreLoadImageCommon (
ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE)); ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE; FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
OriginalFilePath = FilePath; OriginalFilePath = FilePath;
InputFilePath = FilePath;
HandleFilePath = FilePath; HandleFilePath = FilePath;
DeviceHandle = NULL; DeviceHandle = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
AuthenticationStatus = 0; AuthenticationStatus = 0;
ImageIsFromFv = FALSE; ImageIsFromFv = FALSE;
ImageIsFromLoadFile = FALSE;
// //
// If the caller passed a copy of the file, then just use it // If the caller passed a copy of the file, then just use it
@ -1104,6 +1109,33 @@ CoreLoadImageCommon (
if (FilePath == NULL) { if (FilePath == NULL) {
return EFI_INVALID_PARAMETER; 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. // Get the source file buffer by its device path.
// //
@ -1116,26 +1148,12 @@ CoreLoadImageCommon (
if (FHand.Source == NULL) { if (FHand.Source == NULL) {
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
} else { } else {
//
// Try to get the image device handle by checking the match protocol.
//
FHand.FreeBuffer = TRUE; FHand.FreeBuffer = TRUE;
Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle); if (ImageIsFromLoadFile) {
if (!EFI_ERROR (Status)) { //
ImageIsFromFv = TRUE; // LoadFile () may cause the device path of the Handle be updated.
} else { //
HandleFilePath = FilePath; OriginalFilePath = AppendDevicePath (DevicePathFromHandle (DeviceHandle), Node);
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);
}
}
} }
} }
} }
@ -1337,6 +1355,9 @@ Done:
if (FHand.FreeBuffer) { if (FHand.FreeBuffer) {
CoreFreePool (FHand.Source); CoreFreePool (FHand.Source);
} }
if (OriginalFilePath != InputFilePath) {
CoreFreePool (OriginalFilePath);
}
// //
// There was an error. If there's an Image structure, free it // There was an error. If there's an Image structure, free it