-/*++\r
+/** @file\r
\r
-Copyright (c) 2004, Intel Corporation \r
+Copyright (c) 2004 - 2008, Intel Corporation \r
All rights reserved. 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
\r
Abstract:\r
\r
- Creates output file that is a properly formed section per the FV spec.\r
+ Creates output file that is a properly formed section per the PI spec.\r
\r
---*/\r
+**/\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
\r
#define MAX_SECTION_SIZE 0x1000000\r
\r
-static CHAR8 *SectionTypeName[] = {\r
+STATIC CHAR8 *mSectionTypeName[] = {\r
NULL, // 0x00 - reserved\r
"EFI_SECTION_COMPRESSION", // 0x01\r
"EFI_SECTION_GUID_DEFINED", // 0x02\r
"EFI_SECTION_PEI_DEPEX" // 0x1B\r
};\r
\r
-static CHAR8 *CompressionTypeName[] = { "PI_NONE", "PI_STD" };\r
-static CHAR8 *GUIDedSectionAttribue[] = { NULL, "PROCESSING_REQUIRED", "AUTH_STATUS_VALID"};\r
+STATIC CHAR8 *mCompressionTypeName[] = { "PI_NONE", "PI_STD" };\r
+\r
+#define EFI_GUIDED_SECTION_NONE 0x80\r
+STATIC CHAR8 *mGUIDedSectionAttribue[] = { "NONE", "PROCESSING_REQUIRED", "AUTH_STATUS_VALID"};\r
\r
//\r
// Crc32 GUID section related definitions.\r
UINT32 CRC32Checksum;\r
} CRC32_SECTION_HEADER;\r
\r
-static EFI_GUID gZeroGuid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};\r
-static EFI_GUID gEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;\r
-\r
-//\r
-// VerboseMode setting\r
-//\r
-static BOOLEAN VerboseMode = FALSE;\r
+STATIC EFI_GUID mZeroGuid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};\r
+STATIC EFI_GUID mEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;\r
\r
STATIC\r
VOID \r
\r
Arguments:\r
\r
- void\r
+ VOID\r
\r
Returns:\r
\r
//\r
// Summary usage\r
//\r
- fprintf (stdout, "Usage: %s [options] [input_file]\n\n", UTILITY_NAME);\r
+ fprintf (stdout, "\nUsage: %s [options] [input_file]\n\n", UTILITY_NAME);\r
\r
//\r
// Copyright declaration\r
EFI_SECTION_USER_INTERFACE, EFI_SECTION_VERSION,\n\\r
EFI_SECTION_FIRMWARE_VOLUME_IMAGE, EFI_SECTION_RAW,\n\\r
EFI_SECTION_FREEFORM_SUBTYPE_GUID,\n\\r
- EFI_SECTION_PEI_DEPEX. if sectiontype is not given, \n\\r
- EFI_SECTION_ALL is default type.\n");\r
+ EFI_SECTION_PEI_DEPEX. if -s option is not given, \n\\r
+ EFI_SECTION_ALL is default section type.\n");\r
fprintf (stdout, " -c [Type], --compress [Type]\n\\r
Compress method type can be PI_NONE or PI_STD.\n\\r
- if Type is not given, PI_STD is default type.\n"); \r
+ if -c option is not given, PI_STD is default type.\n"); \r
fprintf (stdout, " -g GuidValue, --vendor GuidValue\n\\r
GuidValue is one specific vendor guid value.\n\\r
- Its format is 00000000-0000-0000-0000-000000000000\n");\r
+ Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");\r
+ fprintf (stdout, " -l GuidHeaderLength, --HeaderLength GuidHeaderLength\n\\r
+ GuidHeaderLength is the size of header of guided data\n");\r
fprintf (stdout, " -r GuidAttr, --attributes GuidAttr\n\\r
GuidAttr is guid section atttributes, which may be\n\\r
- PROCESSING_REQUIRED or AUTH_STATUS_VALID\n");\r
+ PROCESSING_REQUIRED, AUTH_STATUS_VALID and NONE. \n\\r
+ if -r option is not given, default PROCESSING_REQUIRED\n");\r
fprintf (stdout, " -n String, --name String\n\\r
String is a NULL terminated string used in Ui section.\n");\r
fprintf (stdout, " -j Number, --buildnumber Number\n\\r
Number is an integer value between 0000 and 9999\n\\r
used in Ver section.\n");\r
fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n");\r
+ fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n");\r
+ fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n");\r
fprintf (stdout, " --version Show program's version number and exit.\n");\r
fprintf (stdout, " -h, --help Show this help message and exit.\n");\r
}\r
\r
VOID\r
-Ascii2UnicodeWriteString (\r
+Ascii2UnicodeString (\r
CHAR8 *String,\r
- FILE *OutFile\r
+ CHAR16 *UniString\r
)\r
/*++\r
\r
\r
Arguments:\r
\r
- String - Pointer to string that is written to FILE.\r
- OutFile - Pointer to FILE\r
+ String - Pointer to string that is written to FILE.\r
+ UniString - Pointer to unicode string\r
\r
Returns:\r
\r
\r
--*/\r
{\r
- UINT32 Index;\r
- UINT8 AsciiNull;\r
-\r
- AsciiNull = 0;\r
-\r
+ while (*String != '\0') {\r
+ *(UniString++) = (CHAR16) *(String++);\r
+ }\r
//\r
- // Next, write out the string... Convert ASCII to Unicode in the process.\r
+ // End the UniString with a NULL.\r
//\r
- Index = 0;\r
- do {\r
- fwrite (&String[Index], 1, 1, OutFile);\r
- fwrite (&AsciiNull, 1, 1, OutFile);\r
- } while (String[Index++] != 0);\r
+ *UniString = '\0';\r
} \r
\r
STATUS\r
CHAR8 **InputFileName,\r
UINT32 InputFileNum,\r
UINT8 SectionType,\r
- FILE *OutFile\r
+ UINT8 **OutFileBuffer\r
)\r
/*++\r
\r
\r
SectionType - A valid section type string\r
\r
- OutFile - Output file handle\r
+ OutFileBuffer - Buffer pointer to Output file contents\r
\r
Returns:\r
\r
FILE *InFile;\r
UINT8 *Buffer;\r
UINT32 TotalLength;\r
- EFI_COMMON_SECTION_HEADER CommonSect;\r
+ EFI_COMMON_SECTION_HEADER *CommonSect;\r
STATUS Status;\r
\r
if (InputFileNum > 1) {\r
fseek (InFile, 0, SEEK_END);\r
InputFileLength = ftell (InFile);\r
fseek (InFile, 0, SEEK_SET);\r
- //\r
- // Fill in the fields in the local section header structure\r
- //\r
- CommonSect.Type = (EFI_SECTION_TYPE) SectionType;\r
- TotalLength = sizeof (CommonSect) + InputFileLength;\r
+ DebugMsg (NULL, 0, 9, "Input file", "File name is %s and File size is %d bytes", InputFileName[0], InputFileLength);\r
+ TotalLength = sizeof (EFI_COMMON_SECTION_HEADER) + InputFileLength;\r
//\r
// Size must fit in 3 bytes\r
//\r
Error (NULL, 0, 2000, "Invalid paramter", "%s file size (0x%X) exceeds section size limit(%dM).", InputFileName[0], TotalLength, MAX_SECTION_SIZE>>20);\r
goto Done;\r
}\r
+ VerboseMsg ("the size of the created section file is %d bytes", TotalLength);\r
//\r
- // Now copy the size into the section header and write out the section header\r
+ // Fill in the fields in the local section header structure\r
//\r
- memcpy (&CommonSect.Size, &TotalLength, 3);\r
- fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);\r
+ Buffer = (UINT8 *) malloc ((size_t) TotalLength);\r
+ if (Buffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); \r
+ goto Done;\r
+ }\r
+ CommonSect = (EFI_COMMON_SECTION_HEADER *) Buffer;\r
+ CommonSect->Type = SectionType;\r
+ CommonSect->Size[0] = (UINT8) (TotalLength & 0xff);\r
+ CommonSect->Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
+ CommonSect->Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
+ \r
//\r
- // Allocate a buffer to read in the contents of the input file. Then\r
- // read it in as one block and write it to the output file.\r
+ // read data from the input file.\r
//\r
if (InputFileLength != 0) {\r
- Buffer = (UINT8 *) malloc ((size_t) InputFileLength);\r
- if (Buffer == NULL) {\r
- Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); \r
- goto Done;\r
- }\r
-\r
- if (fread (Buffer, (size_t) InputFileLength, 1, InFile) != 1) {\r
+ if (fread (Buffer + sizeof (EFI_COMMON_SECTION_HEADER), (size_t) InputFileLength, 1, InFile) != 1) {\r
Error (NULL, 0, 0004, "Error reading file", InputFileName[0]);\r
goto Done;\r
}\r
-\r
- if (fwrite (Buffer, (size_t) InputFileLength, 1, OutFile) != 1) {\r
- Error (NULL, 0, 0002, "Error writing file", NULL);\r
- goto Done;\r
- }\r
}\r
\r
+ //\r
+ // Set OutFileBuffer \r
+ //\r
+ *OutFileBuffer = Buffer;\r
Status = STATUS_SUCCESS;\r
\r
Done:\r
fclose (InFile);\r
- if (Buffer != NULL) {\r
- free (Buffer);\r
- }\r
\r
return Status;\r
}\r
fseek (InFile, 0, SEEK_END);\r
FileSize = ftell (InFile);\r
fseek (InFile, 0, SEEK_SET);\r
+ DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and the size is %d bytes", InputFileName[Index], FileSize); \r
//\r
// Now read the contents of the file into the buffer\r
// Buffer must be enough to contain the file content.\r
Size += FileSize;\r
}\r
\r
+ //\r
+ // Set the real required buffer size.\r
+ //\r
if (Size > *BufferLength) {\r
*BufferLength = Size;\r
return EFI_BUFFER_TOO_SMALL;\r
\r
EFI_STATUS\r
GenSectionCompressionSection (\r
- CHAR8 **InputFileName,\r
+ CHAR8 **InputFileName,\r
UINT32 InputFileNum,\r
UINT8 SectCompSubType,\r
- FILE *OutFile\r
+ UINT8 **OutFileBuffer\r
)\r
/*++\r
\r
\r
SectCompSubType - Specify the compression algorithm requested. \r
\r
- OutFile - Output file handle\r
+ OutFileBuffer - Buffer pointer to Output file contents\r
\r
Returns:\r
\r
UINT8 *FileBuffer;\r
UINT8 *OutputBuffer;\r
EFI_STATUS Status;\r
- EFI_COMPRESSION_SECTION CompressionSect;\r
+ EFI_COMPRESSION_SECTION *CompressionSect;\r
COMPRESS_FUNCTION CompressFunction;\r
\r
InputLength = 0;\r
\r
Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
- OutputBuffer = malloc (CompressedLength);\r
+ OutputBuffer = malloc (CompressedLength + sizeof (EFI_COMPRESSION_SECTION));\r
if (!OutputBuffer) {\r
free (FileBuffer);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);\r
+ Status = CompressFunction (FileBuffer, InputLength, OutputBuffer + sizeof (EFI_COMPRESSION_SECTION), &CompressedLength);\r
}\r
\r
free (FileBuffer);\r
}\r
}\r
\r
+ DebugMsg (NULL, 0, 9, "comprss file size", \r
+ "the original section size is %d bytes and the compressed section size is %d bytes", InputLength, CompressedLength);\r
TotalLength = CompressedLength + sizeof (EFI_COMPRESSION_SECTION);\r
if (TotalLength >= MAX_SECTION_SIZE) {\r
Error (NULL, 0, 2000, "Invalid paramter", "The size of all files exceeds section size limit(%dM).", MAX_SECTION_SIZE>>20);\r
}\r
return STATUS_ERROR;\r
}\r
+ VerboseMsg ("the size of the created section file is %d bytes", TotalLength);\r
\r
//\r
// Add the section header for the compressed data\r
//\r
- CompressionSect.CommonHeader.Type = EFI_SECTION_COMPRESSION;\r
- CompressionSect.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
- CompressionSect.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
- CompressionSect.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
- CompressionSect.CompressionType = SectCompSubType;\r
- CompressionSect.UncompressedLength = InputLength;\r
-\r
- fwrite (&CompressionSect, sizeof (CompressionSect), 1, OutFile);\r
- fwrite (FileBuffer, CompressedLength, 1, OutFile);\r
- free (FileBuffer);\r
+ CompressionSect = (EFI_COMPRESSION_SECTION *) FileBuffer;\r
+ \r
+ CompressionSect->CommonHeader.Type = EFI_SECTION_COMPRESSION;\r
+ CompressionSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
+ CompressionSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
+ CompressionSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
+ CompressionSect->CompressionType = SectCompSubType;\r
+ CompressionSect->UncompressedLength = InputLength;\r
+\r
+ //\r
+ // Set OutFileBuffer \r
+ //\r
+ *OutFileBuffer = FileBuffer;\r
+\r
return EFI_SUCCESS;\r
}\r
\r
UINT32 InputFileNum,\r
EFI_GUID *VendorGuid,\r
UINT16 DataAttribute,\r
- FILE *OutFile\r
+ UINT32 DataHeaderSize,\r
+ UINT8 **OutFileBuffer\r
)\r
/*++\r
\r
\r
DataAttribute - Specify attribute for the vendor guid data. \r
\r
- OutFile - Output file handle\r
+ DataHeaderSize- Guided Data Header Size\r
+ \r
+ OutFileBuffer - Buffer pointer to Output file contents\r
\r
Returns:\r
\r
{\r
UINT32 TotalLength;\r
UINT32 InputLength;\r
+ UINT32 Offset;\r
UINT8 *FileBuffer;\r
UINT32 Crc32Checksum;\r
EFI_STATUS Status;\r
- CRC32_SECTION_HEADER Crc32GuidSect;\r
- EFI_GUID_DEFINED_SECTION VendorGuidSect;\r
+ CRC32_SECTION_HEADER *Crc32GuidSect;\r
+ EFI_GUID_DEFINED_SECTION *VendorGuidSect;\r
\r
InputLength = 0;\r
+ Offset = 0;\r
FileBuffer = NULL;\r
+\r
+ if (CompareGuid (VendorGuid, &mEfiCrc32SectionGuid) == 0) {\r
+ Offset = sizeof (CRC32_SECTION_HEADER);\r
+ } else {\r
+ Offset = sizeof (EFI_GUID_DEFINED_SECTION);\r
+ }\r
+\r
//\r
// read all input file contents into a buffer\r
// first get the size of all file contents\r
);\r
\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
- FileBuffer = (UINT8 *) malloc (InputLength);\r
+ FileBuffer = (UINT8 *) malloc (InputLength + Offset);\r
if (FileBuffer == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");\r
return EFI_OUT_OF_RESOURCES;\r
Status = GetSectionContents (\r
InputFileName,\r
InputFileNum,\r
- FileBuffer,\r
+ FileBuffer + Offset,\r
&InputLength\r
);\r
}\r
if (FileBuffer != NULL) {\r
free (FileBuffer);\r
}\r
+ Error (NULL, 0, 0001, "Error opening file for reading", InputFileName[0]);\r
return Status;\r
}\r
\r
+ if (InputLength == 0) {\r
+ Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s can't be zero", InputFileName);\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
//\r
- // Now data is in FileBuffer\r
+ // Now data is in FileBuffer + Offset\r
//\r
- if (CompareGuid (VendorGuid, &gEfiCrc32SectionGuid) == 0) {\r
+ if (CompareGuid (VendorGuid, &mEfiCrc32SectionGuid) == 0) {\r
//\r
// Default Guid section is CRC32.\r
//\r
Crc32Checksum = 0;\r
- CalculateCrc32 (FileBuffer, InputLength, &Crc32Checksum);\r
+ CalculateCrc32 (FileBuffer + Offset, InputLength, &Crc32Checksum);\r
\r
TotalLength = InputLength + sizeof (CRC32_SECTION_HEADER);\r
if (TotalLength >= MAX_SECTION_SIZE) {\r
free (FileBuffer);\r
return STATUS_ERROR;\r
}\r
-\r
- Crc32GuidSect.GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED;\r
- Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
- Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
- Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
- memcpy (&(Crc32GuidSect.GuidSectionHeader.SectionDefinitionGuid), &gEfiCrc32SectionGuid, sizeof (EFI_GUID));\r
- Crc32GuidSect.GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;\r
- Crc32GuidSect.GuidSectionHeader.DataOffset = sizeof (CRC32_SECTION_HEADER);\r
- Crc32GuidSect.CRC32Checksum = Crc32Checksum;\r
- fwrite (&Crc32GuidSect, sizeof (Crc32GuidSect), 1, OutFile); \r
+ \r
+ Crc32GuidSect = (CRC32_SECTION_HEADER *) FileBuffer;\r
+ Crc32GuidSect->GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED;\r
+ Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
+ Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
+ Crc32GuidSect->GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
+ memcpy (&(Crc32GuidSect->GuidSectionHeader.SectionDefinitionGuid), &mEfiCrc32SectionGuid, sizeof (EFI_GUID));\r
+ Crc32GuidSect->GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;\r
+ Crc32GuidSect->GuidSectionHeader.DataOffset = sizeof (CRC32_SECTION_HEADER);\r
+ Crc32GuidSect->CRC32Checksum = Crc32Checksum;\r
+ DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %d", Crc32GuidSect->GuidSectionHeader.DataOffset);\r
\r
} else {\r
TotalLength = InputLength + sizeof (EFI_GUID_DEFINED_SECTION);\r
return STATUS_ERROR;\r
}\r
\r
- VendorGuidSect.CommonHeader.Type = EFI_SECTION_GUID_DEFINED;\r
- VendorGuidSect.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
- VendorGuidSect.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
- VendorGuidSect.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
- memcpy (&(VendorGuidSect.SectionDefinitionGuid), VendorGuid, sizeof (EFI_GUID));\r
- VendorGuidSect.Attributes = DataAttribute;\r
- VendorGuidSect.DataOffset = sizeof (EFI_GUID_DEFINED_SECTION);\r
- fwrite (&VendorGuidSect, sizeof (EFI_GUID_DEFINED_SECTION), 1, OutFile); \r
+ VendorGuidSect = (EFI_GUID_DEFINED_SECTION *) FileBuffer;\r
+ VendorGuidSect->CommonHeader.Type = EFI_SECTION_GUID_DEFINED;\r
+ VendorGuidSect->CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);\r
+ VendorGuidSect->CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);\r
+ VendorGuidSect->CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);\r
+ memcpy (&(VendorGuidSect->SectionDefinitionGuid), VendorGuid, sizeof (EFI_GUID));\r
+ VendorGuidSect->Attributes = DataAttribute;\r
+ VendorGuidSect->DataOffset = sizeof (EFI_GUID_DEFINED_SECTION) + DataHeaderSize;\r
+ DebugMsg (NULL, 0, 9, "Guided section", "Data offset is %d", VendorGuidSect->DataOffset);\r
}\r
-\r
- fwrite (FileBuffer, InputLength, 1, OutFile);\r
- free (FileBuffer);\r
+ VerboseMsg ("the size of the created section file is %d bytes", TotalLength);\r
+ \r
+ //\r
+ // Set OutFileBuffer \r
+ //\r
+ *OutFileBuffer = FileBuffer;\r
\r
return EFI_SUCCESS;\r
}\r
CHAR8 *SectionName;\r
CHAR8 *CompressionName;\r
CHAR8 *StringBuffer;\r
- EFI_GUID VendorGuid = gZeroGuid;\r
+ EFI_GUID VendorGuid = mZeroGuid;\r
INT32 VersionNumber;\r
UINT8 SectType;\r
UINT8 SectCompSubType;\r
UINT16 SectGuidAttribute; \r
- EFI_COMMON_SECTION_HEADER CommonSect;\r
+ UINT64 SectGuidHeaderLength;\r
+ EFI_VERSION_SECTION *VersionSect;\r
+ EFI_USER_INTERFACE_SECTION *UiSect;\r
UINT32 InputLength;\r
- UINT8 *FileBuffer;\r
+ UINT8 *OutFileBuffer;\r
EFI_STATUS Status;\r
+ UINT64 LogLevel;\r
\r
InputFileName = NULL;\r
OutputFileName = NULL;\r
SectType = EFI_SECTION_ALL;\r
SectCompSubType = 0;\r
SectGuidAttribute = 0;\r
- FileBuffer = NULL;\r
+ OutFileBuffer = NULL;\r
InputLength = 0;\r
Status = STATUS_SUCCESS;\r
+ LogLevel = 0;\r
+ SectGuidHeaderLength = 0;\r
+ VersionSect = NULL;\r
+ UiSect = NULL;\r
\r
SetUtilityName (UTILITY_NAME);\r
\r
if (argc == 1) {\r
- Error (NULL, 0, 1001, "Missing options", "Input file");\r
+ Error (NULL, 0, 1001, "Missing options", "No options input");\r
Usage ();\r
return STATUS_ERROR;\r
}\r
while (argc > 0) {\r
if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--SectionType") == 0)) {\r
SectionName = argv[1];\r
+ if (SectionName == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Section Type can't be NULL");\r
+ goto Finish;\r
+ }\r
argc -= 2;\r
argv += 2;\r
continue; \r
\r
if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--outputfile") == 0)) {\r
OutputFileName = argv[1];\r
+ if (OutputFileName == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Output file can't be NULL");\r
+ goto Finish;\r
+ }\r
argc -= 2;\r
argv += 2;\r
continue; \r
\r
if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--compress") == 0)) {\r
CompressionName = argv[1];\r
+ if (CompressionName == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Compression Type can't be NULL");\r
+ goto Finish;\r
+ }\r
argc -= 2;\r
argv += 2;\r
continue;\r
}\r
\r
if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--attributes") == 0)) {\r
- if (stricmp (argv[1], GUIDedSectionAttribue[EFI_GUIDED_SECTION_PROCESSING_REQUIRED]) == 0) {\r
+ if (stricmp (argv[1], mGUIDedSectionAttribue[EFI_GUIDED_SECTION_PROCESSING_REQUIRED]) == 0) {\r
SectGuidAttribute |= EFI_GUIDED_SECTION_PROCESSING_REQUIRED;\r
- } else if (stricmp (argv[1], GUIDedSectionAttribue[EFI_GUIDED_SECTION_AUTH_STATUS_VALID]) == 0) {\r
+ } else if (stricmp (argv[1], mGUIDedSectionAttribue[EFI_GUIDED_SECTION_AUTH_STATUS_VALID]) == 0) {\r
SectGuidAttribute |= EFI_GUIDED_SECTION_AUTH_STATUS_VALID;\r
+ } else if (stricmp (argv[1], mGUIDedSectionAttribue[0]) == 0) {\r
+ //\r
+ // NONE attribute\r
+ //\r
+ SectGuidAttribute |= EFI_GUIDED_SECTION_NONE;\r
} else {\r
Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
goto Finish;\r
continue;\r
}\r
\r
+ if ((stricmp (argv[0], "-l") == 0) || (stricmp (argv[0], "--HeaderLength") == 0)) {\r
+ Status = AsciiStringToUint64 (argv[1], FALSE, &SectGuidHeaderLength);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value for GuidHeaderLength", "%s = %s", argv[0], argv[1]);\r
+ goto Finish;\r
+ }\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue;\r
+ }\r
+\r
if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--name") == 0)) {\r
StringBuffer = argv[1];\r
+ if (StringBuffer == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Name can't be NULL");\r
+ goto Finish;\r
+ }\r
argc -= 2;\r
argv += 2;\r
continue;\r
}\r
\r
if ((stricmp (argv[0], "-j") == 0) || (stricmp (argv[0], "--buildnumber") == 0)) {\r
+ if (argv[1] == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "build number can't be NULL");\r
+ goto Finish;\r
+ }\r
//\r
// Verify string is a integrator number\r
//\r
}\r
\r
if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {\r
- VerboseMode = TRUE;\r
+ SetPrintLevel (VERBOSE_LOG_LEVEL);\r
+ VerboseMsg ("Verbose output Mode Set!");\r
argc --;\r
argv ++;\r
continue;\r
}\r
+\r
+ if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {\r
+ SetPrintLevel (KEY_LOG_LEVEL);\r
+ KeyMsg ("Quiet output Mode Set!");\r
+ argc --;\r
+ argv ++;\r
+ continue;\r
+ }\r
+\r
+ if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {\r
+ Status = AsciiStringToUint64 (argv[1], FALSE, &LogLevel);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+ goto Finish;\r
+ }\r
+ if (LogLevel > 9) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0~9, currnt input level is %d", LogLevel);\r
+ goto Finish;\r
+ }\r
+ SetPrintLevel (LogLevel);\r
+ DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[1]);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue;\r
+ }\r
+\r
//\r
// Get Input file name\r
//\r
argv ++;\r
}\r
\r
- if (VerboseMode) {\r
- fprintf (stdout, "%s tool start.\n", UTILITY_NAME);\r
- }\r
+ VerboseMsg ("%s tool start.", UTILITY_NAME);\r
+\r
//\r
// Parse all command line parameters to get the corresponding section type.\r
//\r
+ VerboseMsg ("Section type is %s", SectionName);\r
if (SectionName == NULL) {\r
//\r
// No specified Section type, default is SECTION_ALL.\r
//\r
SectType = EFI_SECTION_ALL;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_COMPRESSION]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_COMPRESSION]) == 0) {\r
SectType = EFI_SECTION_COMPRESSION;\r
if (CompressionName == NULL) {\r
//\r
// Default is PI_STD compression algorithm.\r
//\r
SectCompSubType = EFI_STANDARD_COMPRESSION;\r
- } else if (stricmp (CompressionName, CompressionTypeName[EFI_NOT_COMPRESSED]) == 0) {\r
+ } else if (stricmp (CompressionName, mCompressionTypeName[EFI_NOT_COMPRESSED]) == 0) {\r
SectCompSubType = EFI_NOT_COMPRESSED;\r
- } else if (stricmp (CompressionName, CompressionTypeName[EFI_STANDARD_COMPRESSION]) == 0) {\r
+ } else if (stricmp (CompressionName, mCompressionTypeName[EFI_STANDARD_COMPRESSION]) == 0) {\r
SectCompSubType = EFI_STANDARD_COMPRESSION;\r
} else {\r
Error (NULL, 0, 1003, "Invalid option value", "--compress = %s", CompressionName);\r
goto Finish;\r
}\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_GUID_DEFINED]) == 0) {\r
+ VerboseMsg ("Compress method is %s", mCompressionTypeName [SectCompSubType]);\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_GUID_DEFINED]) == 0) {\r
SectType = EFI_SECTION_GUID_DEFINED;\r
\r
- if (CompareGuid (&VendorGuid, &gZeroGuid) == 0) {\r
- memcpy (&VendorGuid, &gEfiCrc32SectionGuid, sizeof (EFI_GUID));\r
+ if (CompareGuid (&VendorGuid, &mZeroGuid) == 0) {\r
+ memcpy (&VendorGuid, &mEfiCrc32SectionGuid, sizeof (EFI_GUID));\r
}\r
\r
if (SectGuidAttribute == 0) {\r
SectGuidAttribute = EFI_GUIDED_SECTION_PROCESSING_REQUIRED;\r
}\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_PE32]) == 0) {\r
+ if ((SectGuidAttribute & EFI_GUIDED_SECTION_NONE) != 0) {\r
+ //\r
+ // NONE attribute, clear attribute value.\r
+ //\r
+ SectGuidAttribute = 0;\r
+ }\r
+ VerboseMsg ("Vendor Guid is %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", \r
+ VendorGuid.Data1,\r
+ VendorGuid.Data2,\r
+ VendorGuid.Data3,\r
+ VendorGuid.Data4[0],\r
+ VendorGuid.Data4[1],\r
+ VendorGuid.Data4[2],\r
+ VendorGuid.Data4[3],\r
+ VendorGuid.Data4[4],\r
+ VendorGuid.Data4[5],\r
+ VendorGuid.Data4[6],\r
+ VendorGuid.Data4[7]);\r
+ if ((SectGuidAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) {\r
+ VerboseMsg ("Guid Attribute is %s", mGUIDedSectionAttribue[EFI_GUIDED_SECTION_PROCESSING_REQUIRED]);\r
+ }\r
+ if ((SectGuidAttribute & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) != 0) {\r
+ VerboseMsg ("Guid Attribute is %s", mGUIDedSectionAttribue[EFI_GUIDED_SECTION_AUTH_STATUS_VALID]);\r
+ }\r
+ if (SectGuidHeaderLength != 0) {\r
+ VerboseMsg ("Guid Data Header size is 0x%x", SectGuidHeaderLength);\r
+ }\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_PE32]) == 0) {\r
SectType = EFI_SECTION_PE32;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_PIC]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_PIC]) == 0) {\r
SectType = EFI_SECTION_PIC;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_TE]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_TE]) == 0) {\r
SectType = EFI_SECTION_TE;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_DXE_DEPEX]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_DXE_DEPEX]) == 0) {\r
SectType = EFI_SECTION_DXE_DEPEX;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_VERSION]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_VERSION]) == 0) {\r
SectType = EFI_SECTION_VERSION;\r
if (VersionNumber < 0 || VersionNumber > 9999) {\r
Error (NULL, 0, 1003, "Invalid option value", "%d is not in 0~9999", VersionNumber);\r
goto Finish;\r
}\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_USER_INTERFACE]) == 0) {\r
+ VerboseMsg ("Version section number is %d", VersionNumber);\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_USER_INTERFACE]) == 0) {\r
SectType = EFI_SECTION_USER_INTERFACE;\r
if (StringBuffer[0] == '\0') {\r
Error (NULL, 0, 1001, "Missing option", "user interface string");\r
goto Finish;\r
}\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_COMPATIBILITY16]) == 0) {\r
+ VerboseMsg ("UI section string name is %s", StringBuffer);\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_COMPATIBILITY16]) == 0) {\r
SectType = EFI_SECTION_COMPATIBILITY16;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_FIRMWARE_VOLUME_IMAGE]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_FIRMWARE_VOLUME_IMAGE]) == 0) {\r
SectType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_FREEFORM_SUBTYPE_GUID]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_FREEFORM_SUBTYPE_GUID]) == 0) {\r
SectType = EFI_SECTION_FREEFORM_SUBTYPE_GUID;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_RAW]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_RAW]) == 0) {\r
SectType = EFI_SECTION_RAW;\r
- } else if (stricmp (SectionName, SectionTypeName[EFI_SECTION_PEI_DEPEX]) == 0) {\r
+ } else if (stricmp (SectionName, mSectionTypeName[EFI_SECTION_PEI_DEPEX]) == 0) {\r
SectType = EFI_SECTION_PEI_DEPEX;\r
} else {\r
Error (NULL, 0, 1003, "Invalid option value", "SectionType = %s", SectionName);\r
goto Finish;\r
}\r
\r
+ //\r
+ // GuidValue is only required by Guided section.\r
+ //\r
+ if ((SectType != EFI_SECTION_GUID_DEFINED) && (CompareGuid (&VendorGuid, &mZeroGuid) != 0)) {\r
+ fprintf (stdout, "Warning: the input guid value is not required for this section type %s\n", SectionName);\r
+ }\r
+ \r
+ //\r
+ // Check whether there is input file\r
+ // \r
if ((SectType != EFI_SECTION_VERSION) && (SectType != EFI_SECTION_USER_INTERFACE)) {\r
//\r
- // The input file are required for those section type.\r
+ // The input file are required for other section type.\r
//\r
if (InputFileNum == 0) {\r
Error (NULL, 0, 1001, "Missing options", "Input files");\r
goto Finish;\r
}\r
}\r
- \r
//\r
- // Open output file\r
+ // Check whether there is output file\r
//\r
+ for (Index = 0; Index < InputFileNum; Index ++) {\r
+ VerboseMsg ("the %dth input file name is %s", Index, InputFileName[Index]);\r
+ }\r
if (OutputFileName == NULL) {\r
Error (NULL, 0, 1001, "Missing options", "Output file");\r
goto Finish;\r
// OutFile = stdout;\r
- } else {\r
- OutFile = fopen (OutputFileName, "wb");\r
}\r
+ VerboseMsg ("Output file name is %s", OutputFileName);\r
\r
- if (OutFile == NULL) {\r
- Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
- goto Finish;\r
- }\r
- \r
//\r
// At this point, we've fully validated the command line, and opened appropriate\r
// files, so let's go and do what we've been asked to do...\r
InputFileName,\r
InputFileNum,\r
SectCompSubType,\r
- OutFile\r
+ &OutFileBuffer\r
);\r
break;\r
\r
InputFileNum,\r
&VendorGuid,\r
SectGuidAttribute,\r
- OutFile\r
+ (UINT32) SectGuidHeaderLength,\r
+ &OutFileBuffer\r
);\r
break;\r
\r
case EFI_SECTION_VERSION:\r
- CommonSect.Type = (EFI_SECTION_TYPE) SectType;\r
-\r
- Index = sizeof (CommonSect);\r
+ Index = sizeof (EFI_COMMON_SECTION_HEADER);\r
//\r
// 2 bytes for the build number UINT16\r
//\r
// StringBuffer is ascii.. unicode is 2X + 2 bytes for terminating unicode null.\r
//\r
Index += (strlen (StringBuffer) * 2) + 2;\r
- memcpy (&CommonSect.Size, &Index, 3);\r
- fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);\r
- fwrite (&VersionNumber, sizeof (UINT16), 1, OutFile);\r
- Ascii2UnicodeWriteString (StringBuffer, OutFile);\r
+ OutFileBuffer = (UINT8 *) malloc (Index);\r
+ if (OutFileBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");\r
+ goto Finish;\r
+ }\r
+ VersionSect = (EFI_VERSION_SECTION *) OutFileBuffer;\r
+ VersionSect->CommonHeader.Type = SectType;\r
+ VersionSect->CommonHeader.Size[0] = (UINT8) (Index & 0xff);\r
+ VersionSect->CommonHeader.Size[1] = (UINT8) ((Index & 0xff00) >> 8);\r
+ VersionSect->CommonHeader.Size[2] = (UINT8) ((Index & 0xff0000) >> 16);\r
+ VersionSect->BuildNumber = (UINT16) VersionNumber;\r
+ Ascii2UnicodeString (StringBuffer, VersionSect->VersionString);\r
+ VerboseMsg ("the size of the created section file is %d bytes", Index);\r
break;\r
\r
case EFI_SECTION_USER_INTERFACE:\r
- CommonSect.Type = (EFI_SECTION_TYPE) SectType;\r
- Index = sizeof (CommonSect);\r
+ Index = sizeof (EFI_COMMON_SECTION_HEADER);\r
//\r
// StringBuffer is ascii.. unicode is 2X + 2 bytes for terminating unicode null.\r
//\r
Index += (strlen (StringBuffer) * 2) + 2;\r
- memcpy (&CommonSect.Size, &Index, 3);\r
- fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);\r
- Ascii2UnicodeWriteString (StringBuffer, OutFile);\r
- break;\r
+ OutFileBuffer = (UINT8 *) malloc (Index);\r
+ if (OutFileBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");\r
+ goto Finish;\r
+ }\r
+ UiSect = (EFI_USER_INTERFACE_SECTION *) OutFileBuffer;\r
+ UiSect->CommonHeader.Type = SectType;\r
+ UiSect->CommonHeader.Size[0] = (UINT8) (Index & 0xff);\r
+ UiSect->CommonHeader.Size[1] = (UINT8) ((Index & 0xff00) >> 8);\r
+ UiSect->CommonHeader.Size[2] = (UINT8) ((Index & 0xff0000) >> 16);\r
+ Ascii2UnicodeString (StringBuffer, UiSect->FileNameString);\r
+ VerboseMsg ("the size of the created section file is %d bytes", Index);\r
+ break;\r
\r
case EFI_SECTION_ALL:\r
//\r
Status = GetSectionContents (\r
InputFileName,\r
InputFileNum,\r
- FileBuffer,\r
+ OutFileBuffer,\r
&InputLength\r
);\r
\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
- FileBuffer = (UINT8 *) malloc (InputLength);\r
- if (FileBuffer == NULL) {\r
+ OutFileBuffer = (UINT8 *) malloc (InputLength);\r
+ if (OutFileBuffer == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");\r
goto Finish;\r
}\r
Status = GetSectionContents (\r
InputFileName,\r
InputFileNum,\r
- FileBuffer,\r
+ OutFileBuffer,\r
&InputLength\r
);\r
}\r
- \r
- if (Status == EFI_SUCCESS) {\r
- fwrite (FileBuffer, InputLength, 1, OutFile);\r
- }\r
-\r
- if (FileBuffer != NULL) {\r
- free (FileBuffer);\r
- }\r
- \r
+ VerboseMsg ("the size of the created section file is %d bytes", InputLength);\r
break;\r
default:\r
//\r
InputFileName,\r
InputFileNum,\r
SectType,\r
- OutFile\r
+ &OutFileBuffer\r
);\r
break;\r
}\r
+ \r
+ if (Status != EFI_SUCCESS || OutFileBuffer == NULL) {\r
+ Error (NULL, 0, 2000, "Status is not successful", "Status value is 0x%X", (UINTN) Status);\r
+ goto Finish;\r
+ }\r
+\r
+ //\r
+ // Get output file length\r
+ //\r
+ if (SectType != EFI_SECTION_ALL) {\r
+ InputLength = SECTION_SIZE (OutFileBuffer);\r
+ }\r
+ \r
+ //\r
+ // Write the output file\r
+ //\r
+ OutFile = fopen (OutputFileName, "wb");\r
+ if (OutFile == NULL) {\r
+ Error (NULL, 0, 0001, "Error opening file for writing", OutputFileName);\r
+ goto Finish;\r
+ }\r
+\r
+ fwrite (OutFileBuffer, InputLength, 1, OutFile);\r
\r
Finish:\r
if (InputFileName != NULL) {\r
free (InputFileName);\r
}\r
\r
+ if (OutFileBuffer != NULL) {\r
+ free (OutFileBuffer);\r
+ }\r
+\r
if (OutFile != NULL) {\r
fclose (OutFile);\r
}\r
\r
- if (VerboseMode) {\r
- fprintf (stdout, "%s tool done with return code is 0x%x.\n", UTILITY_NAME, GetUtilityStatus ()); \r
- }\r
+ VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ());\r
\r
return GetUtilityStatus ();\r
}\r