One GenFvImage can handle all archs now.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@459 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
bbahnsen
2006-06-09 21:14:37 +00:00
parent 6de5f959d6
commit 1507f64ec4
3 changed files with 7 additions and 304 deletions

View File

@ -1306,168 +1306,6 @@ Returns:
return EFI_SUCCESS;
}
EFI_STATUS
RebaseFfsFile (
IN OUT EFI_FFS_FILE_HEADER *FfsFile,
IN EFI_PHYSICAL_ADDRESS BaseAddress
)
/*++
Routine Description:
This function determines if a file is XIP and should be rebased. It will
rebase any PE32 sections found in the file using the base address.
Arguments:
FfsFile A pointer to Ffs file image.
BaseAddress The base address to use for rebasing the file image.
Returns:
EFI_SUCCESS The image was properly rebased.
EFI_INVALID_PARAMETER An input parameter is invalid.
EFI_ABORTED An error occurred while rebasing the input file image.
EFI_OUT_OF_RESOURCES Could not allocate a required resource.
--*/
{
EFI_STATUS Status;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
UINTN MemoryImagePointer;
UINTN MemoryImagePointerAligned;
EFI_PHYSICAL_ADDRESS ImageAddress;
UINT64 ImageSize;
EFI_PHYSICAL_ADDRESS EntryPoint;
UINT32 Pe32FileSize;
UINT32 NewPe32BaseAddress;
UINTN Index;
EFI_FILE_SECTION_POINTER CurrentPe32Section;
UINT8 FileGuidString[80];
//
// Verify input parameters
//
if (FfsFile == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Convert the GUID to a string so we can at least report which file
// if we find an error.
//
PrintGuidToBuffer (&FfsFile->Name, FileGuidString, sizeof (FileGuidString), TRUE);
//
// Do some nominal checks on the file, then check for XIP.
//
Status = VerifyFfsFile (FfsFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "invalid FFS file", FileGuidString);
return EFI_INVALID_PARAMETER;
}
if (FfsFile->Type != EFI_FV_FILETYPE_SECURITY_CORE &&
FfsFile->Type != EFI_FV_FILETYPE_PEI_CORE &&
FfsFile->Type != EFI_FV_FILETYPE_PEIM
) {
//
// File is not XIP, so don't rebase
//
return EFI_SUCCESS;
}
//
// Rebase each PE32 section
//
for (Index = 1;; Index++) {
Status = GetSectionByType (FfsFile, EFI_SECTION_PE32, Index, &CurrentPe32Section);
if (EFI_ERROR (Status)) {
break;
}
//
// Calculate the PE32 base address, the FFS file base plus the offset of the PE32 section
//
NewPe32BaseAddress = ((UINT32) BaseAddress) + ((UINTN) CurrentPe32Section.Pe32Section - (UINTN) FfsFile);
//
// Initialize context
//
memset (&ImageContext, 0, sizeof (ImageContext));
ImageContext.Handle = (VOID *) ((UINTN) CurrentPe32Section.Pe32Section + sizeof (EFI_PE32_SECTION));
ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;
Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "GetImageInfo() failed", FileGuidString);
return Status;
}
//
// Allocate a buffer for the image to be loaded into.
//
Pe32FileSize = GetLength (CurrentPe32Section.Pe32Section->CommonHeader.Size);
MemoryImagePointer = (UINTN) (malloc (Pe32FileSize + 0x1000));
MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);
if (MemoryImagePointerAligned == 0) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return EFI_OUT_OF_RESOURCES;
}
//
// bugbug
//
ImageContext.ImageAddress = MemoryImagePointerAligned;
Status = PeCoffLoaderLoadImage (&ImageContext);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "LoadImage() failure", FileGuidString);
free ((VOID *) MemoryImagePointer);
return Status;
}
Status = PeCoffLoaderRelocateImage (&ImageContext);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "RelocateImage() failure", FileGuidString);
free ((VOID *) MemoryImagePointer);
return Status;
}
ImageAddress = ImageContext.ImageAddress;
ImageSize = ImageContext.ImageSize;
EntryPoint = ImageContext.EntryPoint;
if (ImageSize > Pe32FileSize) {
Error (
NULL,
0,
0,
"rebased PE32 is larger than original PE32 image",
"0x%X > 0x%X on file %s",
ImageSize,
Pe32FileSize,
FileGuidString
);
free ((VOID *) MemoryImagePointer);
return EFI_ABORTED;
}
memcpy (CurrentPe32Section.Pe32Section, (VOID *) MemoryImagePointerAligned, Pe32FileSize);
free ((VOID *) MemoryImagePointer);
}
//
// the above for loop will always exit with EFI_NOT_FOUND if it completes
// normally. If Index == 1 at exit, then no PE32 sections were found. If it
// exits with any other error code, then something broke...
//
if (Status != EFI_NOT_FOUND) {
Error (NULL, 0, 0, "failed to parse PE32 section", FileGuidString);
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
AddSymFile (