[edk2] [RFC patch 4/4] MdeModulePkg/DriverSample: Add smaple questions with bit VarStore

Dandan Bi posted 4 patches 7 years, 8 months ago
[edk2] [RFC patch 4/4] MdeModulePkg/DriverSample: Add smaple questions with bit VarStore
Posted by Dandan Bi 7 years, 8 months ago
1.Construct the EFI VarStore with: (a) bit fields (b) nested structure(
the nested structure contains bit fields).
2.Construct oneof/numeric/check to refer the bit fields of the
EFI VarStore.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../Universal/DriverSampleDxe/DriverSample.c       | 56 +++++++++++++++++++
 .../Universal/DriverSampleDxe/DriverSample.h       |  1 +
 .../Universal/DriverSampleDxe/NVDataStruc.h        | 19 +++++++
 MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr     | 65 ++++++++++++++++++++++
 .../Universal/DriverSampleDxe/VfrStrings.uni       | 12 ++++
 5 files changed, 153 insertions(+)

diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
index f103b9c..b226a65 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     MyBitVar[] = L"MyBitVar";
 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, MyBitVar)) {
+      return EFI_UNSUPPORTED;
+    }
+
     //
     // Set Request to the unified request string.
     //
     ConfigRequest = Request;
     //
@@ -883,10 +888,13 @@ RouteConfig (
   // through hii database, not support in this path.
   //
   if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
     return EFI_UNSUPPORTED;
   }
+  if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyBitVar)) {
+    return EFI_UNSUPPORTED;
+  }
 
   //
   // Get Buffer Storage data from EFI variable
   //
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
@@ -1683,10 +1691,11 @@ DriverSampleInit (
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;
   BOOLEAN                         ActionFlag;
   EFI_STRING                      ConfigRequestHdr;
   EFI_STRING                      NameRequestHdr;
   MY_EFI_VARSTORE_DATA            *VarStoreConfig;
+  MY_BITS_VARSTORE_DATA           *BitsVarStoreConfig;
   EFI_INPUT_KEY                   HotKey;
   EDKII_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
 
   //
   // Initialize the local variables.
@@ -1962,10 +1971,57 @@ DriverSampleInit (
       return EFI_INVALID_PARAMETER;
     }
   }
   FreePool (ConfigRequestHdr);
 
+  //
+  // Initialize Bits efi varstore configuration data
+  //
+  BitsVarStoreConfig = &mPrivateData->BitsVarStoreConfig;
+  ZeroMem (BitsVarStoreConfig, sizeof (MY_BITS_VARSTORE_DATA));
+
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyBitVar, DriverHandle[0]);
+  ASSERT (ConfigRequestHdr != NULL);
+
+  BufferSize = sizeof (MY_BITS_VARSTORE_DATA);
+  Status = gRT->GetVariable (MyBitVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, BitsVarStoreConfig);
+  if (EFI_ERROR (Status)) {
+    //
+    // Store zero data to EFI variable Storage.
+    //
+    Status = gRT->SetVariable(
+                    MyBitVar,
+                    &gDriverSampleFormSetGuid,
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+                    sizeof (MY_BITS_VARSTORE_DATA),
+                    BitsVarStoreConfig
+                    );
+    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..6947cea 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_BITS_VARSTORE_DATA            BitsVarStoreConfig;
 
   //
   // 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..9b74dda 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
+++ b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h
@@ -29,10 +29,11 @@ Revision History:
 #include <Guid/HiiFormMapMethodGuid.h>
 #include <Guid/DriverSampleHii.h>
 #include <Guid/ZeroGuid.h>
 
 #define CONFIGURATION_VARSTORE_ID    0x1234
+#define BITS_VARSTORE_ID    0x2345
 
 #pragma pack(1)
 typedef struct {
   UINT16  MyStringData[40];
   UINT16  SomethingHiddenForHtml;
@@ -77,10 +78,28 @@ typedef struct {
   UINT16        Field16;
   UINT8         OrderedList[3];
   UINT16        SubmittedCallback;
 } MY_EFI_VARSTORE_DATA;
 
+typedef struct {
+  UINT16   Field16;
+  UINT8    MyBits4 : 1; ///< Bits 0
+  UINT8    MyBits3 : 3; ///< Bits 3:1
+  UINT8    MyBits5 : 3; ///< Bits 6:4
+  UINT16   MyBits6 : 4; ///< Bits 3:0
+  UINT8    Field8;
+} MY_BITS_VARSTORE_DATA1;
+
+typedef struct {
+  UINT16   Field16;
+  MY_BITS_VARSTORE_DATA1  BitsData;
+  UINT8    Field8;
+  UINT16   MyBits7 : 3; ///< Bits 2:0
+  UINT16   MyBits8 : 3; ///< Bits 5:3
+  UINT16   MyBits9 : 1; ///< Bits 6
+} MY_BITS_VARSTORE_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..cbc8f6d 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
+++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
@@ -86,10 +86,18 @@ formset
     attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,  // EFI variable attribures  
     name  = MyEfiVar,
     guid  = DRIVER_SAMPLE_FORMSET_GUID;
 
   //
+  // Define a Buffer Storage (EFI_IFR_VARSTORE)
+  //
+  efivarstore MY_BITS_VARSTORE_DATA,       // This is the data structure type
+    attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,  // EFI variable attribures
+    name  = MyBitVar,                       // Define referenced name in vfr
+    guid  = DRIVER_SAMPLE_FORMSET_GUID;     // GUID of this buffer storage
+
+  //
   // 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]
     name = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME1), // Define Name list of this storage, refer it by MyNameValueVar[1]
@@ -112,10 +120,67 @@ formset
 
     subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT);
 
     subtitle text = STRING_TOKEN(STR_SUBTITLE_TEXT2);
 
+    checkbox varid   = MyBitVar.BitsData.MyBits4,
+             questionid = 0x6666,
+             prompt   = STRING_TOKEN(STR_BIT_NEST_CHECK_BOX_PROMPT),
+             help     = STRING_TOKEN(STR_CHECK_BOX_HELP),
+             flags    = CHECKBOX_DEFAULT,
+    endcheckbox;
+
+    oneof varid  = MyBitVar.BitsData.MyBits3,
+      prompt      = STRING_TOKEN(STR_ONE_OF_BIT_NEST_PROMPT),
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),
+      option text = STRING_TOKEN(STR_BOOT_ORDER1), value = 0, flags = MANUFACTURING;
+      option text = STRING_TOKEN(STR_BOOT_ORDER2), value = 1, flags = DEFAULT;
+    endoneof;
+
+    numeric varid   = MyBitVar.BitsData.MyBits5,
+            prompt  = STRING_TOKEN(STR_BIT_NEST_NUMERIC_PROMPT),
+            help    = STRING_TOKEN(STR_NUMERIC_HELP0),
+            minimum = 0,
+            maximum = 7,
+            step    = 0,
+            default = 5, defaultstore = MyStandardDefault,     // This is standard default value
+            default = 6, defaultstore = MyManufactureDefault,  // This is manufacture default value
+    endnumeric;
+
+   numeric varid   = MyBitVar.BitsData.MyBits6,
+            prompt  = STRING_TOKEN(STR_BIT_NEST_NUMERIC_PROMPT),
+            help    = STRING_TOKEN(STR_NUMERIC_HELP0),
+            minimum = 0,
+            maximum = 15,
+            step    = 0,
+            default = 11, defaultstore = MyStandardDefault,     // This is standard default value
+            default = 12, defaultstore = MyManufactureDefault,  // This is manufacture default value
+    endnumeric;
+
+    checkbox varid   = MyBitVar.MyBits9,
+             prompt   = STRING_TOKEN(STR_BIT_CHECK_BOX_PROMPT),
+             help     = STRING_TOKEN(STR_CHECK_BOX_HELP),
+             flags    = CHECKBOX_DEFAULT,
+    endcheckbox;
+
+    oneof varid  = MyBitVar.MyBits8,
+      prompt      = STRING_TOKEN(STR_ONE_OF_BIT_PROMPT),
+      help        = STRING_TOKEN(STR_ONE_OF_HELP),
+      option text = STRING_TOKEN(STR_BOOT_ORDER1), value = 0, flags = MANUFACTURING;
+      option text = STRING_TOKEN(STR_BOOT_ORDER2), value = 1, flags = DEFAULT;
+    endoneof;
+
+    numeric varid   = MyBitVar.MyBits7,
+            prompt  = STRING_TOKEN(STR_BIT_NUMERIC_PROMPT),
+            help    = STRING_TOKEN(STR_NUMERIC_HELP0),
+            minimum = 0,
+            maximum = 7,
+            step    = 0,
+            default = 5, defaultstore = MyStandardDefault,     // This is standard default value
+            default = 6, 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..9a52c02 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
+++ b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
@@ -55,10 +55,14 @@
                                        #language fr-FR "Please select the number"                                       
 #string STR_NUMERIC_NUM_HELP           #language en-US "Check the input number, test the efi buffer varstore"
                                        #language fr-FR "Check the input number, test the efi buffer varstore"                                        
 #string STR_ONE_OF_PROMPT              #language en-US "My one-of prompt #1"
                                        #language fr-FR "Mi uno- de guía # 1"
+#string STR_ONE_OF_BIT_PROMPT          #language en-US "BIT one-of"
+                                       #language fr-FR "BIT one-of"
+#string STR_ONE_OF_BIT_NEST_PROMPT     #language en-US "NEST_BIT one-of"
+                                       #language fr-FR "NEST_BIT one-of"
 #string STR_ONE_OF_PROMPT_KEYWORD      #language en-US "My Keyword Namespace Test"
                                        #language fr-FR "My Keyword Namespace Test"
                                        #language x-UEFI-ns "iSCSIBootEnable"
 #string STR_CHECK_KEYWORD_SUPPORT      #language en-US "Check iSCSI Boot Enable"
                                        #language fr-FR "Check iSCSI Boot Enable"
@@ -78,12 +82,20 @@
                                        #language fr-FR "Mi uno- del texto # 6"
 #string STR_BOOT_ORDER1                #language en-US "SmallBootList"
                                        #language fr-FR "Mi uno- del texto # 7"
 #string STR_BOOT_ORDER2                #language en-US "LargeBootList"
                                        #language fr-FR "Mi uno- del texto # 8"
+#string STR_BIT_NUMERIC_PROMPT         #language en-US "BIT numeric"
+                                       #language fr-FR "BIT numeric"
+#string STR_BIT_NEST_NUMERIC_PROMPT    #language en-US "NEST_BIT numeric"
+                                       #language fr-FR "NEST_BIT numeric"
 #string STR_CHECK_BOX_PROMPT           #language en-US "Activate this check box"
                                        #language fr-FR "Active Las Armas Nucleares"
+#string STR_BIT_CHECK_BOX_PROMPT       #language en-US "BIT check box"
+                                       #language fr-FR "BIT check box"
+#string STR_BIT_NEST_CHECK_BOX_PROMPT  #language en-US "NEST_BIT check box"
+                                       #language fr-FR "NEST_BIT check box"
 #string STR_CHECK_BOX_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 "É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."
-- 
1.9.5.msysgit.1

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