[edk2] [patch 1/6] BaseTool/VfrCompile: Support Union type in VFR

Dandan Bi posted 6 patches 7 years, 3 months ago
[edk2] [patch 1/6] BaseTool/VfrCompile: Support Union type in VFR
Posted by Dandan Bi 7 years, 3 months ago
https://bugzilla.tianocore.org/show_bug.cgi?id=603

Update VfrCompiler to parse the UNION type in vfr file

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 BaseTools/Source/C/VfrCompile/VfrSyntax.g       | 81 +++++++++++++++----------
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 17 +++++-
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.h   |  4 +-
 3 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
index 406dbc5..24e0538 100644
--- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g
+++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
@@ -155,10 +155,11 @@ VfrParserStart (
 #token Label("label")                           "label"
 #token Timeout("timeout")                       "timeout"
 #token Inventory("inventory")                   "inventory"
 #token NonNvDataMap("_NON_NV_DATA_MAP")         "_NON_NV_DATA_MAP"
 #token Struct("struct")                         "struct"
+#token Union("union")                           "union"
 #token Boolean("BOOLEAN")                       "BOOLEAN"
 #token Uint64("UINT64")                         "UINT64"
 #token Uint32("UINT32")                         "UINT32"
 #token Uint16("UINT16")                         "UINT16"
 #token Char16("CHAR16")                         "CHAR16"
@@ -270,10 +271,11 @@ vfrProgram > [UINT8 Return] :
      mConstantOnlyInExpression = FALSE;
   >>
   (
       vfrPragmaPackDefinition
     | vfrDataStructDefinition
+    | vfrDataUnionDefinition
   )*
   vfrFormSetDefinition
   << $Return = mParserStatus; >>
   ;
 
@@ -318,140 +320,155 @@ vfrPragmaPackDefinition :
     | pragmaPackNumber
   }
   "\)"
   ;
 
+  vfrDataUnionDefinition :
+  { TypeDef } Union                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
+  { NonNvDataMap }
+  {
+    N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
+  }
+  OpenBrace
+    vfrDataStructFields[TRUE]
+  CloseBrace
+  {
+    N2:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
+  }
+  ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd ();>>
+  ;
+
 vfrDataStructDefinition :
   { TypeDef } Struct                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
   { NonNvDataMap }
   {
     N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
   }
   OpenBrace
-    vfrDataStructFields
+    vfrDataStructFields[FALSE]
   CloseBrace
   {
     N2:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
   }
   ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd (); >>
   ;
 
-vfrDataStructFields :
+vfrDataStructFields [BOOLEAN  FieldInUnion]:
   (
-     dataStructField64     |
-     dataStructField32     |
-     dataStructField16     |
-     dataStructField8      |
-     dataStructFieldBool   |
-     dataStructFieldString |
-     dataStructFieldDate   |
-     dataStructFieldTime   |
-     dataStructFieldRef    |
-     dataStructFieldUser
+     dataStructField64 [FieldInUnion]    |
+     dataStructField32 [FieldInUnion]    |
+     dataStructField16 [FieldInUnion]    |
+     dataStructField8  [FieldInUnion]    |
+     dataStructFieldBool [FieldInUnion]  |
+     dataStructFieldString [FieldInUnion]|
+     dataStructFieldDate  [FieldInUnion] |
+     dataStructFieldTime  [FieldInUnion] |
+     dataStructFieldRef   [FieldInUnion] |
+     dataStructFieldUser [FieldInUnion]
   )*
   ;
 
-dataStructField64 :
+dataStructField64 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT64"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField32 :
+dataStructField32 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT32"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField16 :
+dataStructField16 [BOOLEAN  FieldInUnion]:
   << 
     UINT32 ArrayNum = 0; 
   >>
   ("UINT16" | "CHAR16")
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) "UINT16", ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) "UINT16", ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField8 :
+dataStructField8 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT8"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldBool :
+dataStructFieldBool [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"BOOLEAN"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldString :
+dataStructFieldString [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_STRING_ID"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldDate :
+dataStructFieldDate [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_DATE"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldTime :
+dataStructFieldTime [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_TIME"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldRef :
+dataStructFieldRef [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_REF"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldUser :
+dataStructFieldUser [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   T:StringIdentifier
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), ArrayNum), T); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), ArrayNum, FieldInUnion), T); >>
   ;
 
 //*****************************************************************************
 //
 // the syntax of GUID definition
diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
index 2f97975..37b58e2 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
@@ -1,10 +1,10 @@
 /** @file
   
   Vfr common library functions.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 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                                            
                                                                                           
@@ -1011,19 +1011,22 @@ CVfrVarDataTypeDB::SetNewTypeName (
 
 EFI_VFR_RETURN_CODE
 CVfrVarDataTypeDB::DataTypeAddField (
   IN CHAR8   *FieldName,
   IN CHAR8   *TypeName,
-  IN UINT32 ArrayNum
+  IN UINT32 ArrayNum,
+  IN BOOLEAN FieldInUnion
   )
 {
   SVfrDataField       *pNewField  = NULL;
   SVfrDataType        *pFieldType = NULL;
   SVfrDataField       *pTmp;
   UINT32              Align;
+  UINT32              MaxDataTypeSize;
 
   CHECK_ERROR_RETURN (GetDataType (TypeName, &pFieldType), VFR_RETURN_SUCCESS);
+  MaxDataTypeSize = mNewDataType->mTotalSize;
 
   if (strlen (FieldName) >= MAX_NAME_LEN) {
    return VFR_RETURN_INVALID_PARAMETER;
   }
 
@@ -1055,11 +1058,19 @@ CVfrVarDataTypeDB::DataTypeAddField (
     pTmp->mNext            = pNewField;
     pNewField->mNext       = NULL;
   }
 
   mNewDataType->mAlign     = MIN (mPackAlign, MAX (pFieldType->mAlign, mNewDataType->mAlign));
-  mNewDataType->mTotalSize = pNewField->mOffset + (pNewField->mFieldType->mTotalSize) * ((ArrayNum == 0) ? 1 : ArrayNum);
+
+  if (FieldInUnion) {
+    if (MaxDataTypeSize < pNewField->mFieldType->mTotalSize) {
+      mNewDataType->mTotalSize = pNewField->mFieldType->mTotalSize;
+    }
+    pNewField->mOffset = 0;
+  } else {
+    mNewDataType->mTotalSize = pNewField->mOffset + (pNewField->mFieldType->mTotalSize) * ((ArrayNum == 0) ? 1 : ArrayNum);
+  }
 
   return VFR_RETURN_SUCCESS;
 }
 
 VOID
diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
index 59509c3..0c67d73 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
@@ -1,10 +1,10 @@
 /** @file
   
   Vfr common library functions.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 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                                            
                                                                                           
@@ -203,11 +203,11 @@ public:
   CVfrVarDataTypeDB (VOID);
   ~CVfrVarDataTypeDB (VOID);
 
   VOID                DeclareDataTypeBegin (VOID);
   EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *);
-  EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN UINT32);
+  EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN UINT32, IN BOOLEAN);
   VOID                DeclareDataTypeEnd (VOID);
 
   EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **);
   EFI_VFR_RETURN_CODE GetDataTypeSize (IN CHAR8 *, OUT UINT32 *);
   EFI_VFR_RETURN_CODE GetDataTypeSize (IN UINT8, OUT UINT32 *);
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [patch 1/6] BaseTool/VfrCompile: Support Union type in VFR
Posted by Dong, Eric 7 years, 3 months ago
Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: Bi, Dandan 
Sent: Monday, September 4, 2017 3:16 PM
To: edk2-devel@lists.01.org
Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [patch 1/6] BaseTool/VfrCompile: Support Union type in VFR

https://bugzilla.tianocore.org/show_bug.cgi?id=603

Update VfrCompiler to parse the UNION type in vfr file

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 BaseTools/Source/C/VfrCompile/VfrSyntax.g       | 81 +++++++++++++++----------
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 17 +++++-
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.h   |  4 +-
 3 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
index 406dbc5..24e0538 100644
--- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g
+++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
@@ -155,10 +155,11 @@ VfrParserStart (
 #token Label("label")                           "label"
 #token Timeout("timeout")                       "timeout"
 #token Inventory("inventory")                   "inventory"
 #token NonNvDataMap("_NON_NV_DATA_MAP")         "_NON_NV_DATA_MAP"
 #token Struct("struct")                         "struct"
+#token Union("union")                           "union"
 #token Boolean("BOOLEAN")                       "BOOLEAN"
 #token Uint64("UINT64")                         "UINT64"
 #token Uint32("UINT32")                         "UINT32"
 #token Uint16("UINT16")                         "UINT16"
 #token Char16("CHAR16")                         "CHAR16"
@@ -270,10 +271,11 @@ vfrProgram > [UINT8 Return] :
      mConstantOnlyInExpression = FALSE;
   >>
   (
       vfrPragmaPackDefinition
     | vfrDataStructDefinition
+    | vfrDataUnionDefinition
   )*
   vfrFormSetDefinition
   << $Return = mParserStatus; >>
   ;
 
@@ -318,140 +320,155 @@ vfrPragmaPackDefinition :
     | pragmaPackNumber
   }
   "\)"
   ;
 
+  vfrDataUnionDefinition :
+  { TypeDef } Union                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
+  { NonNvDataMap }
+  {
+    N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
+  }
+  OpenBrace
+    vfrDataStructFields[TRUE]
+  CloseBrace
+  {
+    N2:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
+  }
+  ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd ();>>
+  ;
+
 vfrDataStructDefinition :
   { TypeDef } Struct                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
   { NonNvDataMap }
   {
     N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
   }
   OpenBrace
-    vfrDataStructFields
+    vfrDataStructFields[FALSE]
   CloseBrace
   {
     N2:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
   }
   ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd (); >>
   ;
 
-vfrDataStructFields :
+vfrDataStructFields [BOOLEAN  FieldInUnion]:
   (
-     dataStructField64     |
-     dataStructField32     |
-     dataStructField16     |
-     dataStructField8      |
-     dataStructFieldBool   |
-     dataStructFieldString |
-     dataStructFieldDate   |
-     dataStructFieldTime   |
-     dataStructFieldRef    |
-     dataStructFieldUser
+     dataStructField64 [FieldInUnion]    |
+     dataStructField32 [FieldInUnion]    |
+     dataStructField16 [FieldInUnion]    |
+     dataStructField8  [FieldInUnion]    |
+     dataStructFieldBool [FieldInUnion]  |
+     dataStructFieldString [FieldInUnion]|
+     dataStructFieldDate  [FieldInUnion] |
+     dataStructFieldTime  [FieldInUnion] |
+     dataStructFieldRef   [FieldInUnion] |
+     dataStructFieldUser [FieldInUnion]
   )*
   ;
 
-dataStructField64 :
+dataStructField64 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT64"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField32 :
+dataStructField32 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT32"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField16 :
+dataStructField16 [BOOLEAN  FieldInUnion]:
   << 
     UINT32 ArrayNum = 0; 
   >>
   ("UINT16" | "CHAR16")
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) "UINT16", ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) "UINT16", ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructField8 :
+dataStructField8 [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"UINT8"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldBool :
+dataStructFieldBool [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"BOOLEAN"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldString :
+dataStructFieldString [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_STRING_ID"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldDate :
+dataStructFieldDate [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_DATE"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldTime :
+dataStructFieldTime [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_TIME"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldRef :
+dataStructFieldRef [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   D:"EFI_HII_REF"
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum), N); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), ArrayNum, FieldInUnion), N); >>
   ;
 
-dataStructFieldUser :
+dataStructFieldUser [BOOLEAN  FieldInUnion]:
   << UINT32 ArrayNum = 0; >>
   T:StringIdentifier
   N:StringIdentifier
   {
     OpenBracket I:Number CloseBracket               << ArrayNum = _STOU32(I->getText(), I->getLine()); >>
   }
-  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), ArrayNum), T); >>
+  ";"                                               << _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), ArrayNum, FieldInUnion), T); >>
   ;
 
 //*****************************************************************************
 //
 // the syntax of GUID definition
diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
index 2f97975..37b58e2 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
@@ -1,10 +1,10 @@
 /** @file
   
   Vfr common library functions.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 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                                            
                                                                                           
@@ -1011,19 +1011,22 @@ CVfrVarDataTypeDB::SetNewTypeName (
 
 EFI_VFR_RETURN_CODE
 CVfrVarDataTypeDB::DataTypeAddField (
   IN CHAR8   *FieldName,
   IN CHAR8   *TypeName,
-  IN UINT32 ArrayNum
+  IN UINT32 ArrayNum,
+  IN BOOLEAN FieldInUnion
   )
 {
   SVfrDataField       *pNewField  = NULL;
   SVfrDataType        *pFieldType = NULL;
   SVfrDataField       *pTmp;
   UINT32              Align;
+  UINT32              MaxDataTypeSize;
 
   CHECK_ERROR_RETURN (GetDataType (TypeName, &pFieldType), VFR_RETURN_SUCCESS);
+  MaxDataTypeSize = mNewDataType->mTotalSize;
 
   if (strlen (FieldName) >= MAX_NAME_LEN) {
    return VFR_RETURN_INVALID_PARAMETER;
   }
 
@@ -1055,11 +1058,19 @@ CVfrVarDataTypeDB::DataTypeAddField (
     pTmp->mNext            = pNewField;
     pNewField->mNext       = NULL;
   }
 
   mNewDataType->mAlign     = MIN (mPackAlign, MAX (pFieldType->mAlign, mNewDataType->mAlign));
-  mNewDataType->mTotalSize = pNewField->mOffset + (pNewField->mFieldType->mTotalSize) * ((ArrayNum == 0) ? 1 : ArrayNum);
+
+  if (FieldInUnion) {
+    if (MaxDataTypeSize < pNewField->mFieldType->mTotalSize) {
+      mNewDataType->mTotalSize = pNewField->mFieldType->mTotalSize;
+    }
+    pNewField->mOffset = 0;
+  } else {
+    mNewDataType->mTotalSize = pNewField->mOffset + 
+ (pNewField->mFieldType->mTotalSize) * ((ArrayNum == 0) ? 1 : 
+ ArrayNum);  }
 
   return VFR_RETURN_SUCCESS;
 }
 
 VOID
diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
index 59509c3..0c67d73 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
@@ -1,10 +1,10 @@
 /** @file
   
   Vfr common library functions.
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 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                                            
                                                                                           
@@ -203,11 +203,11 @@ public:
   CVfrVarDataTypeDB (VOID);
   ~CVfrVarDataTypeDB (VOID);
 
   VOID                DeclareDataTypeBegin (VOID);
   EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *);
-  EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN UINT32);
+  EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN 
+ UINT32, IN BOOLEAN);
   VOID                DeclareDataTypeEnd (VOID);
 
   EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **);
   EFI_VFR_RETURN_CODE GetDataTypeSize (IN CHAR8 *, OUT UINT32 *);
   EFI_VFR_RETURN_CODE GetDataTypeSize (IN UINT8, OUT UINT32 *);
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel