[edk2] [patch] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check

Dandan Bi posted 1 patch 6 years, 5 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
.../VarCheckHiiLib/InternalVarCheckStructure.h     |  17 +-
MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h  |   4 +-
.../Library/VarCheckHiiLib/VarCheckHiiGen.c        | 259 +++++++++++++++------
.../Library/VarCheckHiiLib/VarCheckHiiLib.inf      |   5 +-
.../VarCheckHiiLib/VarCheckHiiLibNullClass.c       |  92 ++++++--
5 files changed, 291 insertions(+), 86 deletions(-)
[edk2] [patch] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check
Posted by Dandan Bi 6 years, 5 months ago
VarCheckHiiLib check the value set to storage based on the possible value
listed in the vfr file. Since we have enhanced vfr to support Question
value stored in bit field, so now enhance VarCheckHiiLib to support bit
field check.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../VarCheckHiiLib/InternalVarCheckStructure.h     |  17 +-
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h  |   4 +-
 .../Library/VarCheckHiiLib/VarCheckHiiGen.c        | 259 +++++++++++++++------
 .../Library/VarCheckHiiLib/VarCheckHiiLib.inf      |   5 +-
 .../VarCheckHiiLib/VarCheckHiiLibNullClass.c       |  92 ++++++--
 5 files changed, 291 insertions(+), 86 deletions(-)

diff --git a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
index a9faed4..b32dd4e 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
@@ -1,9 +1,9 @@
 /** @file
   Internal structure for Var Check Hii.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -40,41 +40,56 @@ typedef struct {
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_HEADER;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ONEOF;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_CHECKBOX;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Minimum; // x = UINT8/UINT16/UINT32/UINT64;
 //UINTx               Maximum; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_NUMERIC;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
   UINT8             MaxContainers;
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ORDEREDLIST;
 
 #pragma pack ()
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
index a54b867..7363edf 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
@@ -1,9 +1,9 @@
 /** @file
   Include file for Var Check Hii handler and bin.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/MemoryAllocationLib.h>
 
+#include <Guid/MdeModuleHii.h>
+
 #include <Protocol/HiiDatabase.h>
 #include <Protocol/FirmwareVolume2.h>
 #include <Protocol/FirmwareVolumeBlock.h>
 
 #include "InternalVarCheckStructure.h"
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
index f018c87..f4b646c 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
@@ -1,9 +1,9 @@
 /** @file
   Var Check Hii bin generation.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -118,12 +118,14 @@ DumpHiiPackage (
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   EFI_IFR_VARSTORE              *IfrVarStore;
   EFI_IFR_VARSTORE_EFI          *IfrEfiVarStore;
+  BOOLEAN                       QuestionStoredInBitField;
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
+  QuestionStoredInBitField = FALSE;
 
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Type   - 0x%02x (%a)\n", HiiPackageHeader->Type, HiiPackageTypeToStr ((UINT8) HiiPackageHeader->Type)));
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Length - 0x%06x\n", HiiPackageHeader->Length));
 
   switch (HiiPackageHeader->Type) {
@@ -155,83 +157,116 @@ DumpHiiPackage (
               DEBUG ((EFI_D_INFO, "      Attributes - 0x%08x\n", IfrEfiVarStore->Attributes));
               DEBUG ((EFI_D_INFO, "      Name       - %a\n", IfrEfiVarStore->Name));
             }
             break;
 
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in bit field----\n"));
+            } else {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in byte field----\n"));
+            }
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->OpCode - 0x%02x (%a)\n", IfrOpCodeHeader->OpCode, IfrOpCodeToStr (IfrOpCodeHeader->OpCode)));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Length - 0x02%x\n", IfrOpCodeHeader->Length));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Scope  - 0x02%x\n", IfrOpCodeHeader->Scope));
             DEBUG ((EFI_D_INFO, "      Prompt       - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Prompt));
             DEBUG ((EFI_D_INFO, "      Help         - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Help));
             DEBUG ((EFI_D_INFO, "      QuestionId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.QuestionId));
             DEBUG ((EFI_D_INFO, "      VarStoreId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId));
-            DEBUG ((EFI_D_INFO, "      VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "    Bit VarStoreInfo (bit level) - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            } else {
+              DEBUG ((EFI_D_INFO, "    VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            }
             {
               EFI_IFR_ONE_OF            *IfrOneOf;
               EFI_IFR_CHECKBOX          *IfrCheckBox;
               EFI_IFR_NUMERIC           *IfrNumeric;
               EFI_IFR_ORDERED_LIST      *IfrOrderedList;
 
               switch (IfrOpCodeHeader->OpCode) {
                 case EFI_IFR_ONE_OF_OP:
                   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrOneOf->Flags));
-                  switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Oneof stored in bit field, the option value are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_CHECKBOX_OP:
                   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrCheckBox->Flags));
                   break;
                 case EFI_IFR_NUMERIC_OP:
                   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrNumeric->Flags));
-                  switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Numeric stored in bit field, the MinValue,MaxValue and Step are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_ORDERED_LIST_OP:
                   IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      MaxContainers - 0x%02x\n", IfrOrderedList->MaxContainers));
@@ -277,10 +312,11 @@ DumpHiiPackage (
                       }
                       break;
                   }
 
                   if (IfrOpCodeHeader->OpCode == EFI_IFR_END_OP) {
+                    QuestionStoredInBitField = FALSE;
                     ASSERT (Scope > 0);
                     Scope--;
                     if (Scope == 0) {
                       break;
                     }
@@ -496,11 +532,11 @@ MergeHiiQuestion (
   if (FromFv) {
     InternalVarCheckFreePool (HiiQuestion);
     return;
   }
 
-  HiiQuestion1 = HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset];
+  HiiQuestion1 = HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel];
   HiiQuestion2 = HiiQuestion;
 
   ASSERT ((HiiQuestion1->OpCode == HiiQuestion2->OpCode) && (HiiQuestion1->StorageWidth == HiiQuestion2->StorageWidth));
 
   switch (HiiQuestion1->OpCode) {
@@ -578,11 +614,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] = NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
@@ -703,11 +739,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] = NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     default:
@@ -829,103 +865,167 @@ GetOneOfOption (
 
 /**
   Parse Hii Question Oneof.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Oneof is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionOneOf (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_ONE_OF                *IfrOneOf;
   VAR_CHECK_HII_QUESTION_ONEOF  *OneOf;
   UINTN                         Length;
   UINT8                         Width;
   UINTN                         OptionCount;
   UINT8                         OptionWidth;
+  UINT8                         BitWidth;
+  UINT8                         TotalBits;
 
   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
+  BitWidth = 0;
 
-  Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When oneof stored in bit field, the bit width is saved in the lower six bits of the flag.
+    // And the options in the oneof is saved as UINT32 type.
+    //
+    BitWidth = IfrOneOf->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, NULL);
   ASSERT (Width == OptionWidth);
 
   Length = sizeof (*OneOf) + OptionCount * Width;
 
   OneOf = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OneOf != NULL);
   OneOf->OpCode       = EFI_IFR_ONE_OF_OP;
   OneOf->Length       = (UINT8) Length;
-  OneOf->VarOffset    = IfrOneOf->Question.VarStoreInfo.VarOffset;
-  OneOf->StorageWidth = Width;
+  OneOf->BitFieldStore = StoredInBitField;
+  if (StoredInBitField) {
+    OneOf->VarOffsetBitLevel    = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffset            = OneOf->VarOffsetBitLevel / 8;
+    OneOf->StorageWidthBitLevel = BitWidth;
+    TotalBits                   = OneOf->VarOffsetBitLevel % 8 + BitWidth;
+    OneOf->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    OneOf->VarOffset            = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffsetBitLevel    = OneOf->VarOffset * 8;
+    OneOf->StorageWidth         = Width;
+    OneOf->StorageWidthBitLevel = Width * 8;
+  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OneOf + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OneOf;
 }
 
 /**
   Parse Hii Question CheckBox.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Checkbox is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionCheckBox (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_CHECKBOX                  *IfrCheckBox;
   VAR_CHECK_HII_QUESTION_CHECKBOX   *CheckBox;
+  UINT8                             TotalBits;
 
   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
 
   CheckBox = InternalVarCheckAllocateZeroPool (sizeof (*CheckBox));
   ASSERT (CheckBox != NULL);
   CheckBox->OpCode       = EFI_IFR_CHECKBOX_OP;
-  CheckBox->Length       = (UINT8) sizeof (*CheckBox);;
-  CheckBox->VarOffset    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
-  CheckBox->StorageWidth = (UINT8) sizeof (BOOLEAN);
+  CheckBox->Length       = (UINT8) sizeof (*CheckBox);
+  CheckBox->BitFieldStore = StoredInBitField;
+  if (StoredInBitField) {
+    CheckBox->VarOffsetBitLevel    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffset            = CheckBox->VarOffsetBitLevel / 8;
+    CheckBox->StorageWidthBitLevel = 1;
+    TotalBits                      = CheckBox->VarOffsetBitLevel % 8 + 1;
+    CheckBox->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    CheckBox->VarOffset            = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffsetBitLevel    = CheckBox->VarOffset * 8;
+    CheckBox->StorageWidth         = (UINT8) sizeof (BOOLEAN);
+    CheckBox->StorageWidthBitLevel = CheckBox->StorageWidth * 8;
+  }
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) CheckBox;
 }
 
 /**
   Parse Hii Question Numeric.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the numeric is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionNumeric (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_NUMERIC                   *IfrNumeric;
   VAR_CHECK_HII_QUESTION_NUMERIC    *Numeric;
   UINT8                             Width;
+  UINT8                             BitWidth;
+  UINT8                             TotalBits;
 
   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
+  BitWidth = 0;
 
   Numeric = InternalVarCheckAllocateZeroPool (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * sizeof (UINT64));
   ASSERT (Numeric != NULL);
 
-  Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When numeric stored in bit field, the bit field width is saved in the lower six bits of the flag.
+    // And the Minimum Maximum of numeric is saved as UINT32 type.
+    //
+    BitWidth = IfrNumeric->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+  }
 
   Numeric->OpCode       = EFI_IFR_NUMERIC_OP;
   Numeric->Length       = (UINT8) (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * Width);
-  Numeric->VarOffset    = IfrNumeric->Question.VarStoreInfo.VarOffset;
-  Numeric->StorageWidth = Width;
+  Numeric->BitFieldStore = StoredInBitField;
+  if (StoredInBitField) {
+    Numeric->VarOffsetBitLevel    = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffset            = Numeric->VarOffsetBitLevel / 8;
+    Numeric->StorageWidthBitLevel = BitWidth;
+    TotalBits                     = Numeric->VarOffsetBitLevel % 8 + BitWidth;
+    Numeric->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    Numeric->VarOffset            = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffsetBitLevel    = Numeric->VarOffset * 8;
+    Numeric->StorageWidth         = Width;
+    Numeric->StorageWidthBitLevel = Width * 8;
+  }
 
   CopyMem (Numeric + 1, &IfrNumeric->data, Width * 2);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) Numeric;
 }
@@ -955,15 +1055,18 @@ ParseHiiQuestionOrderedList (
 
   Length = sizeof (*OrderedList) + OptionCount * OptionWidth;
 
   OrderedList = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OrderedList != NULL);
-  OrderedList->OpCode        = EFI_IFR_ORDERED_LIST_OP;
-  OrderedList->Length        = (UINT8) Length;
-  OrderedList->VarOffset     = IfrOrderedList->Question.VarStoreInfo.VarOffset;
-  OrderedList->StorageWidth  = OptionWidth;
-  OrderedList->MaxContainers = IfrOrderedList->MaxContainers;
+  OrderedList->BitFieldStore        = FALSE;
+  OrderedList->OpCode               = EFI_IFR_ORDERED_LIST_OP;
+  OrderedList->Length               = (UINT8) Length;
+  OrderedList->VarOffset            = IfrOrderedList->Question.VarStoreInfo.VarOffset;
+  OrderedList->StorageWidth         = OptionWidth;
+  OrderedList->MaxContainers        = IfrOrderedList->MaxContainers;
+  OrderedList->VarOffsetBitLevel    = IfrOrderedList->Question.VarStoreInfo.VarOffset * 8;
+  OrderedList->StorageWidthBitLevel = OptionWidth * 8;
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OrderedList + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OrderedList;
 }
@@ -972,32 +1075,37 @@ ParseHiiQuestionOrderedList (
   Parse and create Hii Question node.
 
   @param[in] HiiVariableNode    Pointer to Hii Variable node.
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
   @param[in] FromFv             Hii Question from FV.
+  @param[in] StoredInBitField   Whether the Question is stored in bit field Storage.
 
 **/
 VOID
 ParseHiiQuestion (
   IN VAR_CHECK_HII_VARIABLE_NODE    *HiiVariableNode,
   IN  EFI_IFR_OP_HEADER             *IfrOpCodeHeader,
-  IN BOOLEAN                        FromFv
+  IN BOOLEAN                        FromFv,
+  IN BOOLEAN                        StoredInBitField
   )
 {
   VAR_CHECK_HII_QUESTION_HEADER *HiiQuestion;
 
+  //
+  // Currently only Oneof, Checkbox and numeric can be stored in bit field.
+  //
   switch (IfrOpCodeHeader->OpCode) {
     case EFI_IFR_ONE_OF_OP:
-      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader, StoredInBitField);
       break;
 
     case EFI_IFR_CHECKBOX_OP:
-      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader, StoredInBitField);
       break;
 
     case EFI_IFR_NUMERIC_OP:
-      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader, StoredInBitField);
       break;
 
     case EFI_IFR_ORDERED_LIST_OP:
       HiiQuestion = ParseHiiQuestionOrderedList (IfrOpCodeHeader);
       break;
@@ -1006,14 +1114,14 @@ ParseHiiQuestion (
       ASSERT (FALSE);
       return;
       break;
   }
 
-  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] != NULL) {
+  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel] != NULL) {
     MergeHiiQuestion (HiiVariableNode, HiiQuestion, FromFv);
   } else {
-    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] = HiiQuestion;
+    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel] = HiiQuestion;
   }
 }
 
 /**
   Find Hii variable node by name and GUID.
@@ -1164,11 +1272,11 @@ CreateHiiVariableNode (
     HiiVariableNode->HiiVariable = HiiVariable;
     //
     // The variable store identifier, which is unique within the current form set.
     //
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
-    HiiVariableNode->HiiQuestionArray = InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * sizeof (VAR_CHECK_HII_QUESTION_HEADER *));
+    HiiVariableNode->HiiQuestionArray = InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * 8 * sizeof (VAR_CHECK_HII_QUESTION_HEADER *));
 
     InsertTailList (&mVarCheckHiiList, &HiiVariableNode->Link);
   } else {
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
   }
@@ -1237,24 +1345,37 @@ VarCheckParseHiiPackage (
   )
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   VAR_CHECK_HII_VARIABLE_NODE   *HiiVariableNode;
+  BOOLEAN                       QuestionStoredInBitField;
 
   //
   // Parse and create Hii Variable node list for this Hii Package.
   //
   ParseHiiVariable (HiiPackage);
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
 
+  QuestionStoredInBitField = FALSE;
+
   switch (HiiPackageHeader->Type) {
     case EFI_HII_PACKAGE_FORMS:
       IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) (HiiPackageHeader + 1);
 
       while ((UINTN) IfrOpCodeHeader < (UINTN) HiiPackageHeader + HiiPackageHeader->Length) {
         switch (IfrOpCodeHeader->OpCode) {
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
+          case EFI_IFR_END_OP:
+            QuestionStoredInBitField = FALSE;
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
             HiiVariableNode = FindHiiVariableNodeByVarStoreId (((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId);
@@ -1268,11 +1389,11 @@ VarCheckParseHiiPackage (
                 //
             } else {
               //
               // Normal IFR
               //
-              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, FromFv);
+              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, FromFv, QuestionStoredInBitField);
             }
           default:
             break;
         }
         IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) ((UINTN) IfrOpCodeHeader + IfrOpCodeHeader->Length);
@@ -1339,11 +1460,11 @@ DestroyHiiVariableNode (
     RemoveEntryList (&HiiVariableNode->Link);
 
     //
     // Free the allocated buffer.
     //
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray[Index]);
       }
     }
     InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray);
@@ -1387,11 +1508,11 @@ BuildVarCheckHiiBin (
     BinSize = (UINT32) HEADER_ALIGN (BinSize);
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     HiiVariableLength = HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         HiiVariableLength = (UINT32) HEADER_ALIGN (HiiVariableLength);
@@ -1432,11 +1553,11 @@ BuildVarCheckHiiBin (
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     CopyMem (Ptr, HiiVariableNode->HiiVariable, HiiVariableNode->HiiVariable->HeaderLength);
     Ptr += HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         Ptr = (UINT8 *) HEADER_ALIGN (Ptr);
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
index 98e6983..aeca3ef 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
@@ -1,9 +1,9 @@
 ## @file
 #  NULL class library to register var check HII handler.
 #
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2015 - 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
@@ -44,10 +44,13 @@
   UefiBootServicesTableLib
   MemoryAllocationLib
   PcdLib
   VarCheckLib
 
+[Guids]
+  gEdkiiIfrBitVarstoreGuid                  ## SOMETIMES_CONSUMES  ## GUID
+
 [Protocols]
   gEfiFirmwareVolume2ProtocolGuid           ## SOMETIMES_CONSUMES
   gEfiFirmwareVolumeBlock2ProtocolGuid      ## SOMETIMES_CONSUMES
   gEfiHiiDatabaseProtocolGuid               ## SOMETIMES_CONSUMES
 
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
index 93ff934..1f96712 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
@@ -91,32 +91,53 @@ VarCheckHiiQuestion (
   UINT64   Maximum;
   UINT64   OneValue;
   UINT8    *Ptr;
   UINT8    Index;
   UINT8    MaxContainers;
+  UINTN    StartBit;
+  UINTN    EndBit;
 
   if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
     DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, DataSize));
     return FALSE;
   }
 
   OneData = 0;
   CopyMem (&OneData, (UINT8 *) Data + HiiQuestion->VarOffset, HiiQuestion->StorageWidth);
+  if (HiiQuestion->BitFieldStore) {
+    //
+    // Get the value form the bit field.
+    //
+    StartBit = HiiQuestion->VarOffsetBitLevel % 8;
+    EndBit = StartBit + HiiQuestion->StorageWidthBitLevel - 1;
+    OneData = BitFieldRead64 (OneData, StartBit, EndBit);
+  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < (UINTN) HiiQuestion + HiiQuestion->Length) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         if (OneData == OneValue) {
           //
           // Match
           //
           break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       if ((UINTN) Ptr >= ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         //
         // No match
         //
@@ -136,14 +157,24 @@ VarCheckHiiQuestion (
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if (HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       //
       // No need to check Step, because it is ONLY for UI.
       //
       if ((OneData < Minimum) || (OneData > Maximum)) {
@@ -341,22 +372,41 @@ DumpHiiQuestion (
   UINT64    Minimum;
   UINT64    Maximum;
   UINT64    OneValue;
   UINT8     *Ptr;
 
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in bit field----\n"));
+  } else {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in byte field----\n"));
+  }
+
   DEBUG ((EFI_D_INFO, "  VAR_CHECK_HII_QUESTION_HEADER\n"));
   DEBUG ((EFI_D_INFO, "    OpCode        - 0x%02x (%a)\n", HiiQuestion->OpCode, HiiOpCodeToStr (HiiQuestion->OpCode)));
   DEBUG ((EFI_D_INFO, "    Length        - 0x%02x\n", HiiQuestion->Length));
-  DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
-  DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "  Bit VarOffset(Bit level)     - 0x%04x\n", HiiQuestion->VarOffsetBitLevel));
+    DEBUG ((EFI_D_INFO, "  Bit StorageWidth(Bit level)  - 0x%02x\n", HiiQuestion->StorageWidthBitLevel));
+  } else {
+    DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
+    DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         switch (HiiQuestion->StorageWidth) {
           case sizeof (UINT8):
             DEBUG ((EFI_D_INFO, "    OneOfOption   - 0x%02x\n", OneValue));
             break;
           case sizeof (UINT16):
@@ -370,25 +420,39 @@ DumpHiiQuestion (
             break;
           default:
             ASSERT (FALSE);
             break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
       break;
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if(HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       switch (HiiQuestion->StorageWidth) {
         case sizeof (UINT8):
           DEBUG ((EFI_D_INFO, "    Minimum       - 0x%02x\n", Minimum));
           DEBUG ((EFI_D_INFO, "    Maximum       - 0x%02x\n", Maximum));
-- 
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] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check
Posted by Zeng, Star 6 years, 5 months ago
Hi Dandan,

1. Could we reuse VarOffset/StorageWidth to store bit level info when BitFieldStore = TRUE? Then we can avoid adding VarOffsetBitLevel/StorageWidthBitLevel to reduce the final VarCheckBinSize, and it can be also aligned with HiiDatabase that is using VarOffset to store bit level info when gEdkiiIfrBitVarstoreGuid guid opcode is present, right?

2. Please increase VAR_CHECK_HII_REVISION since we will update the structure definitions.

3. How about to update
"Bit VarStoreInfo (bit level)" to be "VarStoreInfo (bit level)"?
"Bit VarOffset(Bit level)" to be "VarOffset(Bit level)"?
"Bit StorageWidth(Bit level) " to be "StorageWidth(Bit level)"?

4.  How about to update "oneof", "checkbox", "numeric" and "orderedlist" in comments to be consistent with "OneOf", "CheckBox", "Numeric" and "OrderedList"?


Thanks,
Star
-----Original Message-----
From: Bi, Dandan 
Sent: Friday, October 27, 2017 3:25 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [patch] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check

VarCheckHiiLib check the value set to storage based on the possible value listed in the vfr file. Since we have enhanced vfr to support Question value stored in bit field, so now enhance VarCheckHiiLib to support bit field check.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../VarCheckHiiLib/InternalVarCheckStructure.h     |  17 +-
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h  |   4 +-
 .../Library/VarCheckHiiLib/VarCheckHiiGen.c        | 259 +++++++++++++++------
 .../Library/VarCheckHiiLib/VarCheckHiiLib.inf      |   5 +-
 .../VarCheckHiiLib/VarCheckHiiLibNullClass.c       |  92 ++++++--
 5 files changed, 291 insertions(+), 86 deletions(-)

diff --git a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
index a9faed4..b32dd4e 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
@@ -1,9 +1,9 @@
 /** @file
   Internal structure for Var Check Hii.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -40,41 +40,56 @@ typedef struct {
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_HEADER;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ONEOF;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_CHECKBOX;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Minimum; // x = UINT8/UINT16/UINT32/UINT64;
 //UINTx               Maximum; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_NUMERIC;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
   UINT8             MaxContainers;
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ORDEREDLIST;
 
 #pragma pack ()
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
index a54b867..7363edf 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
@@ -1,9 +1,9 @@
 /** @file
   Include file for Var Check Hii handler and bin.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/MemoryAllocationLib.h>
 
+#include <Guid/MdeModuleHii.h>
+
 #include <Protocol/HiiDatabase.h>
 #include <Protocol/FirmwareVolume2.h>
 #include <Protocol/FirmwareVolumeBlock.h>
 
 #include "InternalVarCheckStructure.h"
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
index f018c87..f4b646c 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
@@ -1,9 +1,9 @@
 /** @file
   Var Check Hii bin generation.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -118,12 +118,14 @@ DumpHiiPackage (
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   EFI_IFR_VARSTORE              *IfrVarStore;
   EFI_IFR_VARSTORE_EFI          *IfrEfiVarStore;
+  BOOLEAN                       QuestionStoredInBitField;
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
+  QuestionStoredInBitField = FALSE;
 
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Type   - 0x%02x (%a)\n", HiiPackageHeader->Type, HiiPackageTypeToStr ((UINT8) HiiPackageHeader->Type)));
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Length - 0x%06x\n", HiiPackageHeader->Length));
 
   switch (HiiPackageHeader->Type) {
@@ -155,83 +157,116 @@ DumpHiiPackage (
               DEBUG ((EFI_D_INFO, "      Attributes - 0x%08x\n", IfrEfiVarStore->Attributes));
               DEBUG ((EFI_D_INFO, "      Name       - %a\n", IfrEfiVarStore->Name));
             }
             break;
 
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in bit field----\n"));
+            } else {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in byte field----\n"));
+            }
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->OpCode - 0x%02x (%a)\n", IfrOpCodeHeader->OpCode, IfrOpCodeToStr (IfrOpCodeHeader->OpCode)));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Length - 0x02%x\n", IfrOpCodeHeader->Length));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Scope  - 0x02%x\n", IfrOpCodeHeader->Scope));
             DEBUG ((EFI_D_INFO, "      Prompt       - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Prompt));
             DEBUG ((EFI_D_INFO, "      Help         - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Help));
             DEBUG ((EFI_D_INFO, "      QuestionId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.QuestionId));
             DEBUG ((EFI_D_INFO, "      VarStoreId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId));
-            DEBUG ((EFI_D_INFO, "      VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "    Bit VarStoreInfo (bit level) - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            } else {
+              DEBUG ((EFI_D_INFO, "    VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            }
             {
               EFI_IFR_ONE_OF            *IfrOneOf;
               EFI_IFR_CHECKBOX          *IfrCheckBox;
               EFI_IFR_NUMERIC           *IfrNumeric;
               EFI_IFR_ORDERED_LIST      *IfrOrderedList;
 
               switch (IfrOpCodeHeader->OpCode) {
                 case EFI_IFR_ONE_OF_OP:
                   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrOneOf->Flags));
-                  switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Oneof stored in bit field, the option value are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_CHECKBOX_OP:
                   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrCheckBox->Flags));
                   break;
                 case EFI_IFR_NUMERIC_OP:
                   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrNumeric->Flags));
-                  switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Numeric stored in bit field, the MinValue,MaxValue and Step are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_ORDERED_LIST_OP:
                   IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      MaxContainers - 0x%02x\n", IfrOrderedList->MaxContainers));
@@ -277,10 +312,11 @@ DumpHiiPackage (
                       }
                       break;
                   }
 
                   if (IfrOpCodeHeader->OpCode == EFI_IFR_END_OP) {
+                    QuestionStoredInBitField = FALSE;
                     ASSERT (Scope > 0);
                     Scope--;
                     if (Scope == 0) {
                       break;
                     }
@@ -496,11 +532,11 @@ MergeHiiQuestion (
   if (FromFv) {
     InternalVarCheckFreePool (HiiQuestion);
     return;
   }
 
-  HiiQuestion1 = HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset];
+  HiiQuestion1 = 
+ HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel];
   HiiQuestion2 = HiiQuestion;
 
   ASSERT ((HiiQuestion1->OpCode == HiiQuestion2->OpCode) && (HiiQuestion1->StorageWidth == HiiQuestion2->StorageWidth));
 
   switch (HiiQuestion1->OpCode) {
@@ -578,11 +614,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        
+ HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] = 
+ NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
@@ -703,11 +739,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        
+ HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] = 
+ NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     default:
@@ -829,103 +865,167 @@ GetOneOfOption (
 
 /**
   Parse Hii Question Oneof.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Oneof is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionOneOf (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_ONE_OF                *IfrOneOf;
   VAR_CHECK_HII_QUESTION_ONEOF  *OneOf;
   UINTN                         Length;
   UINT8                         Width;
   UINTN                         OptionCount;
   UINT8                         OptionWidth;
+  UINT8                         BitWidth;
+  UINT8                         TotalBits;
 
   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
+  BitWidth = 0;
 
-  Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When oneof stored in bit field, the bit width is saved in the lower six bits of the flag.
+    // And the options in the oneof is saved as UINT32 type.
+    //
+    BitWidth = IfrOneOf->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, NULL);
   ASSERT (Width == OptionWidth);
 
   Length = sizeof (*OneOf) + OptionCount * Width;
 
   OneOf = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OneOf != NULL);
   OneOf->OpCode       = EFI_IFR_ONE_OF_OP;
   OneOf->Length       = (UINT8) Length;
-  OneOf->VarOffset    = IfrOneOf->Question.VarStoreInfo.VarOffset;
-  OneOf->StorageWidth = Width;
+  OneOf->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    OneOf->VarOffsetBitLevel    = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffset            = OneOf->VarOffsetBitLevel / 8;
+    OneOf->StorageWidthBitLevel = BitWidth;
+    TotalBits                   = OneOf->VarOffsetBitLevel % 8 + BitWidth;
+    OneOf->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    OneOf->VarOffset            = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffsetBitLevel    = OneOf->VarOffset * 8;
+    OneOf->StorageWidth         = Width;
+    OneOf->StorageWidthBitLevel = Width * 8;  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OneOf + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OneOf;  }
 
 /**
   Parse Hii Question CheckBox.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Checkbox is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionCheckBox (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_CHECKBOX                  *IfrCheckBox;
   VAR_CHECK_HII_QUESTION_CHECKBOX   *CheckBox;
+  UINT8                             TotalBits;
 
   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
 
   CheckBox = InternalVarCheckAllocateZeroPool (sizeof (*CheckBox));
   ASSERT (CheckBox != NULL);
   CheckBox->OpCode       = EFI_IFR_CHECKBOX_OP;
-  CheckBox->Length       = (UINT8) sizeof (*CheckBox);;
-  CheckBox->VarOffset    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
-  CheckBox->StorageWidth = (UINT8) sizeof (BOOLEAN);
+  CheckBox->Length       = (UINT8) sizeof (*CheckBox);
+  CheckBox->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    CheckBox->VarOffsetBitLevel    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffset            = CheckBox->VarOffsetBitLevel / 8;
+    CheckBox->StorageWidthBitLevel = 1;
+    TotalBits                      = CheckBox->VarOffsetBitLevel % 8 + 1;
+    CheckBox->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    CheckBox->VarOffset            = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffsetBitLevel    = CheckBox->VarOffset * 8;
+    CheckBox->StorageWidth         = (UINT8) sizeof (BOOLEAN);
+    CheckBox->StorageWidthBitLevel = CheckBox->StorageWidth * 8;  }
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) CheckBox;  }
 
 /**
   Parse Hii Question Numeric.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the numeric is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionNumeric (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_NUMERIC                   *IfrNumeric;
   VAR_CHECK_HII_QUESTION_NUMERIC    *Numeric;
   UINT8                             Width;
+  UINT8                             BitWidth;
+  UINT8                             TotalBits;
 
   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
+  BitWidth = 0;
 
   Numeric = InternalVarCheckAllocateZeroPool (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * sizeof (UINT64));
   ASSERT (Numeric != NULL);
 
-  Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When numeric stored in bit field, the bit field width is saved in the lower six bits of the flag.
+    // And the Minimum Maximum of numeric is saved as UINT32 type.
+    //
+    BitWidth = IfrNumeric->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));  
+ }
 
   Numeric->OpCode       = EFI_IFR_NUMERIC_OP;
   Numeric->Length       = (UINT8) (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * Width);
-  Numeric->VarOffset    = IfrNumeric->Question.VarStoreInfo.VarOffset;
-  Numeric->StorageWidth = Width;
+  Numeric->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    Numeric->VarOffsetBitLevel    = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffset            = Numeric->VarOffsetBitLevel / 8;
+    Numeric->StorageWidthBitLevel = BitWidth;
+    TotalBits                     = Numeric->VarOffsetBitLevel % 8 + BitWidth;
+    Numeric->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    Numeric->VarOffset            = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffsetBitLevel    = Numeric->VarOffset * 8;
+    Numeric->StorageWidth         = Width;
+    Numeric->StorageWidthBitLevel = Width * 8;  }
 
   CopyMem (Numeric + 1, &IfrNumeric->data, Width * 2);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) Numeric;  } @@ -955,15 +1055,18 @@ ParseHiiQuestionOrderedList (
 
   Length = sizeof (*OrderedList) + OptionCount * OptionWidth;
 
   OrderedList = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OrderedList != NULL);
-  OrderedList->OpCode        = EFI_IFR_ORDERED_LIST_OP;
-  OrderedList->Length        = (UINT8) Length;
-  OrderedList->VarOffset     = IfrOrderedList->Question.VarStoreInfo.VarOffset;
-  OrderedList->StorageWidth  = OptionWidth;
-  OrderedList->MaxContainers = IfrOrderedList->MaxContainers;
+  OrderedList->BitFieldStore        = FALSE;
+  OrderedList->OpCode               = EFI_IFR_ORDERED_LIST_OP;
+  OrderedList->Length               = (UINT8) Length;
+  OrderedList->VarOffset            = IfrOrderedList->Question.VarStoreInfo.VarOffset;
+  OrderedList->StorageWidth         = OptionWidth;
+  OrderedList->MaxContainers        = IfrOrderedList->MaxContainers;
+  OrderedList->VarOffsetBitLevel    = IfrOrderedList->Question.VarStoreInfo.VarOffset * 8;
+  OrderedList->StorageWidthBitLevel = OptionWidth * 8;
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OrderedList + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OrderedList;  } @@ -972,32 +1075,37 @@ ParseHiiQuestionOrderedList (
   Parse and create Hii Question node.
 
   @param[in] HiiVariableNode    Pointer to Hii Variable node.
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
   @param[in] FromFv             Hii Question from FV.
+  @param[in] StoredInBitField   Whether the Question is stored in bit field Storage.
 
 **/
 VOID
 ParseHiiQuestion (
   IN VAR_CHECK_HII_VARIABLE_NODE    *HiiVariableNode,
   IN  EFI_IFR_OP_HEADER             *IfrOpCodeHeader,
-  IN BOOLEAN                        FromFv
+  IN BOOLEAN                        FromFv,
+  IN BOOLEAN                        StoredInBitField
   )
 {
   VAR_CHECK_HII_QUESTION_HEADER *HiiQuestion;
 
+  //
+  // Currently only Oneof, Checkbox and numeric can be stored in bit field.
+  //
   switch (IfrOpCodeHeader->OpCode) {
     case EFI_IFR_ONE_OF_OP:
-      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_CHECKBOX_OP:
-      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_NUMERIC_OP:
-      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_ORDERED_LIST_OP:
       HiiQuestion = ParseHiiQuestionOrderedList (IfrOpCodeHeader);
       break;
@@ -1006,14 +1114,14 @@ ParseHiiQuestion (
       ASSERT (FALSE);
       return;
       break;
   }
 
-  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] != NULL) {
+  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel] 
+ != NULL) {
     MergeHiiQuestion (HiiVariableNode, HiiQuestion, FromFv);
   } else {
-    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] = HiiQuestion;
+    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel] = 
+ HiiQuestion;
   }
 }
 
 /**
   Find Hii variable node by name and GUID.
@@ -1164,11 +1272,11 @@ CreateHiiVariableNode (
     HiiVariableNode->HiiVariable = HiiVariable;
     //
     // The variable store identifier, which is unique within the current form set.
     //
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
-    HiiVariableNode->HiiQuestionArray = InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * sizeof (VAR_CHECK_HII_QUESTION_HEADER *));
+    HiiVariableNode->HiiQuestionArray = 
+ InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * 8 * sizeof 
+ (VAR_CHECK_HII_QUESTION_HEADER *));
 
     InsertTailList (&mVarCheckHiiList, &HiiVariableNode->Link);
   } else {
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
   }
@@ -1237,24 +1345,37 @@ VarCheckParseHiiPackage (
   )
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   VAR_CHECK_HII_VARIABLE_NODE   *HiiVariableNode;
+  BOOLEAN                       QuestionStoredInBitField;
 
   //
   // Parse and create Hii Variable node list for this Hii Package.
   //
   ParseHiiVariable (HiiPackage);
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
 
+  QuestionStoredInBitField = FALSE;
+
   switch (HiiPackageHeader->Type) {
     case EFI_HII_PACKAGE_FORMS:
       IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) (HiiPackageHeader + 1);
 
       while ((UINTN) IfrOpCodeHeader < (UINTN) HiiPackageHeader + HiiPackageHeader->Length) {
         switch (IfrOpCodeHeader->OpCode) {
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
+          case EFI_IFR_END_OP:
+            QuestionStoredInBitField = FALSE;
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
             HiiVariableNode = FindHiiVariableNodeByVarStoreId (((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId);
@@ -1268,11 +1389,11 @@ VarCheckParseHiiPackage (
                 //
             } else {
               //
               // Normal IFR
               //
-              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, FromFv);
+              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, 
+ FromFv, QuestionStoredInBitField);
             }
           default:
             break;
         }
         IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) ((UINTN) IfrOpCodeHeader + IfrOpCodeHeader->Length); @@ -1339,11 +1460,11 @@ DestroyHiiVariableNode (
     RemoveEntryList (&HiiVariableNode->Link);
 
     //
     // Free the allocated buffer.
     //
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * 
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray[Index]);
       }
     }
     InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray);
@@ -1387,11 +1508,11 @@ BuildVarCheckHiiBin (
     BinSize = (UINT32) HEADER_ALIGN (BinSize);
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     HiiVariableLength = HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * 
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         HiiVariableLength = (UINT32) HEADER_ALIGN (HiiVariableLength); @@ -1432,11 +1553,11 @@ BuildVarCheckHiiBin (
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     CopyMem (Ptr, HiiVariableNode->HiiVariable, HiiVariableNode->HiiVariable->HeaderLength);
     Ptr += HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size * 
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         Ptr = (UINT8 *) HEADER_ALIGN (Ptr); diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
index 98e6983..aeca3ef 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
@@ -1,9 +1,9 @@
 ## @file
 #  NULL class library to register var check HII handler.
 #
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2015 - 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 @@ -44,10 +44,13 @@
   UefiBootServicesTableLib
   MemoryAllocationLib
   PcdLib
   VarCheckLib
 
+[Guids]
+  gEdkiiIfrBitVarstoreGuid                  ## SOMETIMES_CONSUMES  ## GUID
+
 [Protocols]
   gEfiFirmwareVolume2ProtocolGuid           ## SOMETIMES_CONSUMES
   gEfiFirmwareVolumeBlock2ProtocolGuid      ## SOMETIMES_CONSUMES
   gEfiHiiDatabaseProtocolGuid               ## SOMETIMES_CONSUMES
 
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
index 93ff934..1f96712 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
@@ -91,32 +91,53 @@ VarCheckHiiQuestion (
   UINT64   Maximum;
   UINT64   OneValue;
   UINT8    *Ptr;
   UINT8    Index;
   UINT8    MaxContainers;
+  UINTN    StartBit;
+  UINTN    EndBit;
 
   if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
     DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, DataSize));
     return FALSE;
   }
 
   OneData = 0;
   CopyMem (&OneData, (UINT8 *) Data + HiiQuestion->VarOffset, HiiQuestion->StorageWidth);
+  if (HiiQuestion->BitFieldStore) {
+    //
+    // Get the value form the bit field.
+    //
+    StartBit = HiiQuestion->VarOffsetBitLevel % 8;
+    EndBit = StartBit + HiiQuestion->StorageWidthBitLevel - 1;
+    OneData = BitFieldRead64 (OneData, StartBit, EndBit);  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < (UINTN) HiiQuestion + HiiQuestion->Length) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         if (OneData == OneValue) {
           //
           // Match
           //
           break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       if ((UINTN) Ptr >= ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         //
         // No match
         //
@@ -136,14 +157,24 @@ VarCheckHiiQuestion (
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if (HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       //
       // No need to check Step, because it is ONLY for UI.
       //
       if ((OneData < Minimum) || (OneData > Maximum)) { @@ -341,22 +372,41 @@ DumpHiiQuestion (
   UINT64    Minimum;
   UINT64    Maximum;
   UINT64    OneValue;
   UINT8     *Ptr;
 
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in 
+ bit field----\n"));  } else {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in 
+ byte field----\n"));  }
+
   DEBUG ((EFI_D_INFO, "  VAR_CHECK_HII_QUESTION_HEADER\n"));
   DEBUG ((EFI_D_INFO, "    OpCode        - 0x%02x (%a)\n", HiiQuestion->OpCode, HiiOpCodeToStr (HiiQuestion->OpCode)));
   DEBUG ((EFI_D_INFO, "    Length        - 0x%02x\n", HiiQuestion->Length));
-  DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
-  DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "  Bit VarOffset(Bit level)     - 0x%04x\n", HiiQuestion->VarOffsetBitLevel));
+    DEBUG ((EFI_D_INFO, "  Bit StorageWidth(Bit level)  - 0x%02x\n", 
+ HiiQuestion->StorageWidthBitLevel));
+  } else {
+    DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
+    DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         switch (HiiQuestion->StorageWidth) {
           case sizeof (UINT8):
             DEBUG ((EFI_D_INFO, "    OneOfOption   - 0x%02x\n", OneValue));
             break;
           case sizeof (UINT16):
@@ -370,25 +420,39 @@ DumpHiiQuestion (
             break;
           default:
             ASSERT (FALSE);
             break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
       break;
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if(HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       switch (HiiQuestion->StorageWidth) {
         case sizeof (UINT8):
           DEBUG ((EFI_D_INFO, "    Minimum       - 0x%02x\n", Minimum));
           DEBUG ((EFI_D_INFO, "    Maximum       - 0x%02x\n", Maximum));
--
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] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check
Posted by Bi, Dandan 6 years, 5 months ago
Hi Star,

Thanks for your comments.

Yes, you are right. I will update the patch based on your comments.

Regards,
Dandan

-----Original Message-----
From: Zeng, Star 
Sent: Friday, November 3, 2017 2:04 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>; Zeng, Star <star.zeng@intel.com>
Subject: RE: [patch] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check

Hi Dandan,

1. Could we reuse VarOffset/StorageWidth to store bit level info when BitFieldStore = TRUE? Then we can avoid adding VarOffsetBitLevel/StorageWidthBitLevel to reduce the final VarCheckBinSize, and it can be also aligned with HiiDatabase that is using VarOffset to store bit level info when gEdkiiIfrBitVarstoreGuid guid opcode is present, right?

2. Please increase VAR_CHECK_HII_REVISION since we will update the structure definitions.

3. How about to update
"Bit VarStoreInfo (bit level)" to be "VarStoreInfo (bit level)"?
"Bit VarOffset(Bit level)" to be "VarOffset(Bit level)"?
"Bit StorageWidth(Bit level) " to be "StorageWidth(Bit level)"?

4.  How about to update "oneof", "checkbox", "numeric" and "orderedlist" in comments to be consistent with "OneOf", "CheckBox", "Numeric" and "OrderedList"?


Thanks,
Star
-----Original Message-----
From: Bi, Dandan
Sent: Friday, October 27, 2017 3:25 PM
To: edk2-devel@lists.01.org
Cc: Zeng, Star <star.zeng@intel.com>; Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [patch] MdeModulePkg/VarCheckHii: Enhance VarCheckHiiLib to support bit check

VarCheckHiiLib check the value set to storage based on the possible value listed in the vfr file. Since we have enhanced vfr to support Question value stored in bit field, so now enhance VarCheckHiiLib to support bit field check.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../VarCheckHiiLib/InternalVarCheckStructure.h     |  17 +-
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h  |   4 +-
 .../Library/VarCheckHiiLib/VarCheckHiiGen.c        | 259 +++++++++++++++------
 .../Library/VarCheckHiiLib/VarCheckHiiLib.inf      |   5 +-
 .../VarCheckHiiLib/VarCheckHiiLibNullClass.c       |  92 ++++++--
 5 files changed, 291 insertions(+), 86 deletions(-)

diff --git a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
index a9faed4..b32dd4e 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/InternalVarCheckStructure.h
@@ -1,9 +1,9 @@
 /** @file
   Internal structure for Var Check Hii.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -40,41 +40,56 @@ typedef struct {
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_HEADER;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ONEOF;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 } VAR_CHECK_HII_QUESTION_CHECKBOX;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
 //UINTx               Minimum; // x = UINT8/UINT16/UINT32/UINT64;
 //UINTx               Maximum; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_NUMERIC;
 
 typedef struct {
   UINT8             OpCode;
   UINT8             Length; // Length include this header
   UINT16            VarOffset;
   UINT8             StorageWidth;
+  UINT16            VarOffsetBitLevel;
+  UINT8             StorageWidthBitLevel;
+  BOOLEAN           BitFieldStore; // Whether the Question is stored in bit field
   UINT8             MaxContainers;
 //UINTx               Data[]; // x = UINT8/UINT16/UINT32/UINT64;
 } VAR_CHECK_HII_QUESTION_ORDEREDLIST;
 
 #pragma pack ()
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
index a54b867..7363edf 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHii.h
@@ -1,9 +1,9 @@
 /** @file
   Include file for Var Check Hii handler and bin.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/MemoryAllocationLib.h>
 
+#include <Guid/MdeModuleHii.h>
+
 #include <Protocol/HiiDatabase.h>
 #include <Protocol/FirmwareVolume2.h>
 #include <Protocol/FirmwareVolumeBlock.h>
 
 #include "InternalVarCheckStructure.h"
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
index f018c87..f4b646c 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGen.c
@@ -1,9 +1,9 @@
 /** @file
   Var Check Hii bin generation.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 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
 
@@ -118,12 +118,14 @@ DumpHiiPackage (
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   EFI_IFR_VARSTORE              *IfrVarStore;
   EFI_IFR_VARSTORE_EFI          *IfrEfiVarStore;
+  BOOLEAN                       QuestionStoredInBitField;
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
+  QuestionStoredInBitField = FALSE;
 
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Type   - 0x%02x (%a)\n", HiiPackageHeader->Type, HiiPackageTypeToStr ((UINT8) HiiPackageHeader->Type)));
   DEBUG ((EFI_D_INFO, "  HiiPackageHeader->Length - 0x%06x\n", HiiPackageHeader->Length));
 
   switch (HiiPackageHeader->Type) {
@@ -155,83 +157,116 @@ DumpHiiPackage (
               DEBUG ((EFI_D_INFO, "      Attributes - 0x%08x\n", IfrEfiVarStore->Attributes));
               DEBUG ((EFI_D_INFO, "      Name       - %a\n", IfrEfiVarStore->Name));
             }
             break;
 
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in bit field----\n"));
+            } else {
+              DEBUG ((EFI_D_INFO, "----DumpHiiPackage-The Question is stored in byte field----\n"));
+            }
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->OpCode - 0x%02x (%a)\n", IfrOpCodeHeader->OpCode, IfrOpCodeToStr (IfrOpCodeHeader->OpCode)));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Length - 0x02%x\n", IfrOpCodeHeader->Length));
             DEBUG ((EFI_D_INFO, "    IfrOpCodeHeader->Scope  - 0x02%x\n", IfrOpCodeHeader->Scope));
             DEBUG ((EFI_D_INFO, "      Prompt       - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Prompt));
             DEBUG ((EFI_D_INFO, "      Help         - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.Header.Help));
             DEBUG ((EFI_D_INFO, "      QuestionId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.QuestionId));
             DEBUG ((EFI_D_INFO, "      VarStoreId   - 0x%04x\n", ((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId));
-            DEBUG ((EFI_D_INFO, "      VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            if (QuestionStoredInBitField) {
+              DEBUG ((EFI_D_INFO, "    Bit VarStoreInfo (bit level) - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            } else {
+              DEBUG ((EFI_D_INFO, "    VarStoreInfo - 0x%04x\n", ((EFI_IFR_ONE_OF * )IfrOpCodeHeader)->Question.VarStoreInfo.VarOffset));
+            }
             {
               EFI_IFR_ONE_OF            *IfrOneOf;
               EFI_IFR_CHECKBOX          *IfrCheckBox;
               EFI_IFR_NUMERIC           *IfrNumeric;
               EFI_IFR_ORDERED_LIST      *IfrOrderedList;
 
               switch (IfrOpCodeHeader->OpCode) {
                 case EFI_IFR_ONE_OF_OP:
                   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrOneOf->Flags));
-                  switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Oneof stored in bit field, the option value are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrOneOf->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrOneOf->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrOneOf->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrOneOf->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrOneOf->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrOneOf->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrOneOf->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrOneOf->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrOneOf->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrOneOf->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrOneOf->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrOneOf->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_CHECKBOX_OP:
                   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrCheckBox->Flags));
                   break;
                 case EFI_IFR_NUMERIC_OP:
                   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      Flags         - 0x%02x\n", IfrNumeric->Flags));
-                  switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
-                  case EFI_IFR_NUMERIC_SIZE_1:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_2:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_4:
+                  if (QuestionStoredInBitField) {
+                    //
+                    // For Numeric stored in bit field, the MinValue,MaxValue and Step are saved as UINT32 type.
+                    //
                     DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
                     DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
                     DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
-                    break;
-                  case EFI_IFR_NUMERIC_SIZE_8:
-                    DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
-                    DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
-                    DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
-                    break;
+                  } else {
+                    switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
+                    case EFI_IFR_NUMERIC_SIZE_1:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%02x\n", IfrNumeric->data.u8.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%02x\n", IfrNumeric->data.u8.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%02x\n", IfrNumeric->data.u8.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_2:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%04x\n", IfrNumeric->data.u16.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%04x\n", IfrNumeric->data.u16.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%04x\n", IfrNumeric->data.u16.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_4:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%08x\n", IfrNumeric->data.u32.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%08x\n", IfrNumeric->data.u32.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%08x\n", IfrNumeric->data.u32.Step));
+                      break;
+                    case EFI_IFR_NUMERIC_SIZE_8:
+                      DEBUG ((EFI_D_INFO, "      MinValue      - 0x%016lx\n", IfrNumeric->data.u64.MinValue));
+                      DEBUG ((EFI_D_INFO, "      MaxValue      - 0x%016lx\n", IfrNumeric->data.u64.MaxValue));
+                      DEBUG ((EFI_D_INFO, "      Step          - 0x%016lx\n", IfrNumeric->data.u64.Step));
+                      break;
+                    }
                   }
                   break;
                 case EFI_IFR_ORDERED_LIST_OP:
                   IfrOrderedList = (EFI_IFR_ORDERED_LIST *) IfrOpCodeHeader;
                   DEBUG ((EFI_D_INFO, "      MaxContainers - 0x%02x\n", IfrOrderedList->MaxContainers));
@@ -277,10 +312,11 @@ DumpHiiPackage (
                       }
                       break;
                   }
 
                   if (IfrOpCodeHeader->OpCode == EFI_IFR_END_OP) {
+                    QuestionStoredInBitField = FALSE;
                     ASSERT (Scope > 0);
                     Scope--;
                     if (Scope == 0) {
                       break;
                     }
@@ -496,11 +532,11 @@ MergeHiiQuestion (
   if (FromFv) {
     InternalVarCheckFreePool (HiiQuestion);
     return;
   }
 
-  HiiQuestion1 = HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset];
+  HiiQuestion1 =
+ HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel];
   HiiQuestion2 = HiiQuestion;
 
   ASSERT ((HiiQuestion1->OpCode == HiiQuestion2->OpCode) && (HiiQuestion1->StorageWidth == HiiQuestion2->StorageWidth));
 
   switch (HiiQuestion1->OpCode) {
@@ -578,11 +614,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        
+ HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] =
+ NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
@@ -703,11 +739,11 @@ MergeHiiQuestion (
             Ptr += HiiQuestion1->StorageWidth;
           }
           Ptr2 += HiiQuestion2->StorageWidth;
         }
 
-        HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffset] = NewHiiQuestion;
+        
+ HiiVariableNode->HiiQuestionArray[HiiQuestion1->VarOffsetBitLevel] =
+ NewHiiQuestion;
         InternalVarCheckFreePool (HiiQuestion1);
       }
       break;
 
     default:
@@ -829,103 +865,167 @@ GetOneOfOption (
 
 /**
   Parse Hii Question Oneof.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Oneof is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionOneOf (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_ONE_OF                *IfrOneOf;
   VAR_CHECK_HII_QUESTION_ONEOF  *OneOf;
   UINTN                         Length;
   UINT8                         Width;
   UINTN                         OptionCount;
   UINT8                         OptionWidth;
+  UINT8                         BitWidth;
+  UINT8                         TotalBits;
 
   IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpCodeHeader;
+  BitWidth = 0;
 
-  Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When oneof stored in bit field, the bit width is saved in the lower six bits of the flag.
+    // And the options in the oneof is saved as UINT32 type.
+    //
+    BitWidth = IfrOneOf->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, NULL);
   ASSERT (Width == OptionWidth);
 
   Length = sizeof (*OneOf) + OptionCount * Width;
 
   OneOf = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OneOf != NULL);
   OneOf->OpCode       = EFI_IFR_ONE_OF_OP;
   OneOf->Length       = (UINT8) Length;
-  OneOf->VarOffset    = IfrOneOf->Question.VarStoreInfo.VarOffset;
-  OneOf->StorageWidth = Width;
+  OneOf->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    OneOf->VarOffsetBitLevel    = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffset            = OneOf->VarOffsetBitLevel / 8;
+    OneOf->StorageWidthBitLevel = BitWidth;
+    TotalBits                   = OneOf->VarOffsetBitLevel % 8 + BitWidth;
+    OneOf->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    OneOf->VarOffset            = IfrOneOf->Question.VarStoreInfo.VarOffset;
+    OneOf->VarOffsetBitLevel    = OneOf->VarOffset * 8;
+    OneOf->StorageWidth         = Width;
+    OneOf->StorageWidthBitLevel = Width * 8;  }
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OneOf + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OneOf;  }
 
 /**
   Parse Hii Question CheckBox.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the Checkbox is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionCheckBox (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_CHECKBOX                  *IfrCheckBox;
   VAR_CHECK_HII_QUESTION_CHECKBOX   *CheckBox;
+  UINT8                             TotalBits;
 
   IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpCodeHeader;
 
   CheckBox = InternalVarCheckAllocateZeroPool (sizeof (*CheckBox));
   ASSERT (CheckBox != NULL);
   CheckBox->OpCode       = EFI_IFR_CHECKBOX_OP;
-  CheckBox->Length       = (UINT8) sizeof (*CheckBox);;
-  CheckBox->VarOffset    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
-  CheckBox->StorageWidth = (UINT8) sizeof (BOOLEAN);
+  CheckBox->Length       = (UINT8) sizeof (*CheckBox);
+  CheckBox->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    CheckBox->VarOffsetBitLevel    = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffset            = CheckBox->VarOffsetBitLevel / 8;
+    CheckBox->StorageWidthBitLevel = 1;
+    TotalBits                      = CheckBox->VarOffsetBitLevel % 8 + 1;
+    CheckBox->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    CheckBox->VarOffset            = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+    CheckBox->VarOffsetBitLevel    = CheckBox->VarOffset * 8;
+    CheckBox->StorageWidth         = (UINT8) sizeof (BOOLEAN);
+    CheckBox->StorageWidthBitLevel = CheckBox->StorageWidth * 8;  }
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) CheckBox;  }
 
 /**
   Parse Hii Question Numeric.
 
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
+  @param[in] StoredInBitField   Whether the numeric is stored in bit field Storage.
 
   return Pointer to Hii Question.
 
 **/
 VAR_CHECK_HII_QUESTION_HEADER *
 ParseHiiQuestionNumeric (
-  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader
+  IN EFI_IFR_OP_HEADER  *IfrOpCodeHeader,
+  IN BOOLEAN            StoredInBitField
   )
 {
   EFI_IFR_NUMERIC                   *IfrNumeric;
   VAR_CHECK_HII_QUESTION_NUMERIC    *Numeric;
   UINT8                             Width;
+  UINT8                             BitWidth;
+  UINT8                             TotalBits;
 
   IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpCodeHeader;
+  BitWidth = 0;
 
   Numeric = InternalVarCheckAllocateZeroPool (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * sizeof (UINT64));
   ASSERT (Numeric != NULL);
 
-  Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+  if (StoredInBitField) {
+    //
+    // When numeric stored in bit field, the bit field width is saved in the lower six bits of the flag.
+    // And the Minimum Maximum of numeric is saved as UINT32 type.
+    //
+    BitWidth = IfrNumeric->Flags & EDKII_IFR_NUMERIC_SIZE_BIT;
+    Width = sizeof (UINT32);
+  } else {
+    Width = (UINT8) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); 
+ }
 
   Numeric->OpCode       = EFI_IFR_NUMERIC_OP;
   Numeric->Length       = (UINT8) (sizeof (VAR_CHECK_HII_QUESTION_NUMERIC) + 2 * Width);
-  Numeric->VarOffset    = IfrNumeric->Question.VarStoreInfo.VarOffset;
-  Numeric->StorageWidth = Width;
+  Numeric->BitFieldStore = StoredInBitField;  if (StoredInBitField) {
+    Numeric->VarOffsetBitLevel    = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffset            = Numeric->VarOffsetBitLevel / 8;
+    Numeric->StorageWidthBitLevel = BitWidth;
+    TotalBits                     = Numeric->VarOffsetBitLevel % 8 + BitWidth;
+    Numeric->StorageWidth         = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+  } else {
+    Numeric->VarOffset            = IfrNumeric->Question.VarStoreInfo.VarOffset;
+    Numeric->VarOffsetBitLevel    = Numeric->VarOffset * 8;
+    Numeric->StorageWidth         = Width;
+    Numeric->StorageWidthBitLevel = Width * 8;  }
 
   CopyMem (Numeric + 1, &IfrNumeric->data, Width * 2);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) Numeric;  } @@ -955,15 +1055,18 @@ ParseHiiQuestionOrderedList (
 
   Length = sizeof (*OrderedList) + OptionCount * OptionWidth;
 
   OrderedList = InternalVarCheckAllocateZeroPool (Length);
   ASSERT (OrderedList != NULL);
-  OrderedList->OpCode        = EFI_IFR_ORDERED_LIST_OP;
-  OrderedList->Length        = (UINT8) Length;
-  OrderedList->VarOffset     = IfrOrderedList->Question.VarStoreInfo.VarOffset;
-  OrderedList->StorageWidth  = OptionWidth;
-  OrderedList->MaxContainers = IfrOrderedList->MaxContainers;
+  OrderedList->BitFieldStore        = FALSE;
+  OrderedList->OpCode               = EFI_IFR_ORDERED_LIST_OP;
+  OrderedList->Length               = (UINT8) Length;
+  OrderedList->VarOffset            = IfrOrderedList->Question.VarStoreInfo.VarOffset;
+  OrderedList->StorageWidth         = OptionWidth;
+  OrderedList->MaxContainers        = IfrOrderedList->MaxContainers;
+  OrderedList->VarOffsetBitLevel    = IfrOrderedList->Question.VarStoreInfo.VarOffset * 8;
+  OrderedList->StorageWidthBitLevel = OptionWidth * 8;
 
   GetOneOfOption (IfrOpCodeHeader, &OptionCount, &OptionWidth, OrderedList + 1);
 
   return (VAR_CHECK_HII_QUESTION_HEADER *) OrderedList;  } @@ -972,32 +1075,37 @@ ParseHiiQuestionOrderedList (
   Parse and create Hii Question node.
 
   @param[in] HiiVariableNode    Pointer to Hii Variable node.
   @param[in] IfrOpCodeHeader    Pointer to Ifr OpCode header.
   @param[in] FromFv             Hii Question from FV.
+  @param[in] StoredInBitField   Whether the Question is stored in bit field Storage.
 
 **/
 VOID
 ParseHiiQuestion (
   IN VAR_CHECK_HII_VARIABLE_NODE    *HiiVariableNode,
   IN  EFI_IFR_OP_HEADER             *IfrOpCodeHeader,
-  IN BOOLEAN                        FromFv
+  IN BOOLEAN                        FromFv,
+  IN BOOLEAN                        StoredInBitField
   )
 {
   VAR_CHECK_HII_QUESTION_HEADER *HiiQuestion;
 
+  //
+  // Currently only Oneof, Checkbox and numeric can be stored in bit field.
+  //
   switch (IfrOpCodeHeader->OpCode) {
     case EFI_IFR_ONE_OF_OP:
-      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionOneOf (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_CHECKBOX_OP:
-      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionCheckBox (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_NUMERIC_OP:
-      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader);
+      HiiQuestion = ParseHiiQuestionNumeric (IfrOpCodeHeader, 
+ StoredInBitField);
       break;
 
     case EFI_IFR_ORDERED_LIST_OP:
       HiiQuestion = ParseHiiQuestionOrderedList (IfrOpCodeHeader);
       break;
@@ -1006,14 +1114,14 @@ ParseHiiQuestion (
       ASSERT (FALSE);
       return;
       break;
   }
 
-  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] != NULL) {
+  if (HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel]
+ != NULL) {
     MergeHiiQuestion (HiiVariableNode, HiiQuestion, FromFv);
   } else {
-    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffset] = HiiQuestion;
+    HiiVariableNode->HiiQuestionArray[HiiQuestion->VarOffsetBitLevel] = 
+ HiiQuestion;
   }
 }
 
 /**
   Find Hii variable node by name and GUID.
@@ -1164,11 +1272,11 @@ CreateHiiVariableNode (
     HiiVariableNode->HiiVariable = HiiVariable;
     //
     // The variable store identifier, which is unique within the current form set.
     //
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
-    HiiVariableNode->HiiQuestionArray = InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * sizeof (VAR_CHECK_HII_QUESTION_HEADER *));
+    HiiVariableNode->HiiQuestionArray = 
+ InternalVarCheckAllocateZeroPool (IfrEfiVarStore->Size * 8 * sizeof 
+ (VAR_CHECK_HII_QUESTION_HEADER *));
 
     InsertTailList (&mVarCheckHiiList, &HiiVariableNode->Link);
   } else {
     HiiVariableNode->VarStoreId = IfrEfiVarStore->VarStoreId;
   }
@@ -1237,24 +1345,37 @@ VarCheckParseHiiPackage (
   )
 {
   EFI_HII_PACKAGE_HEADER        *HiiPackageHeader;
   EFI_IFR_OP_HEADER             *IfrOpCodeHeader;
   VAR_CHECK_HII_VARIABLE_NODE   *HiiVariableNode;
+  BOOLEAN                       QuestionStoredInBitField;
 
   //
   // Parse and create Hii Variable node list for this Hii Package.
   //
   ParseHiiVariable (HiiPackage);
 
   HiiPackageHeader = (EFI_HII_PACKAGE_HEADER *) HiiPackage;
 
+  QuestionStoredInBitField = FALSE;
+
   switch (HiiPackageHeader->Type) {
     case EFI_HII_PACKAGE_FORMS:
       IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) (HiiPackageHeader + 1);
 
       while ((UINTN) IfrOpCodeHeader < (UINTN) HiiPackageHeader + HiiPackageHeader->Length) {
         switch (IfrOpCodeHeader->OpCode) {
+          case EFI_IFR_GUID_OP:
+            if (CompareGuid ((EFI_GUID *)((UINTN)IfrOpCodeHeader + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+              QuestionStoredInBitField = TRUE;
+            }
+            break;
+
+          case EFI_IFR_END_OP:
+            QuestionStoredInBitField = FALSE;
+            break;
+
           case EFI_IFR_ONE_OF_OP:
           case EFI_IFR_CHECKBOX_OP:
           case EFI_IFR_NUMERIC_OP:
           case EFI_IFR_ORDERED_LIST_OP:
             HiiVariableNode = FindHiiVariableNodeByVarStoreId (((EFI_IFR_ONE_OF *) IfrOpCodeHeader)->Question.VarStoreId);
@@ -1268,11 +1389,11 @@ VarCheckParseHiiPackage (
                 //
             } else {
               //
               // Normal IFR
               //
-              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, FromFv);
+              ParseHiiQuestion (HiiVariableNode, IfrOpCodeHeader, 
+ FromFv, QuestionStoredInBitField);
             }
           default:
             break;
         }
         IfrOpCodeHeader = (EFI_IFR_OP_HEADER *) ((UINTN) IfrOpCodeHeader + IfrOpCodeHeader->Length); @@ -1339,11 +1460,11 @@ DestroyHiiVariableNode (
     RemoveEntryList (&HiiVariableNode->Link);
 
     //
     // Free the allocated buffer.
     //
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size *
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray[Index]);
       }
     }
     InternalVarCheckFreePool (HiiVariableNode->HiiQuestionArray);
@@ -1387,11 +1508,11 @@ BuildVarCheckHiiBin (
     BinSize = (UINT32) HEADER_ALIGN (BinSize);
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     HiiVariableLength = HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size *
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         HiiVariableLength = (UINT32) HEADER_ALIGN (HiiVariableLength); @@ -1432,11 +1553,11 @@ BuildVarCheckHiiBin (
 
     HiiVariableNode = VAR_CHECK_HII_VARIABLE_FROM_LINK (HiiVariableLink);
     CopyMem (Ptr, HiiVariableNode->HiiVariable, HiiVariableNode->HiiVariable->HeaderLength);
     Ptr += HiiVariableNode->HiiVariable->HeaderLength;
 
-    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size; Index++) {
+    for (Index = 0; Index < HiiVariableNode->HiiVariable->Size *
+ (UINTN) 8; Index++) {
       if (HiiVariableNode->HiiQuestionArray[Index] != NULL) {
         //
         // For Hii Question header align.
         //
         Ptr = (UINT8 *) HEADER_ALIGN (Ptr); diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
index 98e6983..aeca3ef 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf
@@ -1,9 +1,9 @@
 ## @file
 #  NULL class library to register var check HII handler.
 #
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2015 - 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 @@ -44,10 +44,13 @@
   UefiBootServicesTableLib
   MemoryAllocationLib
   PcdLib
   VarCheckLib
 
+[Guids]
+  gEdkiiIfrBitVarstoreGuid                  ## SOMETIMES_CONSUMES  ## GUID
+
 [Protocols]
   gEfiFirmwareVolume2ProtocolGuid           ## SOMETIMES_CONSUMES
   gEfiFirmwareVolumeBlock2ProtocolGuid      ## SOMETIMES_CONSUMES
   gEfiHiiDatabaseProtocolGuid               ## SOMETIMES_CONSUMES
 
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
index 93ff934..1f96712 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
@@ -91,32 +91,53 @@ VarCheckHiiQuestion (
   UINT64   Maximum;
   UINT64   OneValue;
   UINT8    *Ptr;
   UINT8    Index;
   UINT8    MaxContainers;
+  UINTN    StartBit;
+  UINTN    EndBit;
 
   if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
     DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, DataSize));
     return FALSE;
   }
 
   OneData = 0;
   CopyMem (&OneData, (UINT8 *) Data + HiiQuestion->VarOffset, HiiQuestion->StorageWidth);
+  if (HiiQuestion->BitFieldStore) {
+    //
+    // Get the value form the bit field.
+    //
+    StartBit = HiiQuestion->VarOffsetBitLevel % 8;
+    EndBit = StartBit + HiiQuestion->StorageWidthBitLevel - 1;
+    OneData = BitFieldRead64 (OneData, StartBit, EndBit);  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < (UINTN) HiiQuestion + HiiQuestion->Length) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         if (OneData == OneValue) {
           //
           // Match
           //
           break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       if ((UINTN) Ptr >= ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         //
         // No match
         //
@@ -136,14 +157,24 @@ VarCheckHiiQuestion (
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if (HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       //
       // No need to check Step, because it is ONLY for UI.
       //
       if ((OneData < Minimum) || (OneData > Maximum)) { @@ -341,22 +372,41 @@ DumpHiiQuestion (
   UINT64    Minimum;
   UINT64    Maximum;
   UINT64    OneValue;
   UINT8     *Ptr;
 
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in 
+ bit field----\n"));  } else {
+    DEBUG ((EFI_D_INFO, "----DumpHiiQuestion-The Question is stored in 
+ byte field----\n"));  }
+
   DEBUG ((EFI_D_INFO, "  VAR_CHECK_HII_QUESTION_HEADER\n"));
   DEBUG ((EFI_D_INFO, "    OpCode        - 0x%02x (%a)\n", HiiQuestion->OpCode, HiiOpCodeToStr (HiiQuestion->OpCode)));
   DEBUG ((EFI_D_INFO, "    Length        - 0x%02x\n", HiiQuestion->Length));
-  DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
-  DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+
+  if (HiiQuestion->BitFieldStore) {
+    DEBUG ((EFI_D_INFO, "  Bit VarOffset(Bit level)     - 0x%04x\n", HiiQuestion->VarOffsetBitLevel));
+    DEBUG ((EFI_D_INFO, "  Bit StorageWidth(Bit level)  - 0x%02x\n",
+ HiiQuestion->StorageWidthBitLevel));
+  } else {
+    DEBUG ((EFI_D_INFO, "    VarOffset     - 0x%04x\n", HiiQuestion->VarOffset));
+    DEBUG ((EFI_D_INFO, "    StorageWidth  - 0x%02x\n", HiiQuestion->StorageWidth));
+  }
 
   switch (HiiQuestion->OpCode) {
     case EFI_IFR_ONE_OF_OP:
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_ONEOF *) HiiQuestion + 1);
       while ((UINTN) Ptr < ((UINTN) HiiQuestion + HiiQuestion->Length)) {
         OneValue = 0;
-        CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        if (HiiQuestion->BitFieldStore) {
+          //
+          // For Oneof stored in bit field, the value of options are saved as UINT32 type.
+          //
+          CopyMem (&OneValue, Ptr, sizeof (UINT32));
+        } else {
+          CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
+        }
         switch (HiiQuestion->StorageWidth) {
           case sizeof (UINT8):
             DEBUG ((EFI_D_INFO, "    OneOfOption   - 0x%02x\n", OneValue));
             break;
           case sizeof (UINT16):
@@ -370,25 +420,39 @@ DumpHiiQuestion (
             break;
           default:
             ASSERT (FALSE);
             break;
         }
-        Ptr += HiiQuestion->StorageWidth;
+        if (HiiQuestion->BitFieldStore) {
+          Ptr += sizeof (UINT32);
+        } else {
+          Ptr += HiiQuestion->StorageWidth;
+        }
       }
       break;
 
     case EFI_IFR_CHECKBOX_OP:
       break;
 
     case EFI_IFR_NUMERIC_OP:
       Minimum = 0;
       Maximum = 0;
       Ptr = (UINT8 *) ((VAR_CHECK_HII_QUESTION_NUMERIC *) HiiQuestion + 1);
-      CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
-      CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
-      Ptr += HiiQuestion->StorageWidth;
+      if(HiiQuestion->BitFieldStore) {
+        //
+        // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
+        //
+        CopyMem (&Minimum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+        CopyMem (&Maximum, Ptr, sizeof (UINT32));
+        Ptr += sizeof (UINT32);
+      } else {
+        CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+        CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
+        Ptr += HiiQuestion->StorageWidth;
+      }
 
       switch (HiiQuestion->StorageWidth) {
         case sizeof (UINT8):
           DEBUG ((EFI_D_INFO, "    Minimum       - 0x%02x\n", Minimum));
           DEBUG ((EFI_D_INFO, "    Maximum       - 0x%02x\n", Maximum));
--
1.9.5.msysgit.1

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