]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
1 ## @file
2 # process data section generation
3 #
4 # Copyright (c) 2007 - 2017, 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
27 ## generate data section
28 #
29 #
30 class DataSection (DataSectionClassObject):
31 ## The constructor
32 #
33 # @param self The object pointer
34 #
35 def __init__(self):
36 DataSectionClassObject.__init__(self)
37
38 ## GenSection() method
39 #
40 # Generate compressed section
41 #
42 # @param self The object pointer
43 # @param OutputPath Where to place output file
44 # @param ModuleName Which module this section belongs to
45 # @param SecNum Index of section
46 # @param KeyStringList Filter for inputs of section generation
47 # @param FfsInf FfsInfStatement object that contains this section data
48 # @param Dict dictionary contains macro and its value
49 # @retval tuple (Generated file name list, section alignment)
50 #
51 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):
52 #
53 # Prepare the parameter of GenSection
54 #
55 if FfsFile is not None:
56 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
57 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)
58 else:
59 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
60 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)
61
62 """Check Section file exist or not !"""
63
64 if not os.path.exists(self.SectFileName):
65 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,
66 self.SectFileName)
67
68 """Copy Map file to Ffs output"""
69 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)
70 if Filename[(len(Filename)-4):] == '.efi':
71 MapFile = Filename.replace('.efi', '.map')
72 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')
73 if IsMakefile:
74 if GenFdsGlobalVariable.CopyList == []:
75 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]
76 else:
77 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))
78 else:
79 if os.path.exists(MapFile):
80 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):
81 CopyLongFilePath(MapFile, CopyMapFile)
82
83 #Get PE Section alignment when align is set to AUTO
84 if self.Alignment == 'Auto' and self.SecType in ('TE', 'PE32'):
85 ImageObj = PeImageClass (Filename)
86 if ImageObj.SectionAlignment < 0x400:
87 self.Alignment = str (ImageObj.SectionAlignment)
88 elif ImageObj.SectionAlignment < 0x100000:
89 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'
90 else:
91 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'
92
93 NoStrip = True
94 if self.SecType in ('TE', 'PE32'):
95 if self.KeepReloc is not None:
96 NoStrip = self.KeepReloc
97
98 if not NoStrip:
99 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')
100 if not os.path.exists(FileBeforeStrip) or \
101 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):
102 CopyLongFilePath(self.SectFileName, FileBeforeStrip)
103 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
104 GenFdsGlobalVariable.GenerateFirmwareImage(
105 StrippedFile,
106 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
107 Strip=True,
108 IsMakefile = IsMakefile
109 )
110 self.SectFileName = StrippedFile
111
112 if self.SecType == 'TE':
113 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
114 GenFdsGlobalVariable.GenerateFirmwareImage(
115 TeFile,
116 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
117 Type='te',
118 IsMakefile = IsMakefile
119 )
120 self.SectFileName = TeFile
121
122 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))
123 OutputFile = os.path.normpath(OutputFile)
124 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)
125 FileList = [OutputFile]
126 return FileList, self.Alignment