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