BaseTools: Enable structure pcd in FDF file
authorBobCF <bob.c.feng@intel.com>
Fri, 22 Jun 2018 09:14:13 +0000 (17:14 +0800)
committerLiming Gao <liming.gao@intel.com>
Fri, 13 Jul 2018 09:25:43 +0000 (17:25 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/AutoGen/GenC.py
BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools/Source/Python/Workspace/BuildClassObject.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/build/BuildReport.py

index 54c6b73..289309f 100644 (file)
@@ -568,7 +568,7 @@ class WorkspaceAutoGen(AutoGen):
                     DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
 \r
             Platform.SkuName = self.SkuId\r
-            for Name, Guid in PcdSet:\r
+            for Name, Guid,Fileds in PcdSet:\r
                 if (Name, Guid) not in DecPcds:\r
                     EdkLogger.error(\r
                         'build',\r
@@ -582,7 +582,6 @@ class WorkspaceAutoGen(AutoGen):
                     if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
                         or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
                         or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
-                        Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
                         continue\r
                     elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
                         EdkLogger.error(\r
index eac41ed..2dca9ff 100644 (file)
@@ -890,6 +890,8 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
 \r
     if Pcd.PcdValueFromComm:\r
         Pcd.DefaultValue = Pcd.PcdValueFromComm\r
+    elif Pcd.PcdValueFromFdf:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
 \r
     if Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
         TokenNumber = int(Pcd.TokenValue, 0)\r
@@ -1183,6 +1185,8 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
 \r
     if Pcd.PcdValueFromComm:\r
         Pcd.DefaultValue = Pcd.PcdValueFromComm\r
+    elif Pcd.PcdValueFromFdf:\r
+        Pcd.DefaultValue = Pcd.PcdValueFromFdf\r
     #\r
     # Write PCDs\r
     #\r
index 67217c3..e2e6df7 100644 (file)
@@ -83,13 +83,12 @@ T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_
 SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')\r
 \r
 RegionSizePattern = re.compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")\r
-RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
-RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*$")\r
+RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*")\r
+RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$")\r
 ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
 BaseAddrValuePattern = re.compile('^0[xX][0-9a-fA-F]+')\r
 FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
 TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-\r
 AllIncludeFileList = []\r
 \r
 # Get the closest parent\r
@@ -226,8 +225,9 @@ class FileProfile :
         except:\r
             EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
 \r
-\r
+        self.FileName = FileName\r
         self.PcdDict = {}\r
+        self.PcdLocalDict = {}\r
         self.InfList = []\r
         self.InfDict = {'ArchTBD':[]}\r
         # ECC will use this Dict and List information\r
@@ -787,7 +787,7 @@ class FdfParser:
                     continue\r
                 SetLine = self.CurrentLineNumber - 1\r
                 SetOffset = self.CurrentOffsetWithinLine - len('SET')\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 PcdName = "%s.%s" % (PcdPair[1], PcdPair[0])\r
                 if not self.__IsToken( "="):\r
                     raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
@@ -798,6 +798,7 @@ class FdfParser:
                 self.__PcdDict[PcdName] = Value\r
 \r
                 self.Profile.PcdDict[PcdPair] = Value\r
+                self.SetPcdLocalation(PcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
 \r
@@ -1049,6 +1050,29 @@ class FdfParser:
 \r
         return False\r
 \r
+    def __GetNextPcdWord(self):\r
+        self.__SkipWhiteSpace()\r
+        if self.__EndOfFile():\r
+            return False\r
+\r
+        TempChar = self.__CurrentChar()\r
+        StartPos = self.CurrentOffsetWithinLine\r
+        if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') or TempChar == '_' or TempChar == '[' or TempChar == ']':\r
+            self.__GetOneChar()\r
+            while not self.__EndOfLine():\r
+                TempChar = self.__CurrentChar()\r
+                if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') \\r
+                or (TempChar >= '0' and TempChar <= '9') or TempChar == '_' or TempChar == '-' or TempChar == '[' or TempChar == ']':\r
+                    self.__GetOneChar()\r
+\r
+                else:\r
+                    break\r
+\r
+            self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
+            return True\r
+\r
+        return False\r
+\r
     ## __GetNextToken() method\r
     #\r
     #   Get next token unit before a seperator\r
@@ -1240,6 +1264,26 @@ class FdfParser:
 \r
         return (pcdCName, pcdTokenSpaceCName)\r
 \r
+    def __GetNextPcdSettings(self):\r
+        if not self.__GetNextWord():\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+        pcdTokenSpaceCName = self.__Token\r
+\r
+        if not self.__IsToken( "."):\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+\r
+        if not self.__GetNextWord():\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+        pcdCName = self.__Token\r
+\r
+        Fields = []\r
+        while self.__IsToken("."):\r
+            if not self.__GetNextPcdWord():\r
+                raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+            Fields.append(self.__Token)\r
+\r
+        return (pcdCName, pcdTokenSpaceCName,".".join(Fields))\r
+\r
     ## __GetStringData() method\r
     #\r
     #   Get string contents quoted in ""\r
@@ -1567,6 +1611,9 @@ class FdfParser:
 \r
         return True\r
 \r
+    def SetPcdLocalation(self,pcdpair):\r
+        self.Profile.PcdLocalDict[pcdpair] = (self.Profile.FileName,self.CurrentLineNumber)\r
+\r
     ## __GetTokenStatements() method\r
     #\r
     #   Get token statements\r
@@ -1585,9 +1632,10 @@ class FdfParser:
             Obj.BaseAddress = self.__Token\r
 \r
             if self.__IsToken( "|"):\r
-                pcdPair = self.__GetNextPcdName()\r
+                pcdPair = self.__GetNextPcdSettings()\r
                 Obj.BaseAddressPcd = pcdPair\r
                 self.Profile.PcdDict[pcdPair] = Obj.BaseAddress\r
+                self.SetPcdLocalation(pcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
             return True\r
@@ -1601,9 +1649,10 @@ class FdfParser:
 \r
             Size = self.__Token\r
             if self.__IsToken( "|"):\r
-                pcdPair = self.__GetNextPcdName()\r
+                pcdPair = self.__GetNextPcdSettings()\r
                 Obj.SizePcd = pcdPair\r
                 self.Profile.PcdDict[pcdPair] = Size\r
+                self.SetPcdLocalation(pcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
             Obj.Size = long(Size, 0)\r
@@ -1694,9 +1743,10 @@ class FdfParser:
         BlockSize = self.__Token\r
         BlockSizePcd = None\r
         if self.__IsToken( "|"):\r
-            PcdPair = self.__GetNextPcdName()\r
+            PcdPair = self.__GetNextPcdSettings()\r
             BlockSizePcd = PcdPair\r
             self.Profile.PcdDict[PcdPair] = BlockSize\r
+            self.SetPcdLocalation(PcdPair)\r
             FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
         BlockSize = long(BlockSize, 0)\r
@@ -1777,7 +1827,7 @@ class FdfParser:
     #\r
     def __GetSetStatement(self, Obj):\r
         if self.__IsKeyword("SET"):\r
-            PcdPair = self.__GetNextPcdName()\r
+            PcdPair = self.__GetNextPcdSettings()\r
 \r
             if not self.__IsToken( "="):\r
                 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
@@ -1788,6 +1838,7 @@ class FdfParser:
             if Obj:\r
                 Obj.SetVarDict[PcdPair] = Value\r
             self.Profile.PcdDict[PcdPair] = Value\r
+            self.SetPcdLocalation(PcdPair)\r
             FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
             return True\r
@@ -1864,14 +1915,16 @@ class FdfParser:
             IsRegionPcd = (RegionSizeGuidPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]) or\r
                            RegionOffsetPcdPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]))\r
             if IsRegionPcd:\r
-                RegionObj.PcdOffset = self.__GetNextPcdName()\r
+                RegionObj.PcdOffset = self.__GetNextPcdSettings()\r
                 self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + long(Fd.BaseAddress, 0))\r
+                self.SetPcdLocalation(RegionObj.PcdOffset)\r
                 self.__PcdDict['%s.%s' % (RegionObj.PcdOffset[1], RegionObj.PcdOffset[0])] = "0x%x" % RegionObj.Offset\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[RegionObj.PcdOffset] = FileLineTuple\r
                 if self.__IsToken( "|"):\r
-                    RegionObj.PcdSize = self.__GetNextPcdName()\r
+                    RegionObj.PcdSize = self.__GetNextPcdSettings()\r
                     self.Profile.PcdDict[RegionObj.PcdSize] = "0x%08X" % RegionObj.Size\r
+                    self.SetPcdLocalation(RegionObj.PcdSize)\r
                     self.__PcdDict['%s.%s' % (RegionObj.PcdSize[1], RegionObj.PcdSize[0])] = "0x%x" % RegionObj.Size\r
                     FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                     self.Profile.PcdFileLineDict[RegionObj.PcdSize] = FileLineTuple\r
@@ -2609,7 +2662,7 @@ class FdfParser:
             if self.__Token == 'PCD':\r
                 if not self.__IsToken( "("):\r
                     raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 if not self.__IsToken( ")"):\r
                     raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
@@ -3697,7 +3750,7 @@ class FdfParser:
             if self.__Token == 'PCD':\r
                 if not self.__IsToken( "("):\r
                     raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 if not self.__IsToken( ")"):\r
                     raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
@@ -3971,7 +4024,7 @@ class FdfParser:
                     if self.__Token == 'PCD':\r
                         if not self.__IsToken( "("):\r
                             raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                        PcdPair = self.__GetNextPcdName()\r
+                        PcdPair = self.__GetNextPcdSettings()\r
                         if not self.__IsToken( ")"):\r
                             raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                         self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
index c188b47..3b47715 100644 (file)
@@ -70,7 +70,8 @@ class PcdClassObject(object):
         if IsDsc:\r
             self.DscDefaultValue = Value\r
         self.PcdValueFromComm = ""\r
-        self.DefinitionPosition = ("", "")\r
+        self.PcdValueFromFdf = ""\r
+        self.DefinitionPosition = ("","")\r
 \r
     ## Get the maximum number of bytes\r
     def GetPcdMaxSize(self):\r
@@ -78,6 +79,16 @@ class PcdClassObject(object):
             return MAX_SIZE_TYPE[self.DatumType]\r
 \r
         MaxSize = int(self.MaxDatumSize, 10) if self.MaxDatumSize else 0\r
+        if self.PcdValueFromFdf:\r
+            if self.PcdValueFromFdf.startswith("{") and self.PcdValueFromFdf.endswith("}"):\r
+                MaxSize =  max([len(self.PcdValueFromFdf.split(",")),MaxSize])\r
+            elif self.PcdValueFromFdf.startswith("\"") or self.PcdValueFromFdf.startswith("\'"):\r
+                MaxSize =  max([len(self.PcdValueFromFdf)-2+1,MaxSize])\r
+            elif self.PcdValueFromFdf.startswith("L\""):\r
+                MaxSize =  max([2*(len(self.PcdValueFromFdf)-3+1),MaxSize])\r
+            else:\r
+                MaxSize = max([len(self.PcdValueFromFdf),MaxSize])\r
+\r
         if self.PcdValueFromComm:\r
             if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):\r
                 return max([len(self.PcdValueFromComm.split(",")), MaxSize])\r
