public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
@ 2021-07-04 11:15 Ashraf Ali S
  0 siblings, 0 replies; 5+ messages in thread
From: Ashraf Ali S @ 2021-07-04 11:15 UTC (permalink / raw)
  To: devel; +Cc: Ashraf Ali S, Ray Ni, Chasel Chiu, Nate DeSimone, Star Zeng

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3476

parseInfFile currently reading the EFI_BASE_ADDRESS from INF, once the
address found still it's continues to read the complete inf file which
is not required. once the EFI_BASE_ADDRESS read from the INF no need to
read the INF further.
MSFT compiler can generate the map file address 8 or 16 based on which
architecture the INF is compiler. currently it's support for IA32,
it can be update the X64 in future.
modification of few typo errors in parseModMapFile, getCurr function
required

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 IntelFsp2Pkg/Tools/PatchFv.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/PatchFv.py b/IntelFsp2Pkg/Tools/PatchFv.py
index 112de4077a..765dfed8ef 100644
--- a/IntelFsp2Pkg/Tools/PatchFv.py
+++ b/IntelFsp2Pkg/Tools/PatchFv.py
@@ -1,6 +1,6 @@
 ## @ PatchFv.py
 #
-# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -297,17 +297,16 @@ class Symbols:
         #
         fvOffset    = self.getFvOffsetInFd(infFile[0:-4] + ".Fv")
         fdIn        = open(infFile, "r")
-        rptLine     = fdIn.readline()
+        rptLines     = fdIn.readlines()
         self.fdBase = 0xFFFFFFFF
-        while (rptLine != "" ):
-            #EFI_BASE_ADDRESS = 0xFFFDF400
-            match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine)
+        for line in rptLines:
+            match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", line)
             if match is not None:
                 self.fdBase = int(match.group(1), 16) - fvOffset
-            rptLine  = fdIn.readline()
+                break
         fdIn.close()
         if self.fdBase == 0xFFFFFFFF:
-            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % fvFile)
+            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % infFile)
         return 0
 
     #
@@ -402,6 +401,7 @@ class Symbols:
     #
     #  retval      0           Parsed MOD MAP file successfully
     #  retval      1           There is no moduleEntryPoint in modSymbols
+    #  retval      2           There is no offset for moduleEntryPoint in modSymbols
     #
     def parseModMapFile(self, moduleName, mapFile):
         #
@@ -426,7 +426,7 @@ class Symbols:
         else:
             #MSFT
             #0003:00000190       _gComBase                  00007a50     SerialPo
-            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
+            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8,16}\s+)"
             matchKeyGroupIndex = 1
             matchSymbolGroupIndex  = 2
             prefix = ''
@@ -498,7 +498,7 @@ class Symbols:
     #
     #  Get current character
     #
-    #  retval      elf.string[self.index]
+    #  retval      self.string[self.index]
     #  retval      ''                       Exception
     #
     def getCurr(self):
