X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FGenVtf%2FGenVtf.c;h=b68d86a97eb935a16760237d0cb83e2a0378a245;hb=90114c101f2149ec02f7ba66af78addc2d72cb2e;hp=eafbcbf0023df9d7fd435445529d5239d0a89110;hpb=fd171542e0aa89ac12a09d79608173f48019b14b;p=mirror_edk2.git diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf/GenVtf.c index eafbcbf002..b68d86a97e 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -1,23 +1,15 @@ -/** +/** @file +This file contains functions required to generate a boot strap file (BSF) also +known as the Volume Top File (VTF) -Copyright (c) 1999 - 2008, 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 - 2016, 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 - -Module Name: - - GenVtf.c - -Abstract: - - This file contains functions required to generate a boot strap file (BSF) - also known as the Volume Top File (VTF) +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ @@ -105,44 +97,51 @@ ConvertVersionInfo ( /*++ Routine Description: - This function converts GUID string to GUID + This function split version to major version and minor version Arguments: Str - String representing in form XX.XX - MajorVer - The major vertion - MinorVer - The minor vertion + MajorVer - The major version + MinorVer - The minor version Returns: - EFI_SUCCESS - The fuction completed successfully. + EFI_SUCCESS - The function completed successfully. --*/ { - CHAR8 StrPtr[40]; - CHAR8 *Token; - UINTN Length; + CHAR8 TemStr[5] = "0000"; unsigned Major; unsigned Minor; + UINTN Length; Major = 0; Minor = 0; - memset (StrPtr, 0, 40); - Token = strtok (Str, "."); - while (Token != NULL) { - strcat (StrPtr, Token); - Token = strtok (NULL, "."); + if (strstr (Str, ".") != NULL) { + sscanf ( + Str, + "%02x.%02x", + &Major, + &Minor + ); + } else { + Length = strlen(Str); + if (Length < 4) { + strncpy (TemStr + 4 - Length, Str, Length); + } else { + strncpy (TemStr, Str + Length - 4, 4); + } + + sscanf ( + TemStr, + "%02x%02x", + &Major, + &Minor + ); } - Length = strlen (StrPtr); - sscanf ( - StrPtr, - "%01x%02x", - &Major, - &Minor - ); - *MajorVer = (UINT8) Major; *MinorVer = (UINT8) Minor; return EFI_SUCCESS; @@ -342,7 +341,6 @@ Returns: VtfInfo->LocationType = SECOND_VTF; } else { VtfInfo->LocationType = NONE; - Warning(UTILITY_NAME, 0, 0001, "Unknown location for component.", VtfInfo->CompName); } } else if (strnicmp (*TokenStr, "COMP_TYPE", 9) == 0) { TokenStr++; @@ -798,6 +796,7 @@ Returns: TmpFitPtr = (FIT_TABLE *) RelativeAddress; NumFitComponents = TmpFitPtr->CompSize; + *FitPtr = NULL; for (Index = 0; Index < NumFitComponents; Index++) { if ((TmpFitPtr->CvAndType & FIT_TYPE_MASK) == COMP_TYPE_FIT_UNUSED) { @@ -1064,7 +1063,7 @@ Returns: CHAR8 Buff5[10]; CHAR8 Token[50]; - Fp = fopen (VtfInfo->CompSymName, "rb"); + Fp = fopen (LongFilePath (VtfInfo->CompSymName), "rb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompSymName); @@ -1126,6 +1125,7 @@ Returns: EFI_ABORTED - Aborted due to one of the many reasons like: (a) Component Size greater than the specified size. (b) Error opening files. + (c) Fail to get the FIT table address. EFI_INVALID_PARAMETER Value returned from call to UpdateEntryPoint() EFI_OUT_OF_RESOURCES Memory allocation failure. @@ -1135,7 +1135,6 @@ Returns: EFI_STATUS Status; UINT64 CompStartAddress; UINT64 FileSize; - UINT64 NumByteRead; UINT64 NumAdjustByte; UINT8 *Buffer; FILE *Fp; @@ -1147,7 +1146,7 @@ Returns: return EFI_SUCCESS; } - Fp = fopen (VtfInfo->CompBinName, "rb"); + Fp = fopen (LongFilePath (VtfInfo->CompBinName), "rb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompBinName); @@ -1183,7 +1182,7 @@ Returns: // // Read first 64 bytes of PAL header and use it to find version info // - NumByteRead = fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp); + fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp); // // PAL header contains the version info. Currently, we will use the header @@ -1194,7 +1193,7 @@ Returns: } } - NumByteRead = fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); + fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); fclose (Fp); // @@ -1242,6 +1241,10 @@ Returns: } GetNextAvailableFitPtr (&CompFitPtr); + if (CompFitPtr == NULL) { + free (Buffer); + return EFI_ABORTED; + } CompFitPtr->CompAddress = CompStartAddress | IPF_CACHE_BIT; if ((FileSize % 16) != 0) { @@ -1267,7 +1270,7 @@ Returns: // // Update the SYM file for this component based on it's start address. // - Status = UpdateSymFile (CompStartAddress, SymFileName, VtfInfo->CompSymName); + Status = UpdateSymFile (CompStartAddress, SymFileName, VtfInfo->CompSymName, FileSize); if (EFI_ERROR (Status)) { // @@ -1323,12 +1326,11 @@ Returns: UINT64 AbsAddress; UINTN RelativeAddress; UINT64 FileSize; - UINT64 NumByteRead; UINT8 *Buffer; FILE *Fp; FIT_TABLE *PalFitPtr; - Fp = fopen (VtfInfo->CompBinName, "rb"); + Fp = fopen (LongFilePath (VtfInfo->CompBinName), "rb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", VtfInfo->CompBinName); @@ -1361,7 +1363,7 @@ Returns: // // Read, Get version Info and discard the PAL header. // - NumByteRead = fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp); + fread (Buffer, sizeof (UINT8), SIZE_OF_PAL_HEADER, Fp); // // Extract the version info from header of PAL_A. Once done, discrad this buffer @@ -1373,7 +1375,7 @@ Returns: // // Read PAL_A file in a buffer // - NumByteRead = fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); + fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); fclose (Fp); PalStartAddress = Fv1EndAddress - (SIZE_TO_OFFSET_PAL_A_END + FileSize); @@ -1406,7 +1408,7 @@ Returns: // // Update the SYM file for this component based on it's start address. // - Status = UpdateSymFile (PalStartAddress, SymFileName, VtfInfo->CompSymName); + Status = UpdateSymFile (PalStartAddress, SymFileName, VtfInfo->CompSymName, FileSize); if (EFI_ERROR (Status)) { // @@ -1547,7 +1549,7 @@ Returns: VtfBuffer = (VOID *) RelativeAddress; } - Fp = fopen (FileName, "wb"); + Fp = fopen (LongFilePath (FileName), "wb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", FileName); return EFI_ABORTED; @@ -1688,7 +1690,7 @@ Returns: FileHeader->IntegrityCheck.Checksum.File = 0; FileHeader->State = 0; FileHeader->IntegrityCheck.Checksum.Header = CalculateChecksum8 ((UINT8 *) FileHeader, sizeof (EFI_FFS_FILE_HEADER)); - FileHeader->IntegrityCheck.Checksum.File = CalculateChecksum8 ((UINT8 *) FileHeader, TotalVtfSize); + FileHeader->IntegrityCheck.Checksum.File = CalculateChecksum8 ((UINT8 *) (FileHeader + 1), TotalVtfSize - sizeof (EFI_FFS_FILE_HEADER)); FileHeader->State = EFI_FILE_HEADER_CONSTRUCTION | EFI_FILE_HEADER_VALID | EFI_FILE_DATA_VALID; return EFI_SUCCESS; @@ -1718,7 +1720,7 @@ Returns: --*/ { - if ((BaseAddress >= 0) && (FwVolSize > 0x40) && ((BaseAddress + FwVolSize) % 8 == 0)) { + if ((FwVolSize > 0x40) && ((BaseAddress + FwVolSize) % 8 == 0)) { return EFI_SUCCESS; } @@ -1753,14 +1755,13 @@ Returns: UINT8 *Buffer; UINT8 *LocalVtfBuffer; UINTN FileSize; - UINTN NumByteRead; FILE *Fp; if (!strcmp (FileName, "")) { return EFI_INVALID_PARAMETER; } - Fp = fopen (FileName, "rb"); + Fp = fopen (LongFilePath (FileName), "rb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", FileName); @@ -1778,7 +1779,7 @@ Returns: return EFI_OUT_OF_RESOURCES; } - NumByteRead = fread (Buffer, sizeof (UINT8), FileSize, Fp); + fread (Buffer, sizeof (UINT8), FileSize, Fp); LocalVtfBuffer = (UINT8 *) Vtf1EndBuffer - SIZE_IA32_RESET_VECT; memcpy (LocalVtfBuffer, Buffer, FileSize); @@ -2115,7 +2116,6 @@ Returns: FILE *Fp; UINT64 *StartAddressPtr; UINTN FirstFwVSize; - UINTN NumByte; StartAddressPtr = malloc (sizeof (UINT64)); if (StartAddressPtr == NULL) { @@ -2123,7 +2123,7 @@ Returns: } *StartAddressPtr = StartAddress; - Fp = fopen (OutFileName1, "rb"); + Fp = fopen (LongFilePath (OutFileName1), "rb"); if (Fp == NULL) { Error (NULL, 0, 0001, "Error opening file", OutFileName1); @@ -2135,7 +2135,7 @@ Returns: FirstFwVSize = _filelength (fileno (Fp)); fseek (Fp, (long) (FirstFwVSize - (UINTN) (SIZE_IA32_RESET_VECT + SIZE_SALE_ENTRY_POINT)), SEEK_SET); - NumByte = fwrite ((VOID *) StartAddressPtr, sizeof (UINT64), 1, Fp); + fwrite ((VOID *) StartAddressPtr, sizeof (UINT64), 1, Fp); if (Fp) { fclose (Fp); @@ -2153,7 +2153,9 @@ EFI_STATUS UpdateSymFile ( IN UINT64 BaseAddress, IN CHAR8 *DestFileName, - IN CHAR8 *SourceFileName + IN CHAR8 *SourceFileName, + IN UINT64 FileSize + ) /*++ @@ -2167,6 +2169,7 @@ Arguments: BaseAddress - The base address for the new SYM tokens. DestFileName - The destination file. SourceFileName - The source file. + FileSize - Size of bin file. Returns: @@ -2178,14 +2181,14 @@ Returns: { FILE *SourceFile; FILE *DestFile; - CHAR8 Buffer[_MAX_PATH]; - CHAR8 Type[_MAX_PATH]; - CHAR8 Address[_MAX_PATH]; - CHAR8 Section[_MAX_PATH]; - CHAR8 Token[_MAX_PATH]; - CHAR8 BaseToken[_MAX_PATH]; + CHAR8 Buffer[MAX_LONG_FILE_PATH]; + CHAR8 Type[MAX_LONG_FILE_PATH]; + CHAR8 Address[MAX_LONG_FILE_PATH]; + CHAR8 Section[MAX_LONG_FILE_PATH]; + CHAR8 Token[MAX_LONG_FILE_PATH]; + CHAR8 BaseToken[MAX_LONG_FILE_PATH]; UINT64 TokenAddress; - long StartLocation; + long StartLocation; // // Verify input parameters. @@ -2197,7 +2200,7 @@ Returns: // // Open the source file // - SourceFile = fopen (SourceFileName, "r"); + SourceFile = fopen (LongFilePath (SourceFileName), "r"); if (SourceFile == NULL) { // @@ -2216,7 +2219,7 @@ Returns: // // Open the destination file // - DestFile = fopen (DestFileName, "a+"); + DestFile = fopen (LongFilePath (DestFileName), "a+"); if (DestFile == NULL) { fclose (SourceFile); Error (NULL, 0, 0001, "Error opening file", DestFileName); @@ -2247,7 +2250,7 @@ Returns: // // Read the first line // - if (fgets (Buffer, _MAX_PATH, SourceFile) == NULL) { + if (fgets (Buffer, MAX_LONG_FILE_PATH, SourceFile) == NULL) { Buffer[0] = 0; } @@ -2275,13 +2278,20 @@ Returns: // Get the token address // AsciiStringToUint64 (Address, TRUE, &TokenAddress); + if (TokenAddress > FileSize) { + // + // Symbol offset larger than FileSize. This Symbol can't be in Bin file. Don't print them. + // + break; + } // // Add the base address, the size of the FFS file header and the size of the peim header. // TokenAddress += BaseAddress &~IPF_CACHE_BIT; - fprintf (DestFile, "%s | %016llX | %s | %s%s\n", Type, (unsigned long long) TokenAddress, Section, BaseToken, Token); + fprintf (DestFile, "%s | %016llX | ", Type, (unsigned long long) TokenAddress); + fprintf (DestFile, "%s | %s\n %s\n", Section, Token, BaseToken); } } @@ -2367,7 +2377,7 @@ Returns: --*/ { - fprintf (stdout, "%s Version %d.%d\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION); + fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION); } VOID @@ -2398,7 +2408,7 @@ Returns: // // Copyright declaration // - fprintf (stdout, "Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.\n\n"); + fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n"); // // Details Option // @@ -2534,7 +2544,7 @@ Returns: // Get the input VTF file name // VtfFileName = argv[Index+1]; - VtfFP = fopen(VtfFileName, "rb"); + VtfFP = fopen (LongFilePath (VtfFileName), "rb"); if (VtfFP == NULL) { Error (NULL, 0, 0001, "Error opening file", VtfFileName); goto ERROR; @@ -2647,21 +2657,26 @@ Returns: } SymFileName = VTF_SYM_FILE; } else { + assert (OutFileName1); INTN OutFileNameLen = strlen(OutFileName1); - INTN Index; + INTN NewIndex; - for (Index = OutFileNameLen; Index > 0; --Index) { - if (OutFileName1[Index] == '/' || OutFileName1[Index] == '\\') { + for (NewIndex = OutFileNameLen; NewIndex > 0; --NewIndex) { + if (OutFileName1[NewIndex] == '/' || OutFileName1[NewIndex] == '\\') { break; } } - if (Index == 0) { + if (NewIndex == 0) { SymFileName = VTF_SYM_FILE; } else { - INTN SymFileNameLen = Index + 1 + strlen(VTF_SYM_FILE); + INTN SymFileNameLen = NewIndex + 1 + strlen(VTF_SYM_FILE); SymFileName = malloc(SymFileNameLen + 1); - memcpy(SymFileName, OutFileName1, Index + 1); - memcpy(SymFileName + Index + 1, VTF_SYM_FILE, strlen(VTF_SYM_FILE)); + if (SymFileName == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!"); + goto ERROR; + } + memcpy(SymFileName, OutFileName1, NewIndex + 1); + memcpy(SymFileName + NewIndex + 1, VTF_SYM_FILE, strlen(VTF_SYM_FILE)); SymFileName[SymFileNameLen] = '\0'; } if (DebugMode) {