From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=63.147.10.40; helo=atlmailgw1.ami.com; envelope-from=felixp@ami.com; receiver=edk2-devel@lists.01.org Received: from atlmailgw1.ami.com (atlmailgw1.ami.com [63.147.10.40]) (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 C393A2008319E for ; Mon, 18 Feb 2019 08:57:07 -0800 (PST) X-AuditID: ac1060b2-78bff70000002bc0-6d-5c6ae3e12e81 Received: from atlms2.us.megatrends.com (atlms2.us.megatrends.com [172.16.96.152]) (using TLS with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client did not present a certificate) by atlmailgw1.ami.com (Symantec Messaging Gateway) with SMTP id 94.17.11200.2E3EA6C5; Mon, 18 Feb 2019 11:57:06 -0500 (EST) Received: from ATLMS1.us.megatrends.com ([fe80::8c55:daf0:ef05:5605]) by atlms2.us.megatrends.com ([fe80::29dc:a91e:ea0c:cdeb%12]) with mapi id 14.03.0415.000; Mon, 18 Feb 2019 11:57:05 -0500 From: Felix Polyudov To: "'Feng, Bob C'" , "edk2-devel@lists.01.org" CC: Liming Gao Thread-Topic: [edk2] [Patch] BaseTools: Correct the value assignment for StructurePcd Thread-Index: AQHUxbwcKqa720kvIEanYystxaydmKXlyLfQ Date: Mon, 18 Feb 2019 16:57:05 +0000 Message-ID: <9333E191E0D52B4999CE63A99BA663A00302C637BE@atlms1.us.megatrends.com> References: <20190216055434.19492-1-bob.c.feng@intel.com> In-Reply-To: <20190216055434.19492-1-bob.c.feng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.99.93] content-transfer-encoding: quoted-printable MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPKsWRmVeSWpSXmKPExsWyRiBhhu6jx1kxBhtW8Vn8OjqPzWLPoaPM FivubWB3YPZYvOclk0f37H8sAUxRDYw2iXl5+SWJJakKKanFybZKAUWZZYnJlUoKmSm2SoZK CgU5icmpual5JbZKiQUFqXkpSnZcChjABqgsM08hNS85PyUzL91WyTPYX9fCwtRS11DJLiQj VSEzLy2/KDexJDM/TyE5P68EqDo1BSiqkNDFmdH6/QtjwdsbjBUL7m9kbGDcNo2xi5GTQ0LA RKJj+W32LkYuDiGBXUwS6278YYNwDjNK7JvdzA5SxSagKnF8dTMLiC0ikChxd8lKsDgzUHzy uU3MILawQJjEgYeXWSFqwiXm7uoCquEAso0kFt1KBgmzAJUf3LKFCcTmFQiUOLBgA9gRQgKW EkuX3AJr5RSwkuicsh5sPKOAmMT3U2uYIFaJS9x6Mp8J4mgBiSV7zjND2KISLx//Y4WwFSS2 vO+EOk1HYsHuT2wQtrbEsoWvmSH2CkqcnPmEZQKj6CwkY2chaZmFpGUWkpYFjCyrGIUSS3Jy EzNz0ssN9RJzM/WS83M3MULSw6YdjC0XzQ8xCnAwKvHw2tzIihFiTSwrrsw9xCjBwawkwnsM JMSbklhZlVqUH19UmpNafIjRCRgsE5mluEERBkwB8cYGBlKiMI6hiZmJuZG5oaWJubGxkjhv vtqnKCGBdGBKyk5NLUgtghnCxMEp1cBod5BbeE2SuP2GHIOZs+1eWy9Kam7qVX52/3Gv7c2b 7D7N6nzVyla7PkSzzZ1nqxi/5vrXq/sLqrw0/z/IEZ9103hvTaCvdyBLVrzZNb3F3zqmcDn9 P1G+RbH6y941Ko+z+qzmRD/dYt74s7JemiUrxEM7X7M7altJ0hnvn0vMOiaz/24sXKTEUpyR aKjFXFScCABwuWVlMgMAAA== 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: Mon, 18 Feb 2019 16:57:08 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" 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 th= at 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 Structur= ePcd 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/BaseToo= ls/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 @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","0= X")) 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(s= elf._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(("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)): + if int(deme[i].lstrip("[").rstrip("]").stri= p()) >=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 @DatumType.setter diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/S= ource/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 def GenerateSizeFunction(self, Pcd): CApp =3D "// Default Value in Dec \n" CApp =3D CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.Token= SpaceGuidCName, Pcd.TokenCName) - if Pcd.IsArray(): + + if Pcd.IsArray() and Pcd.Capacity[-1] !=3D "-1": + CApp +=3D " *Size =3D (sizeof (%s) > *Size ? sizeof (%s) : *Si= ze);\n" % (Pcd.DatumType,Pcd.DatumType) + else: + if "{CODE(" in Pcd.DefaultValueFromDec: + CApp +=3D " *Size =3D (sizeof (%s_%s_INIT_Value) > *Size ?= sizeof (%s_%s_INIT_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd.Token= CName,Pcd.TokenSpaceGuidCName,Pcd.TokenCName) 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,sk= uname,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.TokenSpaceG= uidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,Pcd.Tok= enCName,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.TokenSp= aceGuidCName,Pcd.TokenCName,skuname,defaultstore,Pcd.TokenSpaceGuidCName,Pcd= .TokenCName,skuname,defaultstore) + else: + CApp +=3D " *Size =3D %s > *Size ? %s= : *Size;\n" % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize= (Pcd)) else: pcddef =3D self.GetPcdDscRawDefaultValue(Pcd,skunam= e,TAB_DEFAULT_STORES_DEFAULT) - if pcddef and "{CODE(" in pcddef: - CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%s_Val= ue) > *Size ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidC= Name,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCNa= me,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.TokenSpaceG= uidCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGui= dCName,Pcd.TokenCName,skuname,TAB_DEFAULT_STORES_DEFAULT) + else: + CApp +=3D " *Size =3D %s > *Size ? %s : *S= ize;\n" % (self.GetStructurePcdMaxSize(Pcd),self.GetStructurePcdMaxSize(Pcd)= ) else: pcddef =3D self.GetPcdDscRawDefaultValue(Pcd,TAB_DEFAULT,TA= B_DEFAULT_STORES_DEFAULT) - if pcddef and "{CODE(" in pcddef: - CApp +=3D " *Size =3D (sizeof (%s_%s_%s_%s_Value) > *S= ize ? sizeof (%s_%s_%s_%s_Value) : *Size);\n" % (Pcd.TokenSpaceGuidCName,Pcd= .TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCName,P= cd.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.TokenSpaceGuidCNam= e,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT,Pcd.TokenSpaceGuidCN= ame,Pcd.TokenCName,TAB_DEFAULT,TAB_DEFAULT_STORES_DEFAULT) + else: + CApp +=3D " *Size =3D %s > *Size ? %s : *Size;\n"= % (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("."), Arr= ayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueF= romComm[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.GetP= cdMaxSize()) + CApp =3D CApp + "}\n" return CApp @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" % (Pc= d.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.DefaultValueF= romDec, TAB_VOID)(True) @@ -1982,18 +1998,35 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error("Build", FORMAT_INVALID, "Invalid value for= mat for %s.%s, from DEC: %s" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, D= efaultValueFromDec)) 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.TokenSpa= ceGuidCName, 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_INI= T_Value) < %d * sizeof(%s)? sizeof(%s_%s_INIT_Value): %d * sizeof(%s);\n' %= (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType, Pc= d.TokenSpaceGuidCName, Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s_INI= T_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_INIT_Value,PcdArr= aySize);\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,pcdarraysize= ,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' % ValueSi= ze + CApp =3D CApp + ' Value =3D %s; // From DEC Defaul= t Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultVal= ueFromDec) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArraySize);\n= ' else: - CApp =3D CApp + ' Value =3D %s; // From DEC Default Va= lue %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFr= omDec) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize= ) + if "{CODE(" in Pcd.DefaultValueFromDec: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s_INIT_V= alue);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_INIT_Value,PcdAr= raySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + else: + CApp =3D CApp + ' Value =3D %s; // From DEC Defaul= t Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultVal= ueFromDec) + CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (Value= Size) 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" % (SkuNam= e, DefaultStoreName) CApp =3D CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.= TokenSpaceGuidCName, Pcd.TokenCName, SkuName, DefaultStoreName, Pcd.BaseDatu= mType) CApp =3D CApp + ' UINT32 FieldSize;\n' CApp =3D CApp + ' CHAR8 *Value;\n' + CApp =3D CApp + ' UINT32 PcdArraySize;\n' CApp =3D CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_D= EFAULT, TAB_DEFAULT_STORES_DEFAULT) inherit_OverrideValues =3D Pcd.SkuOverrideValues[SkuName] pcddefaultvalue =3D self.GetPcdDscRawDefaultValue(Pcd, SkuName, Def= aultStoreName) @@ -2072,37 +2106,83 @@ class DscBuildData(PlatformBuildClassObject): Value, ValueSize =3D ParseFieldValue (FieldList) if (SkuName, DefaultStoreName) =3D=3D (TAB_DEFAULT, TAB_DEFAULT= _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,S= kuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + 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,pcd= arraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName= , DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Val= ue,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + else: + CApp =3D CApp+ ' PcdArraySize =3D sizeof(%s_%s_= %s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, Defaul= tStoreName) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Va= lue,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, D= efaultStoreName) else: CApp =3D CApp + ' Pcd =3D %s; // From DSC Default= Value %s\n' % (Value, Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAU= LT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultV= alue) 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,S= kuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + # + # 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 * sizeof(= %s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName= ,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Sku= Name, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%= s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, D= efaultStoreName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Val= ue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + else: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D %d < siz= eof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdar= raysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' %= ValueSize + CApp =3D CApp + ' Value =3D %s; // From DS= C Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.De= faultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Defaul= tValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArray= Size);\n' else: - CApp =3D CApp + ' Value =3D %s; // From DSC De= fault Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.Defaul= tFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultVal= ue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (V= alueSize) + if "{CODE(" in pcddefaultvalue: + CApp =3D CApp + ' PcdArraySize =3D %d < sizeof= (%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarray= size,ValueSize,Pcd.BaseDatumType,pcdarraysize) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, D= efaultStoreName) + else: + CApp =3D CApp + ' Value =3D %s; // From DS= C Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.De= faultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.Defaul= tValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value, %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,S= kuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + 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,pcd= arraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName= , DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Val= ue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + else: + CApp =3D CApp + ' PcdArraySize =3D sizeof(%s_%s= _%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, Defaul= tStoreName) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, D= efaultStoreName) else: CApp =3D CApp + ' Pcd =3D %s; // From DSC Default= Value %s\n' % (Value, Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName= )) 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,S= kuName, DefaultStoreName,Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + # + # 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 * sizeof(= %s);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultStoreName= ,pcdarraysize,Pcd.BaseDatumType, Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Sku= Name, DefaultStoreName,pcdarraysize,Pcd.BaseDatumType) + else: + CApp + ' PcdArraySize =3D sizeof(%s_%s_%s_%= s_Value);\n ' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, DefaultSto= reName) + CApp =3D CApp + ' memcpy (Pcd, %s_%s_%s_%s_Val= ue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, De= faultStoreName) + else: + if Pcd.Capacity[-1] !=3D "-1": + CApp =3D CApp + ' PcdArraySize =3D %d < siz= eof(%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdar= raysize,ValueSize,Pcd.BaseDatumType,pcdarraysize) + else: + CApp =3D CApp + ' PcdArraySize =3D %d;\n' %= ValueSize + CApp =3D CApp + ' Value =3D %s; // From DS= C Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.Ds= cRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultVa= lue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp =3D CApp + ' memcpy (Pcd, Value, PcdArray= Size);\n' else: - CApp =3D CApp + ' Value =3D %s; // From DSC De= fault Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRaw= Value.get(SkuName, {}).get(DefaultStoreName)) - CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n' % (V= alueSize) + if "{CODE(" in pcddefaultvalue: + CApp =3D CApp + ' PcdArraySize =3D %d < sizeof= (%s) * %d ? %d: sizeof(%s) * %d;\n ' % (ValueSize,Pcd.BaseDatumType,pcdarray= size,ValueSize,Pcd.BaseDatumType,pcdarraysize) + CApp =3D CApp + ' memcpy (Pcd, &%s_%s_%s_%s_Va= lue, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName, D= efaultStoreName) + else: + CApp =3D CApp + ' Value =3D %s; // From DS= C Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.Ds= cRawValue.get(SkuName, {}).get(DefaultStoreName)) + CApp =3D CApp + ' memcpy (Pcd, Value, %d);\n'= % (ValueSize) 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 be= the last field # in a structure. The size formula for this case is: # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (Hi= ghestIndex + 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.PcdArray= Size(),Pcd.BaseDatumType,Pcd.PcdArraySize()) + CApp =3D CApp + ' Size =3D sizeof(%s) * %d; \n' % (Pcd.Bas= eDatumType,Pcd.PcdArraySize()) # # 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): 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 "[]" 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 proprietar= y to American Megatrends, Inc. This communication is intended to be read on= ly by the individual or entity to whom it is addressed or by their designee.= If the reader of this message is not the intended recipient, you are on not= ice that any distribution of this message, in any form, is strictly prohibit= ed. Please promptly notify the sender by reply e-mail or by telephone at 77= 0-246-8600, and then delete or destroy all copies of the transmission.