X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=BaseTools%2FSource%2FC%2FGenFfs%2FGenFfs.c;h=52092e36e74e36520a7cb792388798159a6d3712;hb=97fa0ee9b1cffbb4b97ee35365afa7afcf50e174;hp=e8cd09e947600a8a7c08b0246e7f1ad5267df1e5;hpb=30fdf1140b8d1ce93f3821d986fa165552023440;p=mirror_edk2.git diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c index e8cd09e947..52092e36e7 100644 --- a/BaseTools/Source/C/GenFfs/GenFfs.c +++ b/BaseTools/Source/C/GenFfs/GenFfs.c @@ -1,7 +1,8 @@ -/** +/** @file +This file contains functions required to generate a Firmware File System file. -Copyright (c) 2004-2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2014, 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 @@ -9,15 +10,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: - - GenFfs.c - -Abstract: - - This file contains functions required to generate a Firmware File System - file. - **/ #include @@ -87,7 +79,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); } STATIC @@ -119,7 +111,7 @@ Returns: // // Copyright declaration // - fprintf (stdout, "Copyright (c) 2007, Intel Corporation. All rights reserved.\n\n"); + fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n"); // // Details Option @@ -134,6 +126,8 @@ Returns: EFI_FV_FILETYPE_PEI_CORE, EFI_FV_FILETYPE_DXE_CORE,\n\ EFI_FV_FILETYPE_DRIVER, EFI_FV_FILETYPE_APPLICATION,\n\ EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,\n\ + EFI_FV_FILETYPE_SMM, EFI_FV_FILETYPE_SMM_CORE,\n\ + EFI_FV_FILETYPE_COMBINED_SMM_DXE, \n\ EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE.\n"); fprintf (stdout, " -g FileGuid, --fileguid FileGuid\n\ FileGuid is one module guid.\n\ @@ -282,9 +276,12 @@ Returns: UINT32 Index; FILE *InFile; EFI_COMMON_SECTION_HEADER *SectHeader; - EFI_COMMON_SECTION_HEADER TempSectHeader; + EFI_COMMON_SECTION_HEADER2 TempSectHeader; EFI_TE_IMAGE_HEADER TeHeader; UINT32 TeOffset; + EFI_GUID_DEFINED_SECTION GuidSectHeader; + EFI_GUID_DEFINED_SECTION2 GuidSectHeader2; + UINT32 HeaderSize; Size = 0; Offset = 0; @@ -312,7 +309,7 @@ Returns: // // Open file and read contents // - InFile = fopen (InputFileName[Index], "rb"); + InFile = fopen (LongFilePath (InputFileName[Index]), "rb"); if (InFile == NULL) { Error (NULL, 0, 0001, "Error opening file", InputFileName[Index]); return EFI_ABORTED; @@ -322,13 +319,18 @@ Returns: FileSize = ftell (InFile); fseek (InFile, 0, SEEK_SET); DebugMsg (NULL, 0, 9, "Input section files", - "the input section name is %s and the size is %d bytes", InputFileName[Index], FileSize); + "the input section name is %s and the size is %u bytes", InputFileName[Index], (unsigned) FileSize); // // Check this section is Te/Pe section, and Calculate the numbers of Te/Pe section. // TeOffset = 0; - fread (&TempSectHeader, 1, sizeof (TempSectHeader), InFile); + if (FileSize >= MAX_FFS_SIZE) { + HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER2); + } else { + HeaderSize = sizeof (EFI_COMMON_SECTION_HEADER); + } + fread (&TempSectHeader, 1, HeaderSize, InFile); if (TempSectHeader.Type == EFI_SECTION_TE) { (*PESectionNum) ++; fread (&TeHeader, 1, sizeof (TeHeader), InFile); @@ -337,8 +339,21 @@ Returns: } } else if (TempSectHeader.Type == EFI_SECTION_PE32) { (*PESectionNum) ++; + } else if (TempSectHeader.Type == EFI_SECTION_GUID_DEFINED) { + fseek (InFile, 0, SEEK_SET); + if (FileSize >= MAX_SECTION_SIZE) { + fread (&GuidSectHeader2, 1, sizeof (GuidSectHeader2), InFile); + if ((GuidSectHeader2.Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) { + HeaderSize = GuidSectHeader2.DataOffset; + } + } else { + fread (&GuidSectHeader, 1, sizeof (GuidSectHeader), InFile); + if ((GuidSectHeader.Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == 0) { + HeaderSize = GuidSectHeader.DataOffset; + } + } + (*PESectionNum) ++; } else if (TempSectHeader.Type == EFI_SECTION_COMPRESSION || - TempSectHeader.Type == EFI_SECTION_GUID_DEFINED || TempSectHeader.Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) { // // for the encapsulated section, assume it contains Pe/Te section @@ -356,17 +371,21 @@ Returns: TeOffset = InputFileAlign [Index] - (TeOffset % InputFileAlign [Index]); TeOffset = TeOffset % InputFileAlign [Index]; } - + // // make sure section data meet its alignment requirement by adding one raw pad section. // But the different sections have the different section header. Necessary or not? // Based on section type to adjust offset? Todo // - if ((InputFileAlign [Index] != 0) && (((Size + sizeof (EFI_COMMON_SECTION_HEADER) + TeOffset) % InputFileAlign [Index]) != 0)) { - Offset = (Size + 2 * sizeof (EFI_COMMON_SECTION_HEADER) + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1); - Offset = Offset - Size - sizeof (EFI_COMMON_SECTION_HEADER) - TeOffset; + if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize + TeOffset) % InputFileAlign [Index]) != 0)) { + Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1); + Offset = Offset - Size - HeaderSize - TeOffset; if (FileBuffer != NULL && ((Size + Offset) < *BufferLength)) { + // + // The maximal alignment is 64K, the raw section size must be less than 0xffffff + // + memset (FileBuffer + Size, 0, Offset); SectHeader = (EFI_COMMON_SECTION_HEADER *) (FileBuffer + Size); SectHeader->Type = EFI_SECTION_RAW; SectHeader->Size[0] = (UINT8) (Offset & 0xff); @@ -374,7 +393,7 @@ Returns: SectHeader->Size[2] = (UINT8) ((Offset & 0xff0000) >> 16); } DebugMsg (NULL, 0, 9, "Pad raw section for section data alignment", - "Pad Raw section size is %d", Offset); + "Pad Raw section size is %u", (unsigned) Offset); Size = Size + Offset; } @@ -409,7 +428,7 @@ Returns: int main ( - INT32 argc, + int argc, CHAR8 *argv[] ) /*++ @@ -441,11 +460,12 @@ Returns: UINT8 *FileBuffer; UINT32 FileSize; UINT32 MaxAlignment; - EFI_FFS_FILE_HEADER FfsFileHeader; + EFI_FFS_FILE_HEADER2 FfsFileHeader; FILE *FfsFile; UINT32 Index; UINT64 LogLevel; UINT8 PeSectionNum; + UINT32 HeaderSize; // // Init local variables @@ -679,7 +699,7 @@ Returns: goto Finish; } if (LogLevel > 9) { - Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", LogLevel); + Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel); goto Finish; } SetPrintLevel (LogLevel); @@ -719,7 +739,7 @@ Returns: VerboseMsg ("Fv File type is %s", mFfsFileType [FfsFiletype]); VerboseMsg ("Output file name is %s", OutputFileName); VerboseMsg ("FFS File Guid is %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", - FileGuid.Data1, + (unsigned) FileGuid.Data1, FileGuid.Data2, FileGuid.Data3, FileGuid.Data4[0], @@ -744,7 +764,7 @@ Returns: // InputFileAlign[Index] = 1; } - VerboseMsg ("the %dth input section name is %s and section alignment is %d", Index, InputFileName[Index], InputFileAlign[Index]); + VerboseMsg ("the %dth input section name is %s and section alignment is %u", Index, InputFileName[Index], (unsigned) InputFileAlign[Index]); } // @@ -763,7 +783,7 @@ Returns: if ((FfsFiletype == EFI_FV_FILETYPE_SECURITY_CORE || FfsFiletype == EFI_FV_FILETYPE_PEI_CORE || FfsFiletype == EFI_FV_FILETYPE_DXE_CORE) && (PeSectionNum != 1)) { - Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have one and only one Pe or Te section, but %d Pe/Te section are input", mFfsFileType [FfsFiletype], PeSectionNum); + Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have one and only one Pe or Te section, but %u Pe/Te section are input", mFfsFileType [FfsFiletype], PeSectionNum); goto Finish; } @@ -804,13 +824,13 @@ Returns: // // Create Ffs file header. // - memset (&FfsFileHeader, 0, sizeof (EFI_FFS_FILE_HEADER)); + memset (&FfsFileHeader, 0, sizeof (EFI_FFS_FILE_HEADER2)); memcpy (&FfsFileHeader.Name, &FileGuid, sizeof (EFI_GUID)); FfsFileHeader.Type = FfsFiletype; // // Update FFS Alignment based on the max alignment required by input section files // - VerboseMsg ("the max alignment of all input sections is %d", MaxAlignment); + VerboseMsg ("the max alignment of all input sections is %u", (unsigned) MaxAlignment); for (Index = 0; Index < sizeof (mFfsValidAlign) / sizeof (UINT32) - 1; Index ++) { if ((MaxAlignment > mFfsValidAlign [Index]) && (MaxAlignment <= mFfsValidAlign [Index + 1])) { break; @@ -819,17 +839,28 @@ Returns: if (FfsAlign < Index) { FfsAlign = Index; } - VerboseMsg ("the alignment of the genreated FFS file is %d", mFfsValidAlign [FfsAlign + 1]); - FfsFileHeader.Attributes = FfsAttrib | (FfsAlign << 3); + VerboseMsg ("the alignment of the generated FFS file is %u", (unsigned) mFfsValidAlign [FfsAlign + 1]); // // Now FileSize includes the EFI_FFS_FILE_HEADER // - FileSize += sizeof (EFI_FFS_FILE_HEADER); - VerboseMsg ("the size of the genreated FFS file is %d bytes", FileSize); - FfsFileHeader.Size[0] = (UINT8) (FileSize & 0xFF); - FfsFileHeader.Size[1] = (UINT8) ((FileSize & 0xFF00) >> 8); - FfsFileHeader.Size[2] = (UINT8) ((FileSize & 0xFF0000) >> 16); + if (FileSize + sizeof (EFI_FFS_FILE_HEADER) >= MAX_FFS_SIZE) { + HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); + FileSize += sizeof (EFI_FFS_FILE_HEADER2); + FfsFileHeader.ExtendedSize = FileSize; + memset(FfsFileHeader.Size, 0, sizeof (UINT8) * 3); + FfsAttrib |= FFS_ATTRIB_LARGE_FILE; + } else { + HeaderSize = sizeof (EFI_FFS_FILE_HEADER); + FileSize += sizeof (EFI_FFS_FILE_HEADER); + FfsFileHeader.Size[0] = (UINT8) (FileSize & 0xFF); + FfsFileHeader.Size[1] = (UINT8) ((FileSize & 0xFF00) >> 8); + FfsFileHeader.Size[2] = (UINT8) ((FileSize & 0xFF0000) >> 16); + } + VerboseMsg ("the size of the generated FFS file is %u bytes", (unsigned) FileSize); + + FfsFileHeader.Attributes = (EFI_FFS_FILE_ATTRIBUTES) (FfsAttrib | (FfsAlign << 3)); + // // Fill in checksums and state, these must be zero for checksumming // @@ -839,7 +870,7 @@ Returns: // FfsFileHeader.IntegrityCheck.Checksum.Header = CalculateChecksum8 ( (UINT8 *) &FfsFileHeader, - sizeof (EFI_FFS_FILE_HEADER) + HeaderSize ); if (FfsFileHeader.Attributes & FFS_ATTRIB_CHECKSUM) { @@ -848,7 +879,7 @@ Returns: // FfsFileHeader.IntegrityCheck.Checksum.File = CalculateChecksum8 ( FileBuffer, - FileSize - sizeof (EFI_FFS_FILE_HEADER) + FileSize - HeaderSize ); } else { FfsFileHeader.IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM; @@ -860,7 +891,7 @@ Returns: // Open output file to write ffs data. // remove(OutputFileName); - FfsFile = fopen (OutputFileName, "wb"); + FfsFile = fopen (LongFilePath (OutputFileName), "wb"); if (FfsFile == NULL) { Error (NULL, 0, 0001, "Error opening file", OutputFileName); goto Finish; @@ -868,11 +899,11 @@ Returns: // // write header // - fwrite (&FfsFileHeader, 1, sizeof (FfsFileHeader), FfsFile); + fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile); // // write data // - fwrite (FileBuffer, 1, FileSize - sizeof (EFI_FFS_FILE_HEADER), FfsFile); + fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile); fclose (FfsFile);