X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FTianoTools%2FPeiRebase%2FPeiRebaseExe.c;h=cc07fa06bb98aa2b2f0fc217af961aea1f6d9a2a;hp=7dc95d60afd4182abb9a0ecb8afe680c32643e4e;hb=5049fd31d6b79c5cfabc9d7c9d971d4c1720a6bf;hpb=4df60ea54fd2ee5bf97586f453165ab3533a1aec diff --git a/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c b/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c index 7dc95d60af..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,19 +22,19 @@ Abstract: --*/ -#include -#include #include #include #include + +#include +#include +#include +#include + #include "CommonLib.h" #include "ParseInf.h" #include "FvLib.h" - #include "EfiUtilityMsgs.h" -#include "FirmwareFileSystem.h" -#include "PeCoffLib.h" - #include "PeiRebaseExe.h" EFI_STATUS @@ -63,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: @@ -83,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; @@ -109,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; @@ -121,7 +127,9 @@ Returns: ErasePolarity = FALSE; InputFile = NULL; OutputFile = NULL; + MapFile = NULL; FvImage = NULL; + // // Parse the command line arguments // @@ -186,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"); @@ -193,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 // @@ -247,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) { @@ -275,6 +306,7 @@ Returns: goto Finish; } + // // Get the next file // @@ -314,6 +346,10 @@ Finish: fclose (OutputFile); } + if (MapFile != NULL) { + fclose (MapFile); + } + if (FvImage != NULL) { free (FvImage); } @@ -450,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 ) /*++ @@ -476,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: @@ -516,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. @@ -526,6 +566,7 @@ Returns: } else { TailSize = 0; } + // // 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); return EFI_INVALID_PARAMETER; } + + memset (&ImageContext, 0, sizeof (ImageContext)); + // // Check if XIP file type. If not XIP, don't rebase. // @@ -544,6 +588,7 @@ Returns: ) { return EFI_SUCCESS; } + // // 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; }