X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FTianoTools%2FPeiRebase%2FPeiRebaseExe.c;h=cc07fa06bb98aa2b2f0fc217af961aea1f6d9a2a;hp=e9511644a67f46dac7d3a0aa15ed8d09e0449040;hb=5049fd31d6b79c5cfabc9d7c9d971d4c1720a6bf;hpb=51d48c2666aac102c522f38609d6017f6fcdd6b1 diff --git a/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c b/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c index e9511644a6..cc07fa06bb 100644 --- a/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c +++ b/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c @@ -1,13 +1,13 @@ /*++ -Copyright (c) 1999 - 2005 Intel Corporation. All rights reserved -This software and associated documentation (if any) is furnished -under a license and may only be used or copied in accordance -with the terms of the license. Except as permitted by such -license, no part of this software or documentation may be -reproduced, stored in a retrieval system, or transmitted in any -form or by any means without the express written consent of -Intel Corporation. +Copyright (c) 1999-2006 Intel Corporation. All rights reserved +This program and the accompanying materials 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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: @@ -22,24 +22,21 @@ Abstract: --*/ -#include -#include #include #include #include + +#include +#include +#include +#include + #include "CommonLib.h" #include "ParseInf.h" -// #include #include "FvLib.h" - #include "EfiUtilityMsgs.h" -#include "FirmwareFileSystem.h" -#include "PeCoffLib.h" - #include "PeiRebaseExe.h" -extern PEI_PE_COFF_LOADER_PROTOCOL mPeCoffLoader; - EFI_STATUS ReadHeader ( IN FILE *InputFile, @@ -66,11 +63,13 @@ Arguments: format is a hex number preceded by 0x. InputFileName The name of the input 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. -I InputFileName -O OutputFileName -B BaseAddress + -M MapFileName Returns: @@ -86,11 +85,13 @@ Returns: UINT8 Index; CHAR8 InputFileName[_MAX_PATH]; CHAR8 OutputFileName[_MAX_PATH]; + CHAR8 MapFileName[_MAX_PATH]; EFI_PHYSICAL_ADDRESS BaseAddress; BOOLEAN BaseAddressSet; EFI_STATUS Status; FILE *InputFile; FILE *OutputFile; + FILE *MapFile; UINT64 FvOffset; UINT32 FileCount; int BytesRead; @@ -112,11 +113,13 @@ Returns: PrintUsage (); return STATUS_ERROR; } + // // Initialize variables // InputFileName[0] = 0; OutputFileName[0] = 0; + MapFileName[0] = 0; BaseAddress = 0; BaseAddressSet = FALSE; FvOffset = 0; @@ -124,7 +127,9 @@ Returns: ErasePolarity = FALSE; InputFile = NULL; OutputFile = NULL; + MapFile = NULL; FvImage = NULL; + // // Parse the command line arguments // @@ -189,6 +194,17 @@ Returns: } 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: PrintUsage (); Error (NULL, 0, 0, argv[Index], "unrecognized argument"); @@ -196,6 +212,18 @@ Returns: 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 // @@ -250,7 +278,7 @@ Returns: // Rebase this file // CurrentFileBaseAddress = BaseAddress + ((UINTN) CurrentFile - (UINTN) FvImage); - Status = FfsRebase (CurrentFile, CurrentFileBaseAddress); + Status = FfsRebase (CurrentFile, CurrentFileBaseAddress, MapFile); if (EFI_ERROR (Status)) { switch (Status) { @@ -278,6 +306,7 @@ Returns: goto Finish; } + // // Get the next file // @@ -317,6 +346,10 @@ Finish: fclose (OutputFile); } + if (MapFile != NULL) { + fclose (MapFile); + } + if (FvImage != NULL) { free (FvImage); } @@ -453,20 +486,22 @@ Returns: --*/ { printf ( - "Usage: %s -I InputFileName -O OutputFileName -B BaseAddress\n", + "Usage: %s -I InputFileName -O OutputFileName -B BaseAddress [-M MapFile]\n", UTILITY_NAME ); printf (" Where:\n"); printf (" InputFileName is the name of the EFI FV file to rebase.\n"); printf (" OutputFileName is the desired output file name.\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"); } EFI_STATUS FfsRebase ( IN OUT EFI_FFS_FILE_HEADER *FfsFile, - IN EFI_PHYSICAL_ADDRESS BaseAddress + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN FILE *MapFile OPTIONAL ) /*++ @@ -479,6 +514,7 @@ Arguments: FfsFile A pointer to Ffs file image. BaseAddress The base address to use for rebasing the file image. + MapFile Optional file to dump relocation information into Returns: @@ -491,7 +527,7 @@ Returns: --*/ { EFI_STATUS Status; - EFI_PEI_PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; UINTN MemoryImagePointer; UINTN MemoryImagePointerAligned; EFI_PHYSICAL_ADDRESS ImageAddress; @@ -519,6 +555,7 @@ Returns: 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. @@ -529,6 +566,7 @@ Returns: } else { TailSize = 0; } + // // Do some cursory checks on the FFS file contents // @@ -537,6 +575,9 @@ Returns: Error (NULL, 0, 0, "file does not appear to be a valid FFS file, cannot be rebased", FileGuidString); return EFI_INVALID_PARAMETER; } + + memset (&ImageContext, 0, sizeof (ImageContext)); + // // Check if XIP file type. If not XIP, don't rebase. // @@ -547,6 +588,7 @@ Returns: ) { return EFI_SUCCESS; } + // // Rebase each PE32 section // @@ -570,9 +612,9 @@ Returns: // memset (&ImageContext, 0, sizeof (ImageContext)); ImageContext.Handle = (VOID *) ((UINTN) CurrentPe32Section.Pe32Section + sizeof (EFI_PE32_SECTION)); - ImageContext.ImageRead = (EFI_PEI_PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead; + ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead; - Status = mPeCoffLoader.GetImageInfo (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderGetImageInfo (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "GetImageInfo() call failed on rebase", FileGuidString); @@ -593,7 +635,7 @@ Returns: ImageContext.ImageAddress = MemoryImagePointerAligned; - Status = mPeCoffLoader.LoadImage (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderLoadImage (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "LoadImage() call failed on rebase", FileGuidString); free ((VOID *) MemoryImagePointer); @@ -601,7 +643,7 @@ Returns: } ImageContext.DestinationAddress = NewPe32BaseAddress; - Status = mPeCoffLoader.RelocateImage (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderRelocateImage (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "RelocateImage() call failed on rebase", FileGuidString); free ((VOID *) MemoryImagePointer); @@ -802,9 +844,9 @@ Returns: // memset (&ImageContext, 0, sizeof (ImageContext)); ImageContext.Handle = (VOID *) TEBuffer; - ImageContext.ImageRead = (EFI_PEI_PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead; + ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead; - Status = mPeCoffLoader.GetImageInfo (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderGetImageInfo (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "GetImageInfo() call failed on rebase of TE image", FileGuidString); @@ -825,7 +867,7 @@ Returns: ImageContext.ImageAddress = MemoryImagePointerAligned; - Status = mPeCoffLoader.LoadImage (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderLoadImage (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "LoadImage() call failed on rebase of TE image", FileGuidString); free (TEBuffer); @@ -834,7 +876,7 @@ Returns: } ImageContext.DestinationAddress = NewPe32BaseAddress; - Status = mPeCoffLoader.RelocateImage (&mPeCoffLoader, &ImageContext); + Status = PeCoffLoaderRelocateImage (&ImageContext); if (EFI_ERROR (Status)) { Error (NULL, 0, 0, "RelocateImage() call failed on rebase of TE image", FileGuidString); free ((VOID *) MemoryImagePointer); @@ -931,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; }