@@ -169,6 +180,7 @@ class StructurePcd(PcdClassObject):
         self.DefaultValueFromDec = ""\r
         self.ValueChain = set()\r
         self.PcdFieldValueFromComm = collections.OrderedDict()\r
+        self.PcdFieldValueFromFdf = collections.OrderedDict()\r
     def __repr__(self):\r
         return self.TypeName\r
 \r
@@ -216,6 +228,7 @@ class StructurePcd(PcdClassObject):
         self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions\r
         self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue\r
         self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm\r
+        self.PcdValueFromFdf = PcdObject.PcdValueFromFdf if PcdObject.PcdValueFromFdf else self.PcdValueFromFdf\r
         self.DefinitionPosition = PcdObject.DefinitionPosition if PcdObject.DefinitionPosition else self.DefinitionPosition\r
         if isinstance(PcdObject, StructurePcd):\r
             self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile\r
@@ -231,6 +244,7 @@ class StructurePcd(PcdClassObject):
             self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath\r
             self.ValueChain = PcdObject.ValueChain if PcdObject.ValueChain else self.ValueChain\r
             self.PcdFieldValueFromComm = PcdObject.PcdFieldValueFromComm if PcdObject.PcdFieldValueFromComm else self.PcdFieldValueFromComm\r
