2009-07-17 11:10:31 +02:00
|
|
|
## @file
|
|
|
|
# process rule section generation
|
|
|
|
#
|
2014-08-28 15:53:34 +02:00
|
|
|
# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
|
2009-07-17 11:10:31 +02:00
|
|
|
#
|
2010-05-18 07:04:32 +02:00
|
|
|
# This program and the accompanying materials
|
2009-07-17 11:10:31 +02:00
|
|
|
# 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
|
|
|
|
# http://opensource.org/licenses/bsd-license.php
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2010-03-01 00:39:39 +01:00
|
|
|
from struct import *
|
2009-07-17 11:10:31 +02:00
|
|
|
import Section
|
|
|
|
from GenFdsGlobalVariable import GenFdsGlobalVariable
|
|
|
|
import subprocess
|
|
|
|
from Ffs import Ffs
|
2014-08-15 05:06:48 +02:00
|
|
|
import Common.LongFilePathOs as os
|
2009-07-17 11:10:31 +02:00
|
|
|
from CommonDataClass.FdfClass import EfiSectionClassObject
|
|
|
|
from Common import EdkLogger
|
|
|
|
from Common.BuildToolError import *
|
2010-03-01 00:39:39 +01:00
|
|
|
from Common.Misc import PeImageClass
|
2014-08-15 05:06:48 +02:00
|
|
|
from Common.LongFilePathSupport import OpenLongFilePath as open
|
|
|
|
from Common.LongFilePathSupport import CopyLongFilePath
|
2009-07-17 11:10:31 +02:00
|
|
|
|
|
|
|
## generate rule section
|
|
|
|
#
|
|
|
|
#
|
|
|
|
class EfiSection (EfiSectionClassObject):
|
|
|
|
|
|
|
|
## The constructor
|
|
|
|
#
|
|
|
|
# @param self The object pointer
|
|
|
|
#
|
|
|
|
def __init__(self):
|
|
|
|
EfiSectionClassObject.__init__(self)
|
|
|
|
|
|
|
|
## GenSection() method
|
|
|
|
#
|
|
|
|
# Generate rule section
|
|
|
|
#
|
|
|
|
# @param self The object pointer
|
|
|
|
# @param OutputPath Where to place output file
|
|
|
|
# @param ModuleName Which module this section belongs to
|
|
|
|
# @param SecNum Index of section
|
|
|
|
# @param KeyStringList Filter for inputs of section generation
|
|
|
|
# @param FfsInf FfsInfStatement object that contains this section data
|
|
|
|
# @param Dict dictionary contains macro and its value
|
|
|
|
# @retval tuple (Generated file name list, section alignment)
|
|
|
|
#
|
|
|
|
def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}) :
|
|
|
|
|
|
|
|
if self.FileName != None and self.FileName.startswith('PCD('):
|
|
|
|
self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)
|
|
|
|
"""Prepare the parameter of GenSection"""
|
|
|
|
if FfsInf != None :
|
|
|
|
InfFileName = FfsInf.InfFileName
|
|
|
|
SectionType = FfsInf.__ExtendMacro__(self.SectionType)
|
|
|
|
Filename = FfsInf.__ExtendMacro__(self.FileName)
|
|
|
|
BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)
|
|
|
|
StringData = FfsInf.__ExtendMacro__(self.StringData)
|
|
|
|
NoStrip = True
|
|
|
|
if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):
|
|
|
|
if FfsInf.KeepReloc != None:
|
|
|
|
NoStrip = FfsInf.KeepReloc
|
|
|
|
elif FfsInf.KeepRelocFromRule != None:
|
|
|
|
NoStrip = FfsInf.KeepRelocFromRule
|
|
|
|
elif self.KeepReloc != None:
|
|
|
|
NoStrip = self.KeepReloc
|
|
|
|
elif FfsInf.ShadowFromInfFile != None:
|
|
|
|
NoStrip = FfsInf.ShadowFromInfFile
|
|
|
|
else:
|
|
|
|
EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)
|
|
|
|
|
|
|
|
"""If the file name was pointed out, add it in FileList"""
|
|
|
|
FileList = []
|
|
|
|
if Filename != None:
|
|
|
|
Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)
|
2014-01-27 06:23:15 +01:00
|
|
|
# check if the path is absolute or relative
|
|
|
|
if os.path.isabs(Filename):
|
|
|
|
Filename = os.path.normpath(Filename)
|
|
|
|
else:
|
|
|
|
Filename = os.path.normpath(os.path.join(FfsInf.EfiOutputPath, Filename))
|
2010-03-01 00:39:39 +01:00
|
|
|
|
2009-07-17 11:10:31 +02:00
|
|
|
if not self.Optional:
|
|
|
|
FileList.append(Filename)
|
|
|
|
elif os.path.exists(Filename):
|
|
|
|
FileList.append(Filename)
|
|
|
|
else:
|
|
|
|
FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict)
|
|
|
|
if IsSect :
|
|
|
|
return FileList, self.Alignment
|
|
|
|
|
|
|
|
Index = 0
|
2015-07-16 02:56:14 +02:00
|
|
|
Align = self.Alignment
|
2009-07-17 11:10:31 +02:00
|
|
|
|
|
|
|
""" If Section type is 'VERSION'"""
|
|
|
|
OutputFileList = []
|
|
|
|
if SectionType == 'VERSION':
|
|
|
|
|
|
|
|
InfOverrideVerString = False
|
|
|
|
if FfsInf.Version != None:
|
|
|
|
#StringData = FfsInf.Version
|
|
|
|
BuildNum = FfsInf.Version
|
|
|
|
InfOverrideVerString = True
|
|
|
|
|
|
|
|
if InfOverrideVerString:
|
|
|
|
#VerTuple = ('-n', '"' + StringData + '"')
|
|
|
|
if BuildNum != None and BuildNum != '':
|
|
|
|
BuildNumTuple = ('-j', BuildNum)
|
|
|
|
else:
|
|
|
|
BuildNumTuple = tuple()
|
|
|
|
|
|
|
|
Num = SecNum
|
|
|
|
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',
|
|
|
|
#Ui=StringData,
|
|
|
|
Ver=BuildNum)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
|
|
|
elif FileList != []:
|
|
|
|
for File in FileList:
|
|
|
|
Index = Index + 1
|
|
|
|
Num = '%s.%d' %(SecNum , Index)
|
|
|
|
OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
f = open(File, 'r')
|
|
|
|
VerString = f.read()
|
|
|
|
f.close()
|
|
|
|
BuildNum = VerString
|
|
|
|
if BuildNum != None and BuildNum != '':
|
|
|
|
BuildNumTuple = ('-j', BuildNum)
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',
|
|
|
|
#Ui=VerString,
|
|
|
|
Ver=BuildNum)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
|
|
|
else:
|
|
|
|
BuildNum = StringData
|
|
|
|
if BuildNum != None and BuildNum != '':
|
|
|
|
BuildNumTuple = ('-j', BuildNum)
|
|
|
|
else:
|
|
|
|
BuildNumTuple = tuple()
|
|
|
|
BuildNumString = ' ' + ' '.join(BuildNumTuple)
|
|
|
|
|
|
|
|
#if VerString == '' and
|
|
|
|
if BuildNumString == '':
|
|
|
|
if self.Optional == True :
|
|
|
|
GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")
|
|
|
|
return [], None
|
|
|
|
else:
|
|
|
|
EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)
|
|
|
|
Num = SecNum
|
|
|
|
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',
|
|
|
|
#Ui=VerString,
|
|
|
|
Ver=BuildNum)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
|
|
|
#
|
|
|
|
# If Section Type is 'UI'
|
|
|
|
#
|
|
|
|
elif SectionType == 'UI':
|
|
|
|
|
|
|
|
InfOverrideUiString = False
|
|
|
|
if FfsInf.Ui != None:
|
|
|
|
StringData = FfsInf.Ui
|
|
|
|
InfOverrideUiString = True
|
|
|
|
|
|
|
|
if InfOverrideUiString:
|
|
|
|
Num = SecNum
|
|
|
|
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',
|
|
|
|
Ui=StringData)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
|
|
|
elif FileList != []:
|
|
|
|
for File in FileList:
|
|
|
|
Index = Index + 1
|
|
|
|
Num = '%s.%d' %(SecNum , Index)
|
|
|
|
OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
f = open(File, 'r')
|
|
|
|
UiString = f.read()
|
|
|
|
f.close()
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',
|
|
|
|
Ui=UiString)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
else:
|
|
|
|
if StringData != None and len(StringData) > 0:
|
|
|
|
UiTuple = ('-n', '"' + StringData + '"')
|
|
|
|
else:
|
|
|
|
UiTuple = tuple()
|
|
|
|
|
|
|
|
if self.Optional == True :
|
|
|
|
GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")
|
|
|
|
return '', None
|
|
|
|
else:
|
|
|
|
EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)
|
|
|
|
|
|
|
|
Num = SecNum
|
|
|
|
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',
|
|
|
|
Ui=StringData)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
"""If File List is empty"""
|
|
|
|
if FileList == [] :
|
|
|
|
if self.Optional == True:
|
2014-08-28 15:53:34 +02:00
|
|
|
GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!")
|
|
|
|
return [], None
|
2009-07-17 11:10:31 +02:00
|
|
|
else:
|
2014-08-28 15:53:34 +02:00
|
|
|
EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))
|
2009-07-17 11:10:31 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
"""Convert the File to Section file one by one """
|
|
|
|
for File in FileList:
|
|
|
|
""" Copy Map file to FFS output path """
|
|
|
|
Index = Index + 1
|
|
|
|
Num = '%s.%d' %(SecNum , Index)
|
|
|
|
OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))
|
|
|
|
File = GenFdsGlobalVariable.MacroExtend(File, Dict)
|
2010-03-01 00:39:39 +01:00
|
|
|
|
|
|
|
#Get PE Section alignment when align is set to AUTO
|
|
|
|
if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):
|
|
|
|
ImageObj = PeImageClass (File)
|
|
|
|
if ImageObj.SectionAlignment < 0x400:
|
2015-07-16 02:56:14 +02:00
|
|
|
Align = str (ImageObj.SectionAlignment)
|
2010-03-01 00:39:39 +01:00
|
|
|
else:
|
2015-07-16 02:56:14 +02:00
|
|
|
Align = str (ImageObj.SectionAlignment / 0x400) + 'K'
|
2010-03-01 00:39:39 +01:00
|
|
|
|
2009-07-17 11:10:31 +02:00
|
|
|
if File[(len(File)-4):] == '.efi':
|
|
|
|
MapFile = File.replace('.efi', '.map')
|
|
|
|
if os.path.exists(MapFile):
|
|
|
|
CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')
|
|
|
|
if not os.path.exists(CopyMapFile) or \
|
2014-08-15 05:06:48 +02:00
|
|
|
(os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):
|
|
|
|
CopyLongFilePath(MapFile, CopyMapFile)
|
2009-07-17 11:10:31 +02:00
|
|
|
|
|
|
|
if not NoStrip:
|
|
|
|
FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')
|
|
|
|
if not os.path.exists(FileBeforeStrip) or \
|
|
|
|
(os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):
|
2014-08-15 05:06:48 +02:00
|
|
|
CopyLongFilePath(File, FileBeforeStrip)
|
2009-07-17 11:10:31 +02:00
|
|
|
StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
|
|
|
|
GenFdsGlobalVariable.GenerateFirmwareImage(
|
|
|
|
StrippedFile,
|
2010-03-01 00:39:39 +01:00
|
|
|
[File],
|
2009-07-17 11:10:31 +02:00
|
|
|
Strip=True
|
|
|
|
)
|
|
|
|
File = StrippedFile
|
2010-03-01 00:39:39 +01:00
|
|
|
|
2009-07-17 11:10:31 +02:00
|
|
|
"""For TE Section call GenFw to generate TE image"""
|
|
|
|
|
|
|
|
if SectionType == 'TE':
|
|
|
|
TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
|
|
|
|
GenFdsGlobalVariable.GenerateFirmwareImage(
|
|
|
|
TeFile,
|
2010-03-01 00:39:39 +01:00
|
|
|
[File],
|
2009-07-17 11:10:31 +02:00
|
|
|
Type='te'
|
|
|
|
)
|
|
|
|
File = TeFile
|
|
|
|
|
|
|
|
"""Call GenSection"""
|
|
|
|
GenFdsGlobalVariable.GenerateSection(OutputFile,
|
2010-03-01 00:39:39 +01:00
|
|
|
[File],
|
2009-07-17 11:10:31 +02:00
|
|
|
Section.Section.SectionType.get (SectionType)
|
|
|
|
)
|
|
|
|
OutputFileList.append(OutputFile)
|
|
|
|
|
2015-07-16 02:56:14 +02:00
|
|
|
return OutputFileList, Align
|