mirror of https://github.com/acidanthera/audk.git
BaseTools: Remove EDKI related logic from Trim tool
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1350 Remove EDKI related logic from Trim tool. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
210bd16aff
commit
f293841f93
|
@ -61,70 +61,6 @@ gAslIncludePattern = re.compile("^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.M
|
||||||
## Regular expression for matching C style #include "XXX.asl" in asl file
|
## Regular expression for matching C style #include "XXX.asl" in asl file
|
||||||
gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE)
|
gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE)
|
||||||
## Patterns used to convert EDK conventions to EDK2 ECP conventions
|
## Patterns used to convert EDK conventions to EDK2 ECP conventions
|
||||||
gImportCodePatterns = [
|
|
||||||
[
|
|
||||||
re.compile('^(\s*)\(\*\*PeiServices\)\.PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
|
|
||||||
'''\\1{
|
|
||||||
\\1 STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
|
|
||||||
\\1 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
||||||
\\1 &gEcpPeiPciCfgPpiGuid,
|
|
||||||
\\1 \\2
|
|
||||||
\\1 };
|
|
||||||
\\1 (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
|
|
||||||
\\1}'''
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile('^(\s*)\(\*PeiServices\)->PciCfg\s*=\s*([^;\s]+);', re.MULTILINE),
|
|
||||||
'''\\1{
|
|
||||||
\\1 STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
|
|
||||||
\\1 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
||||||
\\1 &gEcpPeiPciCfgPpiGuid,
|
|
||||||
\\1 \\2
|
|
||||||
\\1 };
|
|
||||||
\\1 (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
|
|
||||||
\\1}'''
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile("(\s*).+->Modify[\s\n]*\(", re.MULTILINE),
|
|
||||||
'\\1PeiLibPciCfgModify ('
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile("(\W*)gRT->ReportStatusCode[\s\n]*\(", re.MULTILINE),
|
|
||||||
'\\1EfiLibReportStatusCode ('
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile('#include\s+EFI_GUID_DEFINITION\s*\(FirmwareFileSystem\)', re.MULTILINE),
|
|
||||||
'#include EFI_GUID_DEFINITION (FirmwareFileSystem)\n#include EFI_GUID_DEFINITION (FirmwareFileSystem2)'
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile('gEfiFirmwareFileSystemGuid', re.MULTILINE),
|
|
||||||
'gEfiFirmwareFileSystem2Guid'
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile('EFI_FVH_REVISION', re.MULTILINE),
|
|
||||||
'EFI_FVH_PI_REVISION'
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_READY_TO_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
|
|
||||||
'\\1EfiCreateEventReadyToBoot (\\2\\3;'
|
|
||||||
],
|
|
||||||
|
|
||||||
[
|
|
||||||
re.compile("(\s*)\S*CreateEvent\s*\([\s\n]*EFI_EVENT_SIGNAL_LEGACY_BOOT[^,]*,((?:[^;]+\n)+)(\s*\));", re.MULTILINE),
|
|
||||||
'\\1EfiCreateEventLegacyBoot (\\2\\3;'
|
|
||||||
],
|
|
||||||
# [
|
|
||||||
# re.compile("(\W)(PEI_PCI_CFG_PPI)(\W)", re.MULTILINE),
|
|
||||||
# '\\1ECP_\\2\\3'
|
|
||||||
# ]
|
|
||||||
]
|
|
||||||
|
|
||||||
## file cache to avoid circular include in ASL file
|
## file cache to avoid circular include in ASL file
|
||||||
gIncludedAslFile = []
|
gIncludedAslFile = []
|
||||||
|
@ -494,97 +430,6 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
|
||||||
fStringIO.close ()
|
fStringIO.close ()
|
||||||
fInputfile.close ()
|
fInputfile.close ()
|
||||||
|
|
||||||
## Trim EDK source code file(s)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @param Source File or directory to be trimmed
|
|
||||||
# @param Target File or directory to store the trimmed content
|
|
||||||
#
|
|
||||||
def TrimEdkSources(Source, Target):
|
|
||||||
if os.path.isdir(Source):
|
|
||||||
for CurrentDir, Dirs, Files in os.walk(Source):
|
|
||||||
if '.svn' in Dirs:
|
|
||||||
Dirs.remove('.svn')
|
|
||||||
elif "CVS" in Dirs:
|
|
||||||
Dirs.remove("CVS")
|
|
||||||
|
|
||||||
for FileName in Files:
|
|
||||||
Dummy, Ext = os.path.splitext(FileName)
|
|
||||||
if Ext.upper() not in ['.C', '.H']: continue
|
|
||||||
if Target is None or Target == '':
|
|
||||||
TrimEdkSourceCode(
|
|
||||||
os.path.join(CurrentDir, FileName),
|
|
||||||
os.path.join(CurrentDir, FileName)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
TrimEdkSourceCode(
|
|
||||||
os.path.join(CurrentDir, FileName),
|
|
||||||
os.path.join(Target, CurrentDir[len(Source)+1:], FileName)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
TrimEdkSourceCode(Source, Target)
|
|
||||||
|
|
||||||
## Trim one EDK source code file
|
|
||||||
#
|
|
||||||
# Do following replacement:
|
|
||||||
#
|
|
||||||
# (**PeiServices\).PciCfg = <*>;
|
|
||||||
# => {
|
|
||||||
# STATIC EFI_PEI_PPI_DESCRIPTOR gEcpPeiPciCfgPpiList = {
|
|
||||||
# (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
||||||
# &gEcpPeiPciCfgPpiGuid,
|
|
||||||
# <*>
|
|
||||||
# };
|
|
||||||
# (**PeiServices).InstallPpi (PeiServices, &gEcpPeiPciCfgPpiList);
|
|
||||||
#
|
|
||||||
# <*>Modify(<*>)
|
|
||||||
# => PeiLibPciCfgModify (<*>)
|
|
||||||
#
|
|
||||||
# gRT->ReportStatusCode (<*>)
|
|
||||||
# => EfiLibReportStatusCode (<*>)
|
|
||||||
#
|
|
||||||
# #include <LoadFile\.h>
|
|
||||||
# => #include <FvLoadFile.h>
|
|
||||||
#
|
|
||||||
# CreateEvent (EFI_EVENT_SIGNAL_READY_TO_BOOT, <*>)
|
|
||||||
# => EfiCreateEventReadyToBoot (<*>)
|
|
||||||
#
|
|
||||||
# CreateEvent (EFI_EVENT_SIGNAL_LEGACY_BOOT, <*>)
|
|
||||||
# => EfiCreateEventLegacyBoot (<*>)
|
|
||||||
#
|
|
||||||
# @param Source File to be trimmed
|
|
||||||
# @param Target File to store the trimmed content
|
|
||||||
#
|
|
||||||
def TrimEdkSourceCode(Source, Target):
|
|
||||||
EdkLogger.verbose("\t%s -> %s" % (Source, Target))
|
|
||||||
CreateDirectory(os.path.dirname(Target))
|
|
||||||
|
|
||||||
try:
|
|
||||||
f = open (Source, 'r')
|
|
||||||
except:
|
|
||||||
EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
|
|
||||||
# read whole file
|
|
||||||
Lines = f.read()
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
NewLines = None
|
|
||||||
for Re, Repl in gImportCodePatterns:
|
|
||||||
if NewLines is None:
|
|
||||||
NewLines = Re.sub(Repl, Lines)
|
|
||||||
else:
|
|
||||||
NewLines = Re.sub(Repl, NewLines)
|
|
||||||
|
|
||||||
# save all lines if trimmed
|
|
||||||
if Source == Target and NewLines == Lines:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
f = open (Target, 'w')
|
|
||||||
except:
|
|
||||||
EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)
|
|
||||||
f.write(NewLines)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
## Parse command line options
|
## Parse command line options
|
||||||
#
|
#
|
||||||
|
@ -603,9 +448,6 @@ def Options():
|
||||||
help="The input file is EFI image"),
|
help="The input file is EFI image"),
|
||||||
make_option("-a", "--asl-file", dest="FileType", const="Asl", action="store_const",
|
make_option("-a", "--asl-file", dest="FileType", const="Asl", action="store_const",
|
||||||
help="The input file is ASL file"),
|
help="The input file is ASL file"),
|
||||||
make_option("-8", "--Edk-source-code", dest="FileType", const="EdkSourceCode", action="store_const",
|
|
||||||
help="The input file is source code for Edk to be trimmed for ECP"),
|
|
||||||
|
|
||||||
make_option("-c", "--convert-hex", dest="ConvertHex", action="store_true",
|
make_option("-c", "--convert-hex", dest="ConvertHex", action="store_true",
|
||||||
help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),
|
help="Convert standard hex format (0xabcd) to MASM format (abcdh)"),
|
||||||
|
|
||||||
|
@ -680,8 +522,6 @@ def Main():
|
||||||
if CommandOptions.OutputFile is None:
|
if CommandOptions.OutputFile is None:
|
||||||
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
|
CommandOptions.OutputFile = os.path.splitext(InputFile)[0] + '.iii'
|
||||||
TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptions.IncludePathFile)
|
TrimAslFile(InputFile, CommandOptions.OutputFile, CommandOptions.IncludePathFile)
|
||||||
elif CommandOptions.FileType == "EdkSourceCode":
|
|
||||||
TrimEdkSources(InputFile, CommandOptions.OutputFile)
|
|
||||||
elif CommandOptions.FileType == "VfrOffsetBin":
|
elif CommandOptions.FileType == "VfrOffsetBin":
|
||||||
GenerateVfrBinSec(CommandOptions.ModuleName, CommandOptions.DebugDir, CommandOptions.OutputFile)
|
GenerateVfrBinSec(CommandOptions.ModuleName, CommandOptions.DebugDir, CommandOptions.OutputFile)
|
||||||
else :
|
else :
|
||||||
|
|
Loading…
Reference in New Issue