]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Misc.py
BaseTools: Fix the bug to parse the new map file format
[mirror_edk2.git] / BaseTools / Source / Python / Common / Misc.py
index 777450d81860a1e9e92daf9d9405c68315a82eba..43d08183f7ebcba7bb935296f171aab087f2744b 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Common routines used by all tools\r
 #\r
-# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -74,7 +74,7 @@ def _parseForGCC(lines, efifilepath, varnames):
     status = 0\r
     sections = []\r
     varoffset = []\r
-    for line in lines:\r
+    for index, line in enumerate(lines):\r
         line = line.strip()\r
         # status machine transection\r
         if status == 0 and line == "Memory Configuration":\r
@@ -88,14 +88,17 @@ def _parseForGCC(lines, efifilepath, varnames):
             continue\r
 \r
         # status handler\r
-        if status == 2:\r
+        if status == 3:\r
             m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)\r
             if m != None:\r
                 sections.append(m.groups(0))\r
             for varname in varnames:\r
-                m = re.match("^([\da-fA-Fx]+) +[_]*(%s)$" % varname, line)\r
+                m = re.match(".data.(%s)$" % varname, line)\r
                 if m != None:\r
-                    varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
+                    if lines[index + 1]:\r
+                        m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip())\r
+                        if m != None:\r
+                            varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
 \r
     if not varoffset:\r
         return []\r
@@ -794,13 +797,18 @@ def GetRelPath(Path1, Path2):
 #\r
 #   @param      CName           The CName of the GUID\r
 #   @param      PackageList     List of packages looking-up in\r
+#   @param      Inffile         The driver file\r
 #\r
 #   @retval     GuidValue   if the CName is found in any given package\r
 #   @retval     None        if the CName is not found in all given packages\r
 #\r
-def GuidValue(CName, PackageList):\r
+def GuidValue(CName, PackageList, Inffile = None):\r
     for P in PackageList:\r
-        if CName in P.Guids:\r
+        GuidKeys = P.Guids.keys()\r
+        if Inffile and P._PrivateGuids:\r
+            if not Inffile.startswith(P.MetaFile.Dir):\r
+                GuidKeys = (dict.fromkeys(x for x in P.Guids if x not in P._PrivateGuids)).keys()\r
+        if CName in GuidKeys:\r
             return P.Guids[CName]\r
     return None\r
 \r
@@ -808,13 +816,18 @@ def GuidValue(CName, PackageList):
 #\r
 #   @param      CName           The CName of the GUID\r
 #   @param      PackageList     List of packages looking-up in\r
+#   @param      Inffile         The driver file\r
 #\r
 #   @retval     GuidValue   if the CName is found in any given package\r
 #   @retval     None        if the CName is not found in all given packages\r
 #\r
-def ProtocolValue(CName, PackageList):\r
+def ProtocolValue(CName, PackageList, Inffile = None):\r
     for P in PackageList:\r
-        if CName in P.Protocols:\r
+        ProtocolKeys = P.Protocols.keys()\r
+        if Inffile and P._PrivateProtocols:\r
+            if not Inffile.startswith(P.MetaFile.Dir):\r
+                ProtocolKeys = (dict.fromkeys(x for x in P.Protocols if x not in P._PrivateProtocols)).keys()\r
+        if CName in ProtocolKeys:\r
             return P.Protocols[CName]\r
     return None\r
 \r
@@ -822,13 +835,18 @@ def ProtocolValue(CName, PackageList):
 #\r
 #   @param      CName           The CName of the GUID\r
 #   @param      PackageList     List of packages looking-up in\r
+#   @param      Inffile         The driver file\r
 #\r
 #   @retval     GuidValue   if the CName is found in any given package\r
 #   @retval     None        if the CName is not found in all given packages\r
 #\r
-def PpiValue(CName, PackageList):\r
+def PpiValue(CName, PackageList, Inffile = None):\r
     for P in PackageList:\r
-        if CName in P.Ppis:\r
+        PpiKeys = P.Ppis.keys()\r
+        if Inffile and P._PrivatePpis:\r
+            if not Inffile.startswith(P.MetaFile.Dir):\r
+                PpiKeys = (dict.fromkeys(x for x in P.Ppis if x not in P._PrivatePpis)).keys()\r
+        if CName in PpiKeys:\r
             return P.Ppis[CName]\r
     return None\r
 \r
@@ -1397,32 +1415,7 @@ def ParseConsoleLog(Filename):
     Opr.close()\r
     Opw.close()\r
 \r
-## AnalyzeDscPcd\r
-#\r
-#  Analyze DSC PCD value, since there is no data type info in DSC\r
-#  This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from database\r
-#  1. Feature flag: TokenSpace.PcdCName|PcdValue\r
-#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]\r
-#  3. Dynamic default:\r
-#     TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]\r
-#     TokenSpace.PcdCName|PcdValue\r
-#  4. Dynamic VPD:\r
-#     TokenSpace.PcdCName|VpdOffset[|VpdValue]\r
-#     TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]\r
-#  5. Dynamic HII:\r
-#     TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]\r
-#  PCD value needs to be located in such kind of string, and the PCD value might be an expression in which\r
-#    there might have "|" operator, also in string value.\r
-#\r
-#  @param Setting: String contain information described above with "TokenSpace.PcdCName|" stripped\r
-#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII\r
-#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL\r
-#  @retval:\r
-#    ValueList: A List contain fields described above\r
-#    IsValid:   True if conforming EBNF, otherwise False\r
-#    Index:     The index where PcdValue is in ValueList\r
-#\r
-def AnalyzeDscPcd(Setting, PcdType, DataType=''):\r
+def AnalyzePcdExpression(Setting):\r
     Setting = Setting.strip()\r
     # There might be escaped quote in a string: \", \\\"\r
     Data = Setting.replace('\\\\', '//').replace('\\\"', '\\\'')\r
@@ -1452,6 +1445,36 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
         FieldList.append(Setting[StartPos:Pos].strip())\r
         StartPos = Pos + 1\r
 \r
+    return FieldList\r
+\r
+## AnalyzeDscPcd\r
+#\r
+#  Analyze DSC PCD value, since there is no data type info in DSC\r
+#  This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from database\r
+#  1. Feature flag: TokenSpace.PcdCName|PcdValue\r
+#  2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]\r
+#  3. Dynamic default:\r
+#     TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]\r
+#     TokenSpace.PcdCName|PcdValue\r
+#  4. Dynamic VPD:\r
+#     TokenSpace.PcdCName|VpdOffset[|VpdValue]\r
+#     TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]\r
+#  5. Dynamic HII:\r
+#     TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]\r
+#  PCD value needs to be located in such kind of string, and the PCD value might be an expression in which\r
+#    there might have "|" operator, also in string value.\r
+#\r
+#  @param Setting: String contain information described above with "TokenSpace.PcdCName|" stripped\r
+#  @param PcdType: PCD type: feature, fixed, dynamic default VPD HII\r
+#  @param DataType: The datum type of PCD: VOID*, UNIT, BOOL\r
+#  @retval:\r
+#    ValueList: A List contain fields described above\r
+#    IsValid:   True if conforming EBNF, otherwise False\r
+#    Index:     The index where PcdValue is in ValueList\r
+#\r
+def AnalyzeDscPcd(Setting, PcdType, DataType=''):\r
+    FieldList = AnalyzePcdExpression(Setting)\r
+\r
     IsValid = True\r
     if PcdType in (MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG):\r
         Value = FieldList[0]\r