public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RFC v2 0/2] Support Union type in VFR
@ 2017-06-05  4:30 Dandan Bi
  2017-06-05  4:30 ` [RFC v2 1/2] BaseTool/VfrCompile: " Dandan Bi
  2017-06-05  4:30 ` [RFC v2 2/2] MdeModulePkg/DriverSample: Add sample questions to refer union type Dandan Bi
  0 siblings, 2 replies; 5+ messages in thread
From: Dandan Bi @ 2017-06-05  4:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Liming Gao, Ruiyu Ni

V2: Update VfrCompiler to use member variable instead of global varable
to indicate whether current date type is Union.

This serie is the POC to update VfrCompiler to support Union type
in VarStore and construct the use cases in DriverSample.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Dandan Bi (2):
  BaseTool/VfrCompile: Support Union type in VFR
  MdeModulePkg/DriverSample: Add sample questions to refer union type

 BaseTools/Source/C/VfrCompile/VfrSyntax.g          | 19 +++++++-
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp    | 16 +++++-
 BaseTools/Source/C/VfrCompile/VfrUtilityLib.h      |  3 +-
 .../Universal/DriverSampleDxe/DriverSample.c       | 57 ++++++++++++++++++++++
 .../Universal/DriverSampleDxe/DriverSample.h       |  1 +
 .../Universal/DriverSampleDxe/NVDataStruc.h        | 18 +++++++
 MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr     | 25 ++++++++++
 .../Universal/DriverSampleDxe/VfrStrings.uni       |  4 ++
 8 files changed, 139 insertions(+), 4 deletions(-)

-- 
1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR
  2017-06-05  4:30 [RFC v2 0/2] Support Union type in VFR Dandan Bi
@ 2017-06-05  4:30 ` Dandan Bi
  2017-06-05  6:49   ` Ni, Ruiyu
  2017-06-05  4:30 ` [RFC v2 2/2] MdeModulePkg/DriverSample: Add sample questions to refer union type Dandan Bi
  1 sibling, 1 reply; 5+ messages in thread
From: Dandan Bi @ 2017-06-05  4:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Liming Gao, Ruiyu Ni

V2: Update VfrCompiler to use member variable instead of global varable
to indicate whether current date type is Union.

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

diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
index 406dbc5..9e1212a 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,12 +320,27 @@ vfrPragmaPackDefinition :
     | pragmaPackNumber
   }
   "\)"
   ;
 
+  vfrDataUnionDefinition :
+  { TypeDef } Union                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (TRUE); >>
+  { NonNvDataMap }
+  {
+    N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
+  }
+  OpenBrace
+    vfrDataStructFields
+  CloseBrace
+  {
+    N2:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
+  }
+  ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd ();>>
+  ;
+
 vfrDataStructDefinition :
-  { TypeDef } Struct                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
+  { TypeDef } Struct                                << gCVfrVarDataTypeDB.DeclareDataTypeBegin (FALSE); >>
   { NonNvDataMap }
   {
     N1:StringIdentifier                             << _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
   }
   OpenBrace
diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
index 2f97975..186b9c9 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
@@ -776,10 +776,11 @@ CVfrVarDataTypeDB::InternalTypesListInit (
     if (New != NULL) {
       strcpy (New->mTypeName, gInternalTypesTable[Index].mTypeName);
       New->mType        = gInternalTypesTable[Index].mType;
       New->mAlign       = gInternalTypesTable[Index].mAlign;
       New->mTotalSize   = gInternalTypesTable[Index].mSize;
+      New->mIsUnionType = FALSE;
       if (strcmp (gInternalTypesTable[Index].mTypeName, "EFI_HII_DATE") == 0) {
         SVfrDataField *pYearField  = new SVfrDataField;
         SVfrDataField *pMonthField = new SVfrDataField;
         SVfrDataField *pDayField   = new SVfrDataField;
 
@@ -964,11 +965,11 @@ CVfrVarDataTypeDB::Pack (
   return VFR_RETURN_SUCCESS;
 }
 
 VOID
 CVfrVarDataTypeDB::DeclareDataTypeBegin (
-  VOID
+  BOOLEAN  IsUnionType
   )
 {
   SVfrDataType *pNewType = NULL;
 
   pNewType               = new SVfrDataType;
@@ -976,10 +977,11 @@ CVfrVarDataTypeDB::DeclareDataTypeBegin (
   pNewType->mType        = EFI_IFR_TYPE_OTHER;
   pNewType->mAlign       = DEFAULT_ALIGN;
   pNewType->mTotalSize   = 0;
   pNewType->mMembers     = NULL;
   pNewType->mNext        = NULL;
+  pNewType->mIsUnionType = IsUnionType;
 
   mNewDataType           = pNewType;
 }
 
 EFI_VFR_RETURN_CODE
@@ -1018,12 +1020,14 @@ CVfrVarDataTypeDB::DataTypeAddField (
 {
   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 +1059,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 (mNewDataType->mIsUnionType) {
+    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..13b75e4 100644
--- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
+++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
@@ -124,10 +124,11 @@ struct SVfrDataType {
   UINT8                     mType;
   UINT32                    mAlign;
   UINT32                    mTotalSize;
   SVfrDataField             *mMembers;
   SVfrDataType              *mNext;
+  BOOLEAN                   mIsUnionType;
 };
 
 #define VFR_PACK_ASSIGN     0x01
 #define VFR_PACK_SHOW       0x02
 #define VFR_PACK_PUSH       0x04
@@ -201,11 +202,11 @@ private:
 
 public:
   CVfrVarDataTypeDB (VOID);
   ~CVfrVarDataTypeDB (VOID);
 
-  VOID                DeclareDataTypeBegin (VOID);
+  VOID                DeclareDataTypeBegin (BOOLEAN);
   EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *);
   EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN UINT32);
   VOID                DeclareDataTypeEnd (VOID);
 
   EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **);
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC v2 2/2] MdeModulePkg/DriverSample: Add sample questions to refer union type
  2017-06-05  4:30 [RFC v2 0/2] Support Union type in VFR Dandan Bi
  2017-06-05  4:30 ` [RFC v2 1/2] BaseTool/VfrCompile: " Dandan Bi
