X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FEfiSection.py;h=74f176cfef2f9833169f1c2b7994ee1c2385ff71;hb=04797875d1d53e53e31eca4fa01bc3cf6929f39c;hp=1be23b4bf7fd85e52f48354875dd00801275b8bf;hpb=8bb63e377bf10f5769e1502f8d22579fdd40c701;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py index 1be23b4bf7..74f176cfef 100644 --- a/BaseTools/Source/Python/GenFds/EfiSection.py +++ b/BaseTools/Source/Python/GenFds/EfiSection.py @@ -3,23 +3,18 @@ # # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# -# 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 -# 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent # ## # Import Modules # +from __future__ import absolute_import from struct import * -import Section -from GenFdsGlobalVariable import GenFdsGlobalVariable +from . import Section +from .GenFdsGlobalVariable import GenFdsGlobalVariable import subprocess -from Ffs import Ffs +from .Ffs import SectionSuffix import Common.LongFilePathOs as os from CommonDataClass.FdfClass import EfiSectionClassObject from Common import EdkLogger @@ -55,7 +50,7 @@ class EfiSection (EfiSectionClassObject): # @retval tuple (Generated file name list, section alignment) # def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) : - + if self.FileName is not None and self.FileName.startswith('PCD('): self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName) """Prepare the parameter of GenSection""" @@ -67,7 +62,7 @@ class EfiSection (EfiSectionClassObject): StringData = FfsInf.__ExtendMacro__(self.StringData) ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)') NoStrip = True - if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM) and SectionType in ('TE', 'PE32'): + if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_MM_CORE_STANDALONE) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32): if FfsInf.KeepReloc is not None: NoStrip = FfsInf.KeepReloc elif FfsInf.KeepRelocFromRule is not None: @@ -98,7 +93,7 @@ class EfiSection (EfiSectionClassObject): if '.depex' in SuffixMap: FileList.append(Filename) else: - FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile) + FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile, SectionType=SectionType) if IsSect : return FileList, self.Alignment @@ -123,7 +118,7 @@ class EfiSection (EfiSectionClassObject): BuildNumTuple = tuple() Num = SecNum - OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', #Ui=StringData, Ver=BuildNum, @@ -133,8 +128,8 @@ class EfiSection (EfiSectionClassObject): elif FileList != []: for File in FileList: Index = Index + 1 - Num = '%s.%d' %(SecNum , Index) - OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType)) + Num = '%s.%d' %(SecNum, Index) + OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType)) f = open(File, 'r') VerString = f.read() f.close() @@ -155,7 +150,7 @@ class EfiSection (EfiSectionClassObject): BuildNumTuple = tuple() BuildNumString = ' ' + ' '.join(BuildNumTuple) - #if VerString == '' and + #if VerString == '' and if BuildNumString == '': if self.Optional == True : GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!") @@ -163,7 +158,7 @@ class EfiSection (EfiSectionClassObject): else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName) Num = SecNum - OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', #Ui=VerString, Ver=BuildNum, @@ -171,9 +166,9 @@ class EfiSection (EfiSectionClassObject): OutputFileList.append(OutputFile) # - # If Section Type is 'UI' + # If Section Type is BINARY_FILE_TYPE_UI # - elif SectionType == 'UI': + elif SectionType == BINARY_FILE_TYPE_UI: InfOverrideUiString = False if FfsInf.Ui is not None: @@ -184,7 +179,7 @@ class EfiSection (EfiSectionClassObject): Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" - OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) @@ -192,8 +187,8 @@ class EfiSection (EfiSectionClassObject): elif FileList != []: for File in FileList: Index = Index + 1 - Num = '%s.%d' %(SecNum , Index) - OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType)) + Num = '%s.%d' %(SecNum, Index) + OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType)) f = open(File, 'r') UiString = f.read() f.close() @@ -217,11 +212,31 @@ class EfiSection (EfiSectionClassObject): Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" - OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) + # + # If Section Type is BINARY_FILE_TYPE_RAW + # + elif SectionType == BINARY_FILE_TYPE_RAW: + """If File List is empty""" + if FileList == []: + if self.Optional == True: + GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!") + return [], None + else: + EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName)) + + elif len(FileList) > 1: + EdkLogger.error("GenFds", GENFDS_ERROR, + "Files suffixed with %s are not allowed to have more than one file in %s[Binaries] section" % ( + self.FileExtension, InfFileName)) + else: + for File in FileList: + File = GenFdsGlobalVariable.MacroExtend(File, Dict) + OutputFileList.append(File) else: """If File List is empty""" @@ -237,19 +252,19 @@ class EfiSection (EfiSectionClassObject): 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 + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType)) + Num = '%s.%d' %(SecNum, Index) + OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get(SectionType)) File = GenFdsGlobalVariable.MacroExtend(File, Dict) - + #Get PE Section alignment when align is set to AUTO - if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'): + if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE): ImageObj = PeImageClass (File) if ImageObj.SectionAlignment < 0x400: Align = str (ImageObj.SectionAlignment) elif ImageObj.SectionAlignment < 0x100000: - Align = str (ImageObj.SectionAlignment / 0x400) + 'K' + Align = str (ImageObj.SectionAlignment // 0x400) + 'K' else: - Align = str (ImageObj.SectionAlignment / 0x100000) + 'M' + Align = str (ImageObj.SectionAlignment // 0x100000) + 'M' if File[(len(File)-4):] == '.efi': MapFile = File.replace('.efi', '.map') @@ -284,10 +299,10 @@ class EfiSection (EfiSectionClassObject): IsMakefile = IsMakefile ) File = StrippedFile - + """For TE Section call GenFw to generate TE image""" - if SectionType == 'TE': + if SectionType == BINARY_FILE_TYPE_TE: TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw') GenFdsGlobalVariable.GenerateFirmwareImage( TeFile,