+            self.PcdFieldValueFromFdf = PcdObject.PcdFieldValueFromFdf if PcdObject.PcdFieldValueFromFdf else self.PcdFieldValueFromFdf\r
 \r
 ## LibraryClassObject\r
 #\r
index 5cc8141..1db201f 100644 (file)
@@ -1131,7 +1131,8 @@ class DscBuildData(PlatformBuildClassObject):
             self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))\r
 \r
             self._Pcds = self.CompletePcdValues(self._Pcds)\r
-            self._Pcds = self.OverrideByFdfCommOverAll(self._Pcds)\r
+            self._Pcds = self.OverrideByFdfOverAll(self._Pcds)\r
+            self._Pcds = self.OverrideByCommOverAll(self._Pcds)\r
             self._Pcds = self.UpdateStructuredPcds(MODEL_PCD_TYPE_LIST, self._Pcds)\r
             self._Pcds = self.CompleteHiiPcdsDefaultStores(self._Pcds)\r
             self._Pcds = self._FilterPcdBySkuUsage(self._Pcds)\r
@@ -1191,7 +1192,34 @@ class DscBuildData(PlatformBuildClassObject):
         return structure_pcd_data\r
 \r
     @staticmethod\r
-    def OverrideByFdfComm(StruPcds):\r
+    def OverrideByFdf(StruPcds,workspace):\r
+        if GlobalData.gFdfParser is None:\r
+            return StruPcds\r
+        StructurePcdInFdf = OrderedDict()\r
+        fdfpcd = GlobalData.gFdfParser.Profile.PcdDict\r
+        fdfpcdlocation = GlobalData.gFdfParser.Profile.PcdLocalDict\r
+        for item in fdfpcd :\r
+            if len(item[2]) and (item[0],item[1]) in StruPcds:\r
+                StructurePcdInFdf[(item[1],item[0],item[2] )] = fdfpcd[item]\r
+        GlobalPcds = {(item[0],item[1]) for item in StructurePcdInFdf}\r
+        for Pcd in StruPcds.values():\r
+            if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) not in GlobalPcds:\r
+                continue\r
+            FieldValues = OrderedDict()\r
+            for item in StructurePcdInFdf:\r
+                if (Pcd.TokenSpaceGuidCName,Pcd.TokenCName) == (item[0],item[1]) and item[2]:\r
+                    FieldValues[item[2]] = StructurePcdInFdf[item]\r
+            for field in FieldValues:\r
+                if field not in Pcd.PcdFieldValueFromFdf:\r
+                    Pcd.PcdFieldValueFromFdf[field] = ["","",""]\r
+                Pcd.PcdFieldValueFromFdf[field][0] = FieldValues[field]\r
+                Pcd.PcdFieldValueFromFdf[field][1] = os.path.relpath(fdfpcdlocation[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName,field)][0],workspace)\r
+                Pcd.PcdFieldValueFromFdf[field][2] = fdfpcdlocation[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName,field)][1]\r
+\r
+        return StruPcds\r
+\r
+    @staticmethod\r
+    def OverrideByComm(StruPcds):\r
         StructurePcdInCom = OrderedDict()\r
         for item in GlobalData.BuildOptionPcd:\r
             if len(item) == 5 and (item[1], item[0]) in StruPcds:\r
