Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinPlatformPkg: Add support for skipping FSP rebase #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,44 +1,86 @@
## @ 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
#

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)
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
#
Expand All @@ -65,14 +107,10 @@
# 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)
Expand Down