]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 = None, IsMakefile = False):
48 #
49 # Prepare the parameter of GenSection
50 #
51 if Dict is None:
52 Dict = {}
53 if FfsFile is not None:
54 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
55 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)
56 else:
57 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
58 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)
59
60 """Check Section file exist or not !"""
61
62 if not os.path.exists(self.SectFileName):
63 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,
64 self.SectFileName)
65
66 """Copy Map file to Ffs output"""
67 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)
68 if Filename[(len(Filename)-4):] == '.efi':
69 MapFile = Filename.replace('.efi', '.map')
70 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')
71 if IsMakefile:
72 if GenFdsGlobalVariable.CopyList == []:
73 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]
74 else:
75 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))
76 else:
77 if os.path.exists(MapFile):
78 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):
79 CopyLongFilePath(MapFile, CopyMapFile)
80
81 #Get PE Section alignment when align is set to AUTO
82 if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
83 self.Alignment = "0"
84 NoStrip = True
85 if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):
86 if self.KeepReloc is not None:
87 NoStrip = self.KeepReloc
88
89 if not NoStrip:
90 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')
91 if not os.path.exists(FileBeforeStrip) or \
92 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):
93 CopyLongFilePath(self.SectFileName, FileBeforeStrip)
94 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
95 GenFdsGlobalVariable.GenerateFirmwareImage(
96 StrippedFile,
97 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
98 Strip=True,
99 IsMakefile = IsMakefile
100 )
101 self.SectFileName = StrippedFile
102
103 if self.SecType == BINARY_FILE_TYPE_TE:
104 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
105 GenFdsGlobalVariable.GenerateFirmwareImage(
106 TeFile,
107 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
108 Type='te',
109 IsMakefile = IsMakefile
110 )
111 self.SectFileName = TeFile
112
113 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get(self.SecType))
114 OutputFile = os.path.normpath(OutputFile)
115 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)
116 FileList = [OutputFile]
117 return FileList, self.Alignment