X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FC%2FVfrCompile%2FVfrCompiler.cpp;h=ff7057a64f4ca751f8da07bd45de8f9e2c5e6a50;hp=508b68371eb3ac7b993afcf3b3be3b79814f3f4a;hb=38eb573b0966af0879b85d5d83b430d95b31a884;hpb=52302d4dee589a5df43a464420c9fe68ba83937d diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp index 508b68371e..ff7057a64f 100644 --- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp @@ -2,8 +2,8 @@ VfrCompiler main class and main function. -Copyright (c) 2004 - 2010, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 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 http://opensource.org/licenses/bsd-license.php @@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. PACKAGE_DATA gCBuffer; PACKAGE_DATA gRBuffer; +CVfrStringDB gCVfrStringDB; VOID CVfrCompiler::DebugError ( @@ -62,22 +63,29 @@ CVfrCompiler::OptionInitialization ( ) { INT32 Index; - + EFI_STATUS Status; + + Status = EFI_SUCCESS; SetUtilityName ((CHAR8*) PROGRAM_NAME); - mOptions.VfrFileName[0] = '\0'; - mOptions.RecordListFile[0] = '\0'; + mOptions.VfrFileName = NULL; + mOptions.RecordListFile = NULL; mOptions.CreateRecordListFile = FALSE; mOptions.CreateIfrPkgFile = FALSE; - mOptions.PkgOutputFileName[0] = '\0'; - mOptions.COutputFileName[0] = '\0'; - mOptions.OutputDirectory[0] = '\0'; - mOptions.PreprocessorOutputFileName[0] = '\0'; - mOptions.VfrBaseFileName[0] = '\0'; + mOptions.PkgOutputFileName = NULL; + mOptions.COutputFileName = NULL; + mOptions.OutputDirectory = NULL; + mOptions.PreprocessorOutputFileName = NULL; + mOptions.VfrBaseFileName = NULL; mOptions.IncludePaths = NULL; mOptions.SkipCPreprocessor = TRUE; mOptions.CPreprocessorOptions = NULL; mOptions.CompatibleMode = FALSE; + mOptions.HasOverrideClassGuid = FALSE; + mOptions.WarningAsError = FALSE; + mOptions.AutoDefault = FALSE; + mOptions.CheckDefault = FALSE; + memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID)); if (Argc == 1) { Usage (); @@ -90,6 +98,10 @@ CVfrCompiler::OptionInitialization ( Usage (); SET_RUN_STATUS (STATUS_DEAD); return; + } else if (stricmp(Argv[Index], "--version") == 0) { + Version (); + SET_RUN_STATUS (STATUS_DEAD); + return; } else if (stricmp(Argv[Index], "-l") == 0) { mOptions.CreateRecordListFile = TRUE; gCIfrRecordInfoDB.TurnOn (); @@ -107,6 +119,16 @@ CVfrCompiler::OptionInitialization ( DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name"); goto Fail; } + if (strlen (Argv[Index]) > MAX_PATH - 1) { + DebugError (NULL, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv[Index]); + goto Fail; + } + + mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + strlen ("\\") + 1); + if (mOptions.OutputDirectory == NULL) { + DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL); + goto Fail; + } strcpy (mOptions.OutputDirectory, Argv[Index]); CHAR8 lastChar = mOptions.OutputDirectory[strlen(mOptions.OutputDirectory) - 1]; @@ -117,7 +139,7 @@ CVfrCompiler::OptionInitialization ( strcat (mOptions.OutputDirectory, "\\"); } } - DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", mOptions.OutputDirectory); + DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", (CHAR8 *) "%s", mOptions.OutputDirectory); } else if (stricmp(Argv[Index], "-b") == 0 || stricmp(Argv[Index], "--create-ifr-package") == 0 || stricmp(Argv[Index], "-ibin") == 0) { mOptions.CreateIfrPkgFile = TRUE; } else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) { @@ -132,6 +154,28 @@ CVfrCompiler::OptionInitialization ( AppendCPreprocessorOptions (Argv[Index]); } else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) { mOptions.CompatibleMode = TRUE; + } else if (stricmp(Argv[Index], "-s") == 0|| stricmp(Argv[Index], "--string-db") == 0) { + Index++; + if ((Index >= Argc) || (Argv[Index][0] == '-')) { + DebugError (NULL, 0, 1001, "Missing option", "-s missing input string file name"); + goto Fail; + } + gCVfrStringDB.SetStringFileName(Argv[Index]); + DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", (CHAR8 *) "%s", Argv[Index]); + } else if ((stricmp (Argv[Index], "-g") == 0) || (stricmp (Argv[Index], "--guid") == 0)) { + Index++; + Status = StringToGuid (Argv[Index], &mOptions.OverrideClassGuid); + if (EFI_ERROR (Status)) { + DebugError (NULL, 0, 1000, "Invalid format:", "%s", Argv[Index]); + goto Fail; + } + mOptions.HasOverrideClassGuid = TRUE; + } else if (stricmp(Argv[Index], "-w") == 0 || stricmp(Argv[Index], "--warning-as-error") == 0) { + mOptions.WarningAsError = TRUE; + } else if (stricmp(Argv[Index], "-a") == 0 ||stricmp(Argv[Index], "--autodefault") == 0) { + mOptions.AutoDefault = TRUE; + } else if (stricmp(Argv[Index], "-d") == 0 ||stricmp(Argv[Index], "--checkdefault") == 0) { + mOptions.CheckDefault = TRUE; } else { DebugError (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]); goto Fail; @@ -142,7 +186,25 @@ CVfrCompiler::OptionInitialization ( DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified."); goto Fail; } else { + if (strlen (Argv[Index]) > MAX_PATH) { + DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv[Index]); + goto Fail; + } + mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1); + if (mOptions.VfrFileName == NULL) { + DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL); + goto Fail; + } strcpy (mOptions.VfrFileName, Argv[Index]); + + if (mOptions.OutputDirectory == NULL) { + mOptions.OutputDirectory = (CHAR8 *) malloc (1); + if (mOptions.OutputDirectory == NULL) { + DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL); + goto Fail; + } + mOptions.OutputDirectory[0] = '\0'; + } } if (SetBaseFileName() != 0) { @@ -165,15 +227,37 @@ CVfrCompiler::OptionInitialization ( Fail: SET_RUN_STATUS (STATUS_DEAD); - mOptions.VfrFileName[0] = '\0'; - mOptions.RecordListFile[0] = '\0'; mOptions.CreateRecordListFile = FALSE; mOptions.CreateIfrPkgFile = FALSE; - mOptions.PkgOutputFileName[0] = '\0'; - mOptions.COutputFileName[0] = '\0'; - mOptions.OutputDirectory[0] = '\0'; - mOptions.PreprocessorOutputFileName[0] = '\0'; - mOptions.VfrBaseFileName[0] = '\0'; + + if (mOptions.VfrFileName != NULL) { + free (mOptions.VfrFileName); + mOptions.VfrFileName = NULL; + } + if (mOptions.VfrBaseFileName != NULL) { + free (mOptions.VfrBaseFileName); + mOptions.VfrBaseFileName = NULL; + } + if (mOptions.OutputDirectory != NULL) { + free (mOptions.OutputDirectory); + mOptions.OutputDirectory = NULL; + } + if (mOptions.PkgOutputFileName != NULL) { + free (mOptions.PkgOutputFileName); + mOptions.PkgOutputFileName = NULL; + } + if (mOptions.COutputFileName != NULL) { + free (mOptions.COutputFileName); + mOptions.COutputFileName = NULL; + } + if (mOptions.PreprocessorOutputFileName != NULL) { + free (mOptions.PreprocessorOutputFileName); + mOptions.PreprocessorOutputFileName = NULL; + } + if (mOptions.RecordListFile != NULL) { + free (mOptions.RecordListFile); + mOptions.RecordListFile = NULL; + } if (mOptions.IncludePaths != NULL) { delete mOptions.IncludePaths; mOptions.IncludePaths = NULL; @@ -249,7 +333,7 @@ CVfrCompiler::SetBaseFileName ( { CHAR8 *pFileName, *pPath, *pExt; - if (mOptions.VfrFileName[0] == '\0') { + if (mOptions.VfrFileName == NULL) { return -1; } @@ -270,8 +354,20 @@ CVfrCompiler::SetBaseFileName ( return -1; } - strncpy (mOptions.VfrBaseFileName, pFileName, pExt - pFileName); - mOptions.VfrBaseFileName[pExt - pFileName] = '\0'; + *pExt = '\0'; + if (strlen (pFileName) > MAX_PATH - 1) { + *pExt = '.'; + return -1; + } + + mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1); + if (mOptions.VfrBaseFileName == NULL) { + *pExt = '.'; + return -1; + } + + strcpy (mOptions.VfrBaseFileName, pFileName); + *pExt = '.'; return 0; } @@ -281,7 +377,22 @@ CVfrCompiler::SetPkgOutputFileName ( VOID ) { - if (mOptions.VfrBaseFileName[0] == '\0') { + INTN Length; + + if (mOptions.VfrBaseFileName == NULL) { + return -1; + } + + Length = strlen (mOptions.OutputDirectory) + + strlen (mOptions.VfrBaseFileName) + + strlen (VFR_PACKAGE_FILENAME_EXTENSION) + + 1; + if (Length > MAX_PATH) { + return -1; + } + + mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length); + if (mOptions.PkgOutputFileName == NULL) { return -1; } @@ -297,7 +408,22 @@ CVfrCompiler::SetCOutputFileName ( VOID ) { - if (mOptions.VfrBaseFileName[0] == '\0') { + INTN Length; + + if (mOptions.VfrBaseFileName == NULL) { + return -1; + } + + Length = strlen (mOptions.OutputDirectory) + + strlen (mOptions.VfrBaseFileName) + + strlen (".c") + + 1; + if (Length > MAX_PATH) { + return -1; + } + + mOptions.COutputFileName = (CHAR8 *) malloc (Length); + if (mOptions.COutputFileName == NULL) { return -1; } @@ -313,7 +439,22 @@ CVfrCompiler::SetPreprocessorOutputFileName ( VOID ) { - if (mOptions.VfrBaseFileName[0] == '\0') { + INTN Length; + + if (mOptions.VfrBaseFileName == NULL) { + return -1; + } + + Length = strlen (mOptions.OutputDirectory) + + strlen (mOptions.VfrBaseFileName) + + strlen (VFR_PREPROCESS_FILENAME_EXTENSION) + + 1; + if (Length > MAX_PATH) { + return -1; + } + + mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length); + if (mOptions.PreprocessorOutputFileName == NULL) { return -1; } @@ -329,7 +470,22 @@ CVfrCompiler::SetRecordListFileName ( VOID ) { - if (mOptions.VfrBaseFileName[0] == '\0') { + INTN Length; + + if (mOptions.VfrBaseFileName == NULL) { + return -1; + } + + Length = strlen (mOptions.OutputDirectory) + + strlen (mOptions.VfrBaseFileName) + + strlen (VFR_RECORDLIST_FILENAME_EXTENSION) + + 1; + if (Length > MAX_PATH) { + return -1; + } + + mOptions.RecordListFile = (CHAR8 *) malloc (Length); + if (mOptions.RecordListFile == NULL) { return -1; } @@ -348,6 +504,8 @@ CVfrCompiler::CVfrCompiler ( mPreProcessCmd = (CHAR8 *) PREPROCESSOR_COMMAND; mPreProcessOpt = (CHAR8 *) PREPROCESSOR_OPTIONS; + SET_RUN_STATUS (STATUS_STARTED); + OptionInitialization(Argc, Argv); if ((IS_RUN_STATUS(STATUS_FAILED)) || (IS_RUN_STATUS(STATUS_DEAD))) { @@ -361,6 +519,41 @@ CVfrCompiler::~CVfrCompiler ( VOID ) { + if (mOptions.VfrFileName != NULL) { + free (mOptions.VfrFileName); + mOptions.VfrFileName = NULL; + } + + if (mOptions.VfrBaseFileName != NULL) { + free (mOptions.VfrBaseFileName); + mOptions.VfrBaseFileName = NULL; + } + + if (mOptions.OutputDirectory != NULL) { + free (mOptions.OutputDirectory); + mOptions.OutputDirectory = NULL; + } + + if (mOptions.PkgOutputFileName != NULL) { + free (mOptions.PkgOutputFileName); + mOptions.PkgOutputFileName = NULL; + } + + if (mOptions.COutputFileName != NULL) { + free (mOptions.COutputFileName); + mOptions.COutputFileName = NULL; + } + + if (mOptions.PreprocessorOutputFileName != NULL) { + free (mOptions.PreprocessorOutputFileName); + mOptions.PreprocessorOutputFileName = NULL; + } + + if (mOptions.RecordListFile != NULL) { + free (mOptions.RecordListFile); + mOptions.RecordListFile = NULL; + } + if (mOptions.IncludePaths != NULL) { delete mOptions.IncludePaths; mOptions.IncludePaths = NULL; @@ -382,13 +575,14 @@ CVfrCompiler::Usage ( UINT32 Index; CONST CHAR8 *Help[] = { " ", - "VfrCompile version " VFR_COMPILER_VERSION VFR_COMPILER_UPDATE_TIME, - "Copyright (c) 2004-2010 Intel Corporation. All rights reserved.", + "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION, + "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.", " ", "Usage: VfrCompile [options] VfrFile", " ", "Options:", " -h, --help prints this help", + " --version prints version info", " -l create an output IFR listing file", " -o DIR, --output-directory DIR", " deposit all output files to directory OutputDir", @@ -399,6 +593,30 @@ CVfrCompiler::Usage ( " do not preprocessing input file", " -c, --compatible-framework", " compatible framework vfr file", + " -s, --string-db", + " input uni string package file", + " -g, --guid", + " override class guid input", + " format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", + " -w --warning-as-error", + " treat warning as an error", + " -a --autodefaut generate default value for question opcode if some default is missing", + " -d --checkdefault check the default information in a question opcode", + NULL + }; + for (Index = 0; Help[Index] != NULL; Index++) { + fprintf (stdout, "%s\n", Help[Index]); + } +} + +VOID +CVfrCompiler::Version ( + VOID + ) +{ + UINT32 Index; + CONST CHAR8 *Help[] = { + "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION, NULL }; for (Index = 0; Help[Index] != NULL; Index++) { @@ -423,7 +641,7 @@ CVfrCompiler::PreProcess ( goto Out; } - if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) { + if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) { DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName); goto Fail; } @@ -459,7 +677,7 @@ CVfrCompiler::PreProcess ( goto Fail; } - delete PreProcessCmd; + delete[] PreProcessCmd; Out: SET_RUN_STATUS (STATUS_PREPROCESSED); @@ -469,10 +687,10 @@ Fail: if (!IS_RUN_STATUS(STATUS_DEAD)) { SET_RUN_STATUS (STATUS_FAILED); } - delete PreProcessCmd; + delete[] PreProcessCmd; } -extern UINT8 VfrParserStart (IN FILE *, IN BOOLEAN); +extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *); VOID CVfrCompiler::Compile ( @@ -481,6 +699,7 @@ CVfrCompiler::Compile ( { FILE *pInFile = NULL; CHAR8 *InFileName = NULL; + INPUT_INFO_TO_SYNTAX InputInfo; if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) { goto Fail; @@ -489,13 +708,21 @@ CVfrCompiler::Compile ( InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName; gCVfrErrorHandle.SetInputFile (InFileName); + gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError); - if ((pInFile = fopen (InFileName, "r")) == NULL) { + if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) { DebugError (NULL, 0, 0001, "Error opening the input file", InFileName); goto Fail; } - if (VfrParserStart (pInFile, mOptions.CompatibleMode) != 0) { + InputInfo.CompatibleMode = mOptions.CompatibleMode; + if (mOptions.HasOverrideClassGuid) { + InputInfo.OverrideClassGuid = &mOptions.OverrideClassGuid; + } else { + InputInfo.OverrideClassGuid = NULL; + } + + if (VfrParserStart (pInFile, &InputInfo) != 0) { goto Fail; } @@ -525,6 +752,25 @@ CVfrCompiler::AdjustBin ( ) { EFI_VFR_RETURN_CODE Status; + + if (!IS_RUN_STATUS(STATUS_COMPILEED)) { + return; + } + + if (gNeedAdjustOpcode) { + // + // When parsing the Vfr, has created some opcodes, now need to update the record info. + // + gCIfrRecordInfoDB.IfrUpdateRecordInfoForDynamicOpcode (FALSE); + } + + // + // Check whether need to check default info for question or auto add default for question. + // + if (mOptions.AutoDefault || mOptions.CheckDefault) { + gCIfrRecordInfoDB.IfrCheckAddDefaultRecord (mOptions.AutoDefault, mOptions.CheckDefault); + } + // // Check Binary Code consistent between Form and IfrRecord // @@ -594,7 +840,7 @@ CVfrCompiler::GenBinary ( } if (mOptions.CreateIfrPkgFile == TRUE) { - if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) { + if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) { DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName); goto Fail; } @@ -637,7 +883,7 @@ CVfrCompiler::GenCFile ( } if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) { - if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) { + if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) { DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName); goto Fail; } @@ -684,17 +930,17 @@ CVfrCompiler::GenRecordListFile ( return; } - if ((pInFile = fopen (InFileName, "r")) == NULL) { + if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) { DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName); return; } - if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) { + if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) { DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile); goto Err1; } - fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSION "\n//\n"); + fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION "\n//\n"); LineNo = 0; while (!feof (pInFile)) { if (fgets (LineBuf, MAX_VFR_LINE_LEN, pInFile) != NULL) { @@ -725,6 +971,8 @@ main ( ) { COMPILER_RUN_STATUS Status; + + SetPrintLevel(WARNING_LOG_LEVEL); CVfrCompiler Compiler(Argc, Argv); Compiler.PreProcess();