From: Dandan Bi <dandan.bi@intel.com>
To: edk2-devel@lists.01.org
Cc: Eric Dong <eric.dong@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH V5 3/6] MdeModulePkg/UefiHiiLib: Validate question with bit fields
Date: Wed, 20 Sep 2017 16:39:05 +0800 [thread overview]
Message-ID: <1505896748-436688-4-git-send-email-dandan.bi@intel.com> (raw)
In-Reply-To: <1505896748-436688-1-git-send-email-dandan.bi@intel.com>
V5: Update the EDKII extension GUID name with EDKII/Edkii prefix.
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=545
In UefiHiiLib, there are codes to validate the current setting of
questions, now update the logic to handle question with bit storage.
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>
---
MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 246 ++++++++++++++++-------
MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h | 4 +-
MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf | 5 +-
3 files changed, 178 insertions(+), 77 deletions(-)
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index 583b9e5..e9e94f4 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -1167,10 +1167,16 @@ ValidateQuestionFromVfr (
EFI_IFR_STRING *IfrString;
CHAR8 *VarStoreName;
UINTN Index;
CHAR16 *QuestionName;
CHAR16 *StringPtr;
+ UINT16 BitOffset;
+ UINT16 BitWidth;
+ UINT16 TotalBits;
+ UINTN StartBit;
+ UINTN EndBit;
+ BOOLEAN QuestionReferBitField;
//
// Initialize the local variables.
//
Index = 0;
@@ -1180,10 +1186,13 @@ ValidateQuestionFromVfr (
IfrVarStore = NULL;
IfrNameValueStore = NULL;
IfrEfiVarStore = NULL;
ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA));
ZeroMem (&VarBlockData, sizeof (VarBlockData));
+ BitOffset = 0;
+ BitWidth = 0;
+ QuestionReferBitField = FALSE;
//
// Check IFR value is in block data, then Validate Value
//
PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
@@ -1343,12 +1352,23 @@ ValidateQuestionFromVfr (
}
} else {
//
// Get Offset by Question header and Width by DataType Flags
//
- Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;
- Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+ if (QuestionReferBitField) {
+ //
+ // Get the byte offset/width for bit field.
+ //
+ BitOffset = IfrOneOf->Question.VarStoreInfo.VarOffset;
+ BitWidth = IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE_BIT;
+ Offset = BitOffset / 8;
+ TotalBits = BitOffset % 8 + BitWidth;
+ Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+ } else {
+ Offset = IfrOneOf->Question.VarStoreInfo.VarOffset;
+ Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE));
+ }
//
// Check whether this question is in current block array.
//
if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
//
@@ -1368,11 +1388,20 @@ ValidateQuestionFromVfr (
//
// Get the current value for oneof opcode
//
VarValue = 0;
- CopyMem (&VarValue, VarBuffer + Offset, Width);
+ if (QuestionReferBitField) {
+ //
+ // Get the value in bit fields.
+ //
+ StartBit = BitOffset % 8;
+ EndBit = StartBit + BitWidth - 1;
+ VarValue = BitFieldRead32 (*(UINT32*)(VarBuffer + Offset), StartBit, EndBit);
+ } else {
+ CopyMem (&VarValue, VarBuffer + Offset, Width);
+ }
}
//
// Set Block Data, to be checked in the following Oneof option opcode.
//
VarBlockData.OpCode = IfrOpHdr->OpCode;
@@ -1414,12 +1443,23 @@ ValidateQuestionFromVfr (
}
} else {
//
// Get Offset by Question header and Width by DataType Flags
//
- Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;
- Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+ if (QuestionReferBitField) {
+ //
+ // Get the byte offset/width for bit field.
+ //
+ BitOffset = IfrNumeric->Question.VarStoreInfo.VarOffset;
+ BitWidth = IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE_BIT;
+ Offset = BitOffset / 8;
+ TotalBits = BitOffset % 8 + BitWidth;
+ Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+ } else {
+ Offset = IfrNumeric->Question.VarStoreInfo.VarOffset;
+ Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE));
+ }
//
// Check whether this question is in current block array.
//
if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
//
@@ -1439,81 +1479,111 @@ ValidateQuestionFromVfr (
//
// Check the current value is in the numeric range.
//
VarValue = 0;
- CopyMem (&VarValue, VarBuffer + Offset, Width);
- }
- if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {
- switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
- case EFI_IFR_NUMERIC_SIZE_1:
- if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
- case EFI_IFR_NUMERIC_SIZE_2:
- if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
- case EFI_IFR_NUMERIC_SIZE_4:
- if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
- case EFI_IFR_NUMERIC_SIZE_8:
- if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
+ if (QuestionReferBitField) {
+ //
+ // Get the value in the bit fields.
+ //
+ StartBit = BitOffset % 8;
+ EndBit = StartBit + BitWidth - 1;
+ VarValue = BitFieldRead32 (*(UINT32*)(VarBuffer + Offset), StartBit, EndBit);
+ } else {
+ CopyMem (&VarValue, VarBuffer + Offset, Width);
}
+ }
+ if ( QuestionReferBitField) {
+ //
+ // Value in bit fields was stored as UINt32 type.
+ //
+ if ((IfrNumeric->Flags & EFI_IFR_DISPLAY_BIT) == 0) {
+ if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ } else {
+ if (VarValue < IfrNumeric->data.u32.MinValue || VarValue > IfrNumeric->data.u32.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ }
} else {
- switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
- case EFI_IFR_NUMERIC_SIZE_1:
- if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
- case EFI_IFR_NUMERIC_SIZE_2:
- if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
- }
- break;
- case EFI_IFR_NUMERIC_SIZE_4:
- if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
+ if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) {
+ switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
+ case EFI_IFR_NUMERIC_SIZE_1:
+ if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_2:
+ if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_4:
+ if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_8:
+ if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
}
- break;
- case EFI_IFR_NUMERIC_SIZE_8:
- if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {
- //
- // Not in the valid range.
- //
- return EFI_INVALID_PARAMETER;
+ } else {
+ switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) {
+ case EFI_IFR_NUMERIC_SIZE_1:
+ if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_2:
+ if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_4:
+ if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
+ case EFI_IFR_NUMERIC_SIZE_8:
+ if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) {
+ //
+ // Not in the valid range.
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ break;
}
- break;
}
}
break;
case EFI_IFR_CHECKBOX_OP:
//
@@ -1552,12 +1622,23 @@ ValidateQuestionFromVfr (
}
} else {
//
// Get Offset by Question header
//
- Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;
- Width = (UINT16) sizeof (BOOLEAN);
+ if (QuestionReferBitField) {
+ //
+ // Get the byte offset/width for bit field.
+ //
+ BitOffset = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+ BitWidth = 1;
+ Offset = BitOffset / 8;
+ TotalBits = BitOffset % 8 + BitWidth;
+ Width = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1);
+ } else {
+ Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset;
+ Width = (UINT16) sizeof (BOOLEAN);
+ }
//
// Check whether this question is in current block array.
//
if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) {
//
@@ -1576,11 +1657,20 @@ ValidateQuestionFromVfr (
}
//
// Check the current value is in the numeric range.
//
VarValue = 0;
- CopyMem (&VarValue, VarBuffer + Offset, Width);
+ if (QuestionReferBitField) {
+ //
+ // Get the value in bit fields.
+ //
+ StartBit = BitOffset % 8;
+ EndBit = StartBit + BitWidth - 1;
+ VarValue = BitFieldRead32 (*(UINT32*)(VarBuffer + Offset), StartBit, EndBit);
+ } else {
+ CopyMem (&VarValue, VarBuffer + Offset, Width);
+ }
}
//
// Boolean type, only 1 and 0 is valid.
//
if (VarValue > 1) {
@@ -1701,10 +1791,11 @@ ValidateQuestionFromVfr (
VarBlockData.OpCode = 0;
}
}
break;
case EFI_IFR_END_OP:
+ QuestionReferBitField = FALSE;
//
// Decrease opcode scope for the validated opcode
//
if (VarBlockData.Scope > 0) {
VarBlockData.Scope --;
@@ -1715,10 +1806,15 @@ ValidateQuestionFromVfr (
//
if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) {
return EFI_INVALID_PARAMETER;
}
break;
+ case EFI_IFR_GUID_OP:
+ if (CompareGuid ((EFI_GUID *)((UINT8*)IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) {
+ QuestionReferBitField = TRUE;
+ }
+ break;
default:
//
// Increase Scope for the validated opcode
//
if (VarBlockData.Scope > 0) {
diff --git a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
index 9bf7696..293c226 100644
--- a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
+++ b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h
@@ -1,9 +1,9 @@
/** @file
Internal include file for the HII Library instance.
- Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2007 - 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
@@ -18,10 +18,12 @@
#include <Uefi.h>
#include <Protocol/DevicePath.h>
#include <Protocol/FormBrowser2.h>
+#include <Guid/MdeModuleHii.h>
+
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HiiLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
diff --git a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
index 62f435a..7ee6842 100644
--- a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+++ b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
@@ -1,9 +1,9 @@
## @file
# HII Library implementation using UEFI HII protocols and services.
#
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 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
@@ -49,5 +49,8 @@
PrintLib
[Protocols]
gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES
gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES
+
+[Guids]
+ gEdkiiIfrBitVarstoreGuid ## SOMETIMES_CONSUMES ## GUID
--
1.9.5.msysgit.1
next prev parent reply other threads:[~2017-09-20 8:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 8:39 [PATCH V5 0/6] Support bitfield in storage of vfr Dandan Bi
2017-09-20 8:39 ` [PATCH V5 1/6] BaseTool/VfrCompiler: Support Bit fields in EFI/Buffer VarStore Dandan Bi
2017-09-20 8:39 ` [PATCH V5 2/6] MdeModulePkg: Add GUID/flags to implement BitField support Dandan Bi
2017-09-20 8:39 ` Dandan Bi [this message]
2017-09-20 8:39 ` [PATCH V5 4/6] MdeModulePkg/HiiDatabase: Handle questions with Bit VarStore Dandan Bi
2017-09-20 8:39 ` [PATCH V5 5/6] MdeModulePkg/SetupBrowser: " Dandan Bi
2017-09-20 8:39 ` [PATCH V5 6/6] MdeModulePkg/DriverSample: Add questions with bit/union VarStore Dandan Bi
2017-09-21 7:30 ` [PATCH V5 0/6] Support bitfield in storage of vfr Gao, Liming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1505896748-436688-4-git-send-email-dandan.bi@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox