Updated PeiRebase to produce a map file of the relocations done by this tool

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1192 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ajfish 2006-08-05 17:22:18 +00:00
parent 8d86099955
commit 5049fd31d6
2 changed files with 63 additions and 5 deletions

View File

@ -63,11 +63,13 @@ Arguments:
format is a hex number preceded by 0x. format is a hex number preceded by 0x.
InputFileName The name of the input FV file. InputFileName The name of the input FV file.
OutputFileName The name of the output FV file. OutputFileName The name of the output FV file.
MapFileName The name of the map file of relocation info.
Arguments come in pair in any order. Arguments come in pair in any order.
-I InputFileName -I InputFileName
-O OutputFileName -O OutputFileName
-B BaseAddress -B BaseAddress
-M MapFileName
Returns: Returns:
@ -83,11 +85,13 @@ Returns:
UINT8 Index; UINT8 Index;
CHAR8 InputFileName[_MAX_PATH]; CHAR8 InputFileName[_MAX_PATH];
CHAR8 OutputFileName[_MAX_PATH]; CHAR8 OutputFileName[_MAX_PATH];
CHAR8 MapFileName[_MAX_PATH];
EFI_PHYSICAL_ADDRESS BaseAddress; EFI_PHYSICAL_ADDRESS BaseAddress;
BOOLEAN BaseAddressSet; BOOLEAN BaseAddressSet;
EFI_STATUS Status; EFI_STATUS Status;
FILE *InputFile; FILE *InputFile;
FILE *OutputFile; FILE *OutputFile;
FILE *MapFile;
UINT64 FvOffset; UINT64 FvOffset;
UINT32 FileCount; UINT32 FileCount;
int BytesRead; int BytesRead;
@ -109,11 +113,13 @@ Returns:
PrintUsage (); PrintUsage ();
return STATUS_ERROR; return STATUS_ERROR;
} }
// //
// Initialize variables // Initialize variables
// //
InputFileName[0] = 0; InputFileName[0] = 0;
OutputFileName[0] = 0; OutputFileName[0] = 0;
MapFileName[0] = 0;
BaseAddress = 0; BaseAddress = 0;
BaseAddressSet = FALSE; BaseAddressSet = FALSE;
FvOffset = 0; FvOffset = 0;
@ -121,7 +127,9 @@ Returns:
ErasePolarity = FALSE; ErasePolarity = FALSE;
InputFile = NULL; InputFile = NULL;
OutputFile = NULL; OutputFile = NULL;
MapFile = NULL;
FvImage = NULL; FvImage = NULL;
// //
// Parse the command line arguments // Parse the command line arguments
// //
@ -186,6 +194,17 @@ Returns:
} }
break; break;
case 'M':
case 'm':
if (strlen (MapFileName) == 0) {
strcpy (MapFileName, argv[Index + 1]);
} else {
PrintUsage ();
Error (NULL, 0, 0, argv[Index + 1], "only one -m MapFileName may be specified");
return STATUS_ERROR;
}
break;
default: default:
PrintUsage (); PrintUsage ();
Error (NULL, 0, 0, argv[Index], "unrecognized argument"); Error (NULL, 0, 0, argv[Index], "unrecognized argument");
@ -193,6 +212,18 @@ Returns:
break; break;
} }
} }
//
// Create the Map file if we need it
//
if (strlen (MapFileName) != 0) {
MapFile = fopen (MapFileName, "w");
if (MapFile == NULL) {
Error (NULL, 0, 0, MapFileName, "failed to open map file");
goto Finish;
}
}
// //
// Open the file containing the FV // Open the file containing the FV
// //
@ -247,7 +278,7 @@ Returns:
// Rebase this file // Rebase this file
// //
CurrentFileBaseAddress = BaseAddress + ((UINTN) CurrentFile - (UINTN) FvImage); CurrentFileBaseAddress = BaseAddress + ((UINTN) CurrentFile - (UINTN) FvImage);
Status = FfsRebase (CurrentFile, CurrentFileBaseAddress); Status = FfsRebase (CurrentFile, CurrentFileBaseAddress, MapFile);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
switch (Status) { switch (Status) {
@ -275,6 +306,7 @@ Returns:
goto Finish; goto Finish;
} }
// //
// Get the next file // Get the next file
// //
@ -314,6 +346,10 @@ Finish:
fclose (OutputFile); fclose (OutputFile);
} }
if (MapFile != NULL) {
fclose (MapFile);
}
if (FvImage != NULL) { if (FvImage != NULL) {
free (FvImage); free (FvImage);
} }
@ -450,20 +486,22 @@ Returns:
--*/ --*/
{ {
printf ( printf (
"Usage: %s -I InputFileName -O OutputFileName -B BaseAddress\n", "Usage: %s -I InputFileName -O OutputFileName -B BaseAddress [-M MapFile]\n",
UTILITY_NAME UTILITY_NAME
); );
printf (" Where:\n"); printf (" Where:\n");
printf (" InputFileName is the name of the EFI FV file to rebase.\n"); printf (" InputFileName is the name of the EFI FV file to rebase.\n");
printf (" OutputFileName is the desired output file name.\n"); printf (" OutputFileName is the desired output file name.\n");
printf (" BaseAddress is the FV base address to rebase agains.\n"); printf (" BaseAddress is the FV base address to rebase agains.\n");
printf (" MapFileName is an optional map file of the relocations\n");
printf (" Argument pair may be in any order.\n\n"); printf (" Argument pair may be in any order.\n\n");
} }
EFI_STATUS EFI_STATUS
FfsRebase ( FfsRebase (
IN OUT EFI_FFS_FILE_HEADER *FfsFile, IN OUT EFI_FFS_FILE_HEADER *FfsFile,
IN EFI_PHYSICAL_ADDRESS BaseAddress IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN FILE *MapFile OPTIONAL
) )
/*++ /*++
@ -476,6 +514,7 @@ Arguments:
FfsFile A pointer to Ffs file image. FfsFile A pointer to Ffs file image.
BaseAddress The base address to use for rebasing the file image. BaseAddress The base address to use for rebasing the file image.
MapFile Optional file to dump relocation information into
Returns: Returns:
@ -516,6 +555,7 @@ Returns:
if (FfsFile == NULL) { if (FfsFile == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// //
// Convert the GUID to a string so we can at least report which file // Convert the GUID to a string so we can at least report which file
// if we find an error. // if we find an error.
@ -526,6 +566,7 @@ Returns:
} else { } else {
TailSize = 0; TailSize = 0;
} }
// //
// Do some cursory checks on the FFS file contents // Do some cursory checks on the FFS file contents
// //
@ -534,6 +575,9 @@ Returns:
Error (NULL, 0, 0, "file does not appear to be a valid FFS file, cannot be rebased", FileGuidString); Error (NULL, 0, 0, "file does not appear to be a valid FFS file, cannot be rebased", FileGuidString);
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
memset (&ImageContext, 0, sizeof (ImageContext));
// //
// Check if XIP file type. If not XIP, don't rebase. // Check if XIP file type. If not XIP, don't rebase.
// //
@ -544,6 +588,7 @@ Returns:
) { ) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// Rebase each PE32 section // Rebase each PE32 section
// //
@ -928,6 +973,18 @@ Returns:
} }
} }
//
// If a map file was selected output mapping information for any file that
// was rebased.
//
if (MapFile != NULL) {
fprintf (MapFile, "File: %s Base:%08lx", FileGuidString, BaseAddress);
if (ImageContext.PdbPointer != NULL) {
fprintf (MapFile, " FileName: %s", ImageContext.PdbPointer);
}
fprintf (MapFile, "\n");
}
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -43,7 +43,7 @@ Abstract:
// //
// The maximum number of arguments accepted from the command line. // The maximum number of arguments accepted from the command line.
// //
#define MAX_ARGS 7 #define MAX_ARGS 9
// //
// The file copy buffer size // The file copy buffer size
@ -131,7 +131,8 @@ Returns:
EFI_STATUS EFI_STATUS
FfsRebase ( FfsRebase (
IN OUT EFI_FFS_FILE_HEADER *FfsFile, IN OUT EFI_FFS_FILE_HEADER *FfsFile,
IN EFI_PHYSICAL_ADDRESS BaseAddress IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN FILE *MapFile OPTIONAL
) )
/*++ /*++