/** @file\r
+Calculate Crc32 value and Verify Crc32 value for input data.\r
\r
-Copyright (c) 2007 - 2010, 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
-\r
-Module Name:\r
-\r
- GenCrc32.c\r
-\r
-Abstract:\r
- Calculate Crc32 value and Verify Crc32 value for input data.\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
\r
#define UTILITY_NAME "GenCrc32"\r
#define UTILITY_MAJOR_VERSION 0\r
-#define UTILITY_MINOR_VERSION 1\r
+#define UTILITY_MINOR_VERSION 2\r
\r
#define CRC32_NULL 0\r
#define CRC32_ENCODE 1\r
-#define CRC32_DECODE 2 \r
+#define CRC32_DECODE 2\r
\r
VOID\r
Version (\r
\r
--*/\r
{\r
- fprintf (stdout, "%s Version %d.%d\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
+ fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
}\r
\r
VOID\r
//\r
// Summary usage\r
//\r
- fprintf (stdout, "\nUsage: %s -e|-d [options] <input_file>\n\n", UTILITY_NAME);\r
- \r
+ fprintf (stdout, "Usage: GenCrc32 -e|-d [options] <input_file>\n\n");\r
+\r
//\r
// Copyright declaration\r
- // \r
- fprintf (stdout, "Copyright (c) 2007 - 2010, 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
- fprintf (stdout, "Options:\n");\r
- fprintf (stdout, " -o FileName, --output FileName\n\\r
- File will be created to store the ouput content.\n");\r
- fprintf (stdout, " -e, --encode Calculate CRC32 value for the input file.\n");\r
- fprintf (stdout, " -d, --decode Verify CRC32 value for the input file.\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, " --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
+ fprintf (stdout, "optional arguments:\n");\r
+ fprintf (stdout, " -h, --help Show this help message and exit\n");\r
+ fprintf (stdout, " --version Show program's version number and exit\n");\r
+ fprintf (stdout, " --debug [DEBUG] Output DEBUG statements, where DEBUG_LEVEL is 0 (min)\n\\r
+ - 9 (max)\n");\r
+ fprintf (stdout, " -v, --verbose Print informational statements\n");\r
+ fprintf (stdout, " -q, --quiet Returns the exit code, error messages will be\n\\r
+ displayed\n");\r
+ fprintf (stdout, " -s, --silent Returns only the exit code; informational and error\n\\r
+ messages are not displayed\n");\r
+ fprintf (stdout, " -e, --encode Calculate CRC32 value for the input file\n");\r
+ fprintf (stdout, " -d, --decode Verify CRC32 value for the input file\n");\r
+ fprintf (stdout, " -o OUTPUT_FILENAME, --output OUTPUT_FILENAME\n\\r
+ Output file name\n");\r
+ fprintf (stdout, " --sfo Reserved for future use\n");\r
+\r
}\r
\r
int\r
UINT32 Crc32Value;\r
FILE *InFile;\r
FILE *OutFile;\r
- \r
+\r
//\r
// Init local variables\r
//\r
argv ++;\r
\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
OutputFileName = argv[1];\r
argc -= 2;\r
argv += 2;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-e") == 0) || (stricmp (argv[0], "--encode") == 0)) {\r
FileAction = CRC32_ENCODE;\r
argc --;\r
argv ++;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--decode") == 0)) {\r
FileAction = CRC32_DECODE;\r
argc --;\r
argv ++;\r
- continue; \r
+ continue;\r
}\r
\r
if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {\r
}\r
\r
VerboseMsg ("%s tool start.", UTILITY_NAME);\r
- \r
+\r
//\r
- // Check Input paramters\r
+ // Check Input parameters\r
//\r
if (FileAction == CRC32_NULL) {\r
Error (NULL, 0, 1001, "Missing option", "either the encode or the decode option must be specified!");\r
} else if (FileAction == CRC32_DECODE) {\r
VerboseMsg ("File will be decoded by Crc32");\r
}\r
- \r
+\r
if (InputFileName == NULL) {\r
Error (NULL, 0, 1001, "Missing option", "Input files are not specified");\r
goto Finish;\r
} else {\r
VerboseMsg ("Output file name is %s", OutputFileName);\r
}\r
- \r
+\r
//\r
// Open Input file and read file data.\r
//\r
- InFile = fopen (InputFileName, "rb");\r
+ InFile = fopen (LongFilePath (InputFileName), "rb");\r
if (InFile == NULL) {\r
Error (NULL, 0, 0001, "Error opening file", InputFileName);\r
return STATUS_ERROR;\r
fseek (InFile, 0, SEEK_END);\r
FileSize = ftell (InFile);\r
fseek (InFile, 0, SEEK_SET);\r
- \r
+\r
FileBuffer = (UINT8 *) malloc (FileSize);\r
if (FileBuffer == NULL) {\r
- Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated!");\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+ fclose (InFile);\r
goto Finish;\r
}\r
- \r
+\r
fread (FileBuffer, 1, FileSize, InFile);\r
fclose (InFile);\r
VerboseMsg ("the size of the input file is %u bytes", (unsigned) FileSize);\r
- \r
+\r
//\r
// Open output file\r
//\r
- OutFile = fopen (OutputFileName, "wb");\r
+ OutFile = fopen (LongFilePath (OutputFileName), "wb");\r
if (OutFile == NULL) {\r
Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
goto Finish;\r
}\r
- \r
+\r
//\r
// Calculate Crc32 value\r
//\r
//\r
// Verify Crc32 Value\r
//\r
+ if (FileSize < sizeof (UINT32)) {\r
+ Error (NULL, 0, 3000, "Invalid", "Input file is invalid!");\r
+ goto Finish;\r
+ }\r
Status = CalculateCrc32 (FileBuffer + sizeof (UINT32), FileSize - sizeof (UINT32), &Crc32Value);\r
if (Status != EFI_SUCCESS) {\r
Error (NULL, 0, 3000, "Invalid", "Calculate CRC32 value failed!");\r
if (FileBuffer != NULL) {\r
free (FileBuffer);\r
}\r
- \r
+\r
if (OutFile != NULL) {\r
fclose (OutFile);\r
}\r
- \r
+\r
VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ());\r
\r
return GetUtilityStatus ();\r
}\r
\r
- \r
- \r
- \r
+\r
+\r
+\r