-- 
2.26.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
@ 2021-07-04 11:22 Ashraf Ali S
  2021-07-05  1:31 ` Chiu, Chasel
  0 siblings, 1 reply; 5+ messages in thread
From: Ashraf Ali S @ 2021-07-04 11:22 UTC (permalink / raw)
  To: devel; +Cc: Ashraf Ali S, Ray Ni, Chasel Chiu, Nate DeSimone, Star Zeng

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3476

parseInfFile currently reading the EFI_BASE_ADDRESS from INF, once the
address found still it's continues to read the complete inf file which
is not required. once the EFI_BASE_ADDRESS read from the INF no need to
read the INF further.
MSFT compiler can generate the map file address 8 or 16 based on which
architecture the INF is compiler. currently it's support for IA32,
it can be update the X64 in future.
modification of few typo errors in parseModMapFile, getCurr function
required

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 IntelFsp2Pkg/Tools/PatchFv.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/PatchFv.py b/IntelFsp2Pkg/Tools/PatchFv.py
index 112de4077a..236019b62d 100644
--- a/IntelFsp2Pkg/Tools/PatchFv.py
+++ b/IntelFsp2Pkg/Tools/PatchFv.py
@@ -1,6 +1,6 @@
 ## @ PatchFv.py
 #
-# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -297,17 +297,17 @@ class Symbols:
         #
         fvOffset    = self.getFvOffsetInFd(infFile[0:-4] + ".Fv")
         fdIn        = open(infFile, "r")
-        rptLine     = fdIn.readline()
+        rptLines     = fdIn.readlines()
         self.fdBase = 0xFFFFFFFF
-        while (rptLine != "" ):
+        for line in rptLines:
             #EFI_BASE_ADDRESS = 0xFFFDF400
-            match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine)
+            match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", line)
             if match is not None:
                 self.fdBase = int(match.group(1), 16) - fvOffset
-            rptLine  = fdIn.readline()
+                break
         fdIn.close()
         if self.fdBase == 0xFFFFFFFF:
-            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % fvFile)
+            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % infFile)
         return 0
 
     #
@@ -402,6 +402,7 @@ class Symbols:
     #
     #  retval      0           Parsed MOD MAP file successfully
     #  retval      1           There is no moduleEntryPoint in modSymbols
+    #  retval      2           There is no offset for moduleEntryPoint in modSymbols
     #
     def parseModMapFile(self, moduleName, mapFile):
         #
@@ -426,7 +427,7 @@ class Symbols:
         else:
             #MSFT
             #0003:00000190       _gComBase                  00007a50     SerialPo
-            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
+            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8,16}\s+)"
             matchKeyGroupIndex = 1
             matchSymbolGroupIndex  = 2
             prefix = ''
@@ -498,7 +499,7 @@ class Symbols:
     #
     #  Get current character
     #
-    #  retval      elf.string[self.index]
+    #  retval      self.string[self.index]
     #  retval      ''                       Exception
     #
     def getCurr(self):
-- 
2.30.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
  2021-07-04 11:22 Ashraf Ali S
@ 2021-07-05  1:31 ` Chiu, Chasel
  0 siblings, 0 replies; 5+ messages in thread
From: Chiu, Chasel @ 2021-07-05  1:31 UTC (permalink / raw)
  To: S, Ashraf Ali, devel@edk2.groups.io
  Cc: Ni, Ray, Desimone, Nathaniel L, Zeng, Star


Thanks Ashraf.
Adding my comments below inline.


> -----Original Message-----
> From: S, Ashraf Ali <ashraf.ali.s@intel.com>
> Sent: Sunday, July 4, 2021 7:23 PM
> To: devel@edk2.groups.io
> Cc: S, Ashraf Ali <ashraf.ali.s@intel.com>; Ni, Ray <ray.ni@intel.com>; Chiu,
> Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3476
> 
> parseInfFile currently reading the EFI_BASE_ADDRESS from INF, once the
> address found still it's continues to read the complete inf file which is not
> required. once the EFI_BASE_ADDRESS read from the INF no need to read
> the INF further.
> MSFT compiler can generate the map file address 8 or 16 based on which
> architecture the INF is compiler. currently it's support for IA32, it can be
> update the X64 in future.
> modification of few typo errors in parseModMapFile, getCurr function
> required
> 
> Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> ---
>  IntelFsp2Pkg/Tools/PatchFv.py | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/Tools/PatchFv.py b/IntelFsp2Pkg/Tools/PatchFv.py
> index 112de4077a..236019b62d 100644
> --- a/IntelFsp2Pkg/Tools/PatchFv.py
> +++ b/IntelFsp2Pkg/Tools/PatchFv.py
> @@ -1,6 +1,6 @@
>  ## @ PatchFv.py
>  #
> -# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2014 - 2021, Intel Corporation. All rights
> +reserved.<BR>
>  # SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -297,17 +297,17
> @@ class Symbols:
>          #
>          fvOffset    = self.getFvOffsetInFd(infFile[0:-4] + ".Fv")
>          fdIn        = open(infFile, "r")
> -        rptLine     = fdIn.readline()
> +        rptLines     = fdIn.readlines()




The target line "EFI_BASE_ADDRESS = 0x********" is usually the second line in the generated INF file, do you think we really need to change to "readlines()" to read whole file?
It looks to me original readline() implementation is better in efficiency, but just need to break when the match found.




>          self.fdBase = 0xFFFFFFFF
> -        while (rptLine != "" ):
> +        for line in rptLines:
>              #EFI_BASE_ADDRESS = 0xFFFDF400
> -            match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)",
> rptLine)
> +            match =
> + re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", line)
>              if match is not None:
>                  self.fdBase = int(match.group(1), 16) - fvOffset
> -            rptLine  = fdIn.readline()
> +                break
>          fdIn.close()
>          if self.fdBase == 0xFFFFFFFF:
> -            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" %
> fvFile)
> +            raise Exception("Could not find EFI_BASE_ADDRESS in INF
> + file!" % infFile)
>          return 0
> 
>      #
> @@ -402,6 +402,7 @@ class Symbols:
>      #
>      #  retval      0           Parsed MOD MAP file successfully
>      #  retval      1           There is no moduleEntryPoint in modSymbols
> +    #  retval      2           There is no offset for moduleEntryPoint in modSymbols
>      #
>      def parseModMapFile(self, moduleName, mapFile):
>          #
> @@ -426,7 +427,7 @@ class Symbols:
>          else:
>              #MSFT
>              #0003:00000190       _gComBase                  00007a50     SerialPo
> -            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-
> F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
> +            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-
> F]{8}\s+(\w+)\s+([0-9a-fA-F]{8,16}\s+)"
>              matchKeyGroupIndex = 1
>              matchSymbolGroupIndex  = 2
>              prefix = ''
> @@ -498,7 +499,7 @@ class Symbols:
>      #
>      #  Get current character
>      #
> -    #  retval      elf.string[self.index]
> +    #  retval      self.string[self.index]
>      #  retval      ''                       Exception
>      #
>      def getCurr(self):
> --
> 2.30.2.windows.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
@ 2021-07-05  7:05 Ashraf Ali S
  0 siblings, 0 replies; 5+ messages in thread
From: Ashraf Ali S @ 2021-07-05  7:05 UTC (permalink / raw)
  To: devel; +Cc: Ashraf Ali S, Ray Ni, Chasel Chiu, Nate DeSimone, Star Zeng

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3476

parseInfFile currently reading the EFI_BASE_ADDRESS from INF, once the
address found still it's continues to read the complete inf file which
is not required. once the EFI_BASE_ADDRESS read from the INF no need to
read the INF further.
MSFT compiler can generate the map file address 8 or 16 based on which
architecture the INF is compiler. currently it's support for IA32,
modified the patchfv to support for all.
modification of few typo errors in parseModMapFile, getCurr function
required

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 IntelFsp2Pkg/Tools/PatchFv.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/PatchFv.py b/IntelFsp2Pkg/Tools/PatchFv.py
index 112de4077a..623eeb55b8 100644
--- a/IntelFsp2Pkg/Tools/PatchFv.py
+++ b/IntelFsp2Pkg/Tools/PatchFv.py
@@ -1,6 +1,6 @@
 ## @ PatchFv.py
 #
-# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -297,17 +297,18 @@ class Symbols:
         #
         fvOffset    = self.getFvOffsetInFd(infFile[0:-4] + ".Fv")
         fdIn        = open(infFile, "r")
-        rptLine     = fdIn.readline()
+        rptLine     = fdIn.readlines()
         self.fdBase = 0xFFFFFFFF
         while (rptLine != "" ):
             #EFI_BASE_ADDRESS = 0xFFFDF400
             match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine)
             if match is not None:
                 self.fdBase = int(match.group(1), 16) - fvOffset
+                break
             rptLine  = fdIn.readline()
         fdIn.close()
         if self.fdBase == 0xFFFFFFFF:
-            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % fvFile)
+            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % infFile)
         return 0
 
     #
@@ -402,6 +403,7 @@ class Symbols:
     #
     #  retval      0           Parsed MOD MAP file successfully
     #  retval      1           There is no moduleEntryPoint in modSymbols
+    #  retval      2           There is no offset for moduleEntryPoint in modSymbols
     #
     def parseModMapFile(self, moduleName, mapFile):
         #
@@ -426,7 +428,7 @@ class Symbols:
         else:
             #MSFT
             #0003:00000190       _gComBase                  00007a50     SerialPo
-            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
+            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8,16}\s+)"
             matchKeyGroupIndex = 1
             matchSymbolGroupIndex  = 2
             prefix = ''
@@ -455,7 +457,13 @@ class Symbols:
                         continue
 
         if not moduleEntryPoint in modSymbols:
-            return 1
+            if matchSymbolGroupIndex == 1:
+                if not '_ModuleEntryPoint' in modSymbols:
+                    return 1
+                else:
+                    moduleEntryPoint = "_ModuleEntryPoint"
+            else:
+                return 1
 
         modEntry = '%s:%s' % (moduleName,moduleEntryPoint)
         if not modEntry in self.dictSymbolAddress:
@@ -498,7 +506,7 @@ class Symbols:
     #
     #  Get current character
     #
-    #  retval      elf.string[self.index]
+    #  retval      self.string[self.index]
     #  retval      ''                       Exception
     #
     def getCurr(self):
-- 
2.30.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification
@ 2021-07-05  8:06 Ashraf Ali S
  0 siblings, 0 replies; 5+ messages in thread
From: Ashraf Ali S @ 2021-07-05  8:06 UTC (permalink / raw)
  To: devel; +Cc: Ashraf Ali S, Ray Ni, Chasel Chiu, Nate DeSimone, Star Zeng

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3476

parseInfFile currently reading the EFI_BASE_ADDRESS from INF, once the
address found still it's continues to read the complete inf file which
is not required. once the EFI_BASE_ADDRESS read from the INF no need to
read the INF further.
MSFT compiler can generate the map file address 8 or 16 based on which
architecture the INF is compiler. currently it's support for IA32,
modified the patchfv to support for all.
modification of few typo errors in parseModMapFile, getCurr function
required

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 IntelFsp2Pkg/Tools/PatchFv.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/PatchFv.py b/IntelFsp2Pkg/Tools/PatchFv.py
index 112de4077a..64b4e927a0 100644
--- a/IntelFsp2Pkg/Tools/PatchFv.py
+++ b/IntelFsp2Pkg/Tools/PatchFv.py
@@ -1,6 +1,6 @@
 ## @ PatchFv.py
 #
-# Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -304,10 +304,11 @@ class Symbols:
             match = re.match("^EFI_BASE_ADDRESS\s*=\s*(0x[a-fA-F0-9]+)", rptLine)
             if match is not None:
                 self.fdBase = int(match.group(1), 16) - fvOffset
+                break
             rptLine  = fdIn.readline()
         fdIn.close()
         if self.fdBase == 0xFFFFFFFF:
-            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % fvFile)
+            raise Exception("Could not find EFI_BASE_ADDRESS in INF file!" % infFile)
         return 0
 
     #
@@ -402,6 +403,7 @@ class Symbols:
     #
     #  retval      0           Parsed MOD MAP file successfully
     #  retval      1           There is no moduleEntryPoint in modSymbols
+    #  retval      2           There is no offset for moduleEntryPoint in modSymbols
     #
     def parseModMapFile(self, moduleName, mapFile):
         #
@@ -426,7 +428,7 @@ class Symbols:
         else:
             #MSFT
             #0003:00000190       _gComBase                  00007a50     SerialPo
-            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8}\s+)"
+            patchMapFileMatchString =  "^\s[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\w+)\s+([0-9a-fA-F]{8,16}\s+)"
             matchKeyGroupIndex = 1
             matchSymbolGroupIndex  = 2
             prefix = ''
@@ -455,7 +457,13 @@ class Symbols:
                         continue
 
         if not moduleEntryPoint in modSymbols:
-            return 1
+            if matchSymbolGroupIndex == 1:
+                if not '_ModuleEntryPoint' in modSymbols:
+                    return 1
+                else:
+                    moduleEntryPoint = "_ModuleEntryPoint"
+            else:
+                return 1
 
         modEntry = '%s:%s' % (moduleName,moduleEntryPoint)
         if not modEntry in self.dictSymbolAddress:
@@ -498,7 +506,7 @@ class Symbols:
     #
     #  Get current character
     #
-    #  retval      elf.string[self.index]
+    #  retval      self.string[self.index]
     #  retval      ''                       Exception
     #
     def getCurr(self):
-- 
2.30.2.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-05  8:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-05  8:06 [PATCH] IntelFsp2Pkg: PatchFv parseInfFile function modification Ashraf Ali S
  -- strict thread matches above, loose matches on Subject: below --
2021-07-05  7:05 Ashraf Ali S
2021-07-04 11:22 Ashraf Ali S
2021-07-05  1:31 ` Chiu, Chasel
2021-07-04 11:15 Ashraf Ali S

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox