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
-Copyright (c) 2006, Intel Corporation \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
+Copyright (c) 2006 - 2007, Intel Corporation\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
// Module global for a template of the PCI option ROM Image Device Path Node\r
//\r
MEMMAP_DEVICE_PATH mPciOptionRomImageDevicePathNodeTemplate = {\r
// Module global for a template of the PCI option ROM Image Device Path Node\r
//\r
MEMMAP_DEVICE_PATH mPciOptionRomImageDevicePathNodeTemplate = {\r
HARDWARE_DEVICE_PATH,\r
HW_MEMMAP_DP,\r
sizeof (MEMMAP_DEVICE_PATH)\r
HARDWARE_DEVICE_PATH,\r
HW_MEMMAP_DP,\r
sizeof (MEMMAP_DEVICE_PATH)\r
/*++\r
\r
Routine Description:\r
/*++\r
\r
Routine Description:\r
Load option rom image for specified PCI device\r
\r
Arguments:\r
Load option rom image for specified PCI device\r
\r
Arguments:\r
gBS->FreePool (RomPcir);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
gBS->FreePool (RomPcir);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
//\r
// Copy Rom image into memory\r
//\r
//\r
// Copy Rom image into memory\r
//\r
for (Offset = 0x10; Offset <= 0x24; Offset += sizeof (UINT32)) {\r
PciIoWrite (PciIo, EfiPciIoWidthUint32, Offset, 1, &gAllZero);\r
}\r
for (Offset = 0x10; Offset <= 0x24; Offset += sizeof (UINT32)) {\r
PciIoWrite (PciIo, EfiPciIoWidthUint32, Offset, 1, &gAllZero);\r
}\r
//\r
// set the Rom base address: now is hardcode\r
// enable its decoder\r
//\r
// set the Rom base address: now is hardcode\r
// enable its decoder\r
PciEnableCommandRegister(PciDevice, EFI_PCI_COMMAND_MEMORY_SPACE);\r
\r
} else {\r
PciEnableCommandRegister(PciDevice, EFI_PCI_COMMAND_MEMORY_SPACE);\r
\r
} else {\r
//\r
// disable command register decode to memory\r
//\r
//\r
// disable command register decode to memory\r
//\r
Routine Description:\r
\r
Process the oprom image.\r
Routine Description:\r
\r
Process the oprom image.\r
Arguments:\r
PciDevice A pointer to a pci device.\r
\r
Returns:\r
\r
EFI Status.\r
Arguments:\r
PciDevice A pointer to a pci device.\r
\r
Returns:\r
\r
EFI Status.\r
--*/\r
{\r
UINT8 Indicator;\r
--*/\r
{\r
UINT8 Indicator;\r
ImageSize = (UINT32) (Pcir->ImageLength * 512);\r
Indicator = Pcir->Indicator;\r
\r
ImageSize = (UINT32) (Pcir->ImageLength * 512);\r
Indicator = Pcir->Indicator;\r
\r
- if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) && \r
+ if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&\r
(EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)) {\r
\r
if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
(EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)) {\r
\r
if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
}\r
\r
if (!SkipImage) {\r
}\r
\r
if (!SkipImage) {\r
- // \r
- // Build full device path to the PCI Option ROM Image being loaded\r
- mPciOptionRomImageDevicePathNodeTemplate.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)RomBarOffset;\r
- mPciOptionRomImageDevicePathNodeTemplate.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(RomBarOffset + ImageSize - 1);\r
+ // Build Memory Mapped device path node to record the image offset into the PCI Option ROM\r
+ //\r
+ mPciOptionRomImageDevicePathNodeTemplate.StartingAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (RomBarOffset - (UINT8 *) RomBar);\r
+ mPciOptionRomImageDevicePathNodeTemplate.EndingAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (RomBarOffset + ImageSize - 1 - (UINT8 *) RomBar);\r
PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, (const EFI_DEVICE_PATH_PROTOCOL *)&mPciOptionRomImageDevicePathNodeTemplate);\r
ASSERT (PciOptionRomImageDevicePath != NULL);\r
\r
PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, (const EFI_DEVICE_PATH_PROTOCOL *)&mPciOptionRomImageDevicePathNodeTemplate);\r
ASSERT (PciOptionRomImageDevicePath != NULL);\r
\r
IN BOOLEAN BootPolicy,\r
IN VOID *SourceBuffer OPTIONAL,\r
IN UINTN SourceSize,\r
IN BOOLEAN BootPolicy,\r
IN VOID *SourceBuffer OPTIONAL,\r
IN UINTN SourceSize,\r
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
OUT EFI_HANDLE *DeviceHandle,\r
IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
OUT UINT32 *AuthenticationStatus\r
OUT EFI_HANDLE *DeviceHandle,\r
IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
OUT UINT32 *AuthenticationStatus\r
BootPolicy,\r
SourceBuffer,\r
SourceSize,\r
BootPolicy,\r
SourceBuffer,\r
SourceSize,\r
&DeviceHandle,\r
&FHand,\r
&AuthenticationStatus\r
&DeviceHandle,\r
&FHand,\r
&AuthenticationStatus\r
//\r
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath\r
//\r
//\r
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath\r
//\r
+ FilePath = OriginalFilePath;\r
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
if (!EFI_ERROR (Status)) {\r
FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);\r
if (!EFI_ERROR (Status)) {\r
FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-Copyright (c) 2006, Intel Corporation \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
+Copyright (c) 2006 - 2007, Intel Corporation\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
ImageFile.c\r
\r
\r
Abstract:\r
\r
ImageFile.c\r
\r
\r
Abstract:\r
\r
IN BOOLEAN BootPolicy,\r
IN VOID *SourceBuffer OPTIONAL,\r
IN UINTN SourceSize,\r
IN BOOLEAN BootPolicy,\r
IN VOID *SourceBuffer OPTIONAL,\r
IN UINTN SourceSize,\r
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
OUT EFI_HANDLE *DeviceHandle,\r
IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
OUT UINT32 *AuthenticationStatus\r
OUT EFI_HANDLE *DeviceHandle,\r
IN IMAGE_FILE_HANDLE *ImageFileHandle,\r
OUT UINT32 *AuthenticationStatus\r
FilePath - The specific file path from which the image is loaded\r
DeviceHandle - Pointer to the return device handle.\r
ImageFileHandle - Pointer to the image file handle.\r
FilePath - The specific file path from which the image is loaded\r
DeviceHandle - Pointer to the return device handle.\r
ImageFileHandle - Pointer to the image file handle.\r
- AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned. \r
- \r
+ AuthenticationStatus - Pointer to a caller-allocated UINT32 in which the authentication status is returned.\r
+\r
Returns:\r
\r
EFI_SUCCESS - Image file successfully opened.\r
Returns:\r
\r
EFI_SUCCESS - Image file successfully opened.\r
EFI_LOAD_ERROR - If the caller passed a copy of the file, and SourceSize is 0.\r
EFI_LOAD_ERROR - If the caller passed a copy of the file, and SourceSize is 0.\r
EFI_INVALID_PARAMETER - File path is not valid.\r
EFI_INVALID_PARAMETER - File path is not valid.\r
EFI_NOT_FOUND - File not found.\r
\r
--*/\r
EFI_NOT_FOUND - File not found.\r
\r
--*/\r
ImageFileHandle->Source = SourceBuffer;\r
ImageFileHandle->SourceSize = SourceSize;\r
*DeviceHandle = NULL;\r
ImageFileHandle->Source = SourceBuffer;\r
ImageFileHandle->SourceSize = SourceSize;\r
*DeviceHandle = NULL;\r
- CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &FilePath, DeviceHandle);\r
+ CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, FilePath, DeviceHandle);\r
if (SourceSize > 0) {\r
Status = EFI_SUCCESS;\r
} else {\r
if (SourceSize > 0) {\r
Status = EFI_SUCCESS;\r
} else {\r
//\r
// Make sure FilePath is valid\r
//\r
//\r
// Make sure FilePath is valid\r
//\r
- if (FilePath == NULL) {\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
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
+ FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) *FilePath;\r
Status = CoreDevicePathToInterface (\r
Status = CoreDevicePathToInterface (\r
- &gEfiFirmwareVolume2ProtocolGuid, \r
- (EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode, \r
- (VOID*)&FwVol, \r
+ &gEfiFirmwareVolume2ProtocolGuid,\r
+ (EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode,\r
+ (VOID*)&FwVol,\r
DeviceHandle\r
);\r
if (!EFI_ERROR (Status)) {\r
DeviceHandle\r
);\r
if (!EFI_ERROR (Status)) {\r
SectionType = EFI_SECTION_PE32;\r
Pe32Buffer = NULL;\r
Status = FwVol->ReadSection (\r
SectionType = EFI_SECTION_PE32;\r
Pe32Buffer = NULL;\r
Status = FwVol->ReadSection (\r
- FwVol, \r
- NameGuid, \r
- SectionType, \r
+ FwVol,\r
+ NameGuid,\r
+ SectionType,\r
0,\r
(VOID **)&Pe32Buffer,\r
&Pe32BufferSize,\r
0,\r
(VOID **)&Pe32Buffer,\r
&Pe32BufferSize,\r
}\r
Pe32Buffer = NULL;\r
Status = FwVol->ReadFile (\r
}\r
Pe32Buffer = NULL;\r
Status = FwVol->ReadFile (\r
- FwVol, \r
- NameGuid, \r
(VOID **)&Pe32Buffer,\r
&Pe32BufferSize,\r
&Type,\r
(VOID **)&Pe32Buffer,\r
&Pe32BufferSize,\r
&Type,\r
AuthenticationStatus\r
);\r
}\r
AuthenticationStatus\r
);\r
}\r
if (!EFI_ERROR (Status)) {\r
//\r
// One of the reads passed so we are done\r
if (!EFI_ERROR (Status)) {\r
//\r
// One of the reads passed so we are done\r
//\r
// Attempt to access the file via a file system interface\r
//\r
//\r
// Attempt to access the file via a file system interface\r
//\r
- FilePathNode = (FILEPATH_DEVICE_PATH *) FilePath;\r
+ FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath;\r
Status = CoreDevicePathToInterface (\r
Status = CoreDevicePathToInterface (\r
- &gEfiSimpleFileSystemProtocolGuid, \r
- (EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode, \r
- (VOID*)&Volume, \r
+ &gEfiSimpleFileSystemProtocolGuid,\r
+ (EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode,\r
+ (VOID*)&Volume,\r
DeviceHandle\r
);\r
if (!EFI_ERROR (Status)) {\r
DeviceHandle\r
);\r
if (!EFI_ERROR (Status)) {\r
//\r
Status = Volume->OpenVolume (Volume, &FileHandle);\r
if (!EFI_ERROR (Status)) {\r
//\r
Status = Volume->OpenVolume (Volume, &FileHandle);\r
if (!EFI_ERROR (Status)) {\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
//\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
FileHandle,\r
&gEfiFileInfoGuid,\r
&FileInfoSize,\r
FileHandle,\r
&gEfiFileInfoGuid,\r
&FileInfoSize,\r
);\r
}\r
if (!EFI_ERROR (Status)) {\r
);\r
}\r
if (!EFI_ERROR (Status)) {\r
\r
\r
//\r
// Try LoadFile style\r
//\r
\r
\r
\r
//\r
// Try LoadFile style\r
//\r
\r
- TempFilePath = FilePath;\r
+ TempFilePath = *FilePath;\r
Status = CoreDevicePathToInterface (\r
&gEfiLoadFileProtocolGuid,\r
&TempFilePath,\r
Status = CoreDevicePathToInterface (\r
&gEfiLoadFileProtocolGuid,\r
&TempFilePath,\r
Arguments:\r
\r
UserHandle - Image file handle\r
Arguments:\r
\r
UserHandle - Image file handle\r
Offset - Offset to the source file\r
Offset - Offset to the source file\r
ReadSize - For input, pointer of size to read;\r
For output, pointer of size actually read.\r
ReadSize - For input, pointer of size to read;\r
For output, pointer of size actually read.\r
Buffer - Buffer to write into\r
\r
Returns:\r
Buffer - Buffer to write into\r
\r
Returns:\r
EndPosition = Offset + *ReadSize;\r
if (EndPosition > FHand->SourceSize) {\r
*ReadSize = (UINT32)(FHand->SourceSize - Offset);\r
EndPosition = Offset + *ReadSize;\r
if (EndPosition > FHand->SourceSize) {\r
*ReadSize = (UINT32)(FHand->SourceSize - Offset);\r
if (Offset >= FHand->SourceSize) {\r
*ReadSize = 0;\r
}\r
if (Offset >= FHand->SourceSize) {\r
*ReadSize = 0;\r
}\r
Arguments:\r
\r
Protocol - The protocol to search for\r
Arguments:\r
\r
Protocol - The protocol to search for\r
FilePath - The specified device path\r
FilePath - The specified device path\r
Interface - Interface of the protocol on the handle\r
Interface - Interface of the protocol on the handle\r
Handle - The handle to the device on the specified device path that supports the protocol.\r
Handle - The handle to the device on the specified device path that supports the protocol.\r
Returns:\r
\r
Status code.\r
Returns:\r
\r
Status code.\r
Routine Description:\r
\r
Helper function called as part of the code needed\r
Routine Description:\r
\r
Helper function called as part of the code needed\r
- to allocate the proper sized buffer for various \r
+ to allocate the proper sized buffer for various\r
EFI interfaces.\r
\r
Arguments:\r
EFI interfaces.\r
\r
Arguments:\r
Buffer - Current allocated buffer, or NULL\r
\r
BufferSize - Current buffer size needed\r
Buffer - Current allocated buffer, or NULL\r
\r
BufferSize - Current buffer size needed\r
- \r
- TRUE - if the buffer was reallocated and the caller \r
+\r
+ TRUE - if the buffer was reallocated and the caller\r
should try the API again.\r
\r
FALSE - buffer could not be allocated and the caller\r
should try the API again.\r
\r
FALSE - buffer could not be allocated and the caller\r
//\r
// If the status code is "buffer too small", resize the buffer\r
//\r
//\r
// If the status code is "buffer too small", resize the buffer\r
//\r
if (*Status == EFI_BUFFER_TOO_SMALL) {\r
if (*Buffer != NULL) {\r
CoreFreePool (*Buffer);\r
if (*Status == EFI_BUFFER_TOO_SMALL) {\r
if (*Buffer != NULL) {\r
CoreFreePool (*Buffer);\r
*Buffer = CoreAllocateBootServicesPool (BufferSize);\r
if (*Buffer != NULL) {\r
TryAgain = TRUE;\r
*Buffer = CoreAllocateBootServicesPool (BufferSize);\r
if (*Buffer != NULL) {\r
TryAgain = TRUE;\r
*Status = EFI_OUT_OF_RESOURCES;\r
*Status = EFI_OUT_OF_RESOURCES;\r