]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: remove redundant if comparison
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
1 ## @file
2 # process data section generation
3 #
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Section
19 from GenFdsGlobalVariable import GenFdsGlobalVariable
20 import subprocess
21 from Ffs import Ffs
22 import Common.LongFilePathOs as os
23 from CommonDataClass.FdfClass import DataSectionClassObject
24 from Common.Misc import PeImageClass
25 from Common.LongFilePathSupport import CopyLongFilePath
26 from Common.DataType import *
27
28 ## generate data section
29 #
30 #
31 class DataSection (DataSectionClassObject):
32 ## The constructor
33 #
34 # @param self The object pointer
35 #
36 def __init__(self):
37 DataSectionClassObject.__init__(self)
38
39 ## GenSection() method
40 #
41 # Generate compressed section
42 #
43 # @param self The object pointer
44 # @param OutputPath Where to place output file
45 # @param ModuleName Which module this section belongs to
46 # @param SecNum Index of section
47 # @param KeyStringList Filter for inputs of section generation
48 # @param FfsInf FfsInfStatement object that contains this section data
49 # @param Dict dictionary contains macro and its value
50 # @retval tuple (Generated file name list, section alignment)
51 #
52 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):
53 #
54 # Prepare the parameter of GenSection
55 #
56 if FfsFile is not None:
57 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
58 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)
59 else:
60 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
61 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)
62
63 """Check Section file exist or not !"""
64
65 if not os.path.exists(self.SectFileName):
66 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,
67 self.SectFileName)
68
69 """Copy Map file to Ffs output"""
70 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)
71 if Filename[(len(Filename)-4):] == '.efi':
72 MapFile = Filename.replace('.efi', '.map')
73 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')
74 if IsMakefile:
75 if GenFdsGlobalVariable.CopyList == []:
76 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]
77 else:
78 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))
79 else:
80 if os.path.exists(MapFile):
81 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):
82 CopyLongFilePath(MapFile, CopyMapFile)
83
84 #Get PE Section alignment when align is set to AUTO
85 if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
86 ImageObj = PeImageClass (Filename)
87 if ImageObj.SectionAlignment < 0x400:
88 self.Alignment = str (ImageObj.SectionAlignment)
89 elif ImageObj.SectionAlignment < 0x100000:
90 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
91 else:
92 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'
93
94 NoStrip = True
95 if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
96 if self.KeepReloc is not None:
97 NoStrip = self.KeepReloc
98
99 if not NoStrip:
100 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')
101 if not os.path.exists(FileBeforeStrip) or \
102 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):
103 CopyLongFilePath(self.SectFileName, FileBeforeStrip)
104 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
105 GenFdsGlobalVariable.GenerateFirmwareImage(
106 StrippedFile,
107 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
108 Strip=True,
109 IsMakefile = IsMakefile
110 )
111 self.SectFileName = StrippedFile
112
113 if self.SecType == BINARY_FILE_TYPE_TE:
114 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
115 GenFdsGlobalVariable.GenerateFirmwareImage(
116 TeFile,
117 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
118 Type='te',
119 IsMakefile = IsMakefile
120 )
121 self.SectFileName = TeFile
122
123 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get(self.SecType))
124 OutputFile = os.path.normpath(OutputFile)
125 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)
126 FileList = [OutputFile]
127 return FileList, self.Alignment