]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FdfParser.py
Sync BaseTools Trunk (version r2524) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index bdb7a777707bc0e9f8443c6112673e81d2e1ffac..c9c620d853803170fe056ffd5946ce786e7ea936 100644 (file)
@@ -77,6 +77,7 @@ SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')
 \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
+ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
 \r
 IncludeFileList = []\r
 \r
@@ -679,7 +680,7 @@ class FdfParser:
                     PreIndex = 0\r
                     StartPos = CurLine.find('$(', PreIndex)\r
                     EndPos = CurLine.find(')', StartPos+2)\r
-                    while StartPos != -1 and EndPos != -1:\r
+                    while StartPos != -1 and EndPos != -1 and self.__Token not in ['!ifdef', '!ifndef', '!if', '!elseif']:\r
                         MacroName = CurLine[StartPos+2 : EndPos]\r
                         MacorValue = self.__GetMacroValue(MacroName)\r
                         if MacorValue != None:\r
@@ -711,6 +712,8 @@ class FdfParser:
                     self.__SetMacroValue(Macro, Value)\r
                     self.__WipeOffArea.append(((DefineLine, DefineOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
             elif self.__Token == 'SET':\r
+                SetLine = self.CurrentLineNumber - 1\r
+                SetOffset = self.CurrentOffsetWithinLine - len('SET')\r
                 PcdPair = self.__GetNextPcdName()\r
                 PcdName = "%s.%s" % (PcdPair[1], PcdPair[0])\r
                 if not self.__IsToken( "="):\r
@@ -720,6 +723,12 @@ class FdfParser:
                 Value = self.__EvaluateConditional(Value, self.CurrentLineNumber, 'eval', True)\r
 \r
                 self.__PcdDict[PcdName] = Value\r
+\r
+                self.Profile.PcdDict[PcdPair] = Value\r
+                FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
+                self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
+\r
+                self.__WipeOffArea.append(((SetLine, SetOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
             elif self.__Token in ('!ifdef', '!ifndef', '!if'):\r
                 IfStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
                 IfList.append([IfStartPos, None, None])\r
@@ -773,6 +782,11 @@ class FdfParser:
                 if self.CurrentLineNumber <= RegionLayoutLine:\r
                     # Don't try the same line twice\r
                     continue\r
+                SetPcd = ShortcutPcdPattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
+                if SetPcd:\r
+                    self.__PcdDict[SetPcd.group('name')] = SetPcd.group('value')\r
+                    RegionLayoutLine = self.CurrentLineNumber\r
+                    continue\r
                 RegionSize = RegionSizePattern.match(self.Profile.FileLinesList[self.CurrentLineNumber - 1])\r
                 if not RegionSize:\r
                     RegionLayoutLine = self.CurrentLineNumber\r
@@ -793,6 +807,7 @@ class FdfParser:
         MacroDict = {}\r
 \r
         # PCD macro\r
+        MacroDict.update(GlobalData.gPlatformPcds)\r
         MacroDict.update(self.__PcdDict)\r
 \r
         # Lowest priority\r
@@ -838,7 +853,19 @@ class FdfParser:
                                 Line=Line)\r
                 return Excpt.result\r
             except Exception, Excpt:\r
-                raise Warning("Invalid expression", *FileLineTuple)\r
+                if hasattr(Excpt, 'Pcd'):\r
+                    if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
+                        Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]\r
+                        raise Warning("Cannot use this PCD (%s) in an expression as"\r
+                                      " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
+                                      " of the DSC file (%s), and it is currently defined in this section:"\r
+                                      " %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]),\r
+                                      *FileLineTuple)\r
+                    else:\r
+                        raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']),\r
+                                      *FileLineTuple)\r
+                else:\r
+                    raise Warning(str(Excpt), *FileLineTuple)\r
         else:\r
             if Expression.startswith('$(') and Expression[-1] == ')':\r
                 Expression = Expression[2:-1]            \r
@@ -2287,6 +2314,10 @@ class FdfParser:
         if not self.__GetNextToken():\r
             raise Warning("expected INF file path", self.FileName, self.CurrentLineNumber)\r
         ffsInf.InfFileName = self.__Token\r
+\r
+        ffsInf.CurrentLineNum = self.CurrentLineNumber\r
+        ffsInf.CurrentLineContent = self.__CurrentLine()\r
+\r
         if ffsInf.InfFileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
             #do case sensitive check for file path\r
             ErrorCode, ErrorInfo = PathClass(NormPath(ffsInf.InfFileName), GenFdsGlobalVariable.WorkSpaceDir).Validate()\r
@@ -2306,9 +2337,6 @@ class FdfParser:
             else:\r
                 raise Warning("Unknown reloc strip flag '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
         \r
-        ffsInf.CurrentLineNum = self.CurrentLineNumber\r
-        ffsInf.CurrentLineContent = self.__CurrentLine()\r
-        \r
         if ForCapsule:\r
             capsuleFfs = CapsuleData.CapsuleFfs()\r
             capsuleFfs.Ffs = ffsInf\r
@@ -2419,9 +2447,6 @@ class FdfParser:
                 \r
         FfsFileObj.NameGuid = self.__Token\r
         \r
-        FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
-        FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
-        \r
         self.__GetFilePart( FfsFileObj, MacroDict.copy())\r
 \r
         if ForCapsule:\r
@@ -2511,6 +2536,8 @@ class FdfParser:
             self.__UndoToken()\r
             self.__GetSectionData( FfsFileObj, MacroDict)\r
         else:\r
+            FfsFileObj.CurrentLineNum = self.CurrentLineNumber\r
+            FfsFileObj.CurrentLineContent = self.__CurrentLine()\r
             FfsFileObj.FileName = self.__Token\r
             if FfsFileObj.FileName.replace('$(WORKSPACE)', '').find('$') == -1:\r
                 #\r
@@ -2840,6 +2867,7 @@ class FdfParser:
             GuidSectionObj.SectionType = "GUIDED"\r
             GuidSectionObj.ProcessRequired = AttribDict["PROCESSING_REQUIRED"]\r
             GuidSectionObj.AuthStatusValid = AttribDict["AUTH_STATUS_VALID"]\r
+            GuidSectionObj.ExtraHeaderSize = AttribDict["EXTRA_HEADER_SIZE"]\r
             # Recursive sections...\r
             while True:\r
                 IsLeafSection = self.__GetLeafSection(GuidSectionObj)\r
@@ -2867,23 +2895,26 @@ class FdfParser:
         AttribDict = {}\r
         AttribDict["PROCESSING_REQUIRED"] = "NONE"\r
         AttribDict["AUTH_STATUS_VALID"] = "NONE"\r
-        if self.__IsKeyword("PROCESSING_REQUIRED") or self.__IsKeyword("AUTH_STATUS_VALID"):\r
+        AttribDict["EXTRA_HEADER_SIZE"] = -1\r
+        while self.__IsKeyword("PROCESSING_REQUIRED") or self.__IsKeyword("AUTH_STATUS_VALID") \\r
+            or self.__IsKeyword("EXTRA_HEADER_SIZE"):\r
             AttribKey = self.__Token\r
 \r
             if not self.__IsToken("="):\r
                 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
 \r
-            if not self.__GetNextToken() or self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
-                raise Warning("expected TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber)\r
-            AttribDict[AttribKey] = self.__Token\r
-\r
-        if self.__IsKeyword("PROCESSING_REQUIRED") or self.__IsKeyword("AUTH_STATUS_VALID"):\r
-            AttribKey = self.__Token\r
-\r
-            if not self.__IsToken("="):\r
-                raise Warning("expected '='")\r
-\r
-            if not self.__GetNextToken() or self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
+            if not self.__GetNextToken():\r
+                raise Warning("expected TRUE(1)/FALSE(0)/Number", self.FileName, self.CurrentLineNumber)\r
+            elif AttribKey == "EXTRA_HEADER_SIZE":\r
+                Base = 10\r
+                if self.__Token[0:2].upper() == "0X":\r
+                    Base = 16\r
+                try:\r
+                    AttribDict[AttribKey] = int(self.__Token, Base)\r
+                    continue\r
+                except ValueError:\r
+                    raise Warning("expected Number", self.FileName, self.CurrentLineNumber)\r
+            elif self.__Token.upper() not in ("TRUE", "FALSE", "1", "0"):\r
                 raise Warning("expected TRUE/FALSE (1/0)", self.FileName, self.CurrentLineNumber)\r
             AttribDict[AttribKey] = self.__Token\r
 \r
@@ -3685,6 +3716,7 @@ class FdfParser:
             GuidSectionObj.SectionType = "GUIDED"\r
             GuidSectionObj.ProcessRequired = AttribDict["PROCESSING_REQUIRED"]\r
             GuidSectionObj.AuthStatusValid = AttribDict["AUTH_STATUS_VALID"]\r
+            GuidSectionObj.ExtraHeaderSize = AttribDict["EXTRA_HEADER_SIZE"]\r
 \r
             # Efi sections...\r
             while True:\r