]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/EfiSection.py
Fix build break caused by adding DebugAgentLib to the DXE Core.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / EfiSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process rule section generation\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5#\r
6# All rights reserved. This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
18import Section\r
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
20import subprocess\r
21from Ffs import Ffs\r
22import os\r
23from CommonDataClass.FdfClass import EfiSectionClassObject\r
24import shutil\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
27\r
28## generate rule section\r
29#\r
30#\r
31class EfiSection (EfiSectionClassObject):\r
32\r
33 ## The constructor\r
34 #\r
35 # @param self The object pointer\r
36 #\r
37 def __init__(self):\r
38 EfiSectionClassObject.__init__(self)\r
39\r
40 ## GenSection() method\r
41 #\r
42 # Generate rule section\r
43 #\r
44 # @param self The object pointer\r
45 # @param OutputPath Where to place output file\r
46 # @param ModuleName Which module this section belongs to\r
47 # @param SecNum Index of section\r
48 # @param KeyStringList Filter for inputs of section generation\r
49 # @param FfsInf FfsInfStatement object that contains this section data\r
50 # @param Dict dictionary contains macro and its value\r
51 # @retval tuple (Generated file name list, section alignment)\r
52 #\r
53 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}) :\r
54 \r
55 if self.FileName != None and self.FileName.startswith('PCD('):\r
56 self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r
57 """Prepare the parameter of GenSection"""\r
58 if FfsInf != None :\r
59 InfFileName = FfsInf.InfFileName\r
60 SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
61 Filename = FfsInf.__ExtendMacro__(self.FileName)\r
62 BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r
63 StringData = FfsInf.__ExtendMacro__(self.StringData)\r
64 NoStrip = True\r
65 if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):\r
66 if FfsInf.KeepReloc != None:\r
67 NoStrip = FfsInf.KeepReloc\r
68 elif FfsInf.KeepRelocFromRule != None:\r
69 NoStrip = FfsInf.KeepRelocFromRule\r
70 elif self.KeepReloc != None:\r
71 NoStrip = self.KeepReloc\r
72 elif FfsInf.ShadowFromInfFile != None:\r
73 NoStrip = FfsInf.ShadowFromInfFile\r
74 else:\r
75 EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)\r
76\r
77 """If the file name was pointed out, add it in FileList"""\r
78 FileList = []\r
79 if Filename != None:\r
80 Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r
81 if not self.Optional:\r
82 FileList.append(Filename)\r
83 elif os.path.exists(Filename):\r
84 FileList.append(Filename)\r
85 else:\r
86 FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict)\r
87 if IsSect :\r
88 return FileList, self.Alignment\r
89\r
90 Index = 0\r
91\r
92 """ If Section type is 'VERSION'"""\r
93 OutputFileList = []\r
94 if SectionType == 'VERSION':\r
95\r
96 InfOverrideVerString = False\r
97 if FfsInf.Version != None:\r
98 #StringData = FfsInf.Version\r
99 BuildNum = FfsInf.Version\r
100 InfOverrideVerString = True\r
101\r
102 if InfOverrideVerString:\r
103 #VerTuple = ('-n', '"' + StringData + '"')\r
104 if BuildNum != None and BuildNum != '':\r
105 BuildNumTuple = ('-j', BuildNum)\r
106 else:\r
107 BuildNumTuple = tuple()\r
108\r
109 Num = SecNum\r
110 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
111 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
112 #Ui=StringData, \r
113 Ver=BuildNum)\r
114 OutputFileList.append(OutputFile)\r
115\r
116 elif FileList != []:\r
117 for File in FileList:\r
118 Index = Index + 1\r
119 Num = '%s.%d' %(SecNum , Index)\r
120 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
121 f = open(File, 'r')\r
122 VerString = f.read()\r
123 f.close()\r
124# VerTuple = ('-n', '"' + VerString + '"')\r
125 BuildNum = VerString\r
126 if BuildNum != None and BuildNum != '':\r
127 BuildNumTuple = ('-j', BuildNum)\r
128 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
129 #Ui=VerString, \r
130 Ver=BuildNum)\r
131 OutputFileList.append(OutputFile)\r
132\r
133 else:\r
134# if StringData != None and len(StringData) > 0:\r
135# VerTuple = ('-n', '"' + StringData + '"')\r
136# else:\r
137# VerTuple = tuple()\r
138# VerString = ' ' + ' '.join(VerTuple)\r
139 BuildNum = StringData\r
140 if BuildNum != None and BuildNum != '':\r
141 BuildNumTuple = ('-j', BuildNum)\r
142 else:\r
143 BuildNumTuple = tuple()\r
144 BuildNumString = ' ' + ' '.join(BuildNumTuple)\r
145\r
146 #if VerString == '' and \r
147 if BuildNumString == '':\r
148 if self.Optional == True :\r
149 GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
150 return [], None\r
151 else:\r
152 EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)\r
153 Num = SecNum\r
154 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
155 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r
156 #Ui=VerString, \r
157 Ver=BuildNum)\r
158 OutputFileList.append(OutputFile)\r
159\r
160 #\r
161 # If Section Type is 'UI'\r
162 #\r
163 elif SectionType == 'UI':\r
164\r
165 InfOverrideUiString = False\r
166 if FfsInf.Ui != None:\r
167 StringData = FfsInf.Ui\r
168 InfOverrideUiString = True\r
169\r
170 if InfOverrideUiString:\r
171 Num = SecNum\r
172 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
173 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
174 Ui=StringData)\r
175 OutputFileList.append(OutputFile)\r
176\r
177 elif FileList != []:\r
178 for File in FileList:\r
179 Index = Index + 1\r
180 Num = '%s.%d' %(SecNum , Index)\r
181 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
182 f = open(File, 'r')\r
183 UiString = f.read()\r
184 f.close()\r
185 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
186 Ui=UiString)\r
187 OutputFileList.append(OutputFile)\r
188 else:\r
189 if StringData != None and len(StringData) > 0:\r
190 UiTuple = ('-n', '"' + StringData + '"')\r
191 else:\r
192 UiTuple = tuple()\r
193\r
194 if self.Optional == True :\r
195 GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
196 return '', None\r
197 else:\r
198 EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)\r
199\r
200 Num = SecNum\r
201 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r
202 GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r
203 Ui=StringData)\r
204 OutputFileList.append(OutputFile)\r
205\r
206\r
207 else:\r
208 """If File List is empty"""\r
209 if FileList == [] :\r
210 if self.Optional == True:\r
211 GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r
212 return [], None\r
213 else:\r
214 EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r
215\r
216 else:\r
217 """Convert the File to Section file one by one """\r
218 for File in FileList:\r
219 """ Copy Map file to FFS output path """\r
220 Index = Index + 1\r
221 Num = '%s.%d' %(SecNum , Index)\r
222 OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r
223 File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r
224 if File[(len(File)-4):] == '.efi':\r
225 MapFile = File.replace('.efi', '.map')\r
226 if os.path.exists(MapFile):\r
227 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
228 if not os.path.exists(CopyMapFile) or \\r
229 (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
230 shutil.copyfile(MapFile, CopyMapFile)\r
231\r
232 if not NoStrip:\r
233 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
234 if not os.path.exists(FileBeforeStrip) or \\r
235 (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r
236 shutil.copyfile(File, FileBeforeStrip)\r
237 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
238 GenFdsGlobalVariable.GenerateFirmwareImage(\r
239 StrippedFile,\r
240 [GenFdsGlobalVariable.MacroExtend(File, Dict)],\r
241 Strip=True\r
242 )\r
243 File = StrippedFile\r
244 """For TE Section call GenFw to generate TE image"""\r
245\r
246 if SectionType == 'TE':\r
247 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
248 GenFdsGlobalVariable.GenerateFirmwareImage(\r
249 TeFile,\r
250 [GenFdsGlobalVariable.MacroExtend(File, Dict)],\r
251 Type='te'\r
252 )\r
253 File = TeFile\r
254\r
255 """Call GenSection"""\r
256 GenFdsGlobalVariable.GenerateSection(OutputFile,\r
257 [GenFdsGlobalVariable.MacroExtend(File)],\r
258 Section.Section.SectionType.get (SectionType)\r
259 )\r
260 OutputFileList.append(OutputFile)\r
261\r
262 return OutputFileList, self.Alignment\r