]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py
Sync BaseTool trunk (version r2610) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / Python / GenPatchPcdTable / GenPatchPcdTable.py
index ca4440f9a2ddb5bb6a761190f81d86c3f48a21ba..6deb0f8471f299c1bde63adf062ea5b7bd2c15a7 100644 (file)
@@ -5,7 +5,7 @@
 #    PCD Name    Offset in binary
 #    ========    ================\r
 #\r
-# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2013, 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
@@ -54,39 +54,54 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
     
     if len(lines) == 0: return None
     if lines[0].strip().find("Archive member included because of file (symbol)") != -1:
-        return _parseForGCC(lines)
+        return _parseForGCC(lines, efifilepath)
     return _parseGeneral(lines, efifilepath)
-    
-def _parseForGCC(lines):
+
+def _parseForGCC(lines, efifilepath):
     """ Parse map file generated by GCC linker """
-    status       = 0
-    imageBase    = -1
-    lastSectionName = None
-    pcds         = []
+    status = 0
+    imageBase = -1
+    sections = []
+    bpcds = []
     for line in lines:
         line = line.strip()
         # status machine transection
-        if status == 0 and line == "Linker script and memory map":
+        if status == 0 and line == "Memory Configuration":
             status = 1
             continue
-        elif status == 1 and line == 'START GROUP':
+        elif status == 1 and line == 'Linker script and memory map':
             status = 2
             continue
-        
-        # status handler:
-        if status == 1:
-            m = re.match('^[\da-fA-FxhH]+ +__image_base__ += +([\da-fA-FhxH]+)', line)
-            if m != None:
-                imageBase = int(m.groups(0)[0], 16)
+        elif status ==2 and line == 'START GROUP':
+            status = 3
+            continue
+
+        # status handler\r
         if status == 2:
-            m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)', line)
+            m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)
             if m != None:
-                lastSectionName = m.groups(0)[0]
+                sections.append(m.groups(0))
         if status == 2:
-            m = re.match("^([\da-fA-Fx]+) +[_]+gPcd_BinaryPatch_([\w_\d]+)", line)
+            m = re.match("^([\da-fA-Fx]+) +[_]+gPcd_BinaryPatch_([\w_\d]+)$", line)
             if m != None:
-                assert imageBase != -1, "Fail to get Binary PCD offsest for unknown image base address"
-                pcds.append((m.groups(0)[1], int(m.groups(0)[0], 16) - imageBase, lastSectionName))
+                bpcds.append((m.groups(0)[1], int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))
+                \r
+    # get section information from efi file\r
+    efisecs = PeImageClass(efifilepath).SectionHeaderList\r
+    if efisecs == None or len(efisecs) == 0:\r
+        return None\r
+    #redirection\r
+    redirection = 0\r
+    for efisec in efisecs:\r
+        for section in sections:\r
+            if section[0].strip() == efisec[0].strip() and section[0].strip() == '.text':\r
+                redirection = int(section[1], 16) - efisec[1]\r
+    pcds = []\r
+    for pcd in bpcds:\r
+        for efisec in efisecs:\r
+            if pcd[1] >= efisec[1] and pcd[1] < efisec[1]+efisec[3]:\r
+                #assert efisec[0].strip() == pcd[3].strip() and efisec[1] + redirection == pcd[2], "There are some differences between map file and efi file"\r
+                pcds.append([pcd[0], efisec[2] + pcd[1] - efisec[1] - redirection, efisec[0]])\r
     return pcds
                 
 def _parseGeneral(lines, efifilepath):