[edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Long1 Huang posted 1 patch 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/802446c5bddb6e7de746d733c68d92c0e09e5ca8.1642007174.git.long1.huang@intel.com
.../Universal/HiiDatabaseDxe/Database.c       | 130 ++++++++++++++----
.../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
2 files changed, 105 insertions(+), 28 deletions(-)

[edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by Long1 Huang 1 week, 5 days ago
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3796

Database.c:
	1. Replace PcdGetExPtr with PcdGetExPtr.
	2. Add FindAuthVariableData function to parse authenticated variable type for getting a correct default value in PcdNvStoreDefaultValueBuffer.

Signed-off-by: Huang Long <long1.huang@intel.com>

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Lin Z Chen <lin.z.chen@intel.com>
Cc: Zhuangzhi Li <zhuangzhi.li@intel.com>
---
 .../Universal/HiiDatabaseDxe/Database.c       | 130 ++++++++++++++----
 .../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
 2 files changed, 105 insertions(+), 28 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index 0b09c24d52..c7a92d6aed 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -603,6 +603,45 @@ FindVariableData (
   return NULL;
 }
 
+/**
+  Find the matched authenticated variable from the input variable storage.
+
+  @param[in] VariableStorage Point to the variable storage header.
+  @param[in] VarGuid         A unique identifier for the variable.
+  @param[in] VarAttribute    The attributes bitmask for the variable.
+  @param[in] VarName         A Null-terminated ascii string that is the name of the variable.
+
+  @return Pointer to the matched variable header or NULL if not found.
+**/
+AUTHENTICATED_VARIABLE_HEADER *
+FindAuthVariableData (
+  IN  VARIABLE_STORE_HEADER  *VariableStorage,
+  IN  EFI_GUID               *VarGuid,
+  IN  UINT32                 VarAttribute,
+  IN  CHAR16                 *VarName
+  )
+{
+  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableHeader;
+  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableEnd;
+
+  AuthVariableEnd    = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8 *)VariableStorage + VariableStorage->Size);
+  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)(VariableStorage + 1);
+  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)HEADER_ALIGN (AuthVariableHeader);
+  while (AuthVariableHeader < AuthVariableEnd) {
+    if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&
+        (AuthVariableHeader->Attributes == VarAttribute) &&
+        (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) == 0))
+    {
+      return AuthVariableHeader;
+    }
+
+    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8 *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);
+    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)HEADER_ALIGN (AuthVariableHeader);
+  }
+
+  return NULL;
+}
+
 /**
   Find question default value from PcdNvStoreDefaultValueBuffer
 
@@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
   IN  BOOLEAN                  BitFieldQuestion
   )
 {
-  VARIABLE_HEADER          *VariableHeader;
-  VARIABLE_STORE_HEADER    *VariableStorage;
-  LIST_ENTRY               *Link;
-  VARSTORAGE_DEFAULT_DATA  *Entry;
-  VARIABLE_STORE_HEADER    *NvStoreBuffer;
-  UINT8                    *DataBuffer;
-  UINT8                    *BufferEnd;
-  BOOLEAN                  IsFound;
-  UINTN                    Index;
-  UINT32                   BufferValue;
-  UINT32                   BitFieldVal;
-  UINTN                    BitOffset;
-  UINTN                    ByteOffset;
-  UINTN                    BitWidth;
-  UINTN                    StartBit;
-  UINTN                    EndBit;
-  PCD_DEFAULT_DATA         *DataHeader;
-  PCD_DEFAULT_INFO         *DefaultInfo;
-  PCD_DATA_DELTA           *DeltaData;
+  VARIABLE_HEADER                   *VariableHeader;
+  AUTHENTICATED_VARIABLE_HEADER     *AuthVariableHeader;
+  VARIABLE_STORE_HEADER             *VariableStorage;
+  LIST_ENTRY                        *Link;
+  VARSTORAGE_DEFAULT_DATA           *Entry;
+  VARIABLE_STORE_HEADER             *NvStoreBuffer;
+  VOID                              *ValueSource;
+  VOID                              *BitValueSource;
+  UINT8                             *DataBuffer;
+  UINT8                             *BufferEnd;
+  BOOLEAN                           AuthFormat;
+  BOOLEAN                           IsFound;
+  UINTN                             Index;
+  UINT32                            BufferValue;
+  UINT32                            BitFieldVal;
+  UINTN                             BitOffset;
+  UINTN                             ByteOffset;
+  UINTN                             BitWidth;
+  UINTN                             StartBit;
+  UINTN                             EndBit;
+  PCD_DEFAULT_DATA                  *DataHeader;
+  PCD_DEFAULT_INFO                  *DefaultInfo;
+  PCD_DATA_DELTA                    *DeltaData;
 
   if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
     gSkuId = LibPcdGetSku ();
@@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
   }
 
   if (Link == &gVarStorageList) {
-    DataBuffer          = (UINT8 *)PcdGetPtr (PcdNvStoreDefaultValueBuffer);
+    DataBuffer          = (UINT8 *)PcdGetExPtr (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
     gNvDefaultStoreSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *)DataBuffer)->Length;
     //
     // The first section data includes NV storage default setting.
@@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
     return EFI_NOT_FOUND;
   }
 
+  //
+  // Judge if the variable type is authenticated, default is false
+  //
+  AuthFormat = FALSE;
+  if (CompareGuid (&VariableStorage->Signature, &gEfiAuthenticatedVariableGuid)) {
+    AuthFormat = TRUE;
+  }
+
   //
   // Find the question default value from the variable storage
   //
-  VariableHeader = FindVariableData (VariableStorage, &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
-  if (VariableHeader == NULL) {
-    return EFI_NOT_FOUND;
+  if(AuthFormat) {
+    AuthVariableHeader = FindAuthVariableData (VariableStorage, &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
+    if (AuthVariableHeader == NULL) {
+      return EFI_NOT_FOUND;
+    }
+  } else {
+    VariableHeader = FindVariableData (VariableStorage, &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
+    if (VariableHeader == NULL) {
+      return EFI_NOT_FOUND;
+    }
   }
 
   StartBit   = 0;
@@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
     Width      = EndBit / 8 + 1;
   }
 
-  if (VariableHeader->DataSize < ByteOffset + Width) {
-    return EFI_INVALID_PARAMETER;
+  if (AuthFormat) {
+    if (AuthVariableHeader->DataSize < ByteOffset + Width) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    ValueSource = (UINT8 *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
+    if (BitFieldQuestion) {
+      BitValueSource = (UINT8 *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize + ByteOffset;
+    }
+  } else {
+    if (VariableHeader->DataSize < ByteOffset + Width) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    ValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
+    if (BitFieldQuestion) {
+      BitValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset;
+    }
   }
 
   //
@@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
   //
   if (ValueBuffer != NULL) {
     if (BitFieldQuestion) {
-      CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);
+      CopyMem (&BufferValue, BitValueSource, Width);
       BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);
       CopyMem (ValueBuffer, &BitFieldVal, Width);
     } else {
-      CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset, Width);
+      CopyMem (ValueBuffer, ValueSource, Width);
     }
   }
 
@@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
   // If no default setting, do nothing
   //
   if (gNvDefaultStoreSize == 0) {
-    gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
+    gNvDefaultStoreSize = PcdGetExSize (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
   }
 
   if (gNvDefaultStoreSize < sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
index 0116fb6ecb..dac4d614a8 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
@@ -86,6 +86,9 @@
   gEfiHiiImageDecoderNameJpegGuid |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ## SOMETIMES_CONSUMES ## GUID
   gEfiHiiImageDecoderNamePngGuid  |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ## SOMETIMES_CONSUMES ## GUID
   gEdkiiIfrBitVarstoreGuid                                                                    ## SOMETIMES_CONSUMES ## GUID
+  gEfiAuthenticatedVariableGuid
+  gEfiVariableGuid
+  gEfiMdeModulePkgTokenSpaceGuid
 
 [Depex]
   TRUE
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85612): https://edk2.groups.io/g/devel/message/85612
Mute This Topic: https://groups.io/mt/88369479/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by Ni, Ray 6 days, 3 hours ago

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Long1 Huang
Sent: Thursday, January 13, 2022 1:06 AM
To: devel@edk2.groups.io
Cc: Huang, Long1 <long1.huang@intel.com>; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>; Chen, Lin Z <lin.z.chen@intel.com>; Li, Zhuangzhi <zhuangzhi.li@intel.com>
Subject: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

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

Database.c:
	1. Replace PcdGetExPtr with PcdGetExPtr.
What does above mean? Replace <a> with <a>?


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85797): https://edk2.groups.io/g/devel/message/85797
Mute This Topic: https://groups.io/mt/88369479/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by Dandan Bi 1 week, 4 days ago
The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@intel.com>

Hi Liming,

Could you also help review it?


Thanks,
Dandan
> -----Original Message-----
> From: Huang, Long1 <long1.huang@intel.com>
> Sent: Thursday, January 13, 2022 1:06 AM
> To: devel@edk2.groups.io
> Cc: Huang, Long1 <long1.huang@intel.com>; Feng, Bob C
> <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi,
> Dandan <dandan.bi@intel.com>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> Zhuangzhi <zhuangzhi.li@intel.com>
> Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> authenticated variable
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3796
> 
> Database.c:
> 	1. Replace PcdGetExPtr with PcdGetExPtr.
> 	2. Add FindAuthVariableData function to parse authenticated
> variable type for getting a correct default value in
> PcdNvStoreDefaultValueBuffer.
> 
> Signed-off-by: Huang Long <long1.huang@intel.com>
> 
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Lin Z Chen <lin.z.chen@intel.com>
> Cc: Zhuangzhi Li <zhuangzhi.li@intel.com>
> ---
>  .../Universal/HiiDatabaseDxe/Database.c       | 130 ++++++++++++++----
>  .../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
>  2 files changed, 105 insertions(+), 28 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> index 0b09c24d52..c7a92d6aed 100644
> --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> @@ -603,6 +603,45 @@ FindVariableData (
>    return NULL;
> 
>  }
> 
> 
> 
> +/**
> 
> +  Find the matched authenticated variable from the input variable storage.
> 
> +
> 
> +  @param[in] VariableStorage Point to the variable storage header.
> 
> +  @param[in] VarGuid         A unique identifier for the variable.
> 
> +  @param[in] VarAttribute    The attributes bitmask for the variable.
> 
> +  @param[in] VarName         A Null-terminated ascii string that is the name of
> the variable.
> 
> +
> 
> +  @return Pointer to the matched variable header or NULL if not found.
> 
> +**/
> 
> +AUTHENTICATED_VARIABLE_HEADER *
> 
> +FindAuthVariableData (
> 
> +  IN  VARIABLE_STORE_HEADER  *VariableStorage,
> 
> +  IN  EFI_GUID               *VarGuid,
> 
> +  IN  UINT32                 VarAttribute,
> 
> +  IN  CHAR16                 *VarName
> 
> +  )
> 
> +{
> 
> +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableHeader;
> 
> +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableEnd;
> 
> +
> 
> +  AuthVariableEnd    = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
> *)VariableStorage + VariableStorage->Size);
> 
> +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> *)(VariableStorage + 1);
> 
> +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> *)HEADER_ALIGN (AuthVariableHeader);
> 
> +  while (AuthVariableHeader < AuthVariableEnd) {
> 
> +    if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&
> 
> +        (AuthVariableHeader->Attributes == VarAttribute) &&
> 
> +        (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) == 0))
> 
> +    {
> 
> +      return AuthVariableHeader;
> 
> +    }
> 
> +
> 
> +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
> *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) +
> AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);
> 
> +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> *)HEADER_ALIGN (AuthVariableHeader);
> 
> +  }
> 
> +
> 
> +  return NULL;
> 
> +}
> 
> +
> 
>  /**
> 
>    Find question default value from PcdNvStoreDefaultValueBuffer
> 
> 
> 
> @@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
>    IN  BOOLEAN                  BitFieldQuestion
> 
>    )
> 
>  {
> 
> -  VARIABLE_HEADER          *VariableHeader;
> 
> -  VARIABLE_STORE_HEADER    *VariableStorage;
> 
> -  LIST_ENTRY               *Link;
> 
> -  VARSTORAGE_DEFAULT_DATA  *Entry;
> 
> -  VARIABLE_STORE_HEADER    *NvStoreBuffer;
> 
> -  UINT8                    *DataBuffer;
> 
> -  UINT8                    *BufferEnd;
> 
> -  BOOLEAN                  IsFound;
> 
> -  UINTN                    Index;
> 
> -  UINT32                   BufferValue;
> 
> -  UINT32                   BitFieldVal;
> 
> -  UINTN                    BitOffset;
> 
> -  UINTN                    ByteOffset;
> 
> -  UINTN                    BitWidth;
> 
> -  UINTN                    StartBit;
> 
> -  UINTN                    EndBit;
> 
> -  PCD_DEFAULT_DATA         *DataHeader;
> 
> -  PCD_DEFAULT_INFO         *DefaultInfo;
> 
> -  PCD_DATA_DELTA           *DeltaData;
> 
> +  VARIABLE_HEADER                   *VariableHeader;
> 
> +  AUTHENTICATED_VARIABLE_HEADER     *AuthVariableHeader;
> 
> +  VARIABLE_STORE_HEADER             *VariableStorage;
> 
> +  LIST_ENTRY                        *Link;
> 
> +  VARSTORAGE_DEFAULT_DATA           *Entry;
> 
> +  VARIABLE_STORE_HEADER             *NvStoreBuffer;
> 
> +  VOID                              *ValueSource;
> 
> +  VOID                              *BitValueSource;
> 
> +  UINT8                             *DataBuffer;
> 
> +  UINT8                             *BufferEnd;
> 
> +  BOOLEAN                           AuthFormat;
> 
> +  BOOLEAN                           IsFound;
> 
> +  UINTN                             Index;
> 
> +  UINT32                            BufferValue;
> 
> +  UINT32                            BitFieldVal;
> 
> +  UINTN                             BitOffset;
> 
> +  UINTN                             ByteOffset;
> 
> +  UINTN                             BitWidth;
> 
> +  UINTN                             StartBit;
> 
> +  UINTN                             EndBit;
> 
> +  PCD_DEFAULT_DATA                  *DataHeader;
> 
> +  PCD_DEFAULT_INFO                  *DefaultInfo;
> 
> +  PCD_DATA_DELTA                    *DeltaData;
> 
> 
> 
>    if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
> 
>      gSkuId = LibPcdGetSku ();
> 
> @@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
>    }
> 
> 
> 
>    if (Link == &gVarStorageList) {
> 
> -    DataBuffer          = (UINT8 *)PcdGetPtr (PcdNvStoreDefaultValueBuffer);
> 
> +    DataBuffer          = (UINT8 *)PcdGetExPtr
> (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> 
>      gNvDefaultStoreSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
> *)DataBuffer)->Length;
> 
>      //
> 
>      // The first section data includes NV storage default setting.
> 
> @@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
>      return EFI_NOT_FOUND;
> 
>    }
> 
> 
> 
> +  //
> 
> +  // Judge if the variable type is authenticated, default is false
> 
> +  //
> 
> +  AuthFormat = FALSE;
> 
> +  if (CompareGuid (&VariableStorage->Signature,
> &gEfiAuthenticatedVariableGuid)) {
> 
> +    AuthFormat = TRUE;
> 
> +  }
> 
> +
> 
>    //
> 
>    // Find the question default value from the variable storage
> 
>    //
> 
> -  VariableHeader = FindVariableData (VariableStorage, &EfiVarStore->Guid,
> EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> 
> -  if (VariableHeader == NULL) {
> 
> -    return EFI_NOT_FOUND;
> 
> +  if(AuthFormat) {
> 
> +    AuthVariableHeader = FindAuthVariableData (VariableStorage,
> &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore-
> >Name);
> 
> +    if (AuthVariableHeader == NULL) {
> 
> +      return EFI_NOT_FOUND;
> 
> +    }
> 
> +  } else {
> 
> +    VariableHeader = FindVariableData (VariableStorage, &EfiVarStore->Guid,
> EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> 
> +    if (VariableHeader == NULL) {
> 
> +      return EFI_NOT_FOUND;
> 
> +    }
> 
>    }
> 
> 
> 
>    StartBit   = 0;
> 
> @@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
>      Width      = EndBit / 8 + 1;
> 
>    }
> 
> 
> 
> -  if (VariableHeader->DataSize < ByteOffset + Width) {
> 
> -    return EFI_INVALID_PARAMETER;
> 
> +  if (AuthFormat) {
> 
> +    if (AuthVariableHeader->DataSize < ByteOffset + Width) {
> 
> +      return EFI_INVALID_PARAMETER;
> 
> +    }
> 
> +
> 
> +    ValueSource = (UINT8 *)AuthVariableHeader + sizeof
> (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize +
> IfrQuestionHdr->VarStoreInfo.VarOffset;
> 
> +    if (BitFieldQuestion) {
> 
> +      BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
> (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize +
> ByteOffset;
> 
> +    }
> 
> +  } else {
> 
> +    if (VariableHeader->DataSize < ByteOffset + Width) {
> 
> +      return EFI_INVALID_PARAMETER;
> 
> +    }
> 
> +
> 
> +    ValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER) +
> VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
> 
> +    if (BitFieldQuestion) {
> 
> +      BitValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER)
> + VariableHeader->NameSize + ByteOffset;
> 
> +    }
> 
>    }
> 
> 
> 
>    //
> 
> @@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
>    //
> 
>    if (ValueBuffer != NULL) {
> 
>      if (BitFieldQuestion) {
> 
> -      CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
> (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);
> 
> +      CopyMem (&BufferValue, BitValueSource, Width);
> 
>        BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);
> 
>        CopyMem (ValueBuffer, &BitFieldVal, Width);
> 
>      } else {
> 
> -      CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
> (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
> >VarStoreInfo.VarOffset, Width);
> 
> +      CopyMem (ValueBuffer, ValueSource, Width);
> 
>      }
> 
>    }
> 
> 
> 
> @@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
>    // If no default setting, do nothing
> 
>    //
> 
>    if (gNvDefaultStoreSize == 0) {
> 
> -    gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
> 
> +    gNvDefaultStoreSize = PcdGetExSize
> (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> 
>    }
> 
> 
> 
>    if (gNvDefaultStoreSize < sizeof
> (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
> 
> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> index 0116fb6ecb..dac4d614a8 100644
> --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> @@ -86,6 +86,9 @@
>    gEfiHiiImageDecoderNameJpegGuid
> |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> SOMETIMES_CONSUMES ## GUID
> 
>    gEfiHiiImageDecoderNamePngGuid
> |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> SOMETIMES_CONSUMES ## GUID
> 
>    gEdkiiIfrBitVarstoreGuid                                                                    ##
> SOMETIMES_CONSUMES ## GUID
> 
> +  gEfiAuthenticatedVariableGuid
> 
> +  gEfiVariableGuid
> 
> +  gEfiMdeModulePkgTokenSpaceGuid
> 
> 
> 
>  [Depex]
> 
>    TRUE
> 
> --
> 2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85655): https://edk2.groups.io/g/devel/message/85655
Mute This Topic: https://groups.io/mt/88369479/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by Dandan Bi 1 week, 1 day ago
 I will push this patch today if no other comment.


Thanks,
Dandan

> -----Original Message-----
> From: Bi, Dandan
> Sent: Thursday, January 13, 2022 1:35 PM
> To: Huang, Long1 <long1.huang@intel.com>; devel@edk2.groups.io
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> Zhuangzhi <zhuangzhi.li@intel.com>
> Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> authenticated variable
> 
> The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@intel.com>
> 
> Hi Liming,
> 
> Could you also help review it?
> 
> 
> Thanks,
> Dandan
> > -----Original Message-----
> > From: Huang, Long1 <long1.huang@intel.com>
> > Sent: Thursday, January 13, 2022 1:06 AM
> > To: devel@edk2.groups.io
> > Cc: Huang, Long1 <long1.huang@intel.com>; Feng, Bob C
> > <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi,
> > Dandan <dandan.bi@intel.com>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> > Zhuangzhi <zhuangzhi.li@intel.com>
> > Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> > authenticated variable
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3796
> >
> > Database.c:
> > 	1. Replace PcdGetExPtr with PcdGetExPtr.
> > 	2. Add FindAuthVariableData function to parse authenticated
> variable
> > type for getting a correct default value in
> > PcdNvStoreDefaultValueBuffer.
> >
> > Signed-off-by: Huang Long <long1.huang@intel.com>
> >
> > Cc: Bob Feng <bob.c.feng@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Dandan Bi <dandan.bi@intel.com>
> > Cc: Lin Z Chen <lin.z.chen@intel.com>
> > Cc: Zhuangzhi Li <zhuangzhi.li@intel.com>
> > ---
> >  .../Universal/HiiDatabaseDxe/Database.c       | 130 ++++++++++++++----
> >  .../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
> >  2 files changed, 105 insertions(+), 28 deletions(-)
> >
> > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > index 0b09c24d52..c7a92d6aed 100644
> > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > @@ -603,6 +603,45 @@ FindVariableData (
> >    return NULL;
> >
> >  }
> >
> >
> >
> > +/**
> >
> > +  Find the matched authenticated variable from the input variable storage.
> >
> > +
> >
> > +  @param[in] VariableStorage Point to the variable storage header.
> >
> > +  @param[in] VarGuid         A unique identifier for the variable.
> >
> > +  @param[in] VarAttribute    The attributes bitmask for the variable.
> >
> > +  @param[in] VarName         A Null-terminated ascii string that is the name
> of
> > the variable.
> >
> > +
> >
> > +  @return Pointer to the matched variable header or NULL if not found.
> >
> > +**/
> >
> > +AUTHENTICATED_VARIABLE_HEADER *
> >
> > +FindAuthVariableData (
> >
> > +  IN  VARIABLE_STORE_HEADER  *VariableStorage,
> >
> > +  IN  EFI_GUID               *VarGuid,
> >
> > +  IN  UINT32                 VarAttribute,
> >
> > +  IN  CHAR16                 *VarName
> >
> > +  )
> >
> > +{
> >
> > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableHeader;
> >
> > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableEnd;
> >
> > +
> >
> > +  AuthVariableEnd    = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
> > *)VariableStorage + VariableStorage->Size);
> >
> > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > *)(VariableStorage + 1);
> >
> > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > *)HEADER_ALIGN (AuthVariableHeader);
> >
> > +  while (AuthVariableHeader < AuthVariableEnd) {
> >
> > +    if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&
> >
> > +        (AuthVariableHeader->Attributes == VarAttribute) &&
> >
> > +        (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) == 0))
> >
> > +    {
> >
> > +      return AuthVariableHeader;
> >
> > +    }
> >
> > +
> >
> > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER *)((UINT8
> > *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) +
> > AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);
> >
> > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > *)HEADER_ALIGN (AuthVariableHeader);
> >
> > +  }
> >
> > +
> >
> > +  return NULL;
> >
> > +}
> >
> > +
> >
> >  /**
> >
> >    Find question default value from PcdNvStoreDefaultValueBuffer
> >
> >
> >
> > @@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
> >    IN  BOOLEAN                  BitFieldQuestion
> >
> >    )
> >
> >  {
> >
> > -  VARIABLE_HEADER          *VariableHeader;
> >
> > -  VARIABLE_STORE_HEADER    *VariableStorage;
> >
> > -  LIST_ENTRY               *Link;
> >
> > -  VARSTORAGE_DEFAULT_DATA  *Entry;
> >
> > -  VARIABLE_STORE_HEADER    *NvStoreBuffer;
> >
> > -  UINT8                    *DataBuffer;
> >
> > -  UINT8                    *BufferEnd;
> >
> > -  BOOLEAN                  IsFound;
> >
> > -  UINTN                    Index;
> >
> > -  UINT32                   BufferValue;
> >
> > -  UINT32                   BitFieldVal;
> >
> > -  UINTN                    BitOffset;
> >
> > -  UINTN                    ByteOffset;
> >
> > -  UINTN                    BitWidth;
> >
> > -  UINTN                    StartBit;
> >
> > -  UINTN                    EndBit;
> >
> > -  PCD_DEFAULT_DATA         *DataHeader;
> >
> > -  PCD_DEFAULT_INFO         *DefaultInfo;
> >
> > -  PCD_DATA_DELTA           *DeltaData;
> >
> > +  VARIABLE_HEADER                   *VariableHeader;
> >
> > +  AUTHENTICATED_VARIABLE_HEADER     *AuthVariableHeader;
> >
> > +  VARIABLE_STORE_HEADER             *VariableStorage;
> >
> > +  LIST_ENTRY                        *Link;
> >
> > +  VARSTORAGE_DEFAULT_DATA           *Entry;
> >
> > +  VARIABLE_STORE_HEADER             *NvStoreBuffer;
> >
> > +  VOID                              *ValueSource;
> >
> > +  VOID                              *BitValueSource;
> >
> > +  UINT8                             *DataBuffer;
> >
> > +  UINT8                             *BufferEnd;
> >
> > +  BOOLEAN                           AuthFormat;
> >
> > +  BOOLEAN                           IsFound;
> >
> > +  UINTN                             Index;
> >
> > +  UINT32                            BufferValue;
> >
> > +  UINT32                            BitFieldVal;
> >
> > +  UINTN                             BitOffset;
> >
> > +  UINTN                             ByteOffset;
> >
> > +  UINTN                             BitWidth;
> >
> > +  UINTN                             StartBit;
> >
> > +  UINTN                             EndBit;
> >
> > +  PCD_DEFAULT_DATA                  *DataHeader;
> >
> > +  PCD_DEFAULT_INFO                  *DefaultInfo;
> >
> > +  PCD_DATA_DELTA                    *DeltaData;
> >
> >
> >
> >    if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
> >
> >      gSkuId = LibPcdGetSku ();
> >
> > @@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
> >    }
> >
> >
> >
> >    if (Link == &gVarStorageList) {
> >
> > -    DataBuffer          = (UINT8 *)PcdGetPtr (PcdNvStoreDefaultValueBuffer);
> >
> > +    DataBuffer          = (UINT8 *)PcdGetExPtr
> > (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> >
> >      gNvDefaultStoreSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
> > *)DataBuffer)->Length;
> >
> >      //
> >
> >      // The first section data includes NV storage default setting.
> >
> > @@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
> >      return EFI_NOT_FOUND;
> >
> >    }
> >
> >
> >
> > +  //
> >
> > +  // Judge if the variable type is authenticated, default is false
> >
> > +  //
> >
> > +  AuthFormat = FALSE;
> >
> > +  if (CompareGuid (&VariableStorage->Signature,
> > &gEfiAuthenticatedVariableGuid)) {
> >
> > +    AuthFormat = TRUE;
> >
> > +  }
> >
> > +
> >
> >    //
> >
> >    // Find the question default value from the variable storage
> >
> >    //
> >
> > -  VariableHeader = FindVariableData (VariableStorage,
> > &EfiVarStore->Guid,
> > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> >
> > -  if (VariableHeader == NULL) {
> >
> > -    return EFI_NOT_FOUND;
> >
> > +  if(AuthFormat) {
> >
> > +    AuthVariableHeader = FindAuthVariableData (VariableStorage,
> > &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore-
> > >Name);
> >
> > +    if (AuthVariableHeader == NULL) {
> >
> > +      return EFI_NOT_FOUND;
> >
> > +    }
> >
> > +  } else {
> >
> > +    VariableHeader = FindVariableData (VariableStorage,
> > + &EfiVarStore->Guid,
> > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> >
> > +    if (VariableHeader == NULL) {
> >
> > +      return EFI_NOT_FOUND;
> >
> > +    }
> >
> >    }
> >
> >
> >
> >    StartBit   = 0;
> >
> > @@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
> >      Width      = EndBit / 8 + 1;
> >
> >    }
> >
> >
> >
> > -  if (VariableHeader->DataSize < ByteOffset + Width) {
> >
> > -    return EFI_INVALID_PARAMETER;
> >
> > +  if (AuthFormat) {
> >
> > +    if (AuthVariableHeader->DataSize < ByteOffset + Width) {
> >
> > +      return EFI_INVALID_PARAMETER;
> >
> > +    }
> >
> > +
> >
> > +    ValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
> +
> > IfrQuestionHdr->VarStoreInfo.VarOffset;
> >
> > +    if (BitFieldQuestion) {
> >
> > +      BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
> +
> > ByteOffset;
> >
> > +    }
> >
> > +  } else {
> >
> > +    if (VariableHeader->DataSize < ByteOffset + Width) {
> >
> > +      return EFI_INVALID_PARAMETER;
> >
> > +    }
> >
> > +
> >
> > +    ValueSource = (UINT8 *)VariableHeader + sizeof (VARIABLE_HEADER)
> > + +
> > VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
> >
> > +    if (BitFieldQuestion) {
> >
> > +      BitValueSource = (UINT8 *)VariableHeader + sizeof
> > + (VARIABLE_HEADER)
> > + VariableHeader->NameSize + ByteOffset;
> >
> > +    }
> >
> >    }
> >
> >
> >
> >    //
> >
> > @@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
> >    //
> >
> >    if (ValueBuffer != NULL) {
> >
> >      if (BitFieldQuestion) {
> >
> > -      CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
> > (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);
> >
> > +      CopyMem (&BufferValue, BitValueSource, Width);
> >
> >        BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);
> >
> >        CopyMem (ValueBuffer, &BitFieldVal, Width);
> >
> >      } else {
> >
> > -      CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
> > (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
> > >VarStoreInfo.VarOffset, Width);
> >
> > +      CopyMem (ValueBuffer, ValueSource, Width);
> >
> >      }
> >
> >    }
> >
> >
> >
> > @@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
> >    // If no default setting, do nothing
> >
> >    //
> >
> >    if (gNvDefaultStoreSize == 0) {
> >
> > -    gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
> >
> > +    gNvDefaultStoreSize = PcdGetExSize
> > (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> >
> >    }
> >
> >
> >
> >    if (gNvDefaultStoreSize < sizeof
> > (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
> >
> > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > index 0116fb6ecb..dac4d614a8 100644
> > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > @@ -86,6 +86,9 @@
> >    gEfiHiiImageDecoderNameJpegGuid
> > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > SOMETIMES_CONSUMES ## GUID
> >
> >    gEfiHiiImageDecoderNamePngGuid
> > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > SOMETIMES_CONSUMES ## GUID
> >
> >    gEdkiiIfrBitVarstoreGuid                                                                    ##
> > SOMETIMES_CONSUMES ## GUID
> >
> > +  gEfiAuthenticatedVariableGuid
> >
> > +  gEfiVariableGuid
> >
> > +  gEfiMdeModulePkgTokenSpaceGuid
> >
> >
> >
> >  [Depex]
> >
> >    TRUE
> >
> > --
> > 2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85722): https://edk2.groups.io/g/devel/message/85722
Mute This Topic: https://groups.io/mt/88369479/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


回复: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by gaoliming 1 week, 1 day ago
Dandan:
  I will review this patch today. Please wait one day for me. 

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dandan Bi
> 发送时间: 2022年1月17日 9:13
> 收件人: Huang, Long1 <long1.huang@intel.com>; devel@edk2.groups.io
> 抄送: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> Zhuangzhi <zhuangzhi.li@intel.com>
> 主题: Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
> Support for authenticated variable
> 
>  I will push this patch today if no other comment.
> 
> 
> Thanks,
> Dandan
> 
> > -----Original Message-----
> > From: Bi, Dandan
> > Sent: Thursday, January 13, 2022 1:35 PM
> > To: Huang, Long1 <long1.huang@intel.com>; devel@edk2.groups.io
> > Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> > Zhuangzhi <zhuangzhi.li@intel.com>
> > Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> > authenticated variable
> >
> > The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@intel.com>
> >
> > Hi Liming,
> >
> > Could you also help review it?
> >
> >
> > Thanks,
> > Dandan
> > > -----Original Message-----
> > > From: Huang, Long1 <long1.huang@intel.com>
> > > Sent: Thursday, January 13, 2022 1:06 AM
> > > To: devel@edk2.groups.io
> > > Cc: Huang, Long1 <long1.huang@intel.com>; Feng, Bob C
> > > <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi,
> > > Dandan <dandan.bi@intel.com>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> > > Zhuangzhi <zhuangzhi.li@intel.com>
> > > Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> > > authenticated variable
> > >
> > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3796
> > >
> > > Database.c:
> > > 	1. Replace PcdGetExPtr with PcdGetExPtr.
> > > 	2. Add FindAuthVariableData function to parse authenticated
> > variable
> > > type for getting a correct default value in
> > > PcdNvStoreDefaultValueBuffer.
> > >
> > > Signed-off-by: Huang Long <long1.huang@intel.com>
> > >
> > > Cc: Bob Feng <bob.c.feng@intel.com>
> > > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > Cc: Dandan Bi <dandan.bi@intel.com>
> > > Cc: Lin Z Chen <lin.z.chen@intel.com>
> > > Cc: Zhuangzhi Li <zhuangzhi.li@intel.com>
> > > ---
> > >  .../Universal/HiiDatabaseDxe/Database.c       | 130
> ++++++++++++++----
> > >  .../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
> > >  2 files changed, 105 insertions(+), 28 deletions(-)
> > >
> > > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > index 0b09c24d52..c7a92d6aed 100644
> > > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > @@ -603,6 +603,45 @@ FindVariableData (
> > >    return NULL;
> > >
> > >  }
> > >
> > >
> > >
> > > +/**
> > >
> > > +  Find the matched authenticated variable from the input variable
> storage.
> > >
> > > +
> > >
> > > +  @param[in] VariableStorage Point to the variable storage header.
> > >
> > > +  @param[in] VarGuid         A unique identifier for the variable.
> > >
> > > +  @param[in] VarAttribute    The attributes bitmask for the variable.
> > >
> > > +  @param[in] VarName         A Null-terminated ascii string that is
> the name
> > of
> > > the variable.
> > >
> > > +
> > >
> > > +  @return Pointer to the matched variable header or NULL if not
found.
> > >
> > > +**/
> > >
> > > +AUTHENTICATED_VARIABLE_HEADER *
> > >
> > > +FindAuthVariableData (
> > >
> > > +  IN  VARIABLE_STORE_HEADER  *VariableStorage,
> > >
> > > +  IN  EFI_GUID               *VarGuid,
> > >
> > > +  IN  UINT32                 VarAttribute,
> > >
> > > +  IN  CHAR16                 *VarName
> > >
> > > +  )
> > >
> > > +{
> > >
> > > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableHeader;
> > >
> > > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableEnd;
> > >
> > > +
> > >
> > > +  AuthVariableEnd    = (AUTHENTICATED_VARIABLE_HEADER
> *)((UINT8
> > > *)VariableStorage + VariableStorage->Size);
> > >
> > > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > *)(VariableStorage + 1);
> > >
> > > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > *)HEADER_ALIGN (AuthVariableHeader);
> > >
> > > +  while (AuthVariableHeader < AuthVariableEnd) {
> > >
> > > +    if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&
> > >
> > > +        (AuthVariableHeader->Attributes == VarAttribute) &&
> > >
> > > +        (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) ==
> 0))
> > >
> > > +    {
> > >
> > > +      return AuthVariableHeader;
> > >
> > > +    }
> > >
> > > +
> > >
> > > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> *)((UINT8
> > > *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER) +
> > > AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);
> > >
> > > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > *)HEADER_ALIGN (AuthVariableHeader);
> > >
> > > +  }
> > >
> > > +
> > >
> > > +  return NULL;
> > >
> > > +}
> > >
> > > +
> > >
> > >  /**
> > >
> > >    Find question default value from PcdNvStoreDefaultValueBuffer
> > >
> > >
> > >
> > > @@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
> > >    IN  BOOLEAN                  BitFieldQuestion
> > >
> > >    )
> > >
> > >  {
> > >
> > > -  VARIABLE_HEADER          *VariableHeader;
> > >
> > > -  VARIABLE_STORE_HEADER    *VariableStorage;
> > >
> > > -  LIST_ENTRY               *Link;
> > >
> > > -  VARSTORAGE_DEFAULT_DATA  *Entry;
> > >
> > > -  VARIABLE_STORE_HEADER    *NvStoreBuffer;
> > >
> > > -  UINT8                    *DataBuffer;
> > >
> > > -  UINT8                    *BufferEnd;
> > >
> > > -  BOOLEAN                  IsFound;
> > >
> > > -  UINTN                    Index;
> > >
> > > -  UINT32                   BufferValue;
> > >
> > > -  UINT32                   BitFieldVal;
> > >
> > > -  UINTN                    BitOffset;
> > >
> > > -  UINTN                    ByteOffset;
> > >
> > > -  UINTN                    BitWidth;
> > >
> > > -  UINTN                    StartBit;
> > >
> > > -  UINTN                    EndBit;
> > >
> > > -  PCD_DEFAULT_DATA         *DataHeader;
> > >
> > > -  PCD_DEFAULT_INFO         *DefaultInfo;
> > >
> > > -  PCD_DATA_DELTA           *DeltaData;
> > >
> > > +  VARIABLE_HEADER                   *VariableHeader;
> > >
> > > +  AUTHENTICATED_VARIABLE_HEADER     *AuthVariableHeader;
> > >
> > > +  VARIABLE_STORE_HEADER             *VariableStorage;
> > >
> > > +  LIST_ENTRY                        *Link;
> > >
> > > +  VARSTORAGE_DEFAULT_DATA           *Entry;
> > >
> > > +  VARIABLE_STORE_HEADER             *NvStoreBuffer;
> > >
> > > +  VOID                              *ValueSource;
> > >
> > > +  VOID                              *BitValueSource;
> > >
> > > +  UINT8                             *DataBuffer;
> > >
> > > +  UINT8                             *BufferEnd;
> > >
> > > +  BOOLEAN                           AuthFormat;
> > >
> > > +  BOOLEAN                           IsFound;
> > >
> > > +  UINTN                             Index;
> > >
> > > +  UINT32                            BufferValue;
> > >
> > > +  UINT32                            BitFieldVal;
> > >
> > > +  UINTN                             BitOffset;
> > >
> > > +  UINTN                             ByteOffset;
> > >
> > > +  UINTN                             BitWidth;
> > >
> > > +  UINTN                             StartBit;
> > >
> > > +  UINTN                             EndBit;
> > >
> > > +  PCD_DEFAULT_DATA                  *DataHeader;
> > >
> > > +  PCD_DEFAULT_INFO                  *DefaultInfo;
> > >
> > > +  PCD_DATA_DELTA                    *DeltaData;
> > >
> > >
> > >
> > >    if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
> > >
> > >      gSkuId = LibPcdGetSku ();
> > >
> > > @@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
> > >    }
> > >
> > >
> > >
> > >    if (Link == &gVarStorageList) {
> > >
> > > -    DataBuffer          = (UINT8 *)PcdGetPtr
> (PcdNvStoreDefaultValueBuffer);
> > >
> > > +    DataBuffer          = (UINT8 *)PcdGetExPtr
> > > (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> > >
> > >      gNvDefaultStoreSize =
> ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
> > > *)DataBuffer)->Length;
> > >
> > >      //
> > >
> > >      // The first section data includes NV storage default setting.
> > >
> > > @@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
> > >      return EFI_NOT_FOUND;
> > >
> > >    }
> > >
> > >
> > >
> > > +  //
> > >
> > > +  // Judge if the variable type is authenticated, default is false
> > >
> > > +  //
> > >
> > > +  AuthFormat = FALSE;
> > >
> > > +  if (CompareGuid (&VariableStorage->Signature,
> > > &gEfiAuthenticatedVariableGuid)) {
> > >
> > > +    AuthFormat = TRUE;
> > >
> > > +  }
> > >
> > > +
> > >
> > >    //
> > >
> > >    // Find the question default value from the variable storage
> > >
> > >    //
> > >
> > > -  VariableHeader = FindVariableData (VariableStorage,
> > > &EfiVarStore->Guid,
> > > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> > >
> > > -  if (VariableHeader == NULL) {
> > >
> > > -    return EFI_NOT_FOUND;
> > >
> > > +  if(AuthFormat) {
> > >
> > > +    AuthVariableHeader = FindAuthVariableData (VariableStorage,
> > > &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16 *)EfiVarStore-
> > > >Name);
> > >
> > > +    if (AuthVariableHeader == NULL) {
> > >
> > > +      return EFI_NOT_FOUND;
> > >
> > > +    }
> > >
> > > +  } else {
> > >
> > > +    VariableHeader = FindVariableData (VariableStorage,
> > > + &EfiVarStore->Guid,
> > > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> > >
> > > +    if (VariableHeader == NULL) {
> > >
> > > +      return EFI_NOT_FOUND;
> > >
> > > +    }
> > >
> > >    }
> > >
> > >
> > >
> > >    StartBit   = 0;
> > >
> > > @@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
> > >      Width      = EndBit / 8 + 1;
> > >
> > >    }
> > >
> > >
> > >
> > > -  if (VariableHeader->DataSize < ByteOffset + Width) {
> > >
> > > -    return EFI_INVALID_PARAMETER;
> > >
> > > +  if (AuthFormat) {
> > >
> > > +    if (AuthVariableHeader->DataSize < ByteOffset + Width) {
> > >
> > > +      return EFI_INVALID_PARAMETER;
> > >
> > > +    }
> > >
> > > +
> > >
> > > +    ValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
> > +
> > > IfrQuestionHdr->VarStoreInfo.VarOffset;
> > >
> > > +    if (BitFieldQuestion) {
> > >
> > > +      BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader->NameSize
> > +
> > > ByteOffset;
> > >
> > > +    }
> > >
> > > +  } else {
> > >
> > > +    if (VariableHeader->DataSize < ByteOffset + Width) {
> > >
> > > +      return EFI_INVALID_PARAMETER;
> > >
> > > +    }
> > >
> > > +
> > >
> > > +    ValueSource = (UINT8 *)VariableHeader + sizeof
> (VARIABLE_HEADER)
> > > + +
> > > VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
> > >
> > > +    if (BitFieldQuestion) {
> > >
> > > +      BitValueSource = (UINT8 *)VariableHeader + sizeof
> > > + (VARIABLE_HEADER)
> > > + VariableHeader->NameSize + ByteOffset;
> > >
> > > +    }
> > >
> > >    }
> > >
> > >
> > >
> > >    //
> > >
> > > @@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
> > >    //
> > >
> > >    if (ValueBuffer != NULL) {
> > >
> > >      if (BitFieldQuestion) {
> > >
> > > -      CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
> > > (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset, Width);
> > >
> > > +      CopyMem (&BufferValue, BitValueSource, Width);
> > >
> > >        BitFieldVal = BitFieldRead32 (BufferValue, StartBit, EndBit);
> > >
> > >        CopyMem (ValueBuffer, &BitFieldVal, Width);
> > >
> > >      } else {
> > >
> > > -      CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
> > > (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
> > > >VarStoreInfo.VarOffset, Width);
> > >
> > > +      CopyMem (ValueBuffer, ValueSource, Width);
> > >
> > >      }
> > >
> > >    }
> > >
> > >
> > >
> > > @@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
> > >    // If no default setting, do nothing
> > >
> > >    //
> > >
> > >    if (gNvDefaultStoreSize == 0) {
> > >
> > > -    gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
> > >
> > > +    gNvDefaultStoreSize = PcdGetExSize
> > > (&gEfiMdeModulePkgTokenSpaceGuid, PcdNvStoreDefaultValueBuffer);
> > >
> > >    }
> > >
> > >
> > >
> > >    if (gNvDefaultStoreSize < sizeof
> > > (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
> > >
> > > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > index 0116fb6ecb..dac4d614a8 100644
> > > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > @@ -86,6 +86,9 @@
> > >    gEfiHiiImageDecoderNameJpegGuid
> > > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > > SOMETIMES_CONSUMES ## GUID
> > >
> > >    gEfiHiiImageDecoderNamePngGuid
> > > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > > SOMETIMES_CONSUMES ## GUID
> > >
> > >    gEdkiiIfrBitVarstoreGuid
> ##
> > > SOMETIMES_CONSUMES ## GUID
> > >
> > > +  gEfiAuthenticatedVariableGuid
> > >
> > > +  gEfiVariableGuid
> > >
> > > +  gEfiMdeModulePkgTokenSpaceGuid
> > >
> > >
> > >
> > >  [Depex]
> > >
> > >    TRUE
> > >
> > > --
> > > 2.25.1
> 
> 
> 
> 
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85724): https://edk2.groups.io/g/devel/message/85724
Mute This Topic: https://groups.io/mt/88477743/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for authenticated variable

Posted by Dandan Bi 1 week, 1 day ago
Sure. Thanks Liming.


Thanks,
Dandan
> -----Original Message-----
> From: gaoliming <gaoliming@byosoft.com.cn>
> Sent: Monday, January 17, 2022 11:12 AM
> To: devel@edk2.groups.io; Bi, Dandan <dandan.bi@intel.com>; Huang,
> Long1 <long1.huang@intel.com>
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Chen, Lin Z <lin.z.chen@intel.com>;
> Li, Zhuangzhi <zhuangzhi.li@intel.com>
> Subject: 回复: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
> Support for authenticated variable
> 
> Dandan:
>   I will review this patch today. Please wait one day for me.
> 
> Thanks
> Liming
> > -----邮件原件-----
> > 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dandan Bi
> > 发送时间: 2022年1月17日 9:13
> > 收件人: Huang, Long1 <long1.huang@intel.com>; devel@edk2.groups.io
> > 抄送: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> > Zhuangzhi <zhuangzhi.li@intel.com>
> > 主题: Re: [edk2-devel] [PATCH] MdeModulePkg/HiiDatabaseDxe: Add
> Support
> > for authenticated variable
> >
> >  I will push this patch today if no other comment.
> >
> >
> > Thanks,
> > Dandan
> >
> > > -----Original Message-----
> > > From: Bi, Dandan
> > > Sent: Thursday, January 13, 2022 1:35 PM
> > > To: Huang, Long1 <long1.huang@intel.com>; devel@edk2.groups.io
> > > Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming
> > > <gaoliming@byosoft.com.cn>; Chen, Lin Z <lin.z.chen@intel.com>; Li,
> > > Zhuangzhi <zhuangzhi.li@intel.com>
> > > Subject: RE: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> > > authenticated variable
> > >
> > > The change is ok to me. Reviewed-by: Dandan Bi <dandan.bi@intel.com>
> > >
> > > Hi Liming,
> > >
> > > Could you also help review it?
> > >
> > >
> > > Thanks,
> > > Dandan
> > > > -----Original Message-----
> > > > From: Huang, Long1 <long1.huang@intel.com>
> > > > Sent: Thursday, January 13, 2022 1:06 AM
> > > > To: devel@edk2.groups.io
> > > > Cc: Huang, Long1 <long1.huang@intel.com>; Feng, Bob C
> > > > <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> > > > Bi, Dandan <dandan.bi@intel.com>; Chen, Lin Z
> > > > <lin.z.chen@intel.com>; Li, Zhuangzhi <zhuangzhi.li@intel.com>
> > > > Subject: [PATCH] MdeModulePkg/HiiDatabaseDxe: Add Support for
> > > > authenticated variable
> > > >
> > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3796
> > > >
> > > > Database.c:
> > > > 	1. Replace PcdGetExPtr with PcdGetExPtr.
> > > > 	2. Add FindAuthVariableData function to parse authenticated
> > > variable
> > > > type for getting a correct default value in
> > > > PcdNvStoreDefaultValueBuffer.
> > > >
> > > > Signed-off-by: Huang Long <long1.huang@intel.com>
> > > >
> > > > Cc: Bob Feng <bob.c.feng@intel.com>
> > > > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > > Cc: Dandan Bi <dandan.bi@intel.com>
> > > > Cc: Lin Z Chen <lin.z.chen@intel.com>
> > > > Cc: Zhuangzhi Li <zhuangzhi.li@intel.com>
> > > > ---
> > > >  .../Universal/HiiDatabaseDxe/Database.c       | 130
> > ++++++++++++++----
> > > >  .../HiiDatabaseDxe/HiiDatabaseDxe.inf         |   3 +
> > > >  2 files changed, 105 insertions(+), 28 deletions(-)
> > > >
> > > > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > > b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > > index 0b09c24d52..c7a92d6aed 100644
> > > > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
> > > > @@ -603,6 +603,45 @@ FindVariableData (
> > > >    return NULL;
> > > >
> > > >  }
> > > >
> > > >
> > > >
> > > > +/**
> > > >
> > > > +  Find the matched authenticated variable from the input variable
> > storage.
> > > >
> > > > +
> > > >
> > > > +  @param[in] VariableStorage Point to the variable storage header.
> > > >
> > > > +  @param[in] VarGuid         A unique identifier for the variable.
> > > >
> > > > +  @param[in] VarAttribute    The attributes bitmask for the variable.
> > > >
> > > > +  @param[in] VarName         A Null-terminated ascii string that is
> > the name
> > > of
> > > > the variable.
> > > >
> > > > +
> > > >
> > > > +  @return Pointer to the matched variable header or NULL if not
> found.
> > > >
> > > > +**/
> > > >
> > > > +AUTHENTICATED_VARIABLE_HEADER *
> > > >
> > > > +FindAuthVariableData (
> > > >
> > > > +  IN  VARIABLE_STORE_HEADER  *VariableStorage,
> > > >
> > > > +  IN  EFI_GUID               *VarGuid,
> > > >
> > > > +  IN  UINT32                 VarAttribute,
> > > >
> > > > +  IN  CHAR16                 *VarName
> > > >
> > > > +  )
> > > >
> > > > +{
> > > >
> > > > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableHeader;
> > > >
> > > > +  AUTHENTICATED_VARIABLE_HEADER  *AuthVariableEnd;
> > > >
> > > > +
> > > >
> > > > +  AuthVariableEnd    = (AUTHENTICATED_VARIABLE_HEADER
> > *)((UINT8
> > > > *)VariableStorage + VariableStorage->Size);
> > > >
> > > > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > > *)(VariableStorage + 1);
> > > >
> > > > +  AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > > *)HEADER_ALIGN (AuthVariableHeader);
> > > >
> > > > +  while (AuthVariableHeader < AuthVariableEnd) {
> > > >
> > > > +    if (CompareGuid (&AuthVariableHeader->VendorGuid, VarGuid) &&
> > > >
> > > > +        (AuthVariableHeader->Attributes == VarAttribute) &&
> > > >
> > > > +        (StrCmp (VarName, (CHAR16 *)(AuthVariableHeader + 1)) ==
> > 0))
> > > >
> > > > +    {
> > > >
> > > > +      return AuthVariableHeader;
> > > >
> > > > +    }
> > > >
> > > > +
> > > >
> > > > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > *)((UINT8
> > > > *)AuthVariableHeader + sizeof (AUTHENTICATED_VARIABLE_HEADER)
> +
> > > > AuthVariableHeader->NameSize + AuthVariableHeader->DataSize);
> > > >
> > > > +    AuthVariableHeader = (AUTHENTICATED_VARIABLE_HEADER
> > > > *)HEADER_ALIGN (AuthVariableHeader);
> > > >
> > > > +  }
> > > >
> > > > +
> > > >
> > > > +  return NULL;
> > > >
> > > > +}
> > > >
> > > > +
> > > >
> > > >  /**
> > > >
> > > >    Find question default value from PcdNvStoreDefaultValueBuffer
> > > >
> > > >
> > > >
> > > > @@ -626,25 +665,29 @@ FindQuestionDefaultSetting (
> > > >    IN  BOOLEAN                  BitFieldQuestion
> > > >
> > > >    )
> > > >
> > > >  {
> > > >
> > > > -  VARIABLE_HEADER          *VariableHeader;
> > > >
> > > > -  VARIABLE_STORE_HEADER    *VariableStorage;
> > > >
> > > > -  LIST_ENTRY               *Link;
> > > >
> > > > -  VARSTORAGE_DEFAULT_DATA  *Entry;
> > > >
> > > > -  VARIABLE_STORE_HEADER    *NvStoreBuffer;
> > > >
> > > > -  UINT8                    *DataBuffer;
> > > >
> > > > -  UINT8                    *BufferEnd;
> > > >
> > > > -  BOOLEAN                  IsFound;
> > > >
> > > > -  UINTN                    Index;
> > > >
> > > > -  UINT32                   BufferValue;
> > > >
> > > > -  UINT32                   BitFieldVal;
> > > >
> > > > -  UINTN                    BitOffset;
> > > >
> > > > -  UINTN                    ByteOffset;
> > > >
> > > > -  UINTN                    BitWidth;
> > > >
> > > > -  UINTN                    StartBit;
> > > >
> > > > -  UINTN                    EndBit;
> > > >
> > > > -  PCD_DEFAULT_DATA         *DataHeader;
> > > >
> > > > -  PCD_DEFAULT_INFO         *DefaultInfo;
> > > >
> > > > -  PCD_DATA_DELTA           *DeltaData;
> > > >
> > > > +  VARIABLE_HEADER                   *VariableHeader;
> > > >
> > > > +  AUTHENTICATED_VARIABLE_HEADER     *AuthVariableHeader;
> > > >
> > > > +  VARIABLE_STORE_HEADER             *VariableStorage;
> > > >
> > > > +  LIST_ENTRY                        *Link;
> > > >
> > > > +  VARSTORAGE_DEFAULT_DATA           *Entry;
> > > >
> > > > +  VARIABLE_STORE_HEADER             *NvStoreBuffer;
> > > >
> > > > +  VOID                              *ValueSource;
> > > >
> > > > +  VOID                              *BitValueSource;
> > > >
> > > > +  UINT8                             *DataBuffer;
> > > >
> > > > +  UINT8                             *BufferEnd;
> > > >
> > > > +  BOOLEAN                           AuthFormat;
> > > >
> > > > +  BOOLEAN                           IsFound;
> > > >
> > > > +  UINTN                             Index;
> > > >
> > > > +  UINT32                            BufferValue;
> > > >
> > > > +  UINT32                            BitFieldVal;
> > > >
> > > > +  UINTN                             BitOffset;
> > > >
> > > > +  UINTN                             ByteOffset;
> > > >
> > > > +  UINTN                             BitWidth;
> > > >
> > > > +  UINTN                             StartBit;
> > > >
> > > > +  UINTN                             EndBit;
> > > >
> > > > +  PCD_DEFAULT_DATA                  *DataHeader;
> > > >
> > > > +  PCD_DEFAULT_INFO                  *DefaultInfo;
> > > >
> > > > +  PCD_DATA_DELTA                    *DeltaData;
> > > >
> > > >
> > > >
> > > >    if (gSkuId == 0xFFFFFFFFFFFFFFFF) {
> > > >
> > > >      gSkuId = LibPcdGetSku ();
> > > >
> > > > @@ -666,7 +709,7 @@ FindQuestionDefaultSetting (
> > > >    }
> > > >
> > > >
> > > >
> > > >    if (Link == &gVarStorageList) {
> > > >
> > > > -    DataBuffer          = (UINT8 *)PcdGetPtr
> > (PcdNvStoreDefaultValueBuffer);
> > > >
> > > > +    DataBuffer          = (UINT8 *)PcdGetExPtr
> > > > (&gEfiMdeModulePkgTokenSpaceGuid,
> PcdNvStoreDefaultValueBuffer);
> > > >
> > > >      gNvDefaultStoreSize =
> > ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER
> > > > *)DataBuffer)->Length;
> > > >
> > > >      //
> > > >
> > > >      // The first section data includes NV storage default setting.
> > > >
> > > > @@ -750,12 +793,27 @@ FindQuestionDefaultSetting (
> > > >      return EFI_NOT_FOUND;
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > > +  //
> > > >
> > > > +  // Judge if the variable type is authenticated, default is
> > > > + false
> > > >
> > > > +  //
> > > >
> > > > +  AuthFormat = FALSE;
> > > >
> > > > +  if (CompareGuid (&VariableStorage->Signature,
> > > > &gEfiAuthenticatedVariableGuid)) {
> > > >
> > > > +    AuthFormat = TRUE;
> > > >
> > > > +  }
> > > >
> > > > +
> > > >
> > > >    //
> > > >
> > > >    // Find the question default value from the variable storage
> > > >
> > > >    //
> > > >
> > > > -  VariableHeader = FindVariableData (VariableStorage,
> > > > &EfiVarStore->Guid,
> > > > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> > > >
> > > > -  if (VariableHeader == NULL) {
> > > >
> > > > -    return EFI_NOT_FOUND;
> > > >
> > > > +  if(AuthFormat) {
> > > >
> > > > +    AuthVariableHeader = FindAuthVariableData (VariableStorage,
> > > > &EfiVarStore->Guid, EfiVarStore->Attributes, (CHAR16
> > > > *)EfiVarStore-
> > > > >Name);
> > > >
> > > > +    if (AuthVariableHeader == NULL) {
> > > >
> > > > +      return EFI_NOT_FOUND;
> > > >
> > > > +    }
> > > >
> > > > +  } else {
> > > >
> > > > +    VariableHeader = FindVariableData (VariableStorage,
> > > > + &EfiVarStore->Guid,
> > > > EfiVarStore->Attributes, (CHAR16 *)EfiVarStore->Name);
> > > >
> > > > +    if (VariableHeader == NULL) {
> > > >
> > > > +      return EFI_NOT_FOUND;
> > > >
> > > > +    }
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > >    StartBit   = 0;
> > > >
> > > > @@ -770,8 +828,24 @@ FindQuestionDefaultSetting (
> > > >      Width      = EndBit / 8 + 1;
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > > -  if (VariableHeader->DataSize < ByteOffset + Width) {
> > > >
> > > > -    return EFI_INVALID_PARAMETER;
> > > >
> > > > +  if (AuthFormat) {
> > > >
> > > > +    if (AuthVariableHeader->DataSize < ByteOffset + Width) {
> > > >
> > > > +      return EFI_INVALID_PARAMETER;
> > > >
> > > > +    }
> > > >
> > > > +
> > > >
> > > > +    ValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > > > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader-
> >NameSize
> > > +
> > > > IfrQuestionHdr->VarStoreInfo.VarOffset;
> > > >
> > > > +    if (BitFieldQuestion) {
> > > >
> > > > +      BitValueSource = (UINT8 *)AuthVariableHeader + sizeof
> > > > (AUTHENTICATED_VARIABLE_HEADER) + AuthVariableHeader-
> >NameSize
> > > +
> > > > ByteOffset;
> > > >
> > > > +    }
> > > >
> > > > +  } else {
> > > >
> > > > +    if (VariableHeader->DataSize < ByteOffset + Width) {
> > > >
> > > > +      return EFI_INVALID_PARAMETER;
> > > >
> > > > +    }
> > > >
> > > > +
> > > >
> > > > +    ValueSource = (UINT8 *)VariableHeader + sizeof
> > (VARIABLE_HEADER)
> > > > + +
> > > > VariableHeader->NameSize + IfrQuestionHdr->VarStoreInfo.VarOffset;
> > > >
> > > > +    if (BitFieldQuestion) {
> > > >
> > > > +      BitValueSource = (UINT8 *)VariableHeader + sizeof
> > > > + (VARIABLE_HEADER)
> > > > + VariableHeader->NameSize + ByteOffset;
> > > >
> > > > +    }
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > >    //
> > > >
> > > > @@ -779,11 +853,11 @@ FindQuestionDefaultSetting (
> > > >    //
> > > >
> > > >    if (ValueBuffer != NULL) {
> > > >
> > > >      if (BitFieldQuestion) {
> > > >
> > > > -      CopyMem (&BufferValue, (UINT8 *)VariableHeader + sizeof
> > > > (VARIABLE_HEADER) + VariableHeader->NameSize + ByteOffset,
> Width);
> > > >
> > > > +      CopyMem (&BufferValue, BitValueSource, Width);
> > > >
> > > >        BitFieldVal = BitFieldRead32 (BufferValue, StartBit,
> > > > EndBit);
> > > >
> > > >        CopyMem (ValueBuffer, &BitFieldVal, Width);
> > > >
> > > >      } else {
> > > >
> > > > -      CopyMem (ValueBuffer, (UINT8 *)VariableHeader + sizeof
> > > > (VARIABLE_HEADER) + VariableHeader->NameSize + IfrQuestionHdr-
> > > > >VarStoreInfo.VarOffset, Width);
> > > >
> > > > +      CopyMem (ValueBuffer, ValueSource, Width);
> > > >
> > > >      }
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > > @@ -832,7 +906,7 @@ UpdateDefaultSettingInFormPackage (
> > > >    // If no default setting, do nothing
> > > >
> > > >    //
> > > >
> > > >    if (gNvDefaultStoreSize == 0) {
> > > >
> > > > -    gNvDefaultStoreSize = PcdGetSize (PcdNvStoreDefaultValueBuffer);
> > > >
> > > > +    gNvDefaultStoreSize = PcdGetExSize
> > > > (&gEfiMdeModulePkgTokenSpaceGuid,
> PcdNvStoreDefaultValueBuffer);
> > > >
> > > >    }
> > > >
> > > >
> > > >
> > > >    if (gNvDefaultStoreSize < sizeof
> > > > (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {
> > > >
> > > > diff --git
> > > > a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > > b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > > index 0116fb6ecb..dac4d614a8 100644
> > > > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
> > > > @@ -86,6 +86,9 @@
> > > >    gEfiHiiImageDecoderNameJpegGuid
> > > > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > > > SOMETIMES_CONSUMES ## GUID
> > > >
> > > >    gEfiHiiImageDecoderNamePngGuid
> > > > |gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol  ##
> > > > SOMETIMES_CONSUMES ## GUID
> > > >
> > > >    gEdkiiIfrBitVarstoreGuid
> > ##
> > > > SOMETIMES_CONSUMES ## GUID
> > > >
> > > > +  gEfiAuthenticatedVariableGuid
> > > >
> > > > +  gEfiVariableGuid
> > > >
> > > > +  gEfiMdeModulePkgTokenSpaceGuid
> > > >
> > > >
> > > >
> > > >  [Depex]
> > > >
> > > >    TRUE
> > > >
> > > > --
> > > > 2.25.1
> >
> >
> >
> > 
> >
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#85726): https://edk2.groups.io/g/devel/message/85726
Mute This Topic: https://groups.io/mt/88478152/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-