## @file
# process FFS generation from INF statement
#
# Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import Rule
import os
import shutil
import StringIO
from struct import *
import Ffs
import subprocess
import sys
import Section
import RuleSimpleFile
import RuleComplexFile
from Common.BuildToolError import *
## generate FFS from INF
#
#
## The constructor
#
# @param self The object pointer
#
self.TargetOverrideList = []
self.ShadowFromInfFile = None
self.KeepRelocFromRule = None
self.OptRomDefs = {}
self.FinalTargetSuffixMap = {}
self.CurrentLineNum = None
self.CurrentLineContent = None
self.InfFileName = None
## GetFinalTargetSuffixMap() method
#
# Get final build target list
return []
if not self.FinalTargetSuffixMap:
FinalBuildTargetList = GenFdsGlobalVariable.GetModuleCodaTargetList(self.InfModule, self.CurrentArch)
for File in FinalBuildTargetList:
# Check if current INF module has DEPEX
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]
PlatformModule = None
LibraryInstance = {}
DepexList = []
if not Module:
continue
if DepexList != []:
break
if LibName in LibraryInstance:
continue
else:
if not LibraryPath:
if not LibraryPath:
continue
LibraryModule = GenFdsGlobalVariable.WorkSpace.BuildObject[LibraryPath, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if DepexList:
# It means this module has DEPEX
return self.FinalTargetSuffixMap
## __InfParse() method
#
# Parse inf file to get module information
#
# @param self The object pointer
# @param Dict dictionary contains macro and value pair
#
#
# Get the InfClass object
#
if ErrorCode != 0:
if self.CurrentArch != None:
Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, self.CurrentArch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
#
# Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath
#
else:
Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClassObj, 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if self.BinFileList == []:
"INF %s specified in FDF could not be found in build ARCH %s!" \
EdkLogger.warn("GenFds", GENFDS_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % (self.InfFileName))
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.InfFileName)
#
# Set OutputPath = ${WorkSpace}\Build\Fv\Ffs\${ModuleGuid}+ ${MdouleName}\
#
## GenFfs() method
#
# Generate FFS
#
# @param self The object pointer
# @param Dict dictionary contains macro and value pair
# @param FvChildAddr Array of the inside FvImage base address
# @param FvParentAddr Parent Fv base address
# @retval string Generated FFS file name
#
#
# Parse Inf file get Module related information
#
#
# Allow binary type module not specify override rule in FDF file.
#
#
# Get the rule of how to generate Ffs file
#
#
# Convert Fv File Type for PI1.1 SMM driver.
#
#
# Framework SMM Driver has no SMM FV file type
#
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM or SMM_CORE FV file type", File=self.InfFileName)
#
# For the rule only has simpleFile
#
return FfsOutput
#
# For Rule has ComplexFile
#
InputSectList, InputSectAlignments = self.__GenComplexFileSection__(Rule, FvChildAddr, FvParentAddr)
return FfsOutput
## __ExtendMacro__() method
#
# Replace macro with its value
#
# @param self The object pointer
# @param String The string to be replaced
# @retval string Macro replaced string
#
MacroDict = {
}
return String
## __GetRule__() method
#
# Get correct rule for generating FFS for this INF
#
# @param self The object pointer
# @retval Rule Rule object
#
CurrentArchList = []
if self.CurrentArch == None:
CurrentArchList = ['common']
else:
for CurrentArch in CurrentArchList:
RuleName = 'RULE' + \
'.' + \
CurrentArch.upper() + \
'.' + \
'.' + \
if Rule != None:
return Rule
RuleName = 'RULE' + \
'.' + \
'COMMON' + \
'.' + \
'.' + \
GenFdsGlobalVariable.VerboseLogger ('Trying to apply common rule %s for INF %s' % (RuleName, self.InfFileName))
if Rule != None:
return Rule
if Rule == None :
## __GetPlatformArchList__() method
#
# Get Arch list this INF built under
#
# @param self The object pointer
# @retval list Arch list
#
DscArchList = []
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if PlatformDataBase != None:
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if PlatformDataBase != None:
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if PlatformDataBase != None:
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'ARM', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if PlatformDataBase != None:
PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'EBC', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
if PlatformDataBase != None:
return DscArchList
## GetCurrentArch() method
#
# Get Arch list of the module from this INF is to be placed into flash
#
# @param self The object pointer
# @retval list Arch list
#
if PlatformArchList != []:
ArchList = []
if self.KeyStringList != []:
if Arch in CurArchList:
else:
UseArchList = []
if ErrorCode != 0:
return Arch
EdkLogger.error("GenFds", GENFDS_ERROR, "GenFds command line option has multiple ARCHs %s. Not able to determine which ARCH is valid for Module %s !" % (str(ArchList), self.InfFileName))
else:
EdkLogger.error("GenFds", GENFDS_ERROR, "Module built under multiple ARCHs %s. Not able to determine which output to put into flash for Module %s !" % (str(ArchList), self.InfFileName))
else:
EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s appears under ARCH %s in platform %s, but current deduced ARCH is %s, so NO build output could be put into flash." \
% (self.InfFileName, str(PlatformArchList), GenFdsGlobalVariable.ActivePlatform, str(set (UseArchList) & set (TargetArchList))))
## __GetEFIOutPutPath__() method
#
# Get the output path for generated files
#
# @param self The object pointer
# @retval string Path that output files from this INF go to
#
Arch = ''
OutputPath = ''
Arch = "NoneArch"
if self.CurrentArch != None:
Arch ,
'OUTPUT'
)
return OutputPath
## __GenSimpleFileSection__() method
#
# Generate section by specified file name or a list of files with file extension
#
# @param self The object pointer
# @param Rule The rule object used to generate section
# @retval string File name of the generated section file
#
#
# Prepare the parameter of GenSection
#
FileList = []
OutputFileList = []
GenSecInputFile = None
else:
else:
Index = 1
#
# Convert Fv Section Type for PI1.1 SMM driver.
#
if SectionType == 'DXE_DEPEX':
SectionType = 'SMM_DEPEX'
#
# Framework SMM Driver has no SMM_DEPEX section type
#
if SectionType == 'SMM_DEPEX':
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)
elif self.ShadowFromInfFile != None:
if FileList != [] :
#Get PE Section alignment when align is set to AUTO
else:
if not NoStrip:
[File],
)
if SectionType == 'TE':
[File],
Type='te'
)
else:
#Get PE Section alignment when align is set to AUTO
else:
if not NoStrip:
)
if SectionType == 'TE':
Type='te'
)
GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType])
return OutputFileList
## __GenSimpleFileFfs__() method
#
# Generate FFS
#
# @param self The object pointer
# @param Rule The rule object used to generate section
# @param InputFileList The output file list from GenSection
# @retval string Generated FFS file name
#
'.ffs'
InputSection = []
SectionAlignments = []
for InputFile in InputFileList:
)
return FfsOutput
## __GenComplexFileSection__() method
#
# Generate section by sections in Rule
#
# @param self The object pointer
# @param Rule The rule object used to generate section
# @param FvChildAddr Array of the inside FvImage base address
# @param FvParentAddr Parent Fv base address
# @retval string File name of the generated section file
#
SectFiles = []
SectAlignments = []
Index = 1
SectList = []
#
# Convert Fv Section Type for PI1.1 SMM driver.
#
#
# Framework SMM Driver has no SMM_DEPEX section type
#
EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Framework SMM module doesn't support SMM_DEPEX section type", File=self.InfFileName)
#
# process the inside FvImage from FvSection or GuidSection
#
if FvChildAddr != []:
if Rule.KeyStringList != []:
SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, Rule.KeyStringList, self)
else :
SectList, Align = Sect.GenSection(self.OutputPath , self.ModuleGuid, SecIndex, self.KeyStringList, self)
if not HasGneratedFlag:
#
# Search the source list in InfData to find if there are .vfr file exist.
#
VfrUniBaseName = {}
VfrUniOffsetList = []
#
# search the .map file to find the offset of vfr binary in the PE32+/TE file.
#
#
# search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
#
#
# Generate the Raw data of raw section
#
"""Call GenSection"""
"EFI_SECTION_RAW"
)
return SectFiles, SectAlignments
## __GenComplexFileFfs__() method
#
# Generate FFS
#
# @param self The object pointer
# @param Rule The rule object used to generate section
# @param InputFileList The output file list from GenSection
# @retval string Generated FFS file name
#
)
return FfsOutput
## __GetGenFfsCmdParameter__() method
#
# Create parameter string for GenFfs
#
# @param self The object pointer
# @param Rule The rule object used to generate section
# @retval tuple (FileType, Fixed, CheckSum, Alignment)
#
result += ('-x',)
result += ('-s',)
return result
## __GetBuildOutputMapFileVfrUniInfo() method
#
#
# @param self The object pointer
#
RetValue = []
try:
try:
except:
finally:
except:
for eachLine in FileLinesList:
#
#
try:
except:
if IsHex:
#
# GCC map file
#
return RetValue
## __GenUniVfrOffsetFile() method
#
# Generate the offset file for the module which contain VFR or UNI file.
#
# @param self The object pointer
# @param UniVfrOffsetFileName The output offset file name.
#
try:
except:
# Use a instance of StringIO to cache data
for Item in VfrUniOffsetList:
#
# UNI offset in image.
# GUID + Offset
# { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
#
UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
else:
#
# VFR binary offset in image.
# GUID + Offset
# { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
#
VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
#
# write data into file.
#
try :
except:
EdkLogger.error("GenFds", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the file been locked or using by other applications." %UniVfrOffsetFileName,None)
fInputfile.close ()