]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
BaseTools: Change source files to DOS format.
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
index 24ac97789237d2275bc1b4d6e9af13627367e295..695ce6cc484c846aaf5261df9d0566d72b97d291 100644 (file)
@@ -2,7 +2,7 @@
   \r
   VfrCompiler main class and main function.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, 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
@@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 PACKAGE_DATA  gCBuffer;\r
 PACKAGE_DATA  gRBuffer;\r
+CVfrStringDB  gCVfrStringDB;\r
 \r
 VOID \r
 CVfrCompiler::DebugError (\r
@@ -62,7 +63,9 @@ CVfrCompiler::OptionInitialization (
   )\r
 {\r
   INT32         Index;\r
-  \r
+  EFI_STATUS    Status;\r
+\r
+  Status = EFI_SUCCESS;\r
   SetUtilityName ((CHAR8*) PROGRAM_NAME);\r
 \r
   mOptions.VfrFileName[0]                = '\0';\r
@@ -78,6 +81,9 @@ CVfrCompiler::OptionInitialization (
   mOptions.SkipCPreprocessor             = TRUE;\r
   mOptions.CPreprocessorOptions          = NULL;\r
   mOptions.CompatibleMode                = FALSE;\r
+  mOptions.HasOverrideClassGuid          = FALSE;\r
+  mOptions.WarningAsError                = FALSE;\r
+  memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID));\r
   \r
   if (Argc == 1) {\r
     Usage ();\r
@@ -90,6 +96,10 @@ CVfrCompiler::OptionInitialization (
       Usage ();\r
       SET_RUN_STATUS (STATUS_DEAD);\r
       return;\r
+    } else if (stricmp(Argv[Index], "--version") == 0) {\r
+      Version ();\r
+      SET_RUN_STATUS (STATUS_DEAD);\r
+      return;\r
     } else if (stricmp(Argv[Index], "-l") == 0) {\r
       mOptions.CreateRecordListFile = TRUE;\r
       gCIfrRecordInfoDB.TurnOn ();\r
@@ -132,6 +142,24 @@ CVfrCompiler::OptionInitialization (
       AppendCPreprocessorOptions (Argv[Index]);\r
     } else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {\r
       mOptions.CompatibleMode = TRUE;\r
+    } else if (stricmp(Argv[Index], "-s") == 0|| stricmp(Argv[Index], "--string-db") == 0) {\r
+      Index++;\r
+      if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
+        DebugError (NULL, 0, 1001, "Missing option", "-s missing input string file name");\r
+        goto Fail;\r
+      }\r
+      gCVfrStringDB.SetStringFileName(Argv[Index]);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", Argv[Index]);\r
+    } else if ((stricmp (Argv[Index], "-g") == 0) || (stricmp (Argv[Index], "--guid") == 0)) {\r
+      Index++;\r
+      Status = StringToGuid (Argv[Index], &mOptions.OverrideClassGuid);\r
+      if (EFI_ERROR (Status)) {\r
+        DebugError (NULL, 0, 1000, "Invalid format:", "%s", Argv[Index]);\r
+        goto Fail;\r
+      }\r
+      mOptions.HasOverrideClassGuid = TRUE;\r
+    } else if (stricmp(Argv[Index], "-w") == 0 || stricmp(Argv[Index], "--warning-as-error") == 0) {\r
+      mOptions.WarningAsError = TRUE;\r
     } else {\r
       DebugError (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
       goto Fail;\r
@@ -348,6 +376,8 @@ CVfrCompiler::CVfrCompiler (
   mPreProcessCmd = (CHAR8 *) PREPROCESSOR_COMMAND;\r
   mPreProcessOpt = (CHAR8 *) PREPROCESSOR_OPTIONS;\r
 \r
+  SET_RUN_STATUS (STATUS_STARTED);\r
+\r
   OptionInitialization(Argc, Argv);\r
 \r
   if ((IS_RUN_STATUS(STATUS_FAILED)) || (IS_RUN_STATUS(STATUS_DEAD))) {\r
@@ -382,13 +412,14 @@ CVfrCompiler::Usage (
   UINT32 Index;\r
   CONST  CHAR8 *Help[] = {\r
     " ", \r
-    "VfrCompile version " VFR_COMPILER_VERSION VFR_COMPILER_UPDATE_TIME,\r
-    "Copyright (c) 2004-2010 Intel Corporation. All rights reserved.",\r
+    "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,\r
+    "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",\r
     " ",\r
     "Usage: VfrCompile [options] VfrFile",\r
     " ",\r
     "Options:",\r
     "  -h, --help     prints this help",\r
+    "  --version      prints version info",\r
     "  -l             create an output IFR listing file",\r
     "  -o DIR, --output-directory DIR",\r
     "                 deposit all output files to directory OutputDir",\r
@@ -399,6 +430,28 @@ CVfrCompiler::Usage (
     "                 do not preprocessing input file",\r
     "  -c, --compatible-framework",\r
     "                 compatible framework vfr file",\r
+    "  -s, --string-db",\r
+    "                 input uni string package file",\r
+    "  -g, --guid",\r
+    "                 override class guid input",\r
+    "                 format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",\r
+    "  -w  --warning-as-error",\r
+    "                 treat warning as an error",\r
+    NULL\r
+    };\r
+  for (Index = 0; Help[Index] != NULL; Index++) {\r
+    fprintf (stdout, "%s\n", Help[Index]);\r
+  }\r
+}\r
+\r
+VOID \r
+CVfrCompiler::Version (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 Index;\r
+  CONST  CHAR8 *Help[] = {\r
+    "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,\r
     NULL\r
     };\r
   for (Index = 0; Help[Index] != NULL; Index++) {\r
@@ -423,7 +476,7 @@ CVfrCompiler::PreProcess (
     goto Out;\r
   }\r
 \r
-  if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {\r
+  if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {\r
     DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
@@ -472,7 +525,7 @@ Fail:
   delete PreProcessCmd;\r
 }\r
 \r
-extern UINT8 VfrParserStart (IN FILE *, IN BOOLEAN);\r
+extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *);\r
 \r
 VOID\r
 CVfrCompiler::Compile (\r
@@ -481,6 +534,7 @@ CVfrCompiler::Compile (
 {\r
   FILE  *pInFile    = NULL;\r
   CHAR8 *InFileName = NULL;\r
+  INPUT_INFO_TO_SYNTAX InputInfo;\r
 \r
   if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) {\r
     goto Fail;\r
@@ -489,13 +543,21 @@ CVfrCompiler::Compile (
   InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
 \r
   gCVfrErrorHandle.SetInputFile (InFileName);\r
+  gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);\r
 \r
-  if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
+  if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
     DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
     goto Fail;\r
   }\r
 \r
-  if (VfrParserStart (pInFile, mOptions.CompatibleMode) != 0) {\r
+  InputInfo.CompatibleMode = mOptions.CompatibleMode;\r
+  if (mOptions.HasOverrideClassGuid) {\r
+    InputInfo.OverrideClassGuid = &mOptions.OverrideClassGuid;\r
+  } else {\r
+    InputInfo.OverrideClassGuid = NULL;\r
+  }\r
+\r
+  if (VfrParserStart (pInFile, &InputInfo) != 0) {\r
     goto Fail;\r
   }\r
 \r
@@ -519,12 +581,55 @@ Fail:
   }\r
 }\r
 \r
+VOID\r
+CVfrCompiler::UpdateInfoForDynamicOpcode (\r
+  VOID\r
+  )\r
+{\r
+  SIfrRecord          *pRecord;\r
+\r
+  if (!gNeedAdjustOpcode) {\r
+    return;\r
+  }\r
+  \r
+  //\r
+  // Base on the original offset info to update the record list.\r
+  //\r
+  if (!gCIfrRecordInfoDB.IfrAdjustDynamicOpcodeInRecords()) {\r
+    DebugError (NULL, 0, 1001, "Error parsing vfr file", "Can find the offset in the record.");\r
+  }\r
+\r
+  //\r
+  // Base on the opcode binary length to recalculate the offset for each opcode.\r
+  //\r
+  gCIfrRecordInfoDB.IfrAdjustOffsetForRecord();\r
+\r
+  //\r
+  // Base on the offset to find the binary address.\r
+  //\r
+  pRecord = gCIfrRecordInfoDB.GetRecordInfoFromOffset(gAdjustOpcodeOffset);\r
+  while (pRecord != NULL) {\r
+    pRecord->mIfrBinBuf = gCFormPkg.GetBufAddrBaseOnOffset(pRecord->mOffset);\r
+    if (pRecord->mIfrBinBuf == NULL) {\r
+      DebugError (NULL, 0, 0001, "Error parsing vfr file", " 0x%X. offset not allocated.", pRecord->mOffset);\r
+    }\r
+    pRecord = pRecord->mNext;\r
+  }\r
+}\r
+\r
 VOID\r
 CVfrCompiler::AdjustBin (\r
   VOID\r
   )\r
 {\r
   EFI_VFR_RETURN_CODE Status;\r
+\r
+  if (!IS_RUN_STATUS(STATUS_COMPILEED)) {\r
+    return;\r
+  }\r
+\r
+  UpdateInfoForDynamicOpcode ();\r
+\r
   //\r
   // Check Binary Code consistent between Form and IfrRecord\r
   //\r
@@ -594,7 +699,7 @@ CVfrCompiler::GenBinary (
   }\r
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
-    if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {\r
+    if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {\r
       DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
@@ -637,7 +742,7 @@ CVfrCompiler::GenCFile (
   }\r
   \r
   if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
-    if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) {\r
+    if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {\r
       DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
       goto Fail;\r
     }\r
@@ -684,17 +789,17 @@ CVfrCompiler::GenRecordListFile (
       return;\r
     }\r
 \r
-    if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
+    if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
       DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
       return;\r
     }\r
 \r
-    if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {\r
+    if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {\r
       DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
-    fprintf (pOutFile, "//\n//  VFR compiler version " VFR_COMPILER_VERSION "\n//\n");\r
+    fprintf (pOutFile, "//\n//  VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION "\n//\n");\r
     LineNo = 0;\r
     while (!feof (pInFile)) {\r
       if (fgets (LineBuf, MAX_VFR_LINE_LEN, pInFile) != NULL) {\r
@@ -725,6 +830,8 @@ main (
   )\r
 {\r
   COMPILER_RUN_STATUS  Status;\r
+\r
+  SetPrintLevel(WARNING_LOG_LEVEL);\r
   CVfrCompiler         Compiler(Argc, Argv);\r
   \r
   Compiler.PreProcess();\r