/** @file\r
This file contains functions required to generate a Firmware File System file.\r
\r
-Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
STATIC EFI_GUID mEfiFfsSectionAlignmentPaddingGuid = EFI_FFS_SECTION_ALIGNMENT_PADDING_GUID;\r
\r
STATIC\r
-VOID \r
+VOID\r
Version (\r
VOID\r
)\r
Arguments:\r
\r
None\r
- \r
+\r
Returns:\r
\r
None\r
- \r
---*/ \r
+\r
+--*/\r
{\r
fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
}\r
// Summary usage\r
//\r
fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);\r
- \r
+\r
//\r
// Copyright declaration\r
- // \r
- fprintf (stdout, "Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.\n\n");\r
+ //\r
+ fprintf (stdout, "Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.\n\n");\r
\r
//\r
// Details Option\r
--*/\r
{\r
UINT8 Index = 0;\r
- \r
+\r
if (String == NULL) {\r
return EFI_FV_FILETYPE_ALL;\r
}\r
OUT UINT8 *PESectionNum\r
)\r
/*++\r
- \r
+\r
Routine Description:\r
- \r
+\r
Get the contents of all section files specified in InputFileName\r
into FileBuffer.\r
- \r
+\r
Arguments:\r
- \r
+\r
InputFileName - Name of the input file.\r
- \r
+\r
InputFileAlign - Alignment required by the input file data.\r
\r
InputFileNum - Number of input files. Should be at least 1.\r
\r
FileBuffer - Output buffer to contain data\r
\r
- BufferLength - On input, this is size of the FileBuffer. \r
+ BufferLength - On input, this is size of the FileBuffer.\r
On output, this is the actual length of the data.\r
\r
MaxAlignment - The max alignment required by all the input file datas.\r
- \r
+\r
PeSectionNum - Calculate the number of Pe/Te Section in this FFS file.\r
\r
Returns:\r
- \r
+\r
EFI_SUCCESS on successful return\r
EFI_INVALID_PARAMETER if InputFileNum is less than 1 or BufferLength point is NULL.\r
EFI_ABORTED if unable to open input file.\r
while ((Size & 0x03) != 0) {\r
Size++;\r
}\r
- \r
- // \r
+\r
+ //\r
// Open file and read contents\r
//\r
InFile = fopen (LongFilePath (InputFileName[Index]), "rb");\r
fseek (InFile, 0, SEEK_END);\r
FileSize = ftell (InFile);\r
fseek (InFile, 0, SEEK_SET);\r
- DebugMsg (NULL, 0, 9, "Input section files", \r
- "the input section name is %s and the size is %u bytes", InputFileName[Index], (unsigned) FileSize); \r
+ DebugMsg (NULL, 0, 9, "Input section files",\r
+ "the input section name is %s and the size is %u bytes", InputFileName[Index], (unsigned) FileSize);\r
\r
//\r
// Check this section is Te/Pe section, and Calculate the numbers of Te/Pe section.\r
}\r
}\r
(*PESectionNum) ++;\r
- } else if (TempSectHeader.Type == EFI_SECTION_COMPRESSION || \r
+ } else if (TempSectHeader.Type == EFI_SECTION_COMPRESSION ||\r
TempSectHeader.Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) {\r
//\r
- // for the encapsulated section, assume it contains Pe/Te section \r
+ // for the encapsulated section, assume it contains Pe/Te section\r
//\r
(*PESectionNum) ++;\r
}\r
if ((InputFileAlign [Index] != 0) && (((Size + HeaderSize + TeOffset) % InputFileAlign [Index]) != 0)) {\r
Offset = (Size + sizeof (EFI_COMMON_SECTION_HEADER) + HeaderSize + TeOffset + InputFileAlign [Index] - 1) & ~(InputFileAlign [Index] - 1);\r
Offset = Offset - Size - HeaderSize - TeOffset;\r
- \r
+\r
if (FileBuffer != NULL && ((Size + Offset) < *BufferLength)) {\r
//\r
// The maximal alignment is 64K, the raw section size must be less than 0xffffff\r
SectHeader->CommonHeader.Type = EFI_SECTION_RAW;\r
}\r
}\r
- DebugMsg (NULL, 0, 9, "Pad raw section for section data alignment", \r
+ DebugMsg (NULL, 0, 9, "Pad raw section for section data alignment",\r
"Pad Raw section size is %u", (unsigned) Offset);\r
\r
Size = Size + Offset;\r
// unsigned 32-bit integer plus the size unit character.\r
//\r
CHAR8 AlignmentBuffer[16];\r
- \r
+\r
//\r
// Init local variables\r
//\r
LogLevel = 0;\r
Index = 0;\r
- FfsAttrib = 0; \r
+ FfsAttrib = 0;\r
FfsAlign = 0;\r
FfsFiletype = EFI_FV_FILETYPE_ALL;\r
OutputFileName = NULL;\r
if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {\r
Version ();\r
Usage ();\r
- return STATUS_SUCCESS; \r
+ return STATUS_SUCCESS;\r
}\r
\r
if (stricmp (argv[0], "--version") == 0) {\r
Version ();\r
- return STATUS_SUCCESS; \r
+ return STATUS_SUCCESS;\r
}\r
\r
while (argc > 0) {\r
}\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--outputfile") == 0)) {\r
OutputFileName = argv[1];\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-g") == 0) || (stricmp (argv[0], "--fileguid") == 0)) {\r
return STATUS_ERROR;\r
}\r
memset (InputFileName, 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (CHAR8 *)));\r
- \r
+\r
InputFileAlign = (UINT32 *) malloc (MAXIMUM_INPUT_FILE_NUM * sizeof (UINT32));\r
if (InputFileAlign == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
InputFileName,\r
(InputFileNum + MAXIMUM_INPUT_FILE_NUM) * sizeof (CHAR8 *)\r
);\r
- \r
+\r
if (InputFileName == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
free (InputFileAlign);\r
InputFileAlign,\r
(InputFileNum + MAXIMUM_INPUT_FILE_NUM) * sizeof (UINT32)\r
);\r
- \r
+\r
if (InputFileAlign == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
free (InputFileName);\r
}\r
memset (&(InputFileAlign[InputFileNum]), 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (UINT32)));\r
}\r
- \r
+\r
InputFileName[InputFileNum] = argv[1];\r
argc -= 2;\r
argv += 2;\r
\r
if (argc <= 0) {\r
- InputFileNum ++;\r
+ InputFileNum ++;\r
break;\r
}\r
- \r
+\r
//\r
// Section File alignment requirement\r
//\r
argv += 2;\r
}\r
InputFileNum ++;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--sectionalign") == 0)) {\r
//\r
if (FfsFiletype == EFI_FV_FILETYPE_ALL) {\r
Error (NULL, 0, 1001, "Missing option", "filetype");\r
- goto Finish; \r
+ goto Finish;\r
}\r
\r
if (CompareGuid (&FileGuid, &mZeroGuid) == 0) {\r
Error (NULL, 0, 1001, "Missing option", "fileguid");\r
- goto Finish; \r
+ goto Finish;\r
}\r
\r
if (InputFileNum == 0) {\r
Error (NULL, 0, 1001, "Missing option", "Input files");\r
goto Finish;\r
}\r
- \r
+\r
//\r
// Output input parameter information\r
//\r
VerboseMsg ("Fv File type is %s", mFfsFileType [FfsFiletype]);\r
VerboseMsg ("Output file name is %s", OutputFileName);\r
- VerboseMsg ("FFS File Guid is %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", \r
+ VerboseMsg ("FFS File Guid is %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",\r
(unsigned) FileGuid.Data1,\r
FileGuid.Data2,\r
FileGuid.Data3,\r
}\r
VerboseMsg ("the %dth input section name is %s and section alignment is %u", Index, InputFileName[Index], (unsigned) InputFileAlign[Index]);\r
}\r
- \r
+\r
//\r
// Calculate the size of all input section files.\r
- // \r
+ //\r
Status = GetSectionContents (\r
InputFileName,\r
InputFileAlign,\r
&MaxAlignment,\r
&PeSectionNum\r
);\r
- \r
- if ((FfsFiletype == EFI_FV_FILETYPE_SECURITY_CORE || \r
+\r
+ if ((FfsFiletype == EFI_FV_FILETYPE_SECURITY_CORE ||\r
FfsFiletype == EFI_FV_FILETYPE_PEI_CORE ||\r
FfsFiletype == EFI_FV_FILETYPE_DXE_CORE) && (PeSectionNum != 1)) {\r
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);\r
goto Finish;\r
}\r
- \r
+\r
if ((FfsFiletype == EFI_FV_FILETYPE_PEIM ||\r
FfsFiletype == EFI_FV_FILETYPE_DRIVER ||\r
FfsFiletype == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER ||\r
FfsFiletype == EFI_FV_FILETYPE_APPLICATION) && (PeSectionNum < 1)) {\r
Error (NULL, 0, 2000, "Invalid parameter", "Fv File type %s must have at least one Pe or Te section, but no Pe/Te section is input", mFfsFileType [FfsFiletype]);\r
- goto Finish; \r
+ goto Finish;\r
}\r
\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
goto Finish;\r
}\r
memset (FileBuffer, 0, FileSize);\r
- \r
+\r
//\r
// read all input file contents into a buffer\r
//\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
goto Finish;\r
}\r
- \r
+\r
//\r
// Create Ffs file header.\r
//\r
memcpy (&FfsFileHeader.Name, &FileGuid, sizeof (EFI_GUID));\r
FfsFileHeader.Type = FfsFiletype;\r
//\r
- // Update FFS Alignment based on the max alignment required by input section files \r
+ // Update FFS Alignment based on the max alignment required by input section files\r
//\r
- VerboseMsg ("the max alignment of all input sections is %u", (unsigned) MaxAlignment); \r
+ VerboseMsg ("the max alignment of all input sections is %u", (unsigned) MaxAlignment);\r
for (Index = 0; Index < sizeof (mFfsValidAlign) / sizeof (UINT32) - 1; Index ++) {\r
if ((MaxAlignment > mFfsValidAlign [Index]) && (MaxAlignment <= mFfsValidAlign [Index + 1])) {\r
break;\r
if (FfsAlign < Index) {\r
FfsAlign = Index;\r
}\r
- VerboseMsg ("the alignment of the generated FFS file is %u", (unsigned) mFfsValidAlign [FfsAlign + 1]); \r
- \r
+ VerboseMsg ("the alignment of the generated FFS file is %u", (unsigned) mFfsValidAlign [FfsAlign + 1]);\r
+\r
//\r
// Now FileSize includes the EFI_FFS_FILE_HEADER\r
//\r
// Ffs header checksum = zero, so only need to calculate ffs body.\r
//\r
FfsFileHeader.IntegrityCheck.Checksum.File = CalculateChecksum8 (\r
- FileBuffer, \r
+ FileBuffer,\r
FileSize - HeaderSize\r
- ); \r
+ );\r
} else {\r
FfsFileHeader.IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM;\r
}\r
\r
FfsFileHeader.State = EFI_FILE_HEADER_CONSTRUCTION | EFI_FILE_HEADER_VALID | EFI_FILE_DATA_VALID;\r
- \r
+\r
//\r
// Open output file to write ffs data.\r
//\r