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