@ 2017-06-05  4:30 ` Dandan Bi
  1 sibling, 0 replies; 5+ messages in thread
From: Dandan Bi @ 2017-06-05  4:30 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Liming Gao, Ruiyu Ni

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../Universal/DriverSampleDxe/DriverSample.c       | 57 ++++++++++++++++++++++
 .../Universal/DriverSampleDxe/DriverSample.h       |  1 +
 .../Universal/DriverSampleDxe/NVDataStruc.h        | 18 +++++++
 MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr     | 25 ++++++++++
 .../Universal/DriverSampleDxe/VfrStrings.uni       |  4 ++
 5 files changed, 105 insertions(+)

diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
index f103b9c..c4cd7f2 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
@@ -18,10 +18,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #define DISPLAY_ONLY_MY_ITEM  0x0002
 
 CHAR16     VariableName[] = L"MyIfrNVData";
 CHAR16     MyEfiVar[] = L"MyEfiVar";
+CHAR16     MyUnionVar[] = L"MyUnionVar";
 EFI_HANDLE                      DriverHandle[2] = {NULL, NULL};
 DRIVER_SAMPLE_PRIVATE_DATA      *mPrivateData = NULL;
 EFI_EVENT                       mEvent;
 
 HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {
@@ -662,10 +663,14 @@ ExtractConfig (
     // through hii database, not support in this path.
     //
     if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {
       return EFI_UNSUPPORTED;
     }
+
+    if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyUnionVar)) {
+      return EFI_UNSUPPORTED;
+    }
     //
     // Set Request to the unified request string.
     //
     ConfigRequest = Request;
     //
@@ -884,10 +889,14 @@ RouteConfig (
   //
   if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
     return EFI_UNSUPPORTED;
   }
 
+  if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyUnionVar)) {
+    return EFI_UNSUPPORTED;
+  }
+
   //
   // Get Buffer Storage data from EFI variable
   //
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
   Status = gRT->GetVariable (
@@ -1685,10 +1694,11 @@ DriverSampleInit (
   EFI_STRING                      ConfigRequestHdr;
   EFI_STRING                      NameRequestHdr;
   MY_EFI_VARSTORE_DATA            *VarStoreConfig;
   EFI_INPUT_KEY                   HotKey;
   EDKII_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
+  MY_UNION_DATA                   *UnionConfig;
 
   //
   // Initialize the local variables.
   //
   ConfigRequestHdr = NULL;
@@ -1962,10 +1972,57 @@ DriverSampleInit (
       return EFI_INVALID_PARAMETER;
     }
   }
   FreePool (ConfigRequestHdr);
 
+  //
+  // Initialize Union efi varstore configuration data
+  //
+  UnionConfig = &mPrivateData->UnionConfig;
+  ZeroMem (UnionConfig, sizeof (MY_UNION_DATA));
+
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyUnionVar, DriverHandle[0]);
+  ASSERT (ConfigRequestHdr != NULL);
+
+  BufferSize = sizeof (MY_UNION_DATA);
+  Status = gRT->GetVariable (MyUnionVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, UnionConfig);
+  if (EFI_ERROR (Status)) {
+    //
+    // Store zero data to EFI variable Storage.
+    //
+    Status = gRT->SetVariable(
+                    MyUnionVar,
+                    &gDriverSampleFormSetGuid,
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+                    sizeof (MY_UNION_DATA),
+                    UnionConfig
+                    );
+    if (EFI_ERROR (Status)) {
+      DriverSampleUnload (ImageHandle);
+      return Status;
+    }
+    //
+    // EFI variable for NV config doesn't exit, we should build this variable
+    // based on default values stored in IFR
+    //
+    ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
+    if (!ActionFlag) {
+      DriverSampleUnload (ImageHandle);
+      return EFI_INVALID_PARAMETER;
+    }
+  } else {
+    //
+    // EFI variable does exist and Validate Current Setting
+    //
+    ActionFlag = HiiValidateSettings (ConfigRequestHdr);
+    if (!ActionFlag) {
+      DriverSampleUnload (ImageHandle);
+      return EFI_INVALID_PARAMETER;
+    }
+  }
+  FreePool (ConfigRequestHdr);
+
   Status = gBS->CreateEventEx (
         EVT_NOTIFY_SIGNAL, 
         TPL_NOTIFY,
         EfiEventEmptyFunction,
         NULL,
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
index 6c97239..895547a 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
@@ -82,10 +82,11 @@ typedef struct {
 
   EFI_HANDLE                       DriverHandle[2];
   EFI_HII_HANDLE                   HiiHandle[2];
   DRIVER_SAMPLE_CONFIGURATION      Configuration;
   MY_EFI_VARSTORE_DATA             VarStoreConfig;
+  MY_UNION_DATA                    UnionConfig;
 
   //
   // Name/Value storage Name list
   //
   EFI_STRING_ID                    NameStringId[NAME_VALUE_NAME_NUMBER];
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
index 195cc8a..eee7282 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
+++ b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
@@ -31,10 +31,22 @@ Revision History:
 #include <Guid/ZeroGuid.h>
 
 #define CONFIGURATION_VARSTORE_ID    0x1234
 
 #pragma pack(1)
+
+typedef struct {
+  UINT8         Field8;
+  UINT16        Field16;
+  UINT8         OrderedList[6];
+} MY_EFI_VARSTORE2_DATA;
+
+typedef union {
+  MY_EFI_VARSTORE2_DATA Data2;
+  UINT8   HowOldAreYouInYearsManual;
+} UNION_DATA_TEST;
+
 typedef struct {
   UINT16  MyStringData[40];
   UINT16  SomethingHiddenForHtml;
   UINT8   HowOldAreYouInYearsManual;
   UINT16  HowTallAreYouManual;
@@ -62,10 +74,11 @@ typedef struct {
   UINT16  SerialPortIo;
   UINT8   SerialPortIrq;
   UINT8   GetDefaultValueFromCallBack;
   UINT8   GetDefaultValueFromAccess;
   EFI_HII_TIME  Time;
+  UNION_DATA_TEST UnionData;
   UINT8   RefreshGuidCount;
   UINT8   Match2;
   UINT8   GetDefaultValueFromCallBackForOrderedList[3];
 } DRIVER_SAMPLE_CONFIGURATION;
 
@@ -77,10 +90,15 @@ typedef struct {
   UINT16        Field16;
   UINT8         OrderedList[3];
   UINT16        SubmittedCallback;
 } MY_EFI_VARSTORE_DATA;
 
+typedef union {
+  MY_EFI_VARSTORE_DATA  Data1;
+  MY_EFI_VARSTORE2_DATA Data2;
+} MY_UNION_DATA;
+
 //
 // Labels definition
 //
 #define LABEL_UPDATE1               0x1234
 #define LABEL_UPDATE2               0x2234
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
index 4bdaf76..9dc88ab 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
+++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
@@ -85,10 +85,15 @@ formset
   efivarstore MY_EFI_VARSTORE_DATA,
     attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,  // EFI variable attribures  
     name  = MyEfiVar,
     guid  = DRIVER_SAMPLE_FORMSET_GUID;
 
+  efivarstore MY_UNION_DATA,
+    attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,  // EFI variable attribures
+    name  = MyUnionVar,
+    guid  = DRIVER_SAMPLE_FORMSET_GUID;
+
   //
   // Define a Name/Value Storage (EFI_IFR_VARSTORE_NAME_VALUE)
   //
   namevaluevarstore MyNameValueVar,                // Define storage reference name in vfr
     name = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME0), // Define Name list of this storage, refer it by MyNameValueVar[0]
@@ -112,10 +117,30 @@ formset
 
     subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT);
 
     subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT2);
 
+    numeric varid   = MyUnionVar.Data2.Field8,
+            prompt  = STRING_TOKEN(STR_UNION_NUMERIC_PROMPT),
+            help    = STRING_TOKEN(STR_UNION_NUMERIC_HELP),
+            minimum = 0,
+            maximum = 20,
+            step    = 0,
+            default = 7, defaultstore = MyStandardDefault,     // This is standard default value
+            default = 8, defaultstore = MyManufactureDefault,  // This is manufacture default value
+    endnumeric;
+
+    numeric varid   = MyIfrNVData.UnionData.Data2.Field8,
+            prompt  = STRING_TOKEN(STR_UNION_NUMERIC_PROMPT),
+            help    = STRING_TOKEN(STR_UNION_NUMERIC_HELP),
+            minimum = 0,
+            maximum = 20,
+            step    = 0,
+            default = 7, defaultstore = MyStandardDefault,     // This is standard default value
+            default = 8, defaultstore = MyManufactureDefault,  // This is manufacture default value
+    endnumeric;
+
     //
     // Define a display only text (EFI_IFR_TEXT)
     //
     text
       help   = STRING_TOKEN(STR_TEXT_HELP),       // Help string
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
index 8d24a47..2a632d4 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
+++ b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
@@ -86,10 +86,14 @@
                                        #language fr-FR "Éste es el mensaje de la ayuda para la activación del armamento nuclear. Cuál es exactamente resistente calcular fuera sobre de eso?"
 #string STR_CHECK_DYNAMIC_PROMPT       #language en-US "Activate Dynamic check box"
                                        #language fr-FR "Activate Dynamico check box"
 #string STR_CHECK_DYNAMIC_HELP         #language en-US "This is the help message for the activation of check boxes.  This is not to be confused with activating Czech boxes, since one can never tell what the ramifications are of activating foreign controlled boxes are."
                                        #language fr-FR "Spanish - This is the help message for the activation of check boxes.  This is not to be confused with activating Czech boxes, since one can never tell what the ramifications are of activating foreign controlled boxes are."
+#string STR_UNION_NUMERIC_PROMPT       #language en-US "UNION numeric"
+                                       #language fr-FR "UNION numeric"
+#string STR_UNION_NUMERIC_HELP         #language en-US "Varstore refer to union type"
+                                       #language fr-FR "Varstore refer to union type"
 #string STR_NUMERIC_PROMPT             #language en-US "How old are you?"
                                        #language fr-FR "Cómo viejo es usted?"
 #string STR_NUMERIC_STEP_PROMPT        #language en-US "How old are you? (Step)"
                                        #language fr-FR "Cómo viejo es usted?(Step)"
 #string STR_NUMERIC_PROMPT1            #language en-US "How tall are you?"
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR
  2017-06-05  4:30 ` [RFC v2 1/2] BaseTool/VfrCompile: " Dandan Bi
