From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A9E772194EB77 for ; Mon, 18 Feb 2019 16:49:32 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Feb 2019 16:49:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,385,1544515200"; d="scan'208";a="125433848" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga008.fm.intel.com with ESMTP; 18 Feb 2019 16:49:32 -0800 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 18 Feb 2019 16:49:32 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 18 Feb 2019 16:49:31 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.110]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.109]) with mapi id 14.03.0415.000; Tue, 19 Feb 2019 08:49:29 +0800 From: "Feng, Bob C" To: Felix Polyudov , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [edk2] [Patch] BaseTools: Correct the value assignment for StructurePcd Thread-Index: AQHUxbwfmbg8o71hXkiEfYD9EXLg8aXlRF+AgAEJoiA= Date: Tue, 19 Feb 2019 00:49:29 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D160089092@SHSMSX101.ccr.corp.intel.com> References: <20190216055434.19492-1-bob.c.feng@intel.com> <9333E191E0D52B4999CE63A99BA663A00302C637BE@atlms1.us.megatrends.com> In-Reply-To: <9333E191E0D52B4999CE63A99BA663A00302C637BE@atlms1.us.megatrends.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: Correct the value assignment for StructurePcd X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 00:49:32 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Felix, Good point. I'll update the patch. Thanks, Bob -----Original Message----- From: Felix Polyudov [mailto:Felixp@ami.com]=20 Sent: Tuesday, February 19, 2019 12:57 AM To: Feng, Bob C ; edk2-devel@lists.01.org Cc: Gao, Liming Subject: RE: [edk2] [Patch] BaseTools: Correct the value assignment for Str= ucturePcd Bob, I think silent trimming of input data is not a good idea. The build tool should either report an error (my preference) or a warning t= hat DSC or DEC input value is too long. -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Feng= , Bob C Sent: Saturday, February 16, 2019 12:55 AM To: edk2-devel@lists.01.org Cc: Liming Gao Subject: [edk2] [Patch] BaseTools: Correct the value assignment for Structu= rePcd This patch is to fix the code bug in StructurePcd overall value assignment = logic. If a Pcd Array size is fixed but the size of actual value in Dsc or = Dec is bigger than the Pcd array size, the tool only copy the data as same = as that Pcd Array size. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- .../Python/Workspace/BuildClassObject.py | 57 ++++--- .../Source/Python/Workspace/DscBuildData.py | 145 ++++++++++++++---- 2 files changed, 147 insertions(+), 55 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTo= ols/Source/Python/Workspace/BuildClassObject.py index 1df042f41c..d6168b62d5 100644 --- a/BaseTools/Source/Python/Workspace/BuildClassObject.py +++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py @@ -76,34 +76,45 @@ class PcdClassObject(object): self.UserDefinedDefaultStoresFlag =3D UserDefinedDefaultStoresFlag self._Capacity =3D None =20 @property def Capacity(self): - self._Capacity =3D [] - dimension =3D ArrayIndex.findall(self._DatumType) - for item in dimension: - maxsize =3D item.lstrip("[").rstrip("]").strip() - if not maxsize: - maxsize =3D "-1" - maxsize =3D str(int(maxsize,16)) if maxsize.startswith(("0x","= 0X")) else maxsize - self._Capacity.append(maxsize) - if hasattr(self, "SkuOverrideValues"): - for sku in self.SkuOverrideValues: - for defaultstore in self.SkuOverrideValues[sku]: - fields =3D self.SkuOverrideValues[sku][defaultstore] - for demesionattr in fields: - deme =3D ArrayIndex.findall(demesionattr) - for i in range(len(deme)-1): - if int(deme[i].lstrip("[").rstrip("]").strip()= ) > int(self._Capacity[i]): - print ("error") - if hasattr(self,"DefaultValues"): - for demesionattr in self.DefaultValues: - deme =3D ArrayIndex.findall(demesionattr) - for i in range(len(deme)-1): - if int(deme[i].lstrip("[").rstrip("]").strip()) > int(= self._Capacity[i]): - print ("error") + if self._Capacity is None: + self._Capacity =3D [] + dimension =3D ArrayIndex.findall(self._DatumType) + for item in dimension: + maxsize =3D item.lstrip("[").rstrip("]").strip() + if not maxsize: + maxsize =3D "-1" + maxsize =3D str(int(maxsize,16)) if maxsize.startswith(("0= x","0X")) else maxsize + self._Capacity.append(maxsize) + if hasattr(self, "SkuOverrideValues"): + for sku in self.SkuOverrideValues: + for defaultstore in self.SkuOverrideValues[sku]: + fields =3D self.SkuOverrideValues[sku][defaultstor= e] + for demesionattr in fields: + deme =3D ArrayIndex.findall(demesionattr) + for i in range(len(deme)): + if int(deme[i].lstrip("[").rstrip("]").str= ip()) >=3D int(self._Capacity[i]): + if self._Capacity[i] !=3D "-1": + raise ("error") + if hasattr(self,"DefaultValues"): + for demesionattr in self.DefaultValues: + deme =3D ArrayIndex.findall(demesionattr) + for i in range(len(deme)): + if int(deme[i].lstrip("[").rstrip("]").strip()) >= =3D int(self._Capacity[i]): + if self._Capacity[i] !=3D "-1": + raise ("error") return self._Capacity + + def PcdArraySize(self): + if self.Capacity[-1] =3D=3D "-1": + return -1 + size =3D 1 + for de in self.Capacity: + size =3D size * int(de) + return size @property def DatumType(self): return self._DatumType =20 @DatumType.setter diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index e45beb3924..09d917c5db 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1763,27 +1763,41 @@ class DscBuildData(PlatformBuildClassObject): return Result =20 def GenerateSizeFunction(self, Pcd): CApp =3D "// Default Value in Dec \n" CApp =3D CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.Toke= nSpaceGuidCName, Pcd.TokenCName) - if Pcd.IsArray(): + + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + CApp +=3D " *Size =3D (sizeof (%s) > *Size ? sizeof (%s) : *S= ize);\n" % (Pcd.DatumType,Pcd.DatumType) + else: + if "{CODE(" in Pcd.DefaultValueFromDec: + CApp +=3D " *Size =3D (sizeof (%s_%s_INIT_Value) > *Size = ?=20 + sizeof (%s_%s_INIT_Value) : *Size);\n" %=20 + (Pcd.TokenSpaceGuidCName,Pcd.TokenCName,Pcd.TokenSpaceGuidCName,Pcd.To + kenCName) if Pcd.Type in PCD_DYNAMIC_TYPE_SET | PCD_DYNAMIC_EX_TYPE_SET: for skuname in Pcd.SkuInfoList: skuobj =3D Pcd.SkuInfoList[skuname] if skuobj.VariableName: for defaultstore in skuobj.DefaultStoreDict: pcddef =3D self.GetPcdDscRawDefaultValue(Pcd,s= kuname,defaultstore) - if pcddef and "{CODE(" in pcddef: - CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%= s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpac= eGuidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,Pcd.= TokenCName,skuname,defaultstore) + if pcddef: + if "{CODE(" in pcddef: + CApp +=3D " *Size =3D (sizeof (%s_%s_= %s_%s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.Token= SpaceGuidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,= Pcd.TokenCName,skuname,defaultstore) + else: + CApp +=3D " *Size =3D %s > *Size ? %s= =20 + : *Size;\n" %=20 + (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd)) else: pcddef =3D self.GetPcdDscRawDefaultValue(Pcd,skuna= me,TAB_DEFAULT_STORES_DEFAULT) - if pcddef and "{CODE(" in pcddef: - CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%s_Va= lue) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGui= dCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuid= CName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT) + if pcddef: + if "{CODE(" in pcddef: + CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%= s_Value) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpac= eGuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpace= GuidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT) + else: + CApp +=3D " *Size =3D %s > *Size ? %s :=20 + *Size;\n" %=20 + (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd)) else: pcddef =3D self.GetPcdDscRawDefaultValue(Pcd,TAB_DEFAULT,T= AB_DEFAULT_STORES_DEFAULT) - if pcddef and "{CODE(" in pcddef: - CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%s_Value) > *= Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,P= cd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCNam= e,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT) + if pcddef: + if "{CODE(" in pcddef: + CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%s_Value)= > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCNa= me,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuid= CName,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT) + else: + CApp +=3D " *Size =3D %s > *Size ? %s : *Size;\n"= =20 + % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd)) for index in Pcd.DefaultValues: FieldList =3D Pcd.DefaultValues[index] if not FieldList: continue for FieldName in FieldList: @@ -1891,10 +1905,11 @@ class DscBuildData(PlatformBuildClassObject): while '[' in FieldName and not Pcd.IsArray: FieldName =3D FieldName.rsplit('[', 1)[0] CApp =3D CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d);= // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), Ar= rayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValu= eFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0]) if Pcd.GetPcdMaxSize(): CApp =3D CApp + " *Size =3D (%d > *Size ? %d : *Size); // The= Pcd maxsize is %d \n" % (Pcd.GetPcdMaxSize(), Pcd.GetPcdMaxSize(), Pcd.Get= PcdMaxSize()) + CApp =3D CApp + "}\n" return CApp =20 @staticmethod def GenerateSizeStatments(Pcd,skuname,defaultstorename): @@ -1971,10 +1986,11 @@ class DscBuildData(PlatformBuildClassObject): def GenerateDefaultValueAssignFunction(self, Pcd): CApp =3D "// Default value in Dec \n" CApp =3D CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (P= cd.TokenSpaceGuidCName, Pcd.TokenCName, Pcd.BaseDatumType) CApp =3D CApp + ' UINT32 FieldSize;\n' CApp =3D CApp + ' CHAR8 *Value;\n' + CApp =3D CApp + ' UINT32 PcdArraySize;\n' DefaultValueFromDec =3D Pcd.DefaultValueFromDec IsArray =3D _IsFieldValueAnArray(Pcd.DefaultValueFromDec) if IsArray: try: DefaultValueFromDec =3D ValueExpressionEx(Pcd.DefaultValue= FromDec, TAB_VOID)(True) @@ -1982,18 +1998,35 @@ class DscBuildData(Platfor= mBuildClassObject): EdkLogger.error("Build", FORMAT_INVALID, "Invalid value fo= rmat for %s.%s, from DEC: %s" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, = DefaultValueFromDec)) DefaultValueFromDec =3D StringToArray(DefaultValueFromDec) Value, ValueSize =3D ParseFieldValue (DefaultValueFromDec) if IsArray: - # - # Use memcpy() to copy value into field - # - if "{CODE(" in Pcd.DefaultValueFromDec: - CApp =3D CApp + ' memcpy (Pcd, %s_%s_INIT_Value, sizeof(%= s_%s_INIT_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.TokenS= paceGuidCName, Pcd.TokenCName) + # + # Use memcpy() to copy value into field + # + if Pcd.IsArray(): + pcdarraysize =3D Pcd.PcdArraySize() + if "{CODE(" in Pcd.DefaultValueFromDec: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s_IN= IT_Value) < %d * sizeof(%s)? sizeof(%s_%s_INIT_Value): %d * sizeof(%s);\n' = % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType, = Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s_IN= IT_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_INIT_Value,PcdAr= raySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + else: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D %d < sizeof(%s)= * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarraysiz= e,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' % ValueS= ize + CApp =3D CApp + ' Value =3D %s; // From DEC Defau= lt Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultV= alueFromDec) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArraySize);\= n' else: - CApp =3D CApp + ' Value =3D %s; // From DEC Default V= alue %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValue= FromDec) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSiz= e) + if "{CODE(" in Pcd.DefaultValueFromDec: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s_INIT_= Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_INIT_Value,PcdA= rraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + else: + CApp =3D CApp + ' Value =3D %s; // From DEC Defau= lt Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultV= alueFromDec) + CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' %=20 + (ValueSize) elif isinstance(Value, str): CApp =3D CApp + ' Pcd =3D %s; // From DEC Default Value %s\n'= % (Value, Pcd.DefaultValueFromDec) for index in Pcd.DefaultValues: FieldList =3D Pcd.DefaultValues[index] if not FieldList: @@ -2052,10 +2085,11 @@ class DscBuildData(PlatformBuildClassObject): def GenerateInitValueFunction(self, Pcd, SkuName, DefaultStoreName): CApp =3D "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuNa= me, DefaultStoreName) CApp =3D CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd= .TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.BaseDa= tumType) CApp =3D CApp + ' UINT32 FieldSize;\n' CApp =3D CApp + ' CHAR8 *Value;\n' + CApp =3D CApp + ' UINT32 PcdArraySize;\n' =20 CApp =3D CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_= DEFAULT, TAB_DEFAULT_STORES_DEFAULT) inherit_OverrideValues =3D Pcd.SkuOverrideValues[SkuName] =20 pcddefaultvalue =3D self.GetPcdDscRawDefaultValue(Pcd, SkuName, De= faultStoreName) @@ -2072,37 +2106,83 @@ class DscBuildData(PlatformBuildCla= ssObject): Value, ValueSize =3D ParseFieldValue (FieldList) =20 if (SkuName, DefaultStoreName) =3D=3D (TAB_DEFAULT, TAB_DEFAUL= T_STORES_DEFAULT): if isinstance(Value, str): if "{CODE(" in Value: - CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value,= sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,= SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + pcdarraysize =3D Pcd.PcdArraySize() + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%= s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s= );\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,= pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Sku= Name, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Va= lue,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + else: + CApp =3D CApp+ ' PcdArraySize =3D sizeof(%s_%s= _%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, Defa= ultStoreName) + CApp =3D CApp + ' memcpy (Pcd,=20 + &%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName,=20 + Pcd.TokenCName,SkuName, DefaultStoreName) else: CApp =3D CApp + ' Pcd =3D %s; // From DSC Default= Value %s\n' % (Value, Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFA= ULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.Defaul= tValue) elif IsArray: - # - # Use memcpy() to copy value into field - # - if Pcd.IsArray() and "{CODE(" in pcddefaultvalue: - CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value,= sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,= SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + # + # Use memcpy() to copy value into field + # + if Pcd.IsArray(): + pcdarraysize =3D Pcd.PcdArraySize() + if "{CODE(" in pcddefaultvalue: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D sizeof(= %s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeo= f(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreN= ame,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName= ,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(= %s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,= DefaultStoreName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + else: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D %d < si= zeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcd= arraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' = % ValueSize + CApp =3D CApp + ' Value =3D %s; // From D= SC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.= DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Def= aultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArra= ySize);\n' else: - CApp =3D CApp + ' Value =3D %s; // From DSC D= efault Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.Defa= ultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Default= Value) if Pcd.DefaultFromDSC else Pcd.DefaultValue) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (= ValueSize) + if "{CODE(" in pcddefaultvalue: + CApp =3D CApp + ' PcdArraySize =3D %d < sizeo= f(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarr= aysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_V= alue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,= DefaultStoreName) + else: + CApp =3D CApp + ' Value =3D %s; // From D= SC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.= DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Def= aultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value,=20 + %d);\n' % (ValueSize) else: if isinstance(Value, str): if "{CODE(" in Value: - CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value,= sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,= SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + pcdarraysize =3D Pcd.PcdArraySize() + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%= s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeof(%s= );\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName,= pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Sku= Name, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%= s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, Defa= ultStoreName) + CApp =3D CApp + ' memcpy (Pcd,=20 + &%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,=20 + Pcd.TokenCName,SkuName, DefaultStoreName) else: CApp =3D CApp + ' Pcd =3D %s; // From DSC Default= Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreNam= e)) elif IsArray: - # - # Use memcpy() to copy value into field - # - if Pcd.IsArray() and "{CODE(" in pcddefaultvalue: - CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Value,= sizeof(%s_%s_%s_%s_Value));\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,= SkuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + # + # Use memcpy() to copy value into field + # + if Pcd.IsArray(): + pcdarraysize =3D Pcd.PcdArraySize() + if "{CODE(" in pcddefaultvalue: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D sizeof(= %s_%s_%s_%s_Value) < %d * sizeof(%s)? sizeof(%s_%s_%s_%s_Value): %d * sizeo= f(%s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreN= ame,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName= ,SkuName, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp + ' PcdArraySize =3D sizeof(%s_%s_%s_= %s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultS= toreName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, = DefaultStoreName) + else: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D %d < si= zeof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcd= arraysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' = % ValueSize + CApp =3D CApp + ' Value =3D %s; // From D= SC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.= DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Defaul= tValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArra= ySize);\n' else: - CApp =3D CApp + ' Value =3D %s; // From DSC D= efault Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscR= awValue.get(SkuName, {}).get(DefaultStoreName)) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (= ValueSize) + if "{CODE(" in pcddefaultvalue: + CApp =3D CApp + ' PcdArraySize =3D %d < sizeo= f(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarr= aysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_V= alue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,= DefaultStoreName) + else: + CApp =3D CApp + ' Value =3D %s; // From D= SC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.= DscRawValue.get(SkuName, {}).get(DefaultStoreName)) + CApp =3D CApp + ' memcpy (Pcd, Value,=20 + %d);\n' % (ValueSize) =20 inheritvalue =3D inherit_OverrideValues.get(DefaultStoreName) if not inheritvalue: inheritvalue =3D [] for index in inheritvalue: @@ -2324,10 +2404,13 @@ class DscBuildData(PlatformBuildClassObject): # the flexible array member. The flexible array member must b= e the last field # in a structure. The size formula for this case is: # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (H= ighestIndex + 1) # CApp =3D CApp + DscBuildData.GenerateSizeStatments(Pcd,SkuName= ,DefaultStoreName) + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' OriginalSize =3D OriginalSize < sizeof(= %s) * %d? OriginalSize:sizeof(%s) * %d; \n' % (Pcd.BaseDatumType,Pcd.PcdArr= aySize(),Pcd.BaseDatumType,Pcd.PcdArraySize()) + CApp =3D CApp + ' Size =3D sizeof(%s) * %d; \n' %=20 + (Pcd.BaseDatumType,Pcd.PcdArraySize()) =20 # # Allocate and zero buffer for the PCD # Must handle cases where current value is smaller, larger, or= same size # Always keep that larger one as the current size @@ -2374,12 = +2457,10 @@ class DscBuildData(PlatformBuildClassObject): =20 def GenerateArrayAssignment(self, Pcd): CApp =3D "" if not Pcd: return CApp - if not Pcd.IsArray(): - return CApp Demesion =3D "" for d in Pcd.Capacity: Demesion +=3D "[]" =20 Value =3D Pcd.DefaultValueFromDec -- 2.18.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Please consider the environment before printing this email. The information contained in this message may be confidential and proprieta= ry to American Megatrends, Inc. This communication is intended to be read = only by the individual or entity to whom it is addressed or by their design= ee. If the reader of this message is not the intended recipient, you are on= notice that any distribution of this message, in any form, is strictly pro= hibited. Please promptly notify the sender by reply e-mail or by telephone= at 770-246-8600, and then delete or destroy all copies of the transmission= .