@@ -1212,7 +1240,8 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcd.PcdFieldValueFromComm[field][2] = FieldValues[field][1][1]\r
         return StruPcds\r
 \r
-    def OverrideByFdfCommOverAll(self, AllPcds):\r
+\r
+    def OverrideByCommOverAll(self,AllPcds):\r
         def CheckStructureInComm(commpcds):\r
             if not commpcds:\r
                 return False\r
@@ -1259,6 +1288,50 @@ class DscBuildData(PlatformBuildClassObject):
                         self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
                         self.Pcds[Name, Guid].DefaultValue = NoFiledValues[( Guid, Name)][0]\r
         return AllPcds\r
+\r
+    def OverrideByFdfOverAll(self,AllPcds):\r
+\r
+        if GlobalData.gFdfParser is None:\r
+            return AllPcds\r
+        NoFiledValues = GlobalData.gFdfParser.Profile.PcdDict\r
+        for Guid,Name,Field in NoFiledValues:\r
+            if len(Field):\r
+                continue\r
+            Value = NoFiledValues[(Guid,Name,Field)]\r
+            if (Name,Guid) in AllPcds:\r
+                Pcd = AllPcds.get((Name,Guid))\r
+                if isinstance(self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName), None),StructurePcd):\r
+                    self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName)).PcdValueFromComm = Value\r
+                else:\r
+                    Pcd.PcdValueFromComm = Value\r
+                    Pcd.DefaultValue = Value\r
+                    for sku in Pcd.SkuInfoList:\r
+                        SkuInfo = Pcd.SkuInfoList[sku]\r
+                        if SkuInfo.DefaultValue:\r
+                            SkuInfo.DefaultValue = Value\r
+                        else:\r
+                            SkuInfo.HiiDefaultValue = Value\r
+                            for defaultstore in SkuInfo.DefaultStoreDict:\r
+                                SkuInfo.DefaultStoreDict[defaultstore] = Value\r
+                    if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII]]:\r
+                        if Pcd.DatumType == TAB_VOID:\r
+                            if not Pcd.MaxDatumSize:\r
+                                Pcd.MaxDatumSize = '0'\r
+                            CurrentSize = int(Pcd.MaxDatumSize,16) if Pcd.MaxDatumSize.upper().startswith("0X") else int(Pcd.MaxDatumSize)\r
+                            OptionSize = len((StringToArray(Pcd.PcdValueFromComm)).split(","))\r
+                            MaxSize = max(CurrentSize, OptionSize)\r
+                            Pcd.MaxDatumSize = str(MaxSize)\r
+            else:\r
+                PcdInDec = self.DecPcds.get((Name,Guid))\r
+                if PcdInDec:\r
+                    PcdInDec.PcdValueFromComm = Value\r
+                    if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
+                                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE],\r
+                                        self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]]:\r
+                        self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec)\r
+                        self.Pcds[Name, Guid].DefaultValue = Value\r
+        return AllPcds\r
+\r
     def UpdateStructuredPcds(self, TypeList, AllPcds):\r
 \r
         DynamicPcdType = [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
@@ -1368,7 +1441,8 @@ class DscBuildData(PlatformBuildClassObject):
                         if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:\r
                             stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])\r
                             stru_pcd.ValueChain.add((skuid, defaultstoreid))\r