@ 2017-06-05  6:49   ` Ni, Ruiyu
  2017-06-05  8:52     ` Bi, Dandan
  0 siblings, 1 reply; 5+ messages in thread
From: Ni, Ruiyu @ 2017-06-05  6:49 UTC (permalink / raw)
  To: Bi, Dandan, edk2-devel@lists.01.org; +Cc: Dong, Eric, Gao, Liming

Dandan,
Is it possible to avoid adding IsUnion member variable?
I remember .G syntax supports passing value to sub-statement.
In this case, can you use: vfrDataStructFields [IsUnion]?

Thanks/Ray

> -----Original Message-----
> From: Bi, Dandan
> Sent: Monday, June 5, 2017 12:31 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>; Ni,
> Ruiyu <ruiyu.ni@intel.com>
> Subject: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR
> 
> V2: Update VfrCompiler to use member variable instead of global varable to
> indicate whether current date type is Union.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Dandan Bi <dandan.bi@intel.com>
> ---
>  BaseTools/Source/C/VfrCompile/VfrSyntax.g       | 19 ++++++++++++++++++-
>  BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 16 ++++++++++++++--
>  BaseTools/Source/C/VfrCompile/VfrUtilityLib.h   |  3 ++-
>  3 files changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g
> b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
> index 406dbc5..9e1212a 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,12 +320,27 @@ vfrPragmaPackDefinition :
>      | pragmaPackNumber
>    }
>    "\)"
>    ;
> 
> +  vfrDataUnionDefinition :
> +  { TypeDef } Union                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (TRUE); >>
> +  { NonNvDataMap }
> +  {
> +    N1:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
> +  }
> +  OpenBrace
> +    vfrDataStructFields
> +  CloseBrace
> +  {
> +    N2:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
> +  }
> +  ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd
> ();>>
> +  ;
> +
>  vfrDataStructDefinition :
> -  { TypeDef } Struct                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
> +  { TypeDef } Struct                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (FALSE); >>
>    { NonNvDataMap }
>    {
>      N1:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
>    }
>    OpenBrace
> diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> index 2f97975..186b9c9 100644
> --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> @@ -776,10 +776,11 @@ CVfrVarDataTypeDB::InternalTypesListInit (
>      if (New != NULL) {
>        strcpy (New->mTypeName, gInternalTypesTable[Index].mTypeName);
>        New->mType        = gInternalTypesTable[Index].mType;
>        New->mAlign       = gInternalTypesTable[Index].mAlign;
>        New->mTotalSize   = gInternalTypesTable[Index].mSize;
> +      New->mIsUnionType = FALSE;
>        if (strcmp (gInternalTypesTable[Index].mTypeName, "EFI_HII_DATE") == 0) {
>          SVfrDataField *pYearField  = new SVfrDataField;
>          SVfrDataField *pMonthField = new SVfrDataField;
>          SVfrDataField *pDayField   = new SVfrDataField;
> 
> @@ -964,11 +965,11 @@ CVfrVarDataTypeDB::Pack (
>    return VFR_RETURN_SUCCESS;
>  }
> 
>  VOID
>  CVfrVarDataTypeDB::DeclareDataTypeBegin (
> -  VOID
> +  BOOLEAN  IsUnionType
>    )
>  {
>    SVfrDataType *pNewType = NULL;
> 
>    pNewType               = new SVfrDataType;
> @@ -976,10 +977,11 @@ CVfrVarDataTypeDB::DeclareDataTypeBegin (
>    pNewType->mType        = EFI_IFR_TYPE_OTHER;
>    pNewType->mAlign       = DEFAULT_ALIGN;
>    pNewType->mTotalSize   = 0;
>    pNewType->mMembers     = NULL;
>    pNewType->mNext        = NULL;
> +  pNewType->mIsUnionType = IsUnionType;
> 
>    mNewDataType           = pNewType;
>  }
> 
>  EFI_VFR_RETURN_CODE
> @@ -1018,12 +1020,14 @@ CVfrVarDataTypeDB::DataTypeAddField (  {
>    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 +1059,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 (mNewDataType->mIsUnionType) {
> +    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..13b75e4 100644
> --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
> +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
> @@ -124,10 +124,11 @@ struct SVfrDataType {
>    UINT8                     mType;
>    UINT32                    mAlign;
>    UINT32                    mTotalSize;
>    SVfrDataField             *mMembers;
>    SVfrDataType              *mNext;
> +  BOOLEAN                   mIsUnionType;
>  };
> 
>  #define VFR_PACK_ASSIGN     0x01
>  #define VFR_PACK_SHOW       0x02
>  #define VFR_PACK_PUSH       0x04
> @@ -201,11 +202,11 @@ private:
> 
>  public:
>    CVfrVarDataTypeDB (VOID);
>    ~CVfrVarDataTypeDB (VOID);
> 
> -  VOID                DeclareDataTypeBegin (VOID);
> +  VOID                DeclareDataTypeBegin (BOOLEAN);
>    EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *);
>    EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN
> UINT32);
>    VOID                DeclareDataTypeEnd (VOID);
> 
>    EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **);
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR
  2017-06-05  6:49   ` Ni, Ruiyu
@ 2017-06-05  8:52     ` Bi, Dandan
  0 siblings, 0 replies; 5+ messages in thread
From: Bi, Dandan @ 2017-06-05  8:52 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org; +Cc: Dong, Eric, Gao, Liming

Hi Ray,

Thanks for your comments! Yes, we also can avoid using member variable.

Based on my understanding, we can parse value to sub-statement.
So when parsing a Struct/Union type, it  can pass this info to its member fields , then we can detect whether current Data Type is Struct or Union.
In this case, we need to update all the definitions of the dataStructField and related functions.

If we add member variable/ global variable, we can keep the definition of the dataStructField same as before, no need to consider whether  they are members
Of a Struct or Union in the parsing  part. When calculating the TotalSize of current  Data Type , we can know the Data Type according to the member variable/ global variable.

I am ok to update the codes to avoid adding new member variable and will send new patches.

Liming/Eric, do you have any comments for this ?


Thanks,
Dandan

-----Original Message-----
From: Ni, Ruiyu 
Sent: Monday, June 5, 2017 2:49 PM
To: Bi, Dandan <dandan.bi@intel.com>; edk2-devel@lists.01.org
Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: RE: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR

Dandan,
Is it possible to avoid adding IsUnion member variable?
I remember .G syntax supports passing value to sub-statement.
In this case, can you use: vfrDataStructFields [IsUnion]?

Thanks/Ray

> -----Original Message-----
> From: Bi, Dandan
> Sent: Monday, June 5, 2017 12:31 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming 
> <liming.gao@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR
> 
> V2: Update VfrCompiler to use member variable instead of global 
> varable to indicate whether current date type is Union.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Dandan Bi <dandan.bi@intel.com>
> ---
>  BaseTools/Source/C/VfrCompile/VfrSyntax.g       | 19 ++++++++++++++++++-
>  BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 16 ++++++++++++++--
>  BaseTools/Source/C/VfrCompile/VfrUtilityLib.h   |  3 ++-
>  3 files changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g
> b/BaseTools/Source/C/VfrCompile/VfrSyntax.g
> index 406dbc5..9e1212a 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,12 +320,27 @@ vfrPragmaPackDefinition :
>      | pragmaPackNumber
>    }
>    "\)"
>    ;
> 
> +  vfrDataUnionDefinition :
> +  { TypeDef } Union                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (TRUE); >>
> +  { NonNvDataMap }
> +  {
> +    N1:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
> +  }
> +  OpenBrace
> +    vfrDataStructFields
> +  CloseBrace
> +  {
> +    N2:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >>
> +  }
> +  ";"                                               << gCVfrVarDataTypeDB.DeclareDataTypeEnd
> ();>>
> +  ;
> +
>  vfrDataStructDefinition :
> -  { TypeDef } Struct                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >>
> +  { TypeDef } Struct                                <<
> gCVfrVarDataTypeDB.DeclareDataTypeBegin (FALSE); >>
>    { NonNvDataMap }
>    {
>      N1:StringIdentifier                             <<
> _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >>
>    }
>    OpenBrace
> diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> index 2f97975..186b9c9 100644
> --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
> @@ -776,10 +776,11 @@ CVfrVarDataTypeDB::InternalTypesListInit (
>      if (New != NULL) {
>        strcpy (New->mTypeName, gInternalTypesTable[Index].mTypeName);
>        New->mType        = gInternalTypesTable[Index].mType;
>        New->mAlign       = gInternalTypesTable[Index].mAlign;
>        New->mTotalSize   = gInternalTypesTable[Index].mSize;
> +      New->mIsUnionType = FALSE;
>        if (strcmp (gInternalTypesTable[Index].mTypeName, "EFI_HII_DATE") == 0) {
>          SVfrDataField *pYearField  = new SVfrDataField;
>          SVfrDataField *pMonthField = new SVfrDataField;
>          SVfrDataField *pDayField   = new SVfrDataField;
> 
> @@ -964,11 +965,11 @@ CVfrVarDataTypeDB::Pack (
>    return VFR_RETURN_SUCCESS;
>  }
> 
>  VOID
>  CVfrVarDataTypeDB::DeclareDataTypeBegin (
> -  VOID
> +  BOOLEAN  IsUnionType
>    )
>  {
>    SVfrDataType *pNewType = NULL;
> 
>    pNewType               = new SVfrDataType;
> @@ -976,10 +977,11 @@ CVfrVarDataTypeDB::DeclareDataTypeBegin (
>    pNewType->mType        = EFI_IFR_TYPE_OTHER;
>    pNewType->mAlign       = DEFAULT_ALIGN;
>    pNewType->mTotalSize   = 0;
>    pNewType->mMembers     = NULL;
>    pNewType->mNext        = NULL;
> +  pNewType->mIsUnionType = IsUnionType;
> 
>    mNewDataType           = pNewType;
>  }
> 
>  EFI_VFR_RETURN_CODE
> @@ -1018,12 +1020,14 @@ CVfrVarDataTypeDB::DataTypeAddField (  {
>    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 +1059,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 (mNewDataType->mIsUnionType) {
> +    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..13b75e4 100644
> --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
> +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h
> @@ -124,10 +124,11 @@ struct SVfrDataType {
>    UINT8                     mType;
>    UINT32                    mAlign;
>    UINT32                    mTotalSize;
>    SVfrDataField             *mMembers;
>    SVfrDataType              *mNext;
> +  BOOLEAN                   mIsUnionType;
>  };
> 
>  #define VFR_PACK_ASSIGN     0x01
>  #define VFR_PACK_SHOW       0x02
>  #define VFR_PACK_PUSH       0x04
> @@ -201,11 +202,11 @@ private:
> 
>  public:
>    CVfrVarDataTypeDB (VOID);
>    ~CVfrVarDataTypeDB (VOID);
> 
> -  VOID                DeclareDataTypeBegin (VOID);
> +  VOID                DeclareDataTypeBegin (BOOLEAN);
>    EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *);
>    EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN 
> UINT32);
>    VOID                DeclareDataTypeEnd (VOID);
> 
>    EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **);
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-05  8:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-05  4:30 [RFC v2 0/2] Support Union type in VFR Dandan Bi
2017-06-05  4:30 ` [RFC v2 1/2] BaseTool/VfrCompile: " Dandan Bi
2017-06-05  6:49   ` Ni, Ruiyu
2017-06-05  8:52     ` Bi, Dandan
2017-06-05  4:30 ` [RFC v2 2/2] MdeModulePkg/DriverSample: Add sample questions to refer union type Dandan Bi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox