[[edk2-devel]] MinPlatformPkg: Add support for skipping FSP rebase

Yang Jie jie.yang at intel.com
Tue Jul 18 07:19:44 UTC 2023


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

Modify the way of processing input arguments in
RebaseFspBinBaseAddress script.
Add an option to skip FSP rebase.

Cc: Chasel Chiu <chasel.chiu at intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone at intel.com>
Cc: Isaac Oram <isaac.w.oram at intel.com>
Cc: Liming Gao <gaoliming at byosoft.com.cn>
Cc: Eric Dong <eric.dong at intel.com>

Signed-off-by: Jie Yang <jie.yang at intel.com>
---
 .../Tools/Fsp/RebaseFspBinBaseAddress.py      | 86 +++++++++++++------
 1 file changed, 62 insertions(+), 24 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseFspBinBaseAddress.py b/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseFspBinBaseAddress.py
index b7e4bcf5f9..c5fb017917 100644
--- a/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseFspBinBaseAddress.py
+++ b/Platform/Intel/MinPlatformPkg/Tools/Fsp/RebaseFspBinBaseAddress.py
@@ -1,6 +1,6 @@
 ## @ RebaseFspBinBaseAddress.py
 #
-# Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2023, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 
@@ -8,30 +8,46 @@ import os
 import sys
 import re
 import subprocess
+import argparse
 
-if len(sys.argv) not in [5,6]:
-  print ("RebaseFspBinBaseAddress.py - Error in number of arguments received")
-  print ("Usage - RebaseFspBinBaseAddress.py <FlashMap file path> <FspBinPkg Folder> <Fsp.fd file name>\
-  <pad_offset for Fsp-S Base Address> <OPTIONAL SplitFspBin.py tool path>")
-  exit(1)
+#
+# Globals for help information
+#
+__description__ = 'Rebase Fsp Bin Base and Split Fsp components.\n'
+__prog__        = sys.argv[0]
+
+Parser = argparse.ArgumentParser(
+                        prog = __prog__,\
+                        description = __description__
+                        )
+
+Parser.add_argument("-fm", "--flashMap", dest = 'flashMap', help = 'FlashMap file path')
+Parser.add_argument("-p", "--fspBinPath", dest = 'fspBinPath', help = 'fsp Bin path')
+Parser.add_argument("-fsp", "--fspBinFile", dest = 'fspBinFile', required = True, help = 'Fsp.fd file name')
+Parser.add_argument("-po", "--padOffset", dest = 'padOffset', help = 'pad offset for Fsp-S Base Address')
+Parser.add_argument("-s", "--splitFspBin", dest = 'splitFspBin', help = 'SplitFspBin.py tool path')
+Parser.add_argument("-sr", "--skipRebase", dest = 'skipRebase',action="store_true", \
+                    help = "Whether skip FSP rebase, the value is True or False")
+Args, Remaining  = Parser.parse_known_args()
+
+if Args.skipRebase == False:
+  if Args.flashMap == None or Args.fspBinPath == None or Args.padOffset == None:
+    print ("RebaseFspBinBaseAddress.py - Invalid argements.")
+    print (" When skipRebase is false, It's necessary to input flashMap, fspBinPkg and padOffset to rebase.")
+    exit(1)
+
+fspBinPath = Args.fspBinFile
 
-flashMapName      = sys.argv[1]
-fspBinPath        = sys.argv[2]
-fspBinFile        = sys.argv[3]
-fvOffset          = int(sys.argv[4], 16)
-fspBinFileRebased = "Fsp_Rebased.fd"
 splitFspBinPath   = os.path.join("edk2","IntelFsp2Pkg","Tools","SplitFspBin.py")
+if Args.splitFspBin != None:
+  splitFspBinPath = Args.splitFspBin
 
-if len(sys.argv) == 6:
-  splitFspBinPath   = sys.argv[5]
+fspBinPath        = Args.fspBinPath
+fspBinFile        = Args.fspBinFile
 
 #
 # Make sure argument passed or valid
-#
-if not os.path.exists(flashMapName):
-  print ("WARNING!  " + str(flashMapName) + " is not found.")
-  exit(1)
-fspBinFilePath = fspBinPath + os.sep + fspBinFile
+#fspBinFilePath = fspBinPath + os.sep + fspBinFile
 if not os.path.exists(fspBinFilePath):
   print ("WARNING!  " + str(fspBinFilePath) + " is not found.")
   exit(1)
@@ -39,6 +55,32 @@ if not os.path.exists(splitFspBinPath):
   print ("WARNING!  " + str(splitFspBinPath) + " is not found.")
   exit(1)
 
+pythontool = 'python'
+if 'PYTHON_HOME' in os.environ:
+    pythontool = os.environ['PYTHON_HOME'] + os.sep + 'python'
+else:
+    pythontool = sys.executable
+
+if Args.skipRebase == True:
+  print("SKip FSP rebase")
+  #
+  # Split FSP bin to FSP-S/M/T segments
+  #
+  splitArguments = fspBinPath + os.sep + fspBinFile + " -o " + fspBinPath + " -n Fsp_Rebased.fd"
+  os.system('"' + pythontool + '"' + " " + splitFspBinPath + " split -f" + splitArguments)
+  exit(0)
+
+fspBinFileRebased = "Fsp_Rebased.fd"
+flashMapName      = Args.flashMap
+fvOffset          = int(Args.padOffset, 16)
+
+#
+# Make sure argument passed or valid
+#
+if not os.path.exists(flashMapName):
+  print ("WARNING!  " + str(flashMapName) + " is not found.")
+  exit(1)
+
 #
 # Get the FSP-S / FSP-M-T FV Base Address from Flash Map
 #
@@ -65,14 +107,10 @@ file.close()
 # Get FSP-M Size, in order to calculate the FSP-T Base. Used SplitFspBin.py script
 # to dump the header, and get the ImageSize in FSP-M section
 #
-pythontool = 'python'
-if 'PYTHON_HOME' in os.environ:
-    pythontool = os.environ['PYTHON_HOME'] + os.sep + 'python'
-else:
-    pythontool = sys.executable
+
 Process = subprocess.Popen([pythontool, splitFspBinPath, "info","-f",fspBinFilePath], stdout=subprocess.PIPE)
 Output = Process.communicate()[0]
-FsptInfo = Output.rsplit(b"FSP_M", 1);
+FsptInfo = Output.rsplit(b"FSP_M", 1)
 for line in FsptInfo[1].split(b"\n"):
   if b"ImageSize" in line:
     fspMSize = int(line.split(b"=")[1], 16)
-- 
2.26.2.windows.1



More information about the edk2-devel-archive mailing list