1. CoreOpenImageFile(): FilePath should be IN OUT.

2. Use offset address to build device path instead of absolute address.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4294 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff
2007-11-09 07:26:24 +00:00
parent 189575e88b
commit cfe9de5244
4 changed files with 74 additions and 73 deletions

View File

@ -1,13 +1,13 @@
/**@file /**@file
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// Module global for a template of the PCI option ROM Image Device Path Node // Module global for a template of the PCI option ROM Image Device Path Node
// //
MEMMAP_DEVICE_PATH mPciOptionRomImageDevicePathNodeTemplate = { MEMMAP_DEVICE_PATH mPciOptionRomImageDevicePathNodeTemplate = {
{ {
HARDWARE_DEVICE_PATH, HARDWARE_DEVICE_PATH,
HW_MEMMAP_DP, HW_MEMMAP_DP,
sizeof (MEMMAP_DEVICE_PATH) sizeof (MEMMAP_DEVICE_PATH)
@ -133,7 +133,7 @@ LoadOpRomImage (
/*++ /*++
Routine Description: Routine Description:
Load option rom image for specified PCI device Load option rom image for specified PCI device
Arguments: Arguments:
@ -265,7 +265,7 @@ Returns:
gBS->FreePool (RomPcir); gBS->FreePool (RomPcir);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// Copy Rom image into memory // Copy Rom image into memory
// //
@ -337,7 +337,7 @@ Returns:
for (Offset = 0x10; Offset <= 0x24; Offset += sizeof (UINT32)) { for (Offset = 0x10; Offset <= 0x24; Offset += sizeof (UINT32)) {
PciIoWrite (PciIo, EfiPciIoWidthUint32, Offset, 1, &gAllZero); PciIoWrite (PciIo, EfiPciIoWidthUint32, Offset, 1, &gAllZero);
} }
// //
// set the Rom base address: now is hardcode // set the Rom base address: now is hardcode
// enable its decoder // enable its decoder
@ -362,7 +362,7 @@ Returns:
PciEnableCommandRegister(PciDevice, EFI_PCI_COMMAND_MEMORY_SPACE); PciEnableCommandRegister(PciDevice, EFI_PCI_COMMAND_MEMORY_SPACE);
} else { } else {
// //
// disable command register decode to memory // disable command register decode to memory
// //
@ -400,14 +400,14 @@ ProcessOpRomImage (
Routine Description: Routine Description:
Process the oprom image. Process the oprom image.
Arguments: Arguments:
PciDevice A pointer to a pci device. PciDevice A pointer to a pci device.
Returns: Returns:
EFI Status. EFI Status.
--*/ --*/
{ {
UINT8 Indicator; UINT8 Indicator;
@ -457,7 +457,7 @@ Returns:
ImageSize = (UINT32) (Pcir->ImageLength * 512); ImageSize = (UINT32) (Pcir->ImageLength * 512);
Indicator = Pcir->Indicator; Indicator = Pcir->Indicator;
if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) && if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&
(EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)) { (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)) {
if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) || if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||
@ -520,11 +520,11 @@ Returns:
} }
if (!SkipImage) { if (!SkipImage) {
//
// Build full device path to the PCI Option ROM Image being loaded
// //
mPciOptionRomImageDevicePathNodeTemplate.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)RomBarOffset; // Build Memory Mapped device path node to record the image offset into the PCI Option ROM
mPciOptionRomImageDevicePathNodeTemplate.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(RomBarOffset + ImageSize - 1); //
mPciOptionRomImageDevicePathNodeTemplate.StartingAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (RomBarOffset - (UINT8 *) RomBar);
mPciOptionRomImageDevicePathNodeTemplate.EndingAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (RomBarOffset + ImageSize - 1 - (UINT8 *) RomBar);
PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, (const EFI_DEVICE_PATH_PROTOCOL *)&mPciOptionRomImageDevicePathNodeTemplate); PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, (const EFI_DEVICE_PATH_PROTOCOL *)&mPciOptionRomImageDevicePathNodeTemplate);
ASSERT (PciOptionRomImageDevicePath != NULL); ASSERT (PciOptionRomImageDevicePath != NULL);

View File

@ -100,7 +100,7 @@ CoreOpenImageFile (
IN BOOLEAN BootPolicy, IN BOOLEAN BootPolicy,
IN VOID *SourceBuffer OPTIONAL, IN VOID *SourceBuffer OPTIONAL,
IN UINTN SourceSize, IN UINTN SourceSize,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
OUT EFI_HANDLE *DeviceHandle, OUT EFI_HANDLE *DeviceHandle,
IN IMAGE_FILE_HANDLE *ImageFileHandle, IN IMAGE_FILE_HANDLE *ImageFileHandle,
OUT UINT32 *AuthenticationStatus OUT UINT32 *AuthenticationStatus

View File

@ -639,7 +639,7 @@ Returns:
BootPolicy, BootPolicy,
SourceBuffer, SourceBuffer,
SourceSize, SourceSize,
FilePath, &FilePath,
&DeviceHandle, &DeviceHandle,
&FHand, &FHand,
&AuthenticationStatus &AuthenticationStatus
@ -679,6 +679,7 @@ Returns:
// //
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath // Pull out just the file portion of the DevicePath for the LoadedImage FilePath
// //
FilePath = OriginalFilePath;
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath); Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL); FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);

View File

@ -1,22 +1,22 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: Module Name:
ImageFile.c ImageFile.c
Abstract: Abstract:
Revision History Revision History
@ -30,7 +30,7 @@ CoreOpenImageFile (
IN BOOLEAN BootPolicy, IN BOOLEAN BootPolicy,
IN VOID *SourceBuffer OPTIONAL, IN VOID *SourceBuffer OPTIONAL,
IN UINTN SourceSize, IN UINTN SourceSize,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
OUT EFI_HANDLE *DeviceHandle, OUT EFI_HANDLE *DeviceHandle,
IN IMAGE_FILE_HANDLE *ImageFileHandle, IN IMAGE_FILE_HANDLE *ImageFileHandle,
OUT UINT32 *AuthenticationStatus OUT UINT32 *AuthenticationStatus
@ -52,16 +52,16 @@ Arguments:
FilePath - The specific file path from which the image is loaded FilePath - The specific file path from which the image is loaded
DeviceHandle - Pointer to the return device handle. DeviceHandle - Pointer to the return device handle.
ImageFileHandle - Pointer to the image file handle. ImageFileHandle - Pointer to the image file handle.
AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned. AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.
Returns: Returns:
EFI_SUCCESS - Image file successfully opened. EFI_SUCCESS - Image file successfully opened.
EFI_LOAD_ERROR - If the caller passed a copy of the file, and SourceSize is 0. EFI_LOAD_ERROR - If the caller passed a copy of the file, and SourceSize is 0.
EFI_INVALID_PARAMETER - File path is not valid. EFI_INVALID_PARAMETER - File path is not valid.
EFI_NOT_FOUND - File not found. EFI_NOT_FOUND - File not found.
--*/ --*/
@ -95,7 +95,7 @@ Returns:
ImageFileHandle->Source = SourceBuffer; ImageFileHandle->Source = SourceBuffer;
ImageFileHandle->SourceSize = SourceSize; ImageFileHandle->SourceSize = SourceSize;
*DeviceHandle = NULL; *DeviceHandle = NULL;
CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &FilePath, DeviceHandle); CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, FilePath, DeviceHandle);
if (SourceSize > 0) { if (SourceSize > 0) {
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} else { } else {
@ -107,18 +107,18 @@ Returns:
// //
// Make sure FilePath is valid // Make sure FilePath is valid
// //
if (FilePath == NULL) { if (*FilePath == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Check to see if it's in a Firmware Volume // Check to see if it's in a Firmware Volume
// //
FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath; FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) *FilePath;
Status = CoreDevicePathToInterface ( Status = CoreDevicePathToInterface (
&gEfiFirmwareVolume2ProtocolGuid, &gEfiFirmwareVolume2ProtocolGuid,
(EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode, (EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode,
(VOID*)&FwVol, (VOID*)&FwVol,
DeviceHandle DeviceHandle
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
@ -131,9 +131,9 @@ Returns:
SectionType = EFI_SECTION_PE32; SectionType = EFI_SECTION_PE32;
Pe32Buffer = NULL; Pe32Buffer = NULL;
Status = FwVol->ReadSection ( Status = FwVol->ReadSection (
FwVol, FwVol,
NameGuid, NameGuid,
SectionType, SectionType,
0, 0,
(VOID **)&Pe32Buffer, (VOID **)&Pe32Buffer,
&Pe32BufferSize, &Pe32BufferSize,
@ -149,8 +149,8 @@ Returns:
} }
Pe32Buffer = NULL; Pe32Buffer = NULL;
Status = FwVol->ReadFile ( Status = FwVol->ReadFile (
FwVol, FwVol,
NameGuid, NameGuid,
(VOID **)&Pe32Buffer, (VOID **)&Pe32Buffer,
&Pe32BufferSize, &Pe32BufferSize,
&Type, &Type,
@ -158,7 +158,7 @@ Returns:
AuthenticationStatus AuthenticationStatus
); );
} }
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// One of the reads passed so we are done // One of the reads passed so we are done
@ -174,11 +174,11 @@ Returns:
// //
// Attempt to access the file via a file system interface // Attempt to access the file via a file system interface
// //
FilePathNode = (FILEPATH_DEVICE_PATH *) FilePath; FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath;
Status = CoreDevicePathToInterface ( Status = CoreDevicePathToInterface (
&gEfiSimpleFileSystemProtocolGuid, &gEfiSimpleFileSystemProtocolGuid,
(EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode, (EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode,
(VOID*)&Volume, (VOID*)&Volume,
DeviceHandle DeviceHandle
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
@ -187,7 +187,7 @@ Returns:
// //
Status = Volume->OpenVolume (Volume, &FileHandle); Status = Volume->OpenVolume (Volume, &FileHandle);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
// Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the // Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the
// directory information and filename can be seperate. The goal is to inch // directory information and filename can be seperate. The goal is to inch
@ -239,7 +239,7 @@ Returns:
FileHandle, FileHandle,
&gEfiFileInfoGuid, &gEfiFileInfoGuid,
&FileInfoSize, &FileInfoSize,
FileInfo FileInfo
); );
} }
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
@ -267,14 +267,14 @@ Returns:
} }
} }
} }
} }
// //
// Try LoadFile style // Try LoadFile style
// //
TempFilePath = FilePath; TempFilePath = *FilePath;
Status = CoreDevicePathToInterface ( Status = CoreDevicePathToInterface (
&gEfiLoadFileProtocolGuid, &gEfiLoadFileProtocolGuid,
&TempFilePath, &TempFilePath,
@ -350,12 +350,12 @@ Routine Description:
Arguments: Arguments:
UserHandle - Image file handle UserHandle - Image file handle
Offset - Offset to the source file Offset - Offset to the source file
ReadSize - For input, pointer of size to read; ReadSize - For input, pointer of size to read;
For output, pointer of size actually read. For output, pointer of size actually read.
Buffer - Buffer to write into Buffer - Buffer to write into
Returns: Returns:
@ -376,7 +376,7 @@ Returns:
EndPosition = Offset + *ReadSize; EndPosition = Offset + *ReadSize;
if (EndPosition > FHand->SourceSize) { if (EndPosition > FHand->SourceSize) {
*ReadSize = (UINT32)(FHand->SourceSize - Offset); *ReadSize = (UINT32)(FHand->SourceSize - Offset);
} }
if (Offset >= FHand->SourceSize) { if (Offset >= FHand->SourceSize) {
*ReadSize = 0; *ReadSize = 0;
} }
@ -402,13 +402,13 @@ Routine Description:
Arguments: Arguments:
Protocol - The protocol to search for Protocol - The protocol to search for
FilePath - The specified device path FilePath - The specified device path
Interface - Interface of the protocol on the handle Interface - Interface of the protocol on the handle
Handle - The handle to the device on the specified device path that supports the protocol. Handle - The handle to the device on the specified device path that supports the protocol.
Returns: Returns:
Status code. Status code.
@ -435,7 +435,7 @@ CoreGrowBuffer (
Routine Description: Routine Description:
Helper function called as part of the code needed Helper function called as part of the code needed
to allocate the proper sized buffer for various to allocate the proper sized buffer for various
EFI interfaces. EFI interfaces.
Arguments: Arguments:
@ -445,10 +445,10 @@ Arguments:
Buffer - Current allocated buffer, or NULL Buffer - Current allocated buffer, or NULL
BufferSize - Current buffer size needed BufferSize - Current buffer size needed
Returns: Returns:
TRUE - if the buffer was reallocated and the caller TRUE - if the buffer was reallocated and the caller
should try the API again. should try the API again.
FALSE - buffer could not be allocated and the caller FALSE - buffer could not be allocated and the caller
@ -473,7 +473,7 @@ Returns:
// //
// If the status code is "buffer too small", resize the buffer // If the status code is "buffer too small", resize the buffer
// //
if (*Status == EFI_BUFFER_TOO_SMALL) { if (*Status == EFI_BUFFER_TOO_SMALL) {
if (*Buffer != NULL) { if (*Buffer != NULL) {
CoreFreePool (*Buffer); CoreFreePool (*Buffer);
@ -482,9 +482,9 @@ Returns:
*Buffer = CoreAllocateBootServicesPool (BufferSize); *Buffer = CoreAllocateBootServicesPool (BufferSize);
if (*Buffer != NULL) { if (*Buffer != NULL) {
TryAgain = TRUE; TryAgain = TRUE;
} else { } else {
*Status = EFI_OUT_OF_RESOURCES; *Status = EFI_OUT_OF_RESOURCES;
} }
} }
// //