X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FGenVtf%2FGenVtf.c;h=b68d86a97eb935a16760237d0cb83e2a0378a245;hb=90114c101f2149ec02f7ba66af78addc2d72cb2e;hp=72fb109fa6505eadfb9c8271e22a50365c81680e;hpb=52302d4dee589a5df43a464420c9fe68ba83937d;p=mirror_edk2.git diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf/GenVtf.c index 72fb109fa6..b68d86a97e 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -1,6 +1,8 @@ -/** +/** @file +This file contains functions required to generate a boot strap file (BSF) also +known as the Volume Top File (VTF) -Copyright (c) 1999-2010 Intel Corporation. All rights reserved +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 @@ -9,16 +11,6 @@ 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: - - GenVtf.c - -Abstract: - - This file contains functions required to generate a boot strap file (BSF) - also known as the Volume Top File (VTF) - **/ // @@ -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; @@ -797,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) { @@ -1063,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); @@ -1125,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. @@ -1134,7 +1135,6 @@ Returns: EFI_STATUS Status; UINT64 CompStartAddress; UINT64 FileSize; - UINT64 NumByteRead; UINT64 NumAdjustByte; UINT8 *Buffer; FILE *Fp; @@ -1146,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); @@ -1182,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 @@ -1193,7 +1193,7 @@ Returns: } } - NumByteRead = fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); + fread (Buffer, sizeof (UINT8), (UINTN) FileSize, Fp); fclose (Fp); // @@ -1241,6 +1241,10 @@ Returns: } GetNextAvailableFitPtr (&CompFitPtr); + if (CompFitPtr == NULL) { + free (Buffer); + return EFI_ABORTED; + } CompFitPtr->CompAddress = CompStartAddress | IPF_CACHE_BIT; if ((FileSize % 16) != 0) { @@ -1322,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); @@ -1360,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 @@ -1372,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); @@ -1546,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; @@ -1717,7 +1720,7 @@ Returns: --*/ { - if ((BaseAddress >= 0) && (FwVolSize > 0x40) && ((BaseAddress + FwVolSize) % 8 == 0)) { + if ((FwVolSize > 0x40) && ((BaseAddress + FwVolSize) % 8 == 0)) { return EFI_SUCCESS; } @@ -1752,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); @@ -1777,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); @@ -2114,7 +2116,6 @@ Returns: FILE *Fp; UINT64 *StartAddressPtr; UINTN FirstFwVSize; - UINTN NumByte; StartAddressPtr = malloc (sizeof (UINT64)); if (StartAddressPtr == NULL) { @@ -2122,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); @@ -2134,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); @@ -2180,12 +2181,12 @@ 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; @@ -2199,7 +2200,7 @@ Returns: // // Open the source file // - SourceFile = fopen (SourceFileName, "r"); + SourceFile = fopen (LongFilePath (SourceFileName), "r"); if (SourceFile == NULL) { // @@ -2218,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); @@ -2249,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; } @@ -2376,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 @@ -2407,7 +2408,7 @@ Returns: // // Copyright declaration // - fprintf (stdout, "Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.\n\n"); + fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n"); // // Details Option // @@ -2543,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; @@ -2656,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) {