-        S_pcd_set = DscBuildData.OverrideByFdfComm(S_pcd_set)\r
+        S_pcd_set = DscBuildData.OverrideByFdf(S_pcd_set,self.WorkspaceDir)\r
+        S_pcd_set = DscBuildData.OverrideByComm(S_pcd_set)\r
         Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)\r
         if Str_Pcd_Values:\r
             for (skuname, StoreName, PcdGuid, PcdName, PcdValue) in Str_Pcd_Values:\r
@@ -1594,6 +1668,30 @@ class DscBuildData(PlatformBuildClassObject):
                             while '[' in FieldName:\r
                                 FieldName = FieldName.rsplit('[', 1)[0]\r
                                 CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, FieldList[FieldName_ori][1], FieldList[FieldName_ori][2], FieldList[FieldName_ori][0])\r
+        if Pcd.PcdFieldValueFromFdf:\r
+            CApp = CApp + "// From fdf \n"\r
+        for FieldName in Pcd.PcdFieldValueFromFdf:\r
+            FieldName = "." + FieldName\r
+            IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0])\r
+            if IsArray and not (Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0].endswith('}')):\r
+                try:\r
+                    Value = ValueExpressionEx(Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0], TAB_VOID, self._GuidDict)(True)\r
+                except BadExpression:\r
+                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
+                                    (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName.strip('.'))), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2]))\r
+                Value, ValueSize = ParseFieldValue(Value)\r
+                CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][1], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][2], Pcd.PcdFieldValueFromFdf[FieldName.strip(".")][0]);\r
+            else:\r
+                NewFieldName = ''\r
+                FieldName_ori = FieldName.strip('.')\r
+                while '[' in  FieldName:\r
+                    NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
+                    ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
+                    FieldName = FieldName.split(']', 1)[1]\r
+                FieldName = NewFieldName + FieldName\r
+                while '[' in FieldName:\r
+                    FieldName = FieldName.rsplit('[', 1)[0]\r
+                    CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %s Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromFdf[FieldName_ori][1], Pcd.PcdFieldValueFromFdf[FieldName_ori][2], Pcd.PcdFieldValueFromFdf[FieldName_ori][0])\r
         if Pcd.PcdFieldValueFromComm:\r
             CApp = CApp + "// From Command Line \n"\r
         for FieldName in Pcd.PcdFieldValueFromComm:\r
