From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web09.7206.1648793352687340022 for ; Thu, 31 Mar 2022 23:09:13 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=PeLqccmI; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: lin.z.chen@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648793352; x=1680329352; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PjvgQ527vwsFk2B8PlZceizsMUOW97NTOQSLD3RX9+o=; b=PeLqccmI+/LzRHIVrfZUaNAlLBL+yoK60r9QJ+HRpoLcbcdBOXuVDNWT AuaEAi/TEl8p1MLnFhXfZLj5FNgBqs8wi2LmIIpRdKo0iv9wmSyU77Myb quxelDUO2JK4mm2RQowbyeoOv62uSwoos0aDe5s+r0QO1TMgRMhO3usNx j/RGMEhPjRL+QHEbeoniLKF2md3nyM4tfI2t9OAd+NgeRFqMyqsHCpVOu yxrASATNK8eqmY8ySEf3iqUrIuqq9/HNL3ef+ilek2NK2mfEf1J3m0gHg 1annDI8dTLBa0+y+zPM25uA/+cMOS94bvF5kb8nPZ3NKWOW7IUJAK5TyV g==; X-IronPort-AV: E=McAfee;i="6200,9189,10303"; a="239987820" X-IronPort-AV: E=Sophos;i="5.90,226,1643702400"; d="scan'208";a="239987820" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2022 23:09:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,226,1643702400"; d="scan'208";a="547665028" Received: from shbiosbuild1001.sh.intel.com ([10.239.133.29]) by orsmga007.jf.intel.com with ESMTP; 31 Mar 2022 23:09:08 -0700 From: "Chen Lin Z" To: jian.j.wang@intel.com, gaoliming@byosoft.com.cn, dandan.bi@intel.com, eric.dong@intel.com, devel@edk2.groups.io Cc: zhuangzhi.li@intel.com, di.zhang@intel.com, Chen Lin Z Subject: [PATCH-V2] Fix Setup numeric default value incorrect issue Date: Fri, 1 Apr 2022 14:09:05 +0800 Message-Id: <20220401060905.841569-1-lin.z.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable When default/manufacturing flag get removed from numeric varid, it can't get default value from StructurePcd in 'UpdateDefaultSettingInFormPackage' function since there is no EFI_IFR_DEFAULT_OP opcode in IFR file. Add a chance to get numeric default value from StructurePcd in the case that numeric minimum value will be used as default value. Signed-off-by: Chen Lin Z Signed-off-by: Dandan Bi --- .../Universal/HiiDatabaseDxe/ConfigRouting.c | 22 ++++++++++++++++++ .../Universal/HiiDatabaseDxe/HiiDatabase.h | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeMod= ulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index 2f792d2965..1c6af853b3 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -2171,6 +2171,7 @@ ParseIfrData ( UINTN PackageOffset;=0D EFI_IFR_VARSTORE *IfrVarStore;=0D EFI_IFR_VARSTORE_EFI *IfrEfiVarStore;=0D + EFI_IFR_VARSTORE_EFI *IfrEfiVarStoreTmp;=0D EFI_IFR_OP_HEADER *IfrOpHdr;=0D EFI_IFR_ONE_OF *IfrOneOf;=0D EFI_IFR_REF4 *IfrRef;=0D @@ -2187,6 +2188,7 @@ ParseIfrData ( IFR_BLOCK_DATA *BlockData;=0D CHAR16 *VarStoreName;=0D UINTN NameSize;=0D + UINTN NvDefaultStoreSize;=0D UINT16 VarWidth;=0D UINT16 VarDefaultId;=0D BOOLEAN FirstOneOfOption;=0D @@ -2212,6 +2214,7 @@ ParseIfrData ( SmallestDefaultId =3D 0xFFFF;=0D FromOtherDefaultOpcode =3D FALSE;=0D QuestionReferBitField =3D FALSE;=0D + IfrEfiVarStoreTmp =3D NULL;=0D =0D //=0D // Go through the form package to parse OpCode one by one.=0D @@ -2303,6 +2306,17 @@ ParseIfrData ( }=0D =0D AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name, VarStoreName= , NameSize);=0D + if (IfrEfiVarStoreTmp !=3D NULL) {=0D + FreePool (IfrEfiVarStoreTmp);=0D + }=0D + IfrEfiVarStoreTmp =3D AllocatePool (IfrEfiVarStore->Header.Length = + AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name));=0D + if (IfrEfiVarStoreTmp =3D=3D NULL) {=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + goto Done;=0D + }=0D +=0D + CopyMem (IfrEfiVarStoreTmp, IfrEfiVarStore, IfrEfiVarStore->Header= .Length);=0D + AsciiStrToUnicodeStrS ((CHAR8 *)IfrEfiVarStore->Name, (CHAR16 *)&(= IfrEfiVarStoreTmp->Name[0]), AsciiStrSize ((CHAR8 *)IfrEfiVarStore->Name) *= sizeof (CHAR16));=0D =0D if (IsThisVarstore (&IfrEfiVarStore->Guid, VarStoreName, ConfigHdr= )) {=0D //=0D @@ -2502,9 +2516,13 @@ ParseIfrData ( //=0D // Set default value base on the DefaultId list get from IFR dat= a.=0D //=0D + NvDefaultStoreSize =3D PcdGetSize (PcdNvStoreDefaultValueBuffer)= ;=0D for (LinkData =3D DefaultIdArray->Entry.ForwardLink; LinkData != =3D &DefaultIdArray->Entry; LinkData =3D LinkData->ForwardLink) {=0D DefaultDataPtr =3D BASE_CR (LinkData, IFR_DEFAULT_DATA,= Entry);=0D DefaultData.DefaultId =3D DefaultDataPtr->DefaultId;=0D + if (NvDefaultStoreSize > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_H= EADER)) {=0D + FindQuestionDefaultSetting (DefaultData.DefaultId, IfrEfiVar= StoreTmp, &(IfrOneOf->Question), &DefaultData.Value, VarWidth, QuestionRefe= rBitField);=0D + }=0D InsertDefaultValue (BlockData, &DefaultData);=0D }=0D }=0D @@ -3192,6 +3210,10 @@ Done: }=0D }=0D =0D + if (IfrEfiVarStoreTmp !=3D NULL) {=0D + FreePool (IfrEfiVarStoreTmp);=0D + }=0D +=0D return Status;=0D }=0D =0D diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h b/MdeModul= ePkg/Universal/HiiDatabaseDxe/HiiDatabase.h index c4ca6ad6ee..421c293cfc 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h @@ -2308,6 +2308,29 @@ HiiGetConfigRespInfo ( IN CONST EFI_HII_DATABASE_PROTOCOL *This=0D );=0D =0D +/**=0D + Find question default value from PcdNvStoreDefaultValueBuffer=0D +=0D + @param DefaultId Default store ID=0D + @param EfiVarStore Point to EFI VarStore header=0D + @param IfrQuestionHdr Point to Question header=0D + @param ValueBuffer Point to Buffer includes the found default set= ting=0D + @param Width Width of the default value=0D + @param BitFieldQuestion Whether the Question is stored in Bit field.=0D +=0D + @retval EFI_SUCCESS Question default value is found.=0D + @retval EFI_NOT_FOUND Question default value is not found.=0D +**/=0D +EFI_STATUS=0D +FindQuestionDefaultSetting (=0D + IN UINT16 DefaultId,=0D + IN EFI_IFR_VARSTORE_EFI *EfiVarStore,=0D + IN EFI_IFR_QUESTION_HEADER *IfrQuestionHdr,=0D + OUT VOID *ValueBuffer,=0D + IN UINTN Width,=0D + IN BOOLEAN BitFieldQuestion=0D + );=0D +=0D //=0D // Global variables=0D //=0D --=20 2.25.1