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