@@ -1835,6 +1933,70 @@ class DscBuildData(PlatformBuildClassObject):
     def GenerateCommandLineValueStatement(Pcd):\r
         CApp = '  Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
         return CApp\r
+    def GenerateFdfValue(self,Pcd):\r
+        CApp = "// Value in Fdf\n"\r
+        CApp = CApp + "void Assign_%s_%s_Fdf_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType)\r
+        CApp = CApp + '  UINT32  FieldSize;\n'\r
+        CApp = CApp + '  CHAR8   *Value;\n'\r
+\r
+        pcddefaultvalue = Pcd.PcdValueFromFdf\r
+        for FieldList in [pcddefaultvalue,Pcd.PcdFieldValueFromFdf]:\r
+            if not FieldList:\r
+                continue\r
+            if pcddefaultvalue and FieldList == pcddefaultvalue:\r
+                IsArray = IsFieldValueAnArray(FieldList)\r
+                if IsArray:\r
+                    try:\r
+                        FieldList = ValueExpressionEx(FieldList, TAB_VOID)(True)\r
+                    except BadExpression:\r
+                        EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Fdf: %s" %\r
+                                        (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
+                Value, ValueSize = ParseFieldValue (FieldList)\r
+\r
+                if isinstance(Value, str):\r
+                    CApp = CApp + '  Pcd = %s; // From Fdf \n' % (Value)\r
+                elif IsArray:\r
+                #\r
+                # Use memcpy() to copy value into field\r
+                #\r
+                    CApp = CApp + '  Value     = %s; // From Fdf .\n' % (DscBuildData.IntToCString(Value, ValueSize))\r
+                    CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
+                continue\r
+            for FieldName in FieldList:\r
+                IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
+                if IsArray:\r
+                    try:\r
+                        FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
+                    except BadExpression:\r
+                        EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
+                                        (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
+                    except:\r
+                        print("error")\r
+                try:\r
+                    Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
+                except Exception:\r
+                    EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName,FieldName)),FieldList[FieldName][1], FieldList[FieldName][2]))\r
+                if isinstance(Value, str):\r
+                    CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                elif IsArray:\r
+                #\r
+                # Use memcpy() to copy value into field\r
+                #\r
+                    CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
+                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                    CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
+                else:\r
+                    if ValueSize > 4:\r
+                        CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                    else:\r
+                        CApp = CApp + '  Pcd->%s = %d; // From %s Line %s Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+        CApp = CApp + "}\n"\r
+        return CApp\r
+\r
+    @staticmethod\r
+    def GenerateFdfValueStatement(Pcd):\r
+        CApp = '  Assign_%s_%s_Fdf_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
+        return CApp\r
 \r
     def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp):\r
         OverrideValues = {DefaultStore:""}\r
@@ -1907,6 +2069,7 @@ class DscBuildData(PlatformBuildClassObject):
             else:\r
                 CApp = CApp + "// SkuName: %s,  DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId\r
                 CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
+            CApp = CApp + DscBuildData.GenerateFdfValueStatement(Pcd)\r
             CApp = CApp + DscBuildData.GenerateCommandLineValueStatement(Pcd)\r
             #\r
             # Set new PCD value and size\r
@@ -1943,6 +2106,7 @@ class DscBuildData(PlatformBuildClassObject):
             Pcd = StructuredPcds[PcdName]\r
             CApp = CApp + self.GenerateSizeFunction(Pcd)\r
             CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)\r
+            CApp = CApp + self.GenerateFdfValue(Pcd)\r
             CApp = CApp + self.GenerateCommandLineValue(Pcd)\r
             if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
index 1555ec3..273e7d4 100644 (file)
@@ -1331,6 +1331,9 @@ class PcdReport(object):
             for Key, Values in OverrideStruct.items():\r
                 if Values[1] and Values[1].endswith('.dsc'):\r
                     OverrideFieldStruct[Key] = Values\r
+        if Pcd.PcdFieldValueFromFdf:\r
+            for Key, Values in Pcd.PcdFieldValueFromFdf.items():\r
+                OverrideFieldStruct[Key] = Values\r
         if Pcd.PcdFieldValueFromComm:\r
             for Key, Values in Pcd.PcdFieldValueFromComm.items():\r
                 OverrideFieldStruct[Key] = Values\r