Skip to content

Commit

Permalink
Enhance VfrCompiler to handle framework vfr file, and print more debu…
Browse files Browse the repository at this point in the history
…g information into .lst file.

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1302 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
lgao4 committed Aug 12, 2008
1 parent 63a826e commit beeede8
Show file tree
Hide file tree
Showing 9 changed files with 1,665 additions and 637 deletions.
120 changes: 105 additions & 15 deletions Source/C/VfrCompile/VfrCompiler.cpp
Expand Up @@ -18,8 +18,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "string.h"
//#include "process.h"
#include "VfrCompiler.h"
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"

PACKAGE_DATA gCBuffer;
PACKAGE_DATA gRBuffer;

VOID
CVfrCompiler::DebugError () {
Error (NULL, 0, 0001, "Error parsing vfr file", " %s", mOptions.VfrFileName);
//_asm int 3;
}

VOID
CVfrCompiler::SET_RUN_STATUS (
IN COMPILER_RUN_STATUS Status
Expand Down Expand Up @@ -58,27 +68,28 @@ CVfrCompiler::OptionInitialization (
mOptions.IncludePaths = NULL;
mOptions.SkipCPreprocessor = FALSE;
mOptions.CPreprocessorOptions = NULL;
mOptions.CompatibleMode = FALSE;

for (Index = 1; (Index < Argc) && (Argv[Index][0] == '-'); Index++) {
if ((strcmp(Argv[Index], "-h") == 0) || (strcmp(Argv[Index], "--help") == 0)) {
if ((stricmp(Argv[Index], "-h") == 0) || (stricmp(Argv[Index], "--help") == 0)) {
Usage ();
SET_RUN_STATUS (STATUS_DEAD);
return;
} else if (strcmp(Argv[Index], "-l") == 0) {
} else if (stricmp(Argv[Index], "-l") == 0) {
mOptions.CreateRecordListFile = TRUE;
gCIfrRecordInfoDB.TurnOn ();
} else if (strcmp(Argv[Index], "-i") == 0) {
} else if (stricmp(Argv[Index], "-i") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
Error (NULL, 0, 1001, "Missing option", "-i missing path argument");
goto Fail;
}

AppendIncludePath(Argv[Index]);
} else if (strcmp(Argv[Index], "-o") == 0 || strcmp(Argv[Index], "--output-directory") == 0) {
} else if (stricmp(Argv[Index], "-o") == 0 || stricmp(Argv[Index], "--output-directory") == 0 || stricmp(Argv[Index], "-od") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
Error (NULL, 0, 1001, "Missing option", "-od missing output directory name");
Error (NULL, 0, 1001, "Missing option", "-o missing output directory name");
goto Fail;
}
strcpy (mOptions.OutputDirectory, Argv[Index]);
Expand All @@ -91,20 +102,21 @@ CVfrCompiler::OptionInitialization (
strcat (mOptions.OutputDirectory, "\\");
}
}
printf("Debug! %s\n", mOptions.OutputDirectory);
} else if (strcmp(Argv[Index], "-b") == 0 || strcmp(Argv[Index], "--create-ifr-package") == 0) {
DebugMsg (NULL, 0, 9, "Output Directory", 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 (strcmp(Argv[Index], "--no-strings") == 0) {
} else if (strcmp(Argv[Index], "-n") == 0 || strcmp(Argv[Index], "--no-pre-processing") == 0) {
} else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) {
mOptions.SkipCPreprocessor = TRUE;
} else if (strcmp(Argv[Index], "-f") == 0 || strcmp(Argv[Index], "--pre-processing-flag") == 0) {
} else if (stricmp(Argv[Index], "-f") == 0 || stricmp(Argv[Index], "--pre-processing-flag") == 0 || stricmp(Argv[Index], "-ppflag") == 0) {
Index++;
if ((Index >= Argc) || (Argv[Index][0] == '-')) {
Error (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");
goto Fail;
}

AppendCPreprocessorOptions (Argv[Index]);
} else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {
mOptions.CompatibleMode = TRUE;
} else {
Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);
Usage ();
Expand Down Expand Up @@ -373,6 +385,8 @@ CVfrCompiler::Usage (
" do not preprocessing input file",
" -f, --pre-processing-flag",
" Preprocessing flags",
" -c, --compatible-framework",
" compatible framework vfr file",
NULL
};
for (Index = 0; Help[Index] != NULL; Index++) {
Expand Down Expand Up @@ -446,7 +460,7 @@ CVfrCompiler::PreProcess (
delete PreProcessCmd;
}

extern UINT8 VfrParserStart (IN FILE *);
extern UINT8 VfrParserStart (IN FILE *, IN BOOLEAN);

VOID
CVfrCompiler::Compile (
Expand All @@ -469,7 +483,7 @@ CVfrCompiler::Compile (
goto Fail;
}

if (VfrParserStart (pInFile) != 0) {
if (VfrParserStart (pInFile, mOptions.CompatibleMode) != 0) {
goto Fail;
}

Expand All @@ -493,6 +507,69 @@ CVfrCompiler::Compile (
}
}

VOID
CVfrCompiler::AdjustBin (
VOID
)
{
EFI_VFR_RETURN_CODE Status;
//
// Check Binary Code consistent between Form and IfrRecord
//

//
// Get Package Data and IfrRecord Data
//
gCFormPkg.BuildPkg (gCBuffer);
gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);

//
// Compare Form and Record data
//
if (gCBuffer.Buffer != NULL && gRBuffer.Buffer != NULL) {
UINT32 Index;
if (gCBuffer.Size != gRBuffer.Size) {
Error (NULL, 0, 0001, "Error parsing vfr file", " %s. FormBinary Size 0x%X is not same to RecordBuffer Size 0x%X", mOptions.VfrFileName, gCBuffer.Size, gRBuffer.Size);
}
for (Index = 0; Index < gCBuffer.Size; Index ++) {
if (gCBuffer.Buffer[Index] != gRBuffer.Buffer[Index]) {
break;
}
}
if (Index != gCBuffer.Size) {
Error (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);
}
DebugMsg (NULL, 0, 9, "IFR Buffer", "Form Buffer same to Record Buffer and Size is 0x%X", Index);
} else if (gCBuffer.Buffer == NULL && gRBuffer.Buffer == NULL) {
//ok
} else {
Error (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);
}

//
// For UEFI mode, not do OpCode Adjust
//
if (mOptions.CompatibleMode) {
//
// Adjust Opcode to be compatible with framework vfr
//
Status = gCIfrRecordInfoDB.IfrRecordAdjust ();
if (Status != VFR_RETURN_SUCCESS) {
//
// Record List Adjust Failed
//
SET_RUN_STATUS (STATUS_FAILED);
return;
}
//
// Re get the IfrRecord Buffer.
//
gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);
}

return;
}

VOID
CVfrCompiler::GenBinary (
VOID
Expand All @@ -509,14 +586,15 @@ CVfrCompiler::GenBinary (
Error (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);
goto Fail;
}
if (gCFormPkg.BuildPkg (pFile) != VFR_RETURN_SUCCESS) {
if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {
fclose (pFile);
goto Fail;
}
fclose (pFile);
}

SET_RUN_STATUS (STATUS_GENBINARY);

return;

Fail:
Expand Down Expand Up @@ -557,7 +635,7 @@ CVfrCompiler::GenCFile (

gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);

if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile) != VFR_RETURN_SUCCESS) {
if (gCFormPkg.GenCFile (mOptions.VfrBaseFileName, pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {
fclose (pFile);
goto Fail;
}
Expand Down Expand Up @@ -609,6 +687,9 @@ CVfrCompiler::GenRecordListFile (
gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, LineNo);
}
}

fprintf (pOutFile, "\n//\n// All Opcode Record List \n//\n");
gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, 0);

fclose (pOutFile);
fclose (pInFile);
Expand All @@ -631,6 +712,7 @@ main (

Compiler.PreProcess();
Compiler.Compile();
Compiler.AdjustBin();
Compiler.GenBinary();
Compiler.GenCFile();
Compiler.GenRecordListFile ();
Expand All @@ -640,6 +722,14 @@ main (
return 2;
}

return 0;
if (gCBuffer.Buffer != NULL) {
delete gCBuffer.Buffer;
}

if (gRBuffer.Buffer != NULL) {
delete gRBuffer.Buffer;
}

return GetUtilityStatus ();
}

23 changes: 13 additions & 10 deletions Source/C/VfrCompile/VfrCompiler.h
@@ -1,15 +1,15 @@
/** @file
VfrCompiler internal defintions.
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

Expand All @@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "VfrUtilityLib.h"

#define PROGRAM_NAME "VfrCompile"
#define VFR_COMPILER_VERSION "1.90 (UEFI 2.1)"
#define VFR_COMPILER_VERSION "1.95 (UEFI 2.1)"

//
// This is how we invoke the C preprocessor on the VFR source file
Expand Down Expand Up @@ -53,6 +53,7 @@ typedef struct {
CHAR8 *IncludePaths;
bool SkipCPreprocessor;
CHAR8 *CPreprocessorOptions;
BOOLEAN CompatibleMode;
} OPTIONS;

typedef enum {
Expand Down Expand Up @@ -97,9 +98,11 @@ class CVfrCompiler {

VOID PreProcess (VOID);
VOID Compile (VOID);
VOID AdjustBin (VOID);
VOID GenBinary (VOID);
VOID GenCFile (VOID);
VOID GenRecordListFile (VOID);
VOID DebugError (VOID);
};

#endif
26 changes: 13 additions & 13 deletions Source/C/VfrCompile/VfrError.cpp
@@ -1,15 +1,15 @@
/** @file
VfrCompiler error handler.
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

Expand Down Expand Up @@ -38,8 +38,8 @@ static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {
{ VFR_RETURN_EFIVARSTORE_USE_ERROR, "can not use the efi varstore like this" },
{ VFR_RETURN_EFIVARSTORE_SIZE_ERROR, "unsupport efi varstore size should be <= 8 bytes" },
{ VFR_RETURN_GET_NVVARSTORE_ERROR, "get name value varstore error" },
{ VFR_RETURN_QVAR_REUSE, "variable reused by more than one question" },
{ VFR_RETURN_FLAGS_UNSUPPORTED, "flags unsupported" },
{ VFR_RETURN_QVAR_REUSE, "variable reused by more than one question" },
{ VFR_RETURN_FLAGS_UNSUPPORTED, "flags unsupported" },
{ VFR_RETURN_ERROR_ARRARY_NUM, "array number error" },
{ VFR_RETURN_DATA_STRING_ERROR, "data field string error or not support"},
{ VFR_RETURN_DEFAULT_VALUE_REDEFINED, "Default value re-defined with different value"},
Expand Down Expand Up @@ -89,7 +89,7 @@ CVfrErrorHandle::SetInputFile (
}

SVfrFileScopeRecord::SVfrFileScopeRecord (
IN CHAR8 *Record,
IN CHAR8 *Record,
IN UINT32 LineNum
)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ SVfrFileScopeRecord::~SVfrFileScopeRecord (

VOID
CVfrErrorHandle::ParseFileScopeRecord (
IN CHAR8 *Record,
IN CHAR8 *Record,
IN UINT32 WholeScopeLine
)
{
Expand Down
18 changes: 9 additions & 9 deletions Source/C/VfrCompile/VfrError.h
@@ -1,15 +1,15 @@
/** @file
VfrCompiler Error definition
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2004 - 2008, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

Expand Down

0 comments on commit beeede8

Please sign in to comment.