]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | AutoGen class.\r | |
3 | \r | |
4 | This class is to generate Autogen.h and Autogen.c according to module surface area\r | |
5 | or library surface area.\r | |
ff225cbb | 6 | \r |
878ddf1f | 7 | Copyright (c) 2006, Intel Corporation\r |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
ff225cbb | 12 | \r |
878ddf1f | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | package org.tianocore.build.autogen;\r | |
19 | \r | |
878ddf1f | 20 | import java.io.File;\r |
73b4e31a | 21 | import java.io.FileInputStream;\r |
22 | import java.io.FileOutputStream;\r | |
878ddf1f | 23 | import java.io.FileReader;\r |
24 | import java.io.FileWriter;\r | |
cb4d97bd | 25 | import java.io.IOException;\r |
878ddf1f | 26 | import java.util.ArrayList;\r |
a29c47e0 | 27 | import java.util.HashSet;\r |
28 | import java.util.Iterator;\r | |
893cea14 | 29 | import java.util.LinkedHashSet;\r |
136adffc | 30 | import java.util.LinkedList;\r |
878ddf1f | 31 | import java.util.List;\r |
32 | import java.util.Map;\r | |
a29c47e0 | 33 | import java.util.Set;\r |
878ddf1f | 34 | \r |
73b4e31a | 35 | import org.apache.tools.ant.BuildException;\r |
36 | import org.apache.xmlbeans.XmlObject;\r | |
d3945b9d | 37 | import org.tianocore.build.exception.AutoGenException;\r |
73b4e31a | 38 | import org.tianocore.build.global.GlobalData;\r |
73b4e31a | 39 | import org.tianocore.build.global.SurfaceAreaQuery;\r |
40 | import org.tianocore.build.id.ModuleIdentification;\r | |
41 | import org.tianocore.build.id.PackageIdentification;\r | |
42 | import org.tianocore.build.pcd.action.PCDAutoGenAction;\r | |
cb4d97bd | 43 | import org.tianocore.common.definitions.ToolDefinitions;\r |
4353d8e1 | 44 | import org.tianocore.common.definitions.EdkDefinitions;\r |
892b0e7a | 45 | import org.tianocore.common.exception.EdkException;\r |
d3945b9d | 46 | import org.tianocore.common.logger.EdkLog;\r |
73b4e31a | 47 | \r |
878ddf1f | 48 | /**\r |
cb4d97bd | 49 | This class is to generate Autogen.h and Autogen.c according to module surface\r |
50 | area or library surface area.\r | |
51 | **/\r | |
878ddf1f | 52 | public class AutoGen {\r |
5f907e4a | 53 | ///\r |
54 | /// The output path of Autogen.h and Autogen.c\r | |
55 | ///\r | |
56 | private String outputPath;\r | |
57 | \r | |
ff225cbb | 58 | ///\r |
59 | /// The name of FV directory\r | |
60 | ///\r | |
73b4e31a | 61 | private String fvDir;\r |
5f907e4a | 62 | \r |
63 | ///\r | |
64 | /// The base name of module or library.\r | |
65 | ///\r | |
66 | private ModuleIdentification moduleId;\r | |
67 | \r | |
68 | ///\r | |
69 | /// The build architecture\r | |
70 | ///\r | |
71 | private String arch;\r | |
72 | \r | |
73 | ///\r | |
74 | /// PcdAutogen instance which is used to manage how to generate the PCD\r | |
75 | /// information.\r | |
76 | ///\r | |
77 | private PCDAutoGenAction myPcdAutogen;\r | |
78 | \r | |
79 | ///\r | |
80 | /// the one of type : NOT_PCD_DRIVER, PEI_PCD_DRIVER, DXE_PCD_DRIVER\r | |
81 | /// \r | |
82 | private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r | |
83 | \r | |
84 | ///\r | |
85 | /// The protocl list which records in module or library surface area and\r | |
86 | /// it's dependence on library instance surface area.\r | |
87 | ///\r | |
88 | private Set<String> mProtocolList = new HashSet<String>();\r | |
89 | \r | |
90 | ///\r | |
91 | /// The Ppi list which recorded in module or library surface area and its\r | |
92 | /// dependency on library instance surface area.\r | |
93 | ///\r | |
94 | private Set<String> mPpiList = new HashSet<String>();\r | |
95 | \r | |
96 | ///\r | |
97 | /// The Guid list which recoreded in module or library surface area and it's\r | |
98 | /// dependence on library instance surface area.\r | |
99 | ///\r | |
100 | private Set<String> mGuidList = new HashSet<String>();\r | |
ff225cbb | 101 | \r |
cb4d97bd | 102 | ///\r |
103 | /// The dependence package list which recoreded in module or library surface\r | |
104 | /// area and it's dependence on library instance surface area.\r | |
105 | ///\r | |
136adffc | 106 | private List<PackageIdentification> mDepPkgList = new LinkedList<PackageIdentification>();\r |
2336382f | 107 | \r |
cb4d97bd | 108 | ///\r |
109 | /// For non library module, add its library instance's construct and destructor to\r | |
4353d8e1 | 110 | /// list. String[0] recode LibConstructor name, String[1] recode Lib instance \r |
e425f073 | 111 | /// module type.\r |
cb4d97bd | 112 | ///\r |
4353d8e1 | 113 | private List<String[]> libConstructList = new ArrayList<String[]>();\r |
114 | private List<String[]> libDestructList = new ArrayList<String[]>();\r | |
5f907e4a | 115 | \r |
cb4d97bd | 116 | ///\r |
117 | /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r | |
118 | ///\r | |
5f907e4a | 119 | private List<String> setVirtalAddList = new ArrayList<String>();\r |
120 | private List<String> exitBootServiceList = new ArrayList<String>();\r | |
121 | \r | |
aacce761 | 122 | private StringBuffer functionDeclarations = new StringBuffer(10240);\r |
123 | \r | |
e425f073 | 124 | //\r |
125 | // flag of PcdComponentNameDisable, PcdDriverDiagnosticDisable \r | |
126 | //\r | |
127 | private boolean componentNamePcd = false;\r | |
128 | private boolean driverDiagnostPcd = false;\r | |
a387de3b | 129 | \r |
e425f073 | 130 | //\r |
131 | // Instance of SurfaceAreaQuery\r | |
132 | //\r | |
83fba802 | 133 | private SurfaceAreaQuery saq = null;\r |
a387de3b | 134 | \r |
2eb7d78d | 135 | private ModuleIdentification parentId = null;\r |
5f907e4a | 136 | \r |
137 | /**\r | |
cb4d97bd | 138 | Construct function\r |
139 | \r | |
140 | This function mainly initialize some member variable.\r | |
141 | \r | |
142 | @param fvDir\r | |
143 | Absolute path of FV directory.\r | |
144 | @param outputPath\r | |
145 | Output path of AutoGen file.\r | |
146 | @param moduleId\r | |
147 | Module identification.\r | |
148 | @param arch\r | |
149 | Target architecture.\r | |
150 | **/\r | |
2eb7d78d | 151 | public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq, ModuleIdentification parentId) {\r |
5f907e4a | 152 | this.outputPath = outputPath;\r |
153 | this.moduleId = moduleId;\r | |
154 | this.arch = arch;\r | |
73b4e31a | 155 | this.fvDir = fvDir;\r |
83fba802 | 156 | this.saq = saq;\r |
2eb7d78d | 157 | this.parentId = parentId;\r |
5f907e4a | 158 | }\r |
159 | \r | |
160 | /**\r | |
cb4d97bd | 161 | saveFile function\r |
162 | \r | |
163 | This function save the content in stringBuffer to file.\r | |
164 | \r | |
165 | @param fileName\r | |
166 | The name of file.\r | |
167 | @param fileBuffer\r | |
168 | The content of AutoGen file in buffer.\r | |
169 | @return boolean \r | |
170 | "true" successful\r | |
171 | "false" failed\r | |
172 | **/\r | |
5f907e4a | 173 | private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r |
a387de3b | 174 | \r |
cb4d97bd | 175 | File autoGenH = new File(fileName);\r |
5f907e4a | 176 | \r |
e425f073 | 177 | //\r |
178 | // if the file exists, compare their content\r | |
179 | //\r | |
cb4d97bd | 180 | if (autoGenH.exists()) {\r |
181 | char[] oldFileBuffer = new char[(int) autoGenH.length()];\r | |
e425f073 | 182 | try {\r |
183 | FileReader fIn = new FileReader(autoGenH);\r | |
184 | fIn.read(oldFileBuffer, 0, (int) autoGenH.length());\r | |
5f907e4a | 185 | fIn.close();\r |
e425f073 | 186 | } catch (IOException e) {\r |
187 | EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r | |
a387de3b | 188 | + "'s " \r |
189 | + fileName \r | |
190 | + " is exist, but can't be open!!");\r | |
e425f073 | 191 | return false;\r |
192 | }\r | |
5f907e4a | 193 | \r |
cb4d97bd | 194 | //\r |
195 | // if we got the same file, don't re-generate it to prevent\r | |
196 | // sources depending on it from re-building\r | |
197 | //\r | |
198 | if (fileBuffer.toString().compareTo(new String(oldFileBuffer)) == 0) {\r | |
199 | return true;\r | |
5f907e4a | 200 | }\r |
cb4d97bd | 201 | }\r |
a387de3b | 202 | \r |
e425f073 | 203 | try {\r |
204 | FileWriter fOut = new FileWriter(autoGenH);\r | |
5f907e4a | 205 | fOut.write(fileBuffer.toString());\r |
e425f073 | 206 | fOut.flush();\r |
5f907e4a | 207 | fOut.close();\r |
e425f073 | 208 | } catch (IOException e) {\r |
209 | EdkLog.log(EdkLog.EDK_INFO, this.moduleId.getName() \r | |
a387de3b | 210 | + "'s " \r |
211 | + fileName \r | |
212 | + " can't be create!!");\r | |
e425f073 | 213 | return false;\r |
a387de3b | 214 | }\r |
5f907e4a | 215 | return true;\r |
216 | }\r | |
217 | \r | |
218 | /**\r | |
cb4d97bd | 219 | genAutogen function\r |
220 | \r | |
221 | This function call libGenAutoGen or moduleGenAutogen function, which\r | |
222 | dependence on generate library autogen or module autogen.\r | |
223 | \r | |
224 | @throws BuildException\r | |
225 | Failed to creat AutoGen.c & AutoGen.h.\r | |
226 | **/\r | |
61528a1b | 227 | public void genAutogen() throws EdkException {\r |
192a42b4 | 228 | //\r |
229 | // If outputPath do not exist, create it.\r | |
230 | //\r | |
231 | File path = new File(outputPath);\r | |
232 | path.mkdirs();\r | |
a387de3b | 233 | \r |
e425f073 | 234 | //\r |
235 | // Check current is library or not, then call the corresponding\r | |
236 | // function.\r | |
237 | //\r | |
238 | if (this.moduleId.isLibrary()) {\r | |
239 | libGenAutogen();\r | |
240 | } else {\r | |
241 | moduleGenAutogen();\r | |
242 | }\r | |
5f907e4a | 243 | }\r |
244 | \r | |
245 | /**\r | |
cb4d97bd | 246 | moduleGenAutogen function\r |
247 | \r | |
248 | This function generates AutoGen.c & AutoGen.h for module.\r | |
249 | \r | |
250 | @throws BuildException\r | |
251 | Faile to create module AutoGen.c & AutoGen.h.\r | |
252 | **/\r | |
61528a1b | 253 | void moduleGenAutogen() throws EdkException {\r |
a387de3b | 254 | setPcdComponentName();\r |
255 | setPcdDriverDiagnostic();\r | |
e425f073 | 256 | collectLibInstanceInfo();\r |
257 | moduleGenAutogenC();\r | |
258 | moduleGenAutogenH();\r | |
5f907e4a | 259 | }\r |
260 | \r | |
261 | /**\r | |
cb4d97bd | 262 | libGenAutogen function\r |
263 | \r | |
264 | This function generates AutoGen.c & AutoGen.h for library.\r | |
265 | \r | |
266 | @throws BuildException\r | |
267 | Faile to create library AutoGen.c & AutoGen.h\r | |
268 | **/\r | |
61528a1b | 269 | void libGenAutogen() throws EdkException {\r |
e425f073 | 270 | libGenAutogenC();\r |
271 | libGenAutogenH();\r | |
5f907e4a | 272 | }\r |
273 | \r | |
274 | /**\r | |
cb4d97bd | 275 | moduleGenAutogenH\r |
276 | \r | |
277 | This function generates AutoGen.h for module.\r | |
278 | \r | |
279 | @throws BuildException\r | |
280 | Failed to generate AutoGen.h.\r | |
281 | **/\r | |
61528a1b | 282 | void moduleGenAutogenH() throws EdkException {\r |
5f907e4a | 283 | \r |
284 | Set<String> libClassIncludeH;\r | |
285 | String moduleType;\r | |
286 | // List<String> headerFileList;\r | |
287 | List<String> headerFileList;\r | |
288 | Iterator item;\r | |
289 | StringBuffer fileBuffer = new StringBuffer(8192);\r | |
290 | \r | |
291 | //\r | |
292 | // Write Autogen.h header notation\r | |
293 | //\r | |
cb4d97bd | 294 | fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r |
5f907e4a | 295 | \r |
296 | //\r | |
297 | // Add #ifndef ${BaseName}_AUTOGENH\r | |
298 | // #def ${BseeName}_AUTOGENH\r | |
299 | //\r | |
cb4d97bd | 300 | fileBuffer.append(CommonDefinition.IFNDEF \r |
a387de3b | 301 | + CommonDefinition.AUTOGENH\r |
302 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
303 | + ToolDefinitions.LINE_SEPARATOR);\r | |
cb4d97bd | 304 | fileBuffer.append(CommonDefinition.DEFINE \r |
a387de3b | 305 | + CommonDefinition.AUTOGENH\r |
306 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
307 | + ToolDefinitions.LINE_SEPARATOR \r | |
308 | + ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 309 | \r |
310 | //\r | |
311 | // Write the specification version and release version at the begine\r | |
312 | // of autogen.h file.\r | |
313 | // Note: the specification version and release version should\r | |
314 | // be got from module surface area instead of hard code by it's\r | |
315 | // moduleType.\r | |
316 | //\r | |
83fba802 | 317 | moduleType = saq.getModuleType();\r |
5f907e4a | 318 | \r |
319 | //\r | |
320 | // Add "extern int __make_me_compile_correctly;" at begin of\r | |
321 | // AutoGen.h.\r | |
322 | //\r | |
cb4d97bd | 323 | fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r |
136adffc | 324 | \r |
325 | //\r | |
326 | // Put EFI_SPECIFICATION_VERSION, and EDK_RELEASE_VERSION.\r | |
878ddf1f | 327 | //\r |
83fba802 | 328 | String[] specList = saq.getExternSpecificaiton();\r |
136adffc | 329 | for (int i = 0; i < specList.length; i++) {\r |
cb4d97bd | 330 | fileBuffer.append(CommonDefinition.DEFINE + specList[i]\r |
aacce761 | 331 | + "\r\n");\r |
5f907e4a | 332 | }\r |
333 | //\r | |
334 | // Write consumed package's mdouleInfo related .h file to autogen.h\r | |
335 | //\r | |
336 | // PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r | |
337 | // .getDependencePkg(this.arch);\r | |
83fba802 | 338 | PackageIdentification[] consumedPkgIdList = saq.getDependencePkg(this.arch);\r |
5f907e4a | 339 | if (consumedPkgIdList != null) {\r |
340 | headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r | |
341 | item = headerFileList.iterator();\r | |
342 | while (item.hasNext()) {\r | |
343 | fileBuffer.append(item.next().toString());\r | |
344 | }\r | |
345 | }\r | |
346 | \r | |
347 | //\r | |
348 | // Write library class's related *.h file to autogen.h.\r | |
349 | //\r | |
700279a9 | 350 | String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch, null);\r |
351 | if (libClassList.length > 0) {\r | |
5f907e4a | 352 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r |
353 | item = libClassIncludeH.iterator();\r | |
354 | while (item.hasNext()) {\r | |
355 | fileBuffer.append(item.next().toString());\r | |
356 | }\r | |
878ddf1f | 357 | }\r |
5f907e4a | 358 | \r |
700279a9 | 359 | libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch, null);\r |
360 | if (libClassList.length > 0) {\r | |
5f907e4a | 361 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r |
362 | item = libClassIncludeH.iterator();\r | |
363 | while (item.hasNext()) {\r | |
364 | fileBuffer.append(item.next().toString());\r | |
365 | }\r | |
366 | }\r | |
aacce761 | 367 | fileBuffer.append("\r\n");\r |
136adffc | 368 | \r |
73b4e31a | 369 | //\r |
ff225cbb | 370 | // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r |
73b4e31a | 371 | // {DEST_DIR_DRBUG}/FlashMap.h\r |
ff225cbb | 372 | //\r |
83fba802 | 373 | if (saq.isHaveTianoR8FlashMap()) {\r |
cb4d97bd | 374 | fileBuffer.append(CommonDefinition.INCLUDE);\r |
73b4e31a | 375 | fileBuffer.append(" <");\r |
aacce761 | 376 | fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r |
73b4e31a | 377 | copyFlashMapHToDebugDir();\r |
378 | }\r | |
379 | \r | |
5f907e4a | 380 | // Write PCD autogen information to AutoGen.h.\r |
381 | //\r | |
382 | if (this.myPcdAutogen != null) {\r | |
aacce761 | 383 | fileBuffer.append("\r\n");\r |
11eb278a | 384 | fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r |
5f907e4a | 385 | }\r |
386 | \r | |
aacce761 | 387 | fileBuffer.append(functionDeclarations);\r |
5f907e4a | 388 | //\r |
389 | // Append the #endif at AutoGen.h\r | |
390 | //\r | |
aacce761 | 391 | fileBuffer.append("#endif\r\n");\r |
5f907e4a | 392 | \r |
393 | //\r | |
394 | // Save string buffer content in AutoGen.h.\r | |
395 | //\r | |
396 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r | |
61528a1b | 397 | throw new AutoGenException("Failed to generate AutoGen.h !!!");\r |
5f907e4a | 398 | }\r |
399 | }\r | |
400 | \r | |
401 | /**\r | |
cb4d97bd | 402 | moduleGenAutogenC\r |
403 | \r | |
404 | This function generates AutoGen.c for module.\r | |
405 | \r | |
406 | @throws BuildException\r | |
407 | Failed to generate AutoGen.c.\r | |
408 | **/\r | |
61528a1b | 409 | void moduleGenAutogenC() throws EdkException {\r |
5f907e4a | 410 | \r |
411 | StringBuffer fileBuffer = new StringBuffer(8192);\r | |
412 | //\r | |
413 | // Write Autogen.c header notation\r | |
414 | //\r | |
cb4d97bd | 415 | fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r |
5f907e4a | 416 | \r |
5f907e4a | 417 | //\r |
418 | // Get the native MSA file infomation. Since before call autogen,\r | |
419 | // the MSA native <Externs> information were overrided. So before\r | |
420 | // process <Externs> it should be set the DOC as the Native MSA info.\r | |
421 | //\r | |
422 | Map<String, XmlObject> doc = GlobalData.getNativeMsa(this.moduleId);\r | |
83fba802 | 423 | saq.push(doc);\r |
5f907e4a | 424 | //\r |
425 | // Write <Extern>\r | |
426 | // DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r | |
427 | // to AutoGen.c\r | |
428 | //\r | |
429 | \r | |
430 | ExternsDriverBindingToAutoGenC(fileBuffer);\r | |
431 | \r | |
432 | //\r | |
433 | // Write DriverExitBootServicesEvent/DriverSetVirtualAddressMapEvent\r | |
434 | // to Autogen.c\r | |
435 | //\r | |
436 | ExternCallBackToAutoGenC(fileBuffer);\r | |
437 | \r | |
438 | //\r | |
439 | // Write EntryPoint to autgoGen.c\r | |
440 | //\r | |
83fba802 | 441 | String[] entryPointList = saq.getModuleEntryPointArray();\r |
e425f073 | 442 | String[] unloadImageList = saq.getModuleUnloadImageArray();\r |
cb4d97bd | 443 | EntryPointToAutoGen(CommonDefinition.remDupString(entryPointList), \r |
a387de3b | 444 | CommonDefinition.remDupString(unloadImageList),\r |
445 | fileBuffer);\r | |
5f907e4a | 446 | \r |
83fba802 | 447 | pcdDriverType = saq.getPcdDriverType();\r |
5f907e4a | 448 | \r |
449 | //\r | |
450 | // Restore the DOC which include the FPD module info.\r | |
451 | //\r | |
83fba802 | 452 | saq.pop();\r |
5f907e4a | 453 | \r |
454 | //\r | |
455 | // Write Guid to autogen.c\r | |
456 | //\r | |
83fba802 | 457 | String guid = CommonDefinition.formatGuidName(saq.getModuleGuid());\r |
2f403520 | 458 | if (this.moduleId.getModuleType().equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r |
a387de3b | 459 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = {");\r |
460 | } else {\r | |
461 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r | |
462 | }\r | |
463 | \r | |
5f907e4a | 464 | if (guid == null) {\r |
465 | throw new AutoGenException("Guid value must set!\n");\r | |
466 | }\r | |
467 | \r | |
468 | //\r | |
469 | // Formate Guid as ANSI c form.Example:\r | |
470 | // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r | |
471 | // 0xf0}}\r | |
472 | //\r | |
473 | \r | |
474 | fileBuffer.append(guid);\r | |
aacce761 | 475 | fileBuffer.append("};\r\n");\r |
5f907e4a | 476 | \r |
477 | //\r | |
478 | // Generate library instance consumed protocol, guid, ppi, pcd list.\r | |
479 | // Save those to this.protocolList, this.ppiList, this.pcdList,\r | |
480 | // this.guidList. Write Consumed library constructor and desconstuct to\r | |
481 | // autogen.c\r | |
482 | //\r | |
136adffc | 483 | LibInstanceToAutogenC(fileBuffer);\r |
ff225cbb | 484 | \r |
878ddf1f | 485 | //\r |
136adffc | 486 | // Get module dependent Package identification.\r |
878ddf1f | 487 | //\r |
83fba802 | 488 | PackageIdentification[] packages = saq.getDependencePkg(this.arch);\r |
5f907e4a | 489 | for (int i = 0; i < packages.length; i++) {\r |
490 | if (!this.mDepPkgList.contains(packages[i])) {\r | |
136adffc | 491 | this.mDepPkgList.add(packages[i]);\r |
878ddf1f | 492 | }\r |
ff225cbb | 493 | \r |
136adffc | 494 | }\r |
ff225cbb | 495 | \r |
5f907e4a | 496 | //\r |
497 | // Write consumed ppi, guid, protocol to autogen.c\r | |
498 | //\r | |
499 | ProtocolGuidToAutogenC(fileBuffer);\r | |
500 | PpiGuidToAutogenC(fileBuffer);\r | |
501 | GuidGuidToAutogenC(fileBuffer);\r | |
ff225cbb | 502 | \r |
5f907e4a | 503 | //\r |
504 | // Call pcd autogen.\r | |
505 | //\r | |
506 | this.myPcdAutogen = new PCDAutoGenAction(moduleId, \r | |
507 | arch, \r | |
508 | false, \r | |
509 | null,\r | |
2eb7d78d | 510 | pcdDriverType, \r |
511 | parentId);\r | |
a387de3b | 512 | \r |
61528a1b | 513 | this.myPcdAutogen.execute();\r |
5f907e4a | 514 | if (this.myPcdAutogen != null) {\r |
aacce761 | 515 | fileBuffer.append("\r\n");\r |
11eb278a | 516 | fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r |
5f907e4a | 517 | }\r |
518 | \r | |
519 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r | |
61528a1b | 520 | throw new AutoGenException("Failed to generate AutoGen.c !!!");\r |
5f907e4a | 521 | }\r |
522 | \r | |
523 | }\r | |
524 | \r | |
525 | /**\r | |
cb4d97bd | 526 | libGenAutogenH\r |
527 | \r | |
528 | This function generates AutoGen.h for library.\r | |
529 | \r | |
530 | @throws BuildException\r | |
531 | Failed to generate AutoGen.c.\r | |
532 | **/\r | |
61528a1b | 533 | void libGenAutogenH() throws EdkException {\r |
5f907e4a | 534 | \r |
535 | Set<String> libClassIncludeH;\r | |
536 | String moduleType;\r | |
537 | List<String> headerFileList;\r | |
538 | Iterator item;\r | |
539 | StringBuffer fileBuffer = new StringBuffer(10240);\r | |
540 | \r | |
541 | //\r | |
542 | // Write Autogen.h header notation\r | |
543 | //\r | |
cb4d97bd | 544 | fileBuffer.append(CommonDefinition.AUTOGENHNOTATION);\r |
5f907e4a | 545 | \r |
546 | //\r | |
547 | // Add #ifndef ${BaseName}_AUTOGENH\r | |
548 | // #def ${BseeName}_AUTOGENH\r | |
549 | //\r | |
cb4d97bd | 550 | fileBuffer.append(CommonDefinition.IFNDEF \r |
a387de3b | 551 | + CommonDefinition.AUTOGENH\r |
552 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
553 | + ToolDefinitions.LINE_SEPARATOR);\r | |
cb4d97bd | 554 | fileBuffer.append(CommonDefinition.DEFINE \r |
a387de3b | 555 | + CommonDefinition.AUTOGENH\r |
556 | + this.moduleId.getGuid().replaceAll("-", "_") \r | |
557 | + ToolDefinitions.LINE_SEPARATOR \r | |
558 | + ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 559 | \r |
560 | //\r | |
561 | // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r | |
562 | // to autogen.h file.\r | |
563 | // Note: the specification version and release version should\r | |
564 | // be get from module surface area instead of hard code.\r | |
565 | //\r | |
cb4d97bd | 566 | fileBuffer.append(CommonDefinition.AUTOGENHBEGIN);\r |
83fba802 | 567 | String[] specList = saq.getExternSpecificaiton();\r |
5f907e4a | 568 | for (int i = 0; i < specList.length; i++) {\r |
aacce761 | 569 | fileBuffer.append(CommonDefinition.DEFINE + specList[i] + "\r\n");\r |
5f907e4a | 570 | }\r |
571 | // fileBuffer.append(CommonDefinition.autoGenHLine1);\r | |
572 | // fileBuffer.append(CommonDefinition.autoGenHLine2);\r | |
573 | \r | |
574 | //\r | |
575 | // Write consumed package's mdouleInfo related *.h file to autogen.h.\r | |
576 | //\r | |
83fba802 | 577 | moduleType = saq.getModuleType();\r |
aacce761 | 578 | PackageIdentification[] cosumedPkglist = saq.getDependencePkg(this.arch);\r |
5f907e4a | 579 | headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r |
580 | item = headerFileList.iterator();\r | |
581 | while (item.hasNext()) {\r | |
582 | fileBuffer.append(item.next().toString());\r | |
583 | }\r | |
584 | //\r | |
585 | // Write library class's related *.h file to autogen.h\r | |
586 | //\r | |
700279a9 | 587 | String[] libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, this.arch, null);\r |
5f907e4a | 588 | if (libClassList != null) {\r |
589 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
590 | item = libClassIncludeH.iterator();\r | |
591 | while (item.hasNext()) {\r | |
592 | fileBuffer.append(item.next().toString());\r | |
593 | }\r | |
594 | }\r | |
595 | \r | |
700279a9 | 596 | libClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, this.arch, null);\r |
5f907e4a | 597 | if (libClassList != null) {\r |
598 | libClassIncludeH = LibraryClassToAutogenH(libClassList);\r | |
599 | item = libClassIncludeH.iterator();\r | |
600 | while (item.hasNext()) {\r | |
601 | fileBuffer.append(item.next().toString());\r | |
602 | }\r | |
603 | }\r | |
cb4d97bd | 604 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
136adffc | 605 | \r |
73b4e31a | 606 | //\r |
ff225cbb | 607 | // If is TianoR8FlashMap, copy {Fv_DIR}/FlashMap.h to\r |
73b4e31a | 608 | // {DEST_DIR_DRBUG}/FlashMap.h\r |
ff225cbb | 609 | //\r |
83fba802 | 610 | if (saq.isHaveTianoR8FlashMap()) {\r |
cb4d97bd | 611 | fileBuffer.append(CommonDefinition.INCLUDE);\r |
73b4e31a | 612 | fileBuffer.append(" <");\r |
aacce761 | 613 | fileBuffer.append(CommonDefinition.TIANOR8PLASHMAPH + ">\r\n");\r |
73b4e31a | 614 | copyFlashMapHToDebugDir();\r |
615 | }\r | |
616 | \r | |
5f907e4a | 617 | //\r |
618 | // Write PCD information to library AutoGen.h.\r | |
619 | //\r | |
620 | if (this.myPcdAutogen != null) {\r | |
aacce761 | 621 | fileBuffer.append("\r\n");\r |
11eb278a | 622 | fileBuffer.append(this.myPcdAutogen.getHAutoGenString());\r |
5f907e4a | 623 | }\r |
f9081b64 | 624 | //\r |
625 | // generate function prototype for constructor and destructor\r | |
626 | // \r | |
aacce761 | 627 | LibConstructorToAutogenH(moduleType);\r |
628 | LibDestructorToAutogenH(moduleType);\r | |
629 | ExternCallBackToAutoGenH(moduleType);\r | |
630 | fileBuffer.append(functionDeclarations);\r | |
5f907e4a | 631 | //\r |
632 | // Append the #endif at AutoGen.h\r | |
633 | //\r | |
aacce761 | 634 | fileBuffer.append("#endif\r\n");\r |
5f907e4a | 635 | //\r |
636 | // Save content of string buffer to AutoGen.h file.\r | |
637 | //\r | |
638 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r | |
61528a1b | 639 | throw new AutoGenException("Failed to generate AutoGen.h !!!");\r |
5f907e4a | 640 | }\r |
641 | }\r | |
642 | \r | |
643 | /**\r | |
cb4d97bd | 644 | libGenAutogenC\r |
645 | \r | |
646 | This function generates AutoGen.h for library.\r | |
647 | \r | |
648 | @throws BuildException\r | |
649 | Failed to generate AutoGen.c.\r | |
650 | **/\r | |
61528a1b | 651 | void libGenAutogenC() throws EdkException {\r |
5f907e4a | 652 | StringBuffer fileBuffer = new StringBuffer(10240);\r |
653 | \r | |
654 | //\r | |
655 | // Write Autogen.c header notation\r | |
656 | //\r | |
cb4d97bd | 657 | fileBuffer.append(CommonDefinition.AUTOGENCNOTATION);\r |
5f907e4a | 658 | \r |
cb4d97bd | 659 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
660 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r | |
5f907e4a | 661 | \r |
662 | //\r | |
663 | // Call pcd autogen.\r | |
664 | //\r | |
665 | this.myPcdAutogen = new PCDAutoGenAction(moduleId,\r | |
666 | arch,\r | |
667 | true,\r | |
7432a214 | 668 | saq.getModulePcdEntryNameArray(this.arch),\r |
2eb7d78d | 669 | pcdDriverType, \r |
670 | parentId);\r | |
61528a1b | 671 | this.myPcdAutogen.execute();\r |
5f907e4a | 672 | if (this.myPcdAutogen != null) {\r |
cb4d97bd | 673 | fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r |
11eb278a | 674 | fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r |
5f907e4a | 675 | }\r |
676 | \r | |
677 | if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r | |
61528a1b | 678 | throw new AutoGenException("Failed to generate AutoGen.c !!!");\r |
5f907e4a | 679 | }\r |
680 | }\r | |
681 | \r | |
682 | /**\r | |
cb4d97bd | 683 | LibraryClassToAutogenH\r |
684 | \r | |
685 | This function returns *.h files declared by library classes which are\r | |
686 | consumed or produced by current build module or library.\r | |
687 | \r | |
688 | @param libClassList\r | |
689 | List of library class which consumed or produce by current\r | |
690 | build module or library.\r | |
691 | @return includeStrList List of *.h file.\r | |
692 | **/\r | |
5f907e4a | 693 | Set<String> LibraryClassToAutogenH(String[] libClassList)\r |
61528a1b | 694 | throws EdkException {\r |
cb4d97bd | 695 | Set<String> includeStrList = new LinkedHashSet<String>();\r |
696 | String includeName[];\r | |
5f907e4a | 697 | String str = "";\r |
698 | \r | |
699 | //\r | |
700 | // Get include file from GlobalData's SPDTable according to\r | |
701 | // library class name.\r | |
702 | //\r | |
5f907e4a | 703 | for (int i = 0; i < libClassList.length; i++) {\r |
cb4d97bd | 704 | includeName = GlobalData.getLibraryClassHeaderFiles(\r |
a387de3b | 705 | saq.getDependencePkg(this.arch),\r |
706 | libClassList[i]);\r | |
707 | if (includeName == null) {\r | |
708 | throw new AutoGenException("Can not find library class ["\r | |
5f907e4a | 709 | + libClassList[i] + "] declaration in any SPD package. ");\r |
710 | }\r | |
cb4d97bd | 711 | for (int j = 0; j < includeName.length; j++) {\r |
712 | String includeNameStr = includeName[j];\r | |
5f907e4a | 713 | if (includeNameStr != null) {\r |
cb4d97bd | 714 | str = CommonDefinition.INCLUDE + " " + "<";\r |
aacce761 | 715 | str = str + includeNameStr + ">\r\n";\r |
cb4d97bd | 716 | includeStrList.add(str);\r |
5f907e4a | 717 | includeNameStr = null;\r |
878ddf1f | 718 | }\r |
5f907e4a | 719 | }\r |
720 | }\r | |
cb4d97bd | 721 | return includeStrList;\r |
5f907e4a | 722 | }\r |
723 | \r | |
724 | /**\r | |
cb4d97bd | 725 | IncludesToAutogenH\r |
726 | \r | |
727 | This function add include file in AutoGen.h file.\r | |
728 | \r | |
729 | @param packageNameList\r | |
730 | List of module depended package.\r | |
731 | @param moduleType\r | |
732 | Module type.\r | |
733 | @return\r | |
734 | **/\r | |
5f907e4a | 735 | List<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r |
736 | String moduleType) throws AutoGenException {\r | |
737 | \r | |
738 | List<String> includeStrList = new LinkedList<String>();\r | |
739 | String pkgHeader;\r | |
740 | String includeStr = "";\r | |
741 | \r | |
742 | //\r | |
743 | // Get include file from moduleInfo file\r | |
744 | //\r | |
745 | for (int i = 0; i < packageNameList.length; i++) {\r | |
746 | pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i],\r | |
747 | moduleType);\r | |
748 | if (pkgHeader == null) {\r | |
749 | throw new AutoGenException("Can not find package ["\r | |
750 | + packageNameList[i]\r | |
751 | + "] declaration in any SPD package. ");\r | |
752 | } else if (!pkgHeader.equalsIgnoreCase("")) {\r | |
aacce761 | 753 | includeStr = CommonDefinition.INCLUDE + " <" + pkgHeader + ">\r\n";\r |
5f907e4a | 754 | includeStrList.add(includeStr);\r |
755 | }\r | |
756 | }\r | |
757 | \r | |
758 | return includeStrList;\r | |
759 | }\r | |
760 | \r | |
761 | /**\r | |
cb4d97bd | 762 | EntryPointToAutoGen\r |
763 | \r | |
764 | This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r | |
765 | information in mas to AutoGen.c\r | |
766 | \r | |
767 | @param entryPointList\r | |
768 | List of entry point.\r | |
769 | @param fileBuffer\r | |
770 | String buffer fo AutoGen.c.\r | |
771 | @throws Exception\r | |
772 | **/\r | |
773 | void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer)\r | |
61528a1b | 774 | throws EdkException {\r |
5f907e4a | 775 | \r |
83fba802 | 776 | String typeStr = saq.getModuleType();\r |
aacce761 | 777 | String debugStr = "DEBUG ((EFI_D_INFO | EFI_D_LOAD, \"Module Entry Point (%s) 0x%%p\\n\", (VOID *)(UINTN)%s));\r\n";\r |
a387de3b | 778 | int unloadImageCount = 0;\r |
cb4d97bd | 779 | int entryPointCount = 0;\r |
5f907e4a | 780 | \r |
781 | //\r | |
782 | // The parameters and return value of entryPoint is difference\r | |
783 | // for difference module type.\r | |
784 | //\r | |
785 | switch (CommonDefinition.getModuleType(typeStr)) {\r | |
786 | \r | |
787 | case CommonDefinition.ModuleTypePeiCore:\r | |
788 | if (entryPointList == null ||entryPointList.length != 1 ) {\r | |
aacce761 | 789 | throw new AutoGenException("Module type = 'PEI_CORE', can have only one module entry point!");\r |
5f907e4a | 790 | } else {\r |
aacce761 | 791 | fileBuffer.append("EFI_STATUS\r\n");\r |
792 | fileBuffer.append("EFIAPI\r\n");\r | |
5f907e4a | 793 | fileBuffer.append(entryPointList[0]);\r |
aacce761 | 794 | fileBuffer.append(" (\r\n");\r |
795 | fileBuffer.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r | |
796 | fileBuffer.append(" IN VOID *OldCoreData\r\n");\r | |
797 | fileBuffer.append(" );\r\n\r\n");\r | |
798 | \r | |
799 | fileBuffer.append("EFI_STATUS\r\n");\r | |
800 | fileBuffer.append("EFIAPI\r\n");\r | |
801 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
802 | fileBuffer.append(" IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r\n");\r | |
803 | fileBuffer.append(" IN VOID *OldCoreData\r\n");\r | |
804 | fileBuffer.append(" )\r\n\r\n");\r | |
805 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 806 | fileBuffer.append(" return ");\r |
807 | fileBuffer.append(entryPointList[0]);\r | |
aacce761 | 808 | fileBuffer.append(" (PeiStartupDescriptor, OldCoreData);\r\n");\r |
809 | fileBuffer.append("}\r\n\r\n");\r | |
5f907e4a | 810 | }\r |
811 | break;\r | |
878ddf1f | 812 | \r |
5f907e4a | 813 | case CommonDefinition.ModuleTypeDxeCore:\r |
aacce761 | 814 | fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r |
5f907e4a | 815 | if (entryPointList == null || entryPointList.length != 1) {\r |
a387de3b | 816 | throw new AutoGenException("Module type = 'DXE_CORE', can have only one module entry point!");\r |
5f907e4a | 817 | } else {\r |
aacce761 | 818 | fileBuffer.append("VOID\r\n");\r |
819 | fileBuffer.append("EFIAPI\r\n");\r | |
5f907e4a | 820 | fileBuffer.append(entryPointList[0]);\r |
aacce761 | 821 | fileBuffer.append(" (\r\n");\r |
822 | fileBuffer.append(" IN VOID *HobStart\r\n");\r | |
823 | fileBuffer.append(" );\r\n\r\n");\r | |
824 | \r | |
825 | fileBuffer.append("VOID\r\n");\r | |
826 | fileBuffer.append("EFIAPI\r\n");\r | |
827 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
828 | fileBuffer.append(" IN VOID *HobStart\r\n");\r | |
829 | fileBuffer.append(" )\r\n\r\n");\r | |
830 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 831 | fileBuffer.append(" ");\r |
832 | fileBuffer.append(entryPointList[0]);\r | |
aacce761 | 833 | fileBuffer.append(" (HobStart);\r\n");\r |
834 | fileBuffer.append("}\r\n\r\n");\r | |
5f907e4a | 835 | }\r |
836 | break;\r | |
837 | \r | |
838 | case CommonDefinition.ModuleTypePeim:\r | |
cb4d97bd | 839 | entryPointCount = 0;\r |
aacce761 | 840 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = 0;\r\n");\r |
5f907e4a | 841 | if (entryPointList == null || entryPointList.length == 0) {\r |
aacce761 | 842 | fileBuffer.append("EFI_STATUS\r\n");\r |
843 | fileBuffer.append("EFIAPI\r\n");\r | |
844 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
845 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
846 | fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
847 | fileBuffer.append(" )\r\n\r\n");\r | |
848 | fileBuffer.append("{\r\n");\r | |
849 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
850 | fileBuffer.append("}\r\n\r\n");\r | |
5f907e4a | 851 | break;\r |
852 | }\r | |
853 | for (int i = 0; i < entryPointList.length; i++) {\r | |
aacce761 | 854 | fileBuffer.append("EFI_STATUS\r\n");\r |
855 | fileBuffer.append("EFIAPI\r\n");\r | |
5f907e4a | 856 | fileBuffer.append(entryPointList[i]);\r |
aacce761 | 857 | fileBuffer.append(" (\r\n");\r |
858 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
859 | fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
860 | fileBuffer.append(" );\r\n");\r | |
5f907e4a | 861 | entryPointCount++;\r |
5f907e4a | 862 | }\r |
863 | \r | |
aacce761 | 864 | fileBuffer.append("EFI_STATUS\r\n");\r |
865 | fileBuffer.append("EFIAPI\r\n");\r | |
866 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
867 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
868 | fileBuffer.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
869 | fileBuffer.append(" )\r\n\r\n");\r | |
870 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 871 | if (entryPointCount == 1) {\r |
a387de3b | 872 | fileBuffer.append(String.format(" " + debugStr, entryPointList[0], entryPointList[0]));\r |
5f907e4a | 873 | fileBuffer.append(" return ");\r |
874 | fileBuffer.append(entryPointList[0]);\r | |
aacce761 | 875 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r |
5f907e4a | 876 | } else {\r |
aacce761 | 877 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r |
878 | fileBuffer.append(" EFI_STATUS CombinedStatus;\r\n\r\n");\r | |
879 | fileBuffer.append(" CombinedStatus = EFI_LOAD_ERROR;\r\n\r\n");\r | |
5f907e4a | 880 | for (int i = 0; i < entryPointList.length; i++) {\r |
881 | if (!entryPointList[i].equals("")) {\r | |
a387de3b | 882 | fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i]));\r |
5f907e4a | 883 | fileBuffer.append(" Status = ");\r |
884 | fileBuffer.append(entryPointList[i]);\r | |
aacce761 | 885 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r |
886 | fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {\r\n");\r | |
887 | fileBuffer.append(" CombinedStatus = Status;\r\n");\r | |
888 | fileBuffer.append(" }\r\n\r\n");\r | |
5f907e4a | 889 | } else {\r |
890 | break;\r | |
891 | }\r | |
892 | }\r | |
aacce761 | 893 | fileBuffer.append(" return CombinedStatus;\r\n");\r |
5f907e4a | 894 | }\r |
aacce761 | 895 | fileBuffer.append("}\r\n\r\n");\r |
5f907e4a | 896 | break;\r |
897 | \r | |
898 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
899 | entryPointCount = 0;\r | |
900 | //\r | |
901 | // If entryPoint is null, create an empty ProcessModuleEntryPointList\r | |
902 | // function.\r | |
903 | //\r | |
904 | if (entryPointList == null || entryPointList.length == 0) {\r | |
a387de3b | 905 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r |
5f907e4a | 906 | fileBuffer.append(Integer.toString(entryPointCount));\r |
aacce761 | 907 | fileBuffer.append(";\r\n");\r |
908 | fileBuffer.append("EFI_STATUS\r\n");\r | |
909 | fileBuffer.append("EFIAPI\r\n");\r | |
910 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
911 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
912 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
913 | fileBuffer.append(" )\r\n\r\n");\r | |
914 | fileBuffer.append("{\r\n");\r | |
915 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
916 | fileBuffer.append("}\r\n\r\n");\r | |
5f907e4a | 917 | \r |
918 | } else {\r | |
919 | for (int i = 0; i < entryPointList.length; i++) {\r | |
aacce761 | 920 | fileBuffer.append("EFI_STATUS\r\n");\r |
921 | fileBuffer.append("EFIAPI\r\n");\r | |
5f907e4a | 922 | fileBuffer.append(entryPointList[i]);\r |
aacce761 | 923 | fileBuffer.append(" (\r\n");\r |
924 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
925 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
926 | fileBuffer.append(" );\r\n");\r | |
5f907e4a | 927 | entryPointCount++;\r |
928 | }\r | |
a387de3b | 929 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r |
5f907e4a | 930 | fileBuffer.append(Integer.toString(entryPointCount));\r |
aacce761 | 931 | fileBuffer.append(";\r\n");\r |
932 | fileBuffer.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r | |
933 | fileBuffer.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n\r\n");\r | |
934 | \r | |
935 | fileBuffer.append("EFI_STATUS\r\n");\r | |
936 | fileBuffer.append("EFIAPI\r\n");\r | |
937 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
938 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
939 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
940 | fileBuffer.append(" )\r\n\r\n");\r | |
941 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 942 | \r |
5f907e4a | 943 | for (int i = 0; i < entryPointList.length; i++) {\r |
aacce761 | 944 | fileBuffer.append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r |
a387de3b | 945 | fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i]));\r |
5f907e4a | 946 | fileBuffer.append(" ExitDriver (");\r |
947 | fileBuffer.append(entryPointList[i]);\r | |
aacce761 | 948 | fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r |
949 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
950 | fileBuffer.append(" }\r\n");\r | |
136adffc | 951 | }\r |
aacce761 | 952 | fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r |
953 | fileBuffer.append("}\r\n\r\n");\r | |
954 | \r | |
955 | fileBuffer.append("VOID\r\n");\r | |
956 | fileBuffer.append("EFIAPI\r\n");\r | |
957 | fileBuffer.append("ExitDriver (\r\n");\r | |
958 | fileBuffer.append(" IN EFI_STATUS Status\r\n");\r | |
959 | fileBuffer.append(" )\r\n\r\n");\r | |
960 | fileBuffer.append("{\r\n");\r | |
961 | fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r | |
962 | fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r | |
963 | fileBuffer.append(" }\r\n");\r | |
964 | fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r | |
965 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
966 | fileBuffer.append("}\r\n\r\n");\r | |
136adffc | 967 | }\r |
ff225cbb | 968 | \r |
969 | \r | |
5f907e4a | 970 | //\r |
971 | // Add "ModuleUnloadImage" for DxeSmmDriver module type;\r | |
972 | //\r | |
136adffc | 973 | \r |
a387de3b | 974 | unloadImageCount = 0;\r |
cb4d97bd | 975 | if (unloadImageList != null) {\r |
976 | for (int i = 0; i < unloadImageList.length; i++) {\r | |
aacce761 | 977 | fileBuffer.append("EFI_STATUS\r\n");\r |
cb4d97bd | 978 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 979 | fileBuffer.append(" (\r\n");\r |
980 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
981 | fileBuffer.append(" );\r\n");\r | |
cb4d97bd | 982 | unloadImageCount++;\r |
a84091c4 | 983 | }\r |
5f907e4a | 984 | }\r |
136adffc | 985 | \r |
a387de3b | 986 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r |
cb4d97bd | 987 | fileBuffer.append(Integer.toString(unloadImageCount));\r |
aacce761 | 988 | fileBuffer.append(";\r\n\r\n");\r |
5f907e4a | 989 | \r |
aacce761 | 990 | fileBuffer.append("EFI_STATUS\r\n");\r |
991 | fileBuffer.append("EFIAPI\r\n");\r | |
992 | fileBuffer.append("ProcessModuleUnloadList (\r\n");\r | |
993 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
994 | fileBuffer.append(" )\r\n");\r | |
995 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 996 | \r |
cb4d97bd | 997 | if (unloadImageCount == 0) {\r |
aacce761 | 998 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r |
cb4d97bd | 999 | } else if (unloadImageCount == 1) {\r |
5f907e4a | 1000 | fileBuffer.append(" return ");\r |
cb4d97bd | 1001 | fileBuffer.append(unloadImageList[0]);\r |
aacce761 | 1002 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1003 | } else {\r |
aacce761 | 1004 | fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r |
1005 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r | |
cb4d97bd | 1006 | for (int i = 0; i < unloadImageList.length; i++) {\r |
5f907e4a | 1007 | if (i == 0) {\r |
136adffc | 1008 | fileBuffer.append(" Status = ");\r |
cb4d97bd | 1009 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1010 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1011 | } else {\r |
aacce761 | 1012 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r |
878ddf1f | 1013 | fileBuffer.append(" ");\r |
cb4d97bd | 1014 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1015 | fileBuffer.append("(ImageHandle);\r\n");\r |
1016 | fileBuffer.append(" } else {\r\n");\r | |
878ddf1f | 1017 | fileBuffer.append(" Status = ");\r |
cb4d97bd | 1018 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1019 | fileBuffer.append("(ImageHandle);\r\n");\r |
1020 | fileBuffer.append(" }\r\n");\r | |
878ddf1f | 1021 | }\r |
5f907e4a | 1022 | }\r |
aacce761 | 1023 | fileBuffer.append(" return Status;\r\n");\r |
5f907e4a | 1024 | }\r |
aacce761 | 1025 | fileBuffer.append("}\r\n\r\n");\r |
5f907e4a | 1026 | break;\r |
1027 | \r | |
1028 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1029 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1030 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1031 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1032 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1033 | entryPointCount = 0;\r | |
aacce761 | 1034 | fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r |
136adffc | 1035 | //\r |
1036 | // If entry point is null, create a empty ProcessModuleEntryPointList function.\r | |
1037 | //\r | |
5f907e4a | 1038 | if (entryPointList == null || entryPointList.length == 0) {\r |
aacce761 | 1039 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = 0;\r\n");\r |
1040 | fileBuffer.append("EFI_STATUS\r\n");\r | |
1041 | fileBuffer.append("EFIAPI\r\n");\r | |
1042 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
1043 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1044 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1045 | fileBuffer.append(" )\r\n\r\n");\r | |
1046 | fileBuffer.append("{\r\n");\r | |
1047 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r | |
1048 | fileBuffer.append("}\r\n");\r | |
5f907e4a | 1049 | \r |
1050 | } else {\r | |
136adffc | 1051 | for (int i = 0; i < entryPointList.length; i++) {\r |
aacce761 | 1052 | fileBuffer.append("EFI_STATUS\r\n");\r |
1053 | fileBuffer.append("EFIAPI\r\n");\r | |
136adffc | 1054 | fileBuffer.append(entryPointList[i]);\r |
aacce761 | 1055 | fileBuffer.append(" (\r\n");\r |
1056 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1057 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1058 | fileBuffer.append(" );\r\n");\r | |
136adffc | 1059 | entryPointCount++;\r |
878ddf1f | 1060 | }\r |
1061 | \r | |
a387de3b | 1062 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverEntryPointCount = ");\r |
136adffc | 1063 | fileBuffer.append(Integer.toString(entryPointCount));\r |
aacce761 | 1064 | fileBuffer.append(";\r\n");\r |
136adffc | 1065 | if (entryPointCount > 1) {\r |
aacce761 | 1066 | fileBuffer.append("static BASE_LIBRARY_JUMP_BUFFER mJumpContext;\r\n");\r |
1067 | fileBuffer.append("static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;\r\n");\r | |
136adffc | 1068 | }\r |
aacce761 | 1069 | fileBuffer.append("\r\n");\r |
878ddf1f | 1070 | \r |
aacce761 | 1071 | fileBuffer.append("EFI_STATUS\r\n");\r |
1072 | fileBuffer.append("EFIAPI\r\n");\r | |
1073 | fileBuffer.append("ProcessModuleEntryPointList (\r\n");\r | |
1074 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1075 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1076 | fileBuffer.append(" )\r\n\r\n");\r | |
1077 | fileBuffer.append("{\r\n");\r | |
878ddf1f | 1078 | \r |
136adffc | 1079 | if (entryPointCount == 1) {\r |
a387de3b | 1080 | fileBuffer.append(String.format(" " + debugStr, entryPointList[0], entryPointList[0]));\r |
1081 | fileBuffer.append(" return ");\r | |
136adffc | 1082 | fileBuffer.append(entryPointList[0]);\r |
aacce761 | 1083 | fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r |
136adffc | 1084 | } else {\r |
1085 | for (int i = 0; i < entryPointList.length; i++) {\r | |
1086 | if (!entryPointList[i].equals("")) {\r | |
aacce761 | 1087 | fileBuffer.append(" if (SetJump (&mJumpContext) == 0) {\r\n");\r |
a387de3b | 1088 | fileBuffer.append(String.format(" " + debugStr, entryPointList[i], entryPointList[i]));\r |
136adffc | 1089 | fileBuffer.append(" ExitDriver (");\r |
1090 | fileBuffer.append(entryPointList[i]);\r | |
aacce761 | 1091 | fileBuffer.append(" (ImageHandle, SystemTable));\r\n");\r |
1092 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
1093 | fileBuffer.append(" }\r\n");\r | |
136adffc | 1094 | } else {\r |
1095 | break;\r | |
1096 | }\r | |
878ddf1f | 1097 | }\r |
aacce761 | 1098 | fileBuffer.append(" return mDriverEntryPointStatus;\r\n");\r |
878ddf1f | 1099 | }\r |
aacce761 | 1100 | fileBuffer.append("}\r\n\r\n");\r |
1101 | \r | |
1102 | fileBuffer.append("VOID\r\n");\r | |
1103 | fileBuffer.append("EFIAPI\r\n");\r | |
1104 | fileBuffer.append("ExitDriver (\r\n");\r | |
1105 | fileBuffer.append(" IN EFI_STATUS Status\r\n");\r | |
1106 | fileBuffer.append(" )\r\n\r\n");\r | |
1107 | fileBuffer.append("{\r\n");\r | |
136adffc | 1108 | if (entryPointCount <= 1) {\r |
aacce761 | 1109 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r |
1110 | fileBuffer.append(" ProcessLibraryDestructorList (gImageHandle, gST);\r\n");\r | |
1111 | fileBuffer.append(" }\r\n");\r | |
136adffc | 1112 | fileBuffer\r |
aacce761 | 1113 | .append(" gBS->Exit (gImageHandle, Status, 0, NULL);\r\n");\r |
878ddf1f | 1114 | } else {\r |
aacce761 | 1115 | fileBuffer.append(" if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {\r\n");\r |
1116 | fileBuffer.append(" mDriverEntryPointStatus = Status;\r\n");\r | |
1117 | fileBuffer.append(" }\r\n");\r | |
1118 | fileBuffer.append(" LongJump (&mJumpContext, (UINTN)-1);\r\n");\r | |
1119 | fileBuffer.append(" ASSERT (FALSE);\r\n");\r | |
878ddf1f | 1120 | }\r |
aacce761 | 1121 | fileBuffer.append("}\r\n\r\n");\r |
878ddf1f | 1122 | }\r |
ff225cbb | 1123 | \r |
5f907e4a | 1124 | //\r |
1125 | // Add ModuleUnloadImage for DxeDriver and UefiDriver module type.\r | |
1126 | //\r | |
d8f1335e | 1127 | //entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r |
1128 | //\r | |
1129 | // Remover duplicate unload entry point.\r | |
1130 | //\r | |
1131 | //entryPointList = CommonDefinition.remDupString(entryPointList);\r | |
1132 | //entryPointCount = 0;\r | |
a387de3b | 1133 | unloadImageCount = 0;\r |
cb4d97bd | 1134 | if (unloadImageList != null) {\r |
1135 | for (int i = 0; i < unloadImageList.length; i++) {\r | |
aacce761 | 1136 | fileBuffer.append("EFI_STATUS\r\n");\r |
1137 | fileBuffer.append("EFIAPI\r\n");\r | |
cb4d97bd | 1138 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1139 | fileBuffer.append(" (\r\n");\r |
1140 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
1141 | fileBuffer.append(" );\r\n");\r | |
cb4d97bd | 1142 | unloadImageCount++;\r |
5f907e4a | 1143 | }\r |
1144 | }\r | |
1145 | \r | |
a387de3b | 1146 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ");\r |
cb4d97bd | 1147 | fileBuffer.append(Integer.toString(unloadImageCount));\r |
aacce761 | 1148 | fileBuffer.append(";\r\n\r\n");\r |
5f907e4a | 1149 | \r |
aacce761 | 1150 | fileBuffer.append("EFI_STATUS\r\n");\r |
1151 | fileBuffer.append("EFIAPI\r\n");\r | |
1152 | fileBuffer.append("ProcessModuleUnloadList (\r\n");\r | |
1153 | fileBuffer.append(" IN EFI_HANDLE ImageHandle\r\n");\r | |
1154 | fileBuffer.append(" )\r\n");\r | |
1155 | fileBuffer.append("{\r\n");\r | |
5f907e4a | 1156 | \r |
cb4d97bd | 1157 | if (unloadImageCount == 0) {\r |
aacce761 | 1158 | fileBuffer.append(" return EFI_SUCCESS;\r\n");\r |
cb4d97bd | 1159 | } else if (unloadImageCount == 1) {\r |
5f907e4a | 1160 | fileBuffer.append(" return ");\r |
cb4d97bd | 1161 | fileBuffer.append(unloadImageList[0]);\r |
aacce761 | 1162 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1163 | } else {\r |
aacce761 | 1164 | fileBuffer.append(" EFI_STATUS Status;\r\n\r\n");\r |
1165 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n\r\n");\r | |
cb4d97bd | 1166 | for (int i = 0; i < unloadImageList.length; i++) {\r |
25832ed3 | 1167 | if (i == 0) {\r |
1168 | fileBuffer.append(" Status = ");\r | |
cb4d97bd | 1169 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1170 | fileBuffer.append("(ImageHandle);\r\n");\r |
5f907e4a | 1171 | } else {\r |
aacce761 | 1172 | fileBuffer.append(" if (EFI_ERROR (Status)) {\r\n");\r |
5f907e4a | 1173 | fileBuffer.append(" ");\r |
cb4d97bd | 1174 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1175 | fileBuffer.append("(ImageHandle);\r\n");\r |
1176 | fileBuffer.append(" } else {\r\n");\r | |
5f907e4a | 1177 | fileBuffer.append(" Status = ");\r |
cb4d97bd | 1178 | fileBuffer.append(unloadImageList[i]);\r |
aacce761 | 1179 | fileBuffer.append("(ImageHandle);\r\n");\r |
1180 | fileBuffer.append(" }\r\n");\r | |
25832ed3 | 1181 | }\r |
5f907e4a | 1182 | }\r |
aacce761 | 1183 | fileBuffer.append(" return Status;\r\n");\r |
5f907e4a | 1184 | }\r |
aacce761 | 1185 | fileBuffer.append("}\r\n\r\n");\r |
5f907e4a | 1186 | break;\r |
1187 | }\r | |
1188 | }\r | |
1189 | \r | |
1190 | /**\r | |
cb4d97bd | 1191 | PpiGuidToAutogenc\r |
1192 | \r | |
1193 | This function gets GUIDs from SPD file accrodeing to <PPIs> information\r | |
1194 | and write those GUIDs to AutoGen.c.\r | |
1195 | \r | |
1196 | @param fileBuffer\r | |
1197 | String Buffer for Autogen.c file.\r | |
1198 | @throws BuildException\r | |
1199 | Guid must set value!\r | |
1200 | **/\r | |
5f907e4a | 1201 | void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r |
1202 | String[] cNameGuid = null;\r | |
1203 | \r | |
1204 | //\r | |
1205 | // Get the all PPI adn PPI Notify from MSA file,\r | |
1206 | // then add those PPI ,and PPI Notify name to list.\r | |
1207 | //\r | |
1208 | \r | |
83fba802 | 1209 | String[] ppiList = saq.getPpiArray(this.arch);\r |
5f907e4a | 1210 | for (int i = 0; i < ppiList.length; i++) {\r |
1211 | this.mPpiList.add(ppiList[i]);\r | |
1212 | }\r | |
1213 | \r | |
83fba802 | 1214 | String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r |
5f907e4a | 1215 | for (int i = 0; i < ppiNotifyList.length; i++) {\r |
1216 | this.mPpiList.add(ppiNotifyList[i]);\r | |
1217 | }\r | |
1218 | \r | |
1219 | //\r | |
1220 | // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r | |
1221 | //\r | |
1222 | Iterator ppiIterator = this.mPpiList.iterator();\r | |
1223 | String ppiKeyWord = null;\r | |
1224 | while (ppiIterator.hasNext()) {\r | |
1225 | ppiKeyWord = ppiIterator.next().toString();\r | |
1226 | cNameGuid = GlobalData.getPpiGuid(this.mDepPkgList, ppiKeyWord);\r | |
1227 | if (cNameGuid != null) {\r | |
aacce761 | 1228 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r |
5f907e4a | 1229 | fileBuffer.append(cNameGuid[0]);\r |
1230 | fileBuffer.append(" = { ");\r | |
1231 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1232 | fileBuffer.append(" } ;");\r | |
1233 | } else {\r | |
1234 | //\r | |
1235 | // If can't find Ppi GUID declaration in every package\r | |
1236 | //\r | |
1237 | throw new AutoGenException("Can not find Ppi GUID ["\r | |
1238 | + ppiKeyWord + "] declaration in any SPD package!");\r | |
1239 | }\r | |
1240 | }\r | |
1241 | }\r | |
1242 | \r | |
1243 | /**\r | |
cb4d97bd | 1244 | ProtocolGuidToAutogenc\r |
1245 | \r | |
1246 | This function gets GUIDs from SPD file accrodeing to <Protocol>\r | |
1247 | information and write those GUIDs to AutoGen.c.\r | |
1248 | \r | |
1249 | @param fileBuffer\r | |
1250 | String Buffer for Autogen.c file.\r | |
1251 | @throws BuildException\r | |
1252 | Protocol name must set.\r | |
1253 | **/\r | |
61528a1b | 1254 | void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException {\r |
5f907e4a | 1255 | String[] cNameGuid = null;\r |
1256 | \r | |
83fba802 | 1257 | String[] protocolList = saq.getProtocolArray(this.arch);\r |
5f907e4a | 1258 | \r |
1259 | //\r | |
1260 | // Add result to Autogen global list.\r | |
1261 | //\r | |
1262 | for (int i = 0; i < protocolList.length; i++) {\r | |
1263 | this.mProtocolList.add(protocolList[i]);\r | |
1264 | }\r | |
1265 | \r | |
a387de3b | 1266 | String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r |
5f907e4a | 1267 | \r |
1268 | for (int i = 0; i < protocolNotifyList.length; i++) {\r | |
1269 | this.mProtocolList.add(protocolNotifyList[i]);\r | |
1270 | }\r | |
1271 | \r | |
1272 | //\r | |
1273 | // Get the NAME and GUID from dependence SPD and write to Autogen.c\r | |
1274 | //\r | |
1275 | Iterator protocolIterator = this.mProtocolList.iterator();\r | |
1276 | String protocolKeyWord = null;\r | |
1277 | \r | |
1278 | \r | |
1279 | while (protocolIterator.hasNext()) {\r | |
1280 | protocolKeyWord = protocolIterator.next().toString();\r | |
1281 | cNameGuid = GlobalData.getProtocolGuid(this.mDepPkgList, protocolKeyWord);\r | |
1282 | if (cNameGuid != null) {\r | |
aacce761 | 1283 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r |
5f907e4a | 1284 | fileBuffer.append(cNameGuid[0]);\r |
1285 | fileBuffer.append(" = { ");\r | |
1286 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1287 | fileBuffer.append(" } ;");\r | |
1288 | } else {\r | |
1289 | //\r | |
1290 | // If can't find protocol GUID declaration in every package\r | |
1291 | //\r | |
61528a1b | 1292 | throw new AutoGenException("Can not find protocol Guid ["\r |
a387de3b | 1293 | + protocolKeyWord + "] declaration in any SPD package!");\r |
5f907e4a | 1294 | }\r |
1295 | }\r | |
1296 | }\r | |
1297 | \r | |
1298 | /**\r | |
cb4d97bd | 1299 | GuidGuidToAutogenc\r |
1300 | \r | |
1301 | This function gets GUIDs from SPD file accrodeing to <Guids> information\r | |
1302 | and write those GUIDs to AutoGen.c.\r | |
1303 | \r | |
1304 | @param fileBuffer\r | |
1305 | String Buffer for Autogen.c file.\r | |
1306 | \r | |
1307 | **/\r | |
5f907e4a | 1308 | void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r |
1309 | String[] cNameGuid = null;\r | |
1310 | String guidKeyWord = null;\r | |
1311 | \r | |
83fba802 | 1312 | String[] guidList = saq.getGuidEntryArray(this.arch);\r |
5f907e4a | 1313 | \r |
1314 | for (int i = 0; i < guidList.length; i++) {\r | |
1315 | this.mGuidList.add(guidList[i]);\r | |
1316 | }\r | |
1317 | \r | |
1318 | \r | |
1319 | Iterator guidIterator = this.mGuidList.iterator();\r | |
1320 | while (guidIterator.hasNext()) {\r | |
1321 | guidKeyWord = guidIterator.next().toString();\r | |
1322 | cNameGuid = GlobalData.getGuid(this.mDepPkgList, guidKeyWord);\r | |
1323 | \r | |
1324 | if (cNameGuid != null) {\r | |
aacce761 | 1325 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r |
5f907e4a | 1326 | fileBuffer.append(cNameGuid[0]);\r |
1327 | fileBuffer.append(" = { ");\r | |
1328 | fileBuffer.append(CommonDefinition.formatGuidName(cNameGuid[1]));\r | |
1329 | fileBuffer.append("} ;");\r | |
1330 | } else {\r | |
1331 | //\r | |
1332 | // If can't find GUID declaration in every package\r | |
1333 | //\r | |
1334 | throw new AutoGenException("Can not find Guid [" + guidKeyWord\r | |
1335 | + "] declaration in any SPD package. ");\r | |
1336 | }\r | |
1337 | \r | |
1338 | }\r | |
1339 | }\r | |
1340 | \r | |
1341 | /**\r | |
cb4d97bd | 1342 | LibInstanceToAutogenC\r |
1343 | \r | |
1344 | This function adds dependent library instance to autogen.c,which\r | |
1345 | includeing library's constructor, destructor, and library dependent ppi,\r | |
1346 | protocol, guid, pcd information.\r | |
1347 | \r | |
1348 | @param fileBuffer\r | |
1349 | String buffer for AutoGen.c\r | |
1350 | @throws BuildException\r | |
1351 | **/\r | |
61528a1b | 1352 | void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException {\r |
a387de3b | 1353 | String moduleType = this.moduleId.getModuleType();\r |
1354 | //\r | |
1355 | // Add library constructor to AutoGen.c\r | |
1356 | //\r | |
700279a9 | 1357 | LibConstructorToAutogenC(libConstructList, moduleType, fileBuffer);\r |
a387de3b | 1358 | //\r |
1359 | // Add library destructor to AutoGen.c\r | |
1360 | //\r | |
700279a9 | 1361 | LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer);\r |
5f907e4a | 1362 | }\r |
1363 | \r | |
f9081b64 | 1364 | /**\r |
1365 | LibConstructorToAutogenH\r | |
1366 | \r | |
1367 | This function writes library constructor declarations AutoGen.h. The library\r | |
1368 | constructor's parameter and return value depend on module type.\r | |
1369 | \r | |
1370 | @param libInstanceList\r | |
1371 | List of library construct name.\r | |
1372 | @param moduleType\r | |
1373 | Module type.\r | |
1374 | @param fileBuffer\r | |
1375 | String buffer for AutoGen.c\r | |
1376 | @throws Exception\r | |
1377 | **/\r | |
aacce761 | 1378 | void LibConstructorToAutogenH(String moduleType) throws EdkException {\r |
f9081b64 | 1379 | boolean isFirst = true;\r |
1380 | \r | |
1381 | //\r | |
1382 | // If not yet parse this library instance's constructor\r | |
1383 | // element,parse it.\r | |
1384 | //\r | |
1385 | String libConstructName = saq.getLibConstructorName();\r | |
1386 | if (libConstructName == null) {\r | |
1387 | return;\r | |
1388 | }\r | |
1389 | \r | |
1390 | //\r | |
1391 | // The library constructor's parameter and return value depend on\r | |
1392 | // module type.\r | |
1393 | //\r | |
1394 | if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r | |
aacce761 | 1395 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1396 | functionDeclarations.append("EFIAPI\r\n");\r | |
1397 | functionDeclarations.append(libConstructName);\r | |
1398 | functionDeclarations.append(" (\r\n");\r | |
1399 | functionDeclarations.append(" VOID\r\n");\r | |
1400 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1401 | } else {\r |
1402 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1403 | case CommonDefinition.ModuleTypeBase:\r | |
aacce761 | 1404 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1405 | functionDeclarations.append("EFIAPI\r\n");\r | |
1406 | functionDeclarations.append(libConstructName);\r | |
1407 | functionDeclarations.append(" (\r\n");\r | |
1408 | functionDeclarations.append(" VOID\r\n");\r | |
1409 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1410 | break;\r |
1411 | \r | |
1412 | case CommonDefinition.ModuleTypePeiCore:\r | |
1413 | case CommonDefinition.ModuleTypePeim:\r | |
aacce761 | 1414 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1415 | functionDeclarations.append("EFIAPI\r\n");\r | |
1416 | functionDeclarations.append(libConstructName);\r | |
1417 | functionDeclarations.append(" (\r\n");\r | |
1418 | functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1419 | functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1420 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1421 | break;\r |
1422 | \r | |
1423 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1424 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1425 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1426 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1427 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1428 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1429 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1430 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1431 | functionDeclarations.append("EFIAPI\r\n");\r | |
1432 | functionDeclarations.append(libConstructName);\r | |
1433 | functionDeclarations.append(" (\r\n");\r | |
1434 | functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1435 | functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1436 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1437 | break;\r |
1438 | \r | |
1439 | }\r | |
1440 | }\r | |
1441 | }\r | |
1442 | \r | |
1443 | /**\r | |
1444 | LibDestructorToAutogenH\r | |
1445 | \r | |
1446 | This function writes library destructor declarations AutoGen.h. The library\r | |
1447 | destructor's parameter and return value depend on module type.\r | |
1448 | \r | |
1449 | @param libInstanceList\r | |
1450 | List of library destructor name.\r | |
1451 | @param moduleType\r | |
1452 | Module type.\r | |
1453 | @param fileBuffer\r | |
1454 | String buffer for AutoGen.c\r | |
1455 | @throws Exception\r | |
1456 | **/\r | |
aacce761 | 1457 | void LibDestructorToAutogenH(String moduleType) throws EdkException {\r |
f9081b64 | 1458 | boolean isFirst = true;\r |
1459 | String libDestructName = saq.getLibDestructorName();\r | |
1460 | if (libDestructName == null) {\r | |
1461 | return;\r | |
1462 | }\r | |
1463 | \r | |
1464 | if (moduleType.equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r | |
aacce761 | 1465 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1466 | functionDeclarations.append("EFIAPI\r\n");\r | |
1467 | functionDeclarations.append(libDestructName);\r | |
1468 | functionDeclarations.append(" (\r\n");\r | |
1469 | functionDeclarations.append(" VOID\r\n");\r | |
1470 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1471 | } else {\r |
1472 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1473 | case CommonDefinition.ModuleTypeBase:\r | |
aacce761 | 1474 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1475 | functionDeclarations.append("EFIAPI\r\n");\r | |
1476 | functionDeclarations.append(libDestructName);\r | |
1477 | functionDeclarations.append(" (\r\n");\r | |
1478 | functionDeclarations.append(" VOID\r\n");\r | |
1479 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1480 | break;\r |
1481 | case CommonDefinition.ModuleTypePeiCore:\r | |
1482 | case CommonDefinition.ModuleTypePeim:\r | |
aacce761 | 1483 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1484 | functionDeclarations.append("EFIAPI\r\n");\r | |
1485 | functionDeclarations.append(libDestructName);\r | |
1486 | functionDeclarations.append(" (\r\n");\r | |
1487 | functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1488 | functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1489 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1490 | break;\r |
1491 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1492 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1493 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1494 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1495 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1496 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1497 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1498 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1499 | functionDeclarations.append("EFIAPI\r\n");\r | |
1500 | functionDeclarations.append(libDestructName);\r | |
1501 | functionDeclarations.append(" (\r\n");\r | |
1502 | functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1503 | functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1504 | functionDeclarations.append(" );\r\n");\r | |
f9081b64 | 1505 | break;\r |
1506 | }\r | |
1507 | }\r | |
1508 | }\r | |
1509 | \r | |
5f907e4a | 1510 | /**\r |
cb4d97bd | 1511 | LibConstructorToAutogenc\r |
1512 | \r | |
1513 | This function writes library constructor list to AutoGen.c. The library\r | |
1514 | constructor's parameter and return value depend on module type.\r | |
1515 | \r | |
1516 | @param libInstanceList\r | |
1517 | List of library construct name.\r | |
1518 | @param moduleType\r | |
1519 | Module type.\r | |
1520 | @param fileBuffer\r | |
1521 | String buffer for AutoGen.c\r | |
1522 | @throws Exception\r | |
1523 | **/\r | |
4353d8e1 | 1524 | void LibConstructorToAutogenC(List<String[]> libInstanceList,\r |
61528a1b | 1525 | String moduleType, StringBuffer fileBuffer) throws EdkException {\r |
5f907e4a | 1526 | boolean isFirst = true;\r |
1527 | \r | |
1528 | //\r | |
1529 | // The library constructor's parameter and return value depend on\r | |
1530 | // module type.\r | |
1531 | //\r | |
1532 | for (int i = 0; i < libInstanceList.size(); i++) {\r | |
a387de3b | 1533 | if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r |
aacce761 | 1534 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1535 | functionDeclarations.append("EFIAPI\r\n");\r | |
1536 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1537 | functionDeclarations.append(" (\r\n");\r | |
1538 | functionDeclarations.append(" VOID\r\n");\r | |
1539 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1540 | } else {\r |
1541 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
4353d8e1 | 1542 | case CommonDefinition.ModuleTypeBase:\r |
aacce761 | 1543 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1544 | functionDeclarations.append("EFIAPI\r\n");\r | |
1545 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1546 | functionDeclarations.append(" (\r\n");\r | |
1547 | functionDeclarations.append(" VOID\r\n");\r | |
1548 | functionDeclarations.append(" );\r\n");\r | |
4353d8e1 | 1549 | break;\r |
1550 | \r | |
1551 | case CommonDefinition.ModuleTypePeiCore:\r | |
1552 | case CommonDefinition.ModuleTypePeim:\r | |
aacce761 | 1553 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1554 | functionDeclarations.append("EFIAPI\r\n");\r | |
1555 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1556 | functionDeclarations.append(" (\r\n");\r | |
1557 | functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1558 | functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1559 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1560 | break;\r |
1561 | \r | |
1562 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1563 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1564 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1565 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1566 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1567 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1568 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1569 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1570 | functionDeclarations.append("EFIAPI\r\n");\r | |
1571 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1572 | functionDeclarations.append(" (\r\n");\r | |
1573 | functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1574 | functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1575 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1576 | break;\r |
1577 | \r | |
1578 | }\r | |
5f907e4a | 1579 | }\r |
1580 | }\r | |
1581 | \r | |
1582 | //\r | |
1583 | // Add ProcessLibraryConstructorList in AutoGen.c\r | |
1584 | //\r | |
aacce761 | 1585 | fileBuffer.append("VOID\r\n");\r |
1586 | fileBuffer.append("EFIAPI\r\n");\r | |
1587 | fileBuffer.append("ProcessLibraryConstructorList (\r\n");\r | |
5f907e4a | 1588 | switch (CommonDefinition.getModuleType(moduleType)) {\r |
1589 | case CommonDefinition.ModuleTypeBase:\r | |
aacce761 | 1590 | fileBuffer.append(" VOID\r\n");\r |
5f907e4a | 1591 | break;\r |
1592 | \r | |
1593 | case CommonDefinition.ModuleTypePeiCore:\r | |
1594 | case CommonDefinition.ModuleTypePeim:\r | |
aacce761 | 1595 | fileBuffer.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r |
5f907e4a | 1596 | fileBuffer\r |
aacce761 | 1597 | .append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r |
5f907e4a | 1598 | break;\r |
1599 | \r | |
1600 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1601 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1602 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1603 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1604 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1605 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1606 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1607 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r |
1608 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
5f907e4a | 1609 | break;\r |
1610 | }\r | |
1611 | \r | |
aacce761 | 1612 | fileBuffer.append(" )\r\n");\r |
1613 | fileBuffer.append("{\r\n");\r | |
136adffc | 1614 | //\r |
1615 | // If no constructor function, return EFI_SUCCESS.\r | |
1616 | //\r | |
5f907e4a | 1617 | for (int i = 0; i < libInstanceList.size(); i++) {\r |
1618 | if (isFirst) {\r | |
aacce761 | 1619 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r |
1620 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r | |
1621 | fileBuffer.append("\r\n");\r | |
5f907e4a | 1622 | isFirst = false;\r |
1623 | }\r | |
a387de3b | 1624 | if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r |
5f907e4a | 1625 | fileBuffer.append(" Status = ");\r |
4353d8e1 | 1626 | fileBuffer.append(libInstanceList.get(i)[0]);\r |
aacce761 | 1627 | fileBuffer.append("();\r\n");\r |
a387de3b | 1628 | } else {\r |
1629 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1630 | case CommonDefinition.ModuleTypeBase:\r | |
1631 | fileBuffer.append(" Status = ");\r | |
1632 | fileBuffer.append(libInstanceList.get(i)[0]);\r | |
aacce761 | 1633 | fileBuffer.append("();\r\n");\r |
a387de3b | 1634 | break;\r |
1635 | case CommonDefinition.ModuleTypePeiCore:\r | |
1636 | case CommonDefinition.ModuleTypePeim:\r | |
1637 | fileBuffer.append(" Status = ");\r | |
1638 | fileBuffer.append(libInstanceList.get(i)[0]);\r | |
aacce761 | 1639 | fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r |
a387de3b | 1640 | break;\r |
1641 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1642 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1643 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1644 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1645 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1646 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1647 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1648 | fileBuffer.append(" Status = ");\r | |
1649 | fileBuffer.append(libInstanceList.get(i)[0]);\r | |
aacce761 | 1650 | fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r |
a387de3b | 1651 | break;\r |
1652 | default:\r | |
1653 | EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r | |
1654 | }\r | |
1655 | \r | |
5f907e4a | 1656 | }\r |
aacce761 | 1657 | fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r |
5f907e4a | 1658 | }\r |
aacce761 | 1659 | fileBuffer.append("}\r\n");\r |
5f907e4a | 1660 | }\r |
1661 | \r | |
1662 | /**\r | |
cb4d97bd | 1663 | LibDestructorToAutogenc\r |
1664 | \r | |
1665 | This function writes library destructor list to AutoGen.c. The library\r | |
1666 | destructor's parameter and return value depend on module type.\r | |
1667 | \r | |
1668 | @param libInstanceList\r | |
1669 | List of library destructor name.\r | |
1670 | @param moduleType\r | |
1671 | Module type.\r | |
1672 | @param fileBuffer\r | |
1673 | String buffer for AutoGen.c\r | |
1674 | @throws Exception\r | |
1675 | **/\r | |
4353d8e1 | 1676 | void LibDestructorToAutogenC(List<String[]> libInstanceList,\r |
61528a1b | 1677 | String moduleType, StringBuffer fileBuffer) throws EdkException {\r |
5f907e4a | 1678 | boolean isFirst = true;\r |
1679 | for (int i = 0; i < libInstanceList.size(); i++) {\r | |
a387de3b | 1680 | if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r |
aacce761 | 1681 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1682 | functionDeclarations.append("EFIAPI\r\n");\r | |
1683 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1684 | functionDeclarations.append(" (\r\n");\r | |
1685 | functionDeclarations.append(" VOID\r\n");\r | |
1686 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1687 | } else {\r |
1688 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1689 | case CommonDefinition.ModuleTypeBase:\r | |
aacce761 | 1690 | functionDeclarations.append("RETURN_STATUS\r\n");\r |
1691 | functionDeclarations.append("EFIAPI\r\n");\r | |
1692 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1693 | functionDeclarations.append(" (\r\n");\r | |
1694 | functionDeclarations.append(" VOID\r\n");\r | |
1695 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1696 | break;\r |
1697 | case CommonDefinition.ModuleTypePeiCore:\r | |
1698 | case CommonDefinition.ModuleTypePeim:\r | |
aacce761 | 1699 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1700 | functionDeclarations.append("EFIAPI\r\n");\r | |
1701 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1702 | functionDeclarations.append(" (\r\n");\r | |
1703 | functionDeclarations.append(" IN EFI_FFS_FILE_HEADER *FfsHeader,\r\n");\r | |
1704 | functionDeclarations.append(" IN EFI_PEI_SERVICES **PeiServices\r\n");\r | |
1705 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1706 | break;\r |
1707 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1708 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1709 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1710 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1711 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1712 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1713 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1714 | functionDeclarations.append("EFI_STATUS\r\n");\r |
1715 | functionDeclarations.append("EFIAPI\r\n");\r | |
1716 | functionDeclarations.append(libInstanceList.get(i)[0]);\r | |
1717 | functionDeclarations.append(" (\r\n");\r | |
1718 | functionDeclarations.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1719 | functionDeclarations.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1720 | functionDeclarations.append(" );\r\n");\r | |
a387de3b | 1721 | break;\r |
1722 | }\r | |
5f907e4a | 1723 | }\r |
1724 | }\r | |
1725 | \r | |
1726 | //\r | |
1727 | // Write ProcessLibraryDestructor list to autogen.c\r | |
1728 | //\r | |
1729 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1730 | case CommonDefinition.ModuleTypeBase:\r | |
1731 | case CommonDefinition.ModuleTypePeiCore:\r | |
1732 | case CommonDefinition.ModuleTypePeim:\r | |
1733 | break;\r | |
1734 | case CommonDefinition.ModuleTypeDxeCore:\r | |
1735 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1736 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1737 | case CommonDefinition.ModuleTypeDxeSmmDriver:\r | |
1738 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1739 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1740 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
aacce761 | 1741 | fileBuffer.append("VOID\r\n");\r |
1742 | fileBuffer.append("EFIAPI\r\n");\r | |
1743 | fileBuffer.append("ProcessLibraryDestructorList (\r\n");\r | |
1744 | fileBuffer.append(" IN EFI_HANDLE ImageHandle,\r\n");\r | |
1745 | fileBuffer.append(" IN EFI_SYSTEM_TABLE *SystemTable\r\n");\r | |
1746 | fileBuffer.append(" )\r\n");\r | |
1747 | fileBuffer.append("{\r\n");\r | |
878ddf1f | 1748 | //\r |
136adffc | 1749 | // If no library destructor function, return EFI_SUCCESS.\r |
878ddf1f | 1750 | //\r |
ff225cbb | 1751 | \r |
5f907e4a | 1752 | for (int i = 0; i < libInstanceList.size(); i++) {\r |
1753 | if (isFirst) {\r | |
aacce761 | 1754 | fileBuffer.append(" EFI_STATUS Status;\r\n");\r |
1755 | fileBuffer.append(" Status = EFI_SUCCESS;\r\n");\r | |
1756 | fileBuffer.append("\r\n");\r | |
5f907e4a | 1757 | isFirst = false;\r |
1758 | }\r | |
a387de3b | 1759 | if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r |
4353d8e1 | 1760 | fileBuffer.append(" Status = ");\r |
1761 | fileBuffer.append(libInstanceList.get(i)[0]);\r | |
aacce761 | 1762 | fileBuffer.append("();\r\n");\r |
1763 | fileBuffer.append(" VOID\r\n");\r | |
a387de3b | 1764 | } else {\r |
1765 | fileBuffer.append(" Status = ");\r | |
1766 | fileBuffer.append(libInstanceList.get(i)[0]);\r | |
aacce761 | 1767 | fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r |
1768 | fileBuffer.append(" ASSERT_EFI_ERROR (Status);\r\n");\r | |
a387de3b | 1769 | }\r |
5f907e4a | 1770 | }\r |
aacce761 | 1771 | fileBuffer.append("}\r\n");\r |
5f907e4a | 1772 | break;\r |
1773 | }\r | |
1774 | }\r | |
1775 | \r | |
1776 | /**\r | |
cb4d97bd | 1777 | ExternsDriverBindingToAutoGenC\r |
1778 | \r | |
1779 | This function is to write DRIVER_BINDING, COMPONENT_NAME,\r | |
1780 | DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r | |
1781 | \r | |
1782 | @param fileBuffer\r | |
1783 | String buffer for AutoGen.c\r | |
1784 | **/\r | |
5f907e4a | 1785 | void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r |
61528a1b | 1786 | throws EdkException {\r |
5f907e4a | 1787 | //\r |
d8f1335e | 1788 | // Get the arry of extern. The driverBindingGroup is a 2 dimension array.\r |
e425f073 | 1789 | // The second dimension is include following element: DriverBinding, \r |
1790 | // ComponentName, DriverConfiguration, DriverDiag;\r | |
1791 | // \r | |
d8f1335e | 1792 | String[][] driverBindingGroup = this.saq.getExternProtocolGroup();\r |
5f907e4a | 1793 | \r |
e87022aa | 1794 | \r |
a387de3b | 1795 | //\r |
1796 | // inital BitMask;\r | |
1797 | // \r | |
1798 | int BitMask = 0;\r | |
5f907e4a | 1799 | \r |
1800 | //\r | |
1801 | // Write driver binding protocol extern to autogen.c\r | |
1802 | //\r | |
d8f1335e | 1803 | for (int i = 0; i < driverBindingGroup.length; i++) {\r |
e425f073 | 1804 | if (driverBindingGroup[i][0] != null) {\r |
1805 | fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r | |
d8f1335e | 1806 | fileBuffer.append(driverBindingGroup[i][0]);\r |
aacce761 | 1807 | fileBuffer.append(";\r\n");\r |
a387de3b | 1808 | }\r |
5f907e4a | 1809 | }\r |
1810 | \r | |
1811 | //\r | |
1812 | // Write component name protocol extern to autogen.c\r | |
1813 | //\r | |
e425f073 | 1814 | if (!componentNamePcd) {\r |
1815 | for (int i = 0; i < driverBindingGroup.length; i++) {\r | |
1816 | if (driverBindingGroup[i][1]!= null) {\r | |
1817 | if (driverBindingGroup[i][0] != null) {\r | |
1818 | BitMask |= 0x01;\r | |
1819 | fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r | |
e87022aa | 1820 | fileBuffer.append(driverBindingGroup[i][1]);\r |
aacce761 | 1821 | fileBuffer.append(";\r\n");\r |
e425f073 | 1822 | } else {\r |
e87022aa | 1823 | throw new AutoGenException("DriverBinding can't be empty!!");\r |
e425f073 | 1824 | }\r |
a387de3b | 1825 | }\r |
1826 | }\r | |
1827 | }\r | |
1828 | \r | |
5f907e4a | 1829 | //\r |
1830 | // Write driver configration protocol extern to autogen.c\r | |
1831 | //\r | |
e425f073 | 1832 | for (int i = 0; i < driverBindingGroup.length; i++) {\r |
1833 | if (driverBindingGroup[i][2] != null) {\r | |
1834 | if (driverBindingGroup[i][0] != null) {\r | |
d8f1335e | 1835 | BitMask |= 0x02;\r |
e425f073 | 1836 | fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r |
d8f1335e | 1837 | fileBuffer.append(driverBindingGroup[i][2]);\r |
aacce761 | 1838 | fileBuffer.append(";\r\n");\r |
e425f073 | 1839 | } else {\r |
d8f1335e | 1840 | throw new AutoGenException("DriverBinding can't be empty!!");\r |
e425f073 | 1841 | }\r |
1842 | }\r | |
1843 | }\r | |
a387de3b | 1844 | \r |
5f907e4a | 1845 | //\r |
1846 | // Write driver dignastic protocol extern to autogen.c\r | |
1847 | //\r | |
e425f073 | 1848 | if (!driverDiagnostPcd) {\r |
1849 | for (int i = 0; i < driverBindingGroup.length; i++) {\r | |
1850 | if (driverBindingGroup[i][3] != null) {\r | |
1851 | if (driverBindingGroup[i][0] != null) {\r | |
e87022aa | 1852 | BitMask |= 0x04;\r |
1853 | fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r | |
1854 | fileBuffer.append(driverBindingGroup[i][3]);\r | |
aacce761 | 1855 | fileBuffer.append(";\r\n");\r |
e425f073 | 1856 | } else {\r |
e87022aa | 1857 | throw new AutoGenException("DriverBinding can't be empty!!");\r |
e425f073 | 1858 | }\r |
1859 | }\r | |
1860 | }\r | |
1861 | }\r | |
a387de3b | 1862 | \r |
1863 | \r | |
5f907e4a | 1864 | //\r |
1865 | // Write driver module protocol bitmask.\r | |
1866 | //\r | |
a387de3b | 1867 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverModelProtocolBitmask = ");\r |
5f907e4a | 1868 | fileBuffer.append(Integer.toString(BitMask));\r |
aacce761 | 1869 | fileBuffer.append(";\r\n");\r |
5f907e4a | 1870 | \r |
1871 | //\r | |
1872 | // Write driver module protocol list entry\r | |
1873 | //\r | |
a387de3b | 1874 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverModelProtocolListEntries = ");\r |
5f907e4a | 1875 | \r |
d8f1335e | 1876 | fileBuffer.append(Integer.toString(driverBindingGroup.length));\r |
aacce761 | 1877 | fileBuffer.append(";\r\n");\r |
5f907e4a | 1878 | \r |
1879 | //\r | |
1880 | // Write drive module protocol list to autogen.c\r | |
1881 | //\r | |
e425f073 | 1882 | if (driverBindingGroup.length > 0) {\r |
a387de3b | 1883 | fileBuffer.append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST _gDriverModelProtocolList[] = {");\r |
1884 | }\r | |
1885 | \r | |
1886 | \r | |
d8f1335e | 1887 | for (int i = 0; i < driverBindingGroup.length; i++) {\r |
5f907e4a | 1888 | if (i != 0) {\r |
1889 | fileBuffer.append(",");\r | |
1890 | }\r | |
e425f073 | 1891 | //\r |
1892 | // DriverBinding\r | |
1893 | // \r | |
aacce761 | 1894 | fileBuffer.append("\r\n {\r\n");\r |
5f907e4a | 1895 | fileBuffer.append(" &");\r |
d8f1335e | 1896 | fileBuffer.append(driverBindingGroup[i][0]);\r |
aacce761 | 1897 | fileBuffer.append(", \r\n");\r |
a387de3b | 1898 | \r |
e87022aa | 1899 | //\r |
e425f073 | 1900 | // ComponentName\r |
1901 | // \r | |
1902 | if (driverBindingGroup[i][1] != null && componentNamePcd != true) {\r | |
5f907e4a | 1903 | fileBuffer.append(" &");\r |
d8f1335e | 1904 | fileBuffer.append(driverBindingGroup[i][1]);\r |
aacce761 | 1905 | fileBuffer.append(", \r\n");\r |
5f907e4a | 1906 | } else {\r |
aacce761 | 1907 | fileBuffer.append(" NULL, \r\n");\r |
5f907e4a | 1908 | }\r |
1909 | \r | |
e425f073 | 1910 | //\r |
1911 | // DriverConfiguration\r | |
1912 | // \r | |
d8f1335e | 1913 | if (driverBindingGroup[i][2] != null) {\r |
5f907e4a | 1914 | fileBuffer.append(" &");\r |
d8f1335e | 1915 | fileBuffer.append(driverBindingGroup[i][2]);\r |
aacce761 | 1916 | fileBuffer.append(", \r\n");\r |
5f907e4a | 1917 | } else {\r |
aacce761 | 1918 | fileBuffer.append(" NULL, \r\n");\r |
5f907e4a | 1919 | }\r |
1920 | \r | |
e425f073 | 1921 | //\r |
1922 | // DriverDiagnostic\r | |
1923 | // \r | |
1924 | if (driverBindingGroup[i][3] != null && driverDiagnostPcd != true) {\r | |
5f907e4a | 1925 | fileBuffer.append(" &");\r |
d8f1335e | 1926 | fileBuffer.append(driverBindingGroup[i][3]);\r |
aacce761 | 1927 | fileBuffer.append(", \r\n");\r |
5f907e4a | 1928 | } else {\r |
aacce761 | 1929 | fileBuffer.append(" NULL, \r\n");\r |
5f907e4a | 1930 | }\r |
1931 | fileBuffer.append(" }");\r | |
1932 | }\r | |
d8f1335e | 1933 | \r |
e425f073 | 1934 | if (driverBindingGroup.length > 0) {\r |
aacce761 | 1935 | fileBuffer.append("\r\n};\r\n");\r |
1936 | }\r | |
1937 | }\r | |
1938 | \r | |
1939 | /**\r | |
1940 | ExternCallBackToAutoGenC\r | |
1941 | \r | |
1942 | This function adds <SetVirtualAddressMapCallBack> and\r | |
1943 | <ExitBootServicesCallBack> infomation to AutoGen.c\r | |
1944 | \r | |
1945 | @param fileBuffer\r | |
1946 | String buffer for AutoGen.c\r | |
1947 | @throws BuildException\r | |
1948 | **/\r | |
1949 | void ExternCallBackToAutoGenH(String moduleType)\r | |
1950 | throws EdkException {\r | |
1951 | //\r | |
1952 | // Collect module's <SetVirtualAddressMapCallBack> and\r | |
1953 | // <ExitBootServiceCallBack> and add to setVirtualAddList\r | |
1954 | // exitBootServiceList.\r | |
1955 | //\r | |
1956 | String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r | |
1957 | String[] exitBoots = saq.getExitBootServicesCallBackArray();\r | |
1958 | //\r | |
1959 | // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r | |
1960 | // and <ExitBootServicesCallBack>\r | |
1961 | //\r | |
1962 | switch (CommonDefinition.getModuleType(moduleType)) {\r | |
1963 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
1964 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
1965 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
1966 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
1967 | case CommonDefinition.ModuleTypeUefiApplication:\r | |
1968 | //\r | |
1969 | // Write SetVirtualAddressMap function definition.\r | |
1970 | //\r | |
1971 | for (int i = 0; setVirtuals != null && i < setVirtuals.length; i++) {\r | |
1972 | if (setVirtuals[i].equalsIgnoreCase("")) {\r | |
1973 | continue;\r | |
1974 | }\r | |
1975 | functionDeclarations.append("VOID\r\n");\r | |
1976 | functionDeclarations.append("EFIAPI\r\n");\r | |
1977 | functionDeclarations.append(setVirtuals[i]);\r | |
1978 | functionDeclarations.append(" (\r\n");\r | |
1979 | functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r | |
1980 | functionDeclarations.append(" IN VOID *Context\r\n");\r | |
1981 | functionDeclarations.append(" );\r\n\r\n");\r | |
1982 | }\r | |
1983 | \r | |
1984 | //\r | |
1985 | // Write DriverExitBootServices function definition.\r | |
1986 | //\r | |
1987 | for (int i = 0; exitBoots != null && i < exitBoots.length; i++) {\r | |
1988 | if (exitBoots[i].equalsIgnoreCase("")) {\r | |
1989 | continue;\r | |
1990 | }\r | |
1991 | \r | |
1992 | functionDeclarations.append("VOID\r\n");\r | |
1993 | functionDeclarations.append("EFIAPI\r\n");\r | |
1994 | functionDeclarations.append(exitBoots[i]);\r | |
1995 | functionDeclarations.append(" (\r\n");\r | |
1996 | functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r | |
1997 | functionDeclarations.append(" IN VOID *Context\r\n");\r | |
1998 | functionDeclarations.append(" );\r\n\r\n");\r | |
1999 | }\r | |
2000 | break;\r | |
2001 | default:\r | |
2002 | break;\r | |
e425f073 | 2003 | }\r |
5f907e4a | 2004 | }\r |
2005 | \r | |
2006 | /**\r | |
cb4d97bd | 2007 | ExternCallBackToAutoGenC\r |
2008 | \r | |
2009 | This function adds <SetVirtualAddressMapCallBack> and\r | |
2010 | <ExitBootServicesCallBack> infomation to AutoGen.c\r | |
2011 | \r | |
2012 | @param fileBuffer\r | |
2013 | String buffer for AutoGen.c\r | |
2014 | @throws BuildException\r | |
2015 | **/\r | |
5f907e4a | 2016 | void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r |
61528a1b | 2017 | throws EdkException {\r |
5f907e4a | 2018 | //\r |
2019 | // Collect module's <SetVirtualAddressMapCallBack> and\r | |
2020 | // <ExitBootServiceCallBack> and add to setVirtualAddList\r | |
2021 | // exitBootServiceList.\r | |
2022 | //\r | |
83fba802 | 2023 | String[] setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r |
2024 | String[] exitBoots = saq.getExitBootServicesCallBackArray();\r | |
a2733a33 | 2025 | if (setVirtuals != null) {\r |
2026 | for (int j = 0; j < setVirtuals.length; j++) {\r | |
5f907e4a | 2027 | this.setVirtalAddList.add(setVirtuals[j]);\r |
2028 | }\r | |
2029 | }\r | |
2030 | if (exitBoots != null) {\r | |
2031 | for (int k = 0; k < exitBoots.length; k++) {\r | |
2032 | this.exitBootServiceList.add(exitBoots[k]);\r | |
2033 | }\r | |
2034 | }\r | |
2035 | //\r | |
2036 | // Add c code in autogen.c which relate to <SetVirtualAddressMapCallBack>\r | |
2037 | // and <ExitBootServicesCallBack>\r | |
2038 | //\r | |
2039 | String moduleType = this.moduleId.getModuleType();\r | |
5f907e4a | 2040 | switch (CommonDefinition.getModuleType(moduleType)) {\r |
2041 | case CommonDefinition.ModuleTypeDxeDriver:\r | |
2042 | case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r | |
2043 | case CommonDefinition.ModuleTypeDxeSalDriver:\r | |
2044 | case CommonDefinition.ModuleTypeUefiDriver:\r | |
e425f073 | 2045 | case CommonDefinition.ModuleTypeUefiApplication:\r |
2046 | //\r | |
2047 | // If moduleType is one of above, call setVirtualAddressToAutogenC,\r | |
2048 | // and setExitBootServiceToAutogenC.\r | |
2049 | // \r | |
c60019f6 | 2050 | setVirtualAddressToAutogenC(fileBuffer);\r |
e425f073 | 2051 | setExitBootServiceToAutogenC(fileBuffer);\r |
5f907e4a | 2052 | break;\r |
2053 | default:\r | |
2054 | break;\r | |
2055 | }\r | |
5f907e4a | 2056 | }\r |
878ddf1f | 2057 | \r |
cb4d97bd | 2058 | /**\r |
2059 | copyFlashMapHToDebugDir\r | |
2060 | \r | |
2061 | This function is to copy the falshmap.h to debug directory and change \r | |
2062 | its name to TianoR8FlashMap.h\r | |
2063 | \r | |
2064 | @param \r | |
2065 | @return\r | |
2066 | **/\r | |
73b4e31a | 2067 | private void copyFlashMapHToDebugDir() throws AutoGenException{\r |
ff225cbb | 2068 | \r |
cb4d97bd | 2069 | File inFile = new File(fvDir + File.separatorChar + CommonDefinition.FLASHMAPH);\r |
73b4e31a | 2070 | int size = (int)inFile.length();\r |
2071 | byte[] buffer = new byte[size];\r | |
cb4d97bd | 2072 | File outFile = new File (this.outputPath + File.separatorChar + CommonDefinition.TIANOR8PLASHMAPH);\r |
5f907e4a | 2073 | //\r |
2074 | // If TianoR8FlashMap.h existed and the flashMap.h don't change,\r | |
2075 | // do nothing.\r | |
2076 | //\r | |
31a9215c | 2077 | if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r |
e425f073 | 2078 | if (inFile.exists()) {\r |
a387de3b | 2079 | try {\r |
e425f073 | 2080 | FileInputStream fis = new FileInputStream (inFile);\r |
2081 | fis.read(buffer);\r | |
2082 | FileOutputStream fos = new FileOutputStream(outFile);\r | |
2083 | fos.write(buffer);\r | |
2084 | fis.close();\r | |
2085 | fos.close();\r | |
a387de3b | 2086 | } catch (IOException e) {\r |
61528a1b | 2087 | throw new AutoGenException("The file, flashMap.h can't be open!");\r |
e425f073 | 2088 | }\r |
a387de3b | 2089 | \r |
e425f073 | 2090 | } else {\r |
2091 | throw new AutoGenException("The file, flashMap.h doesn't exist!");\r | |
2092 | }\r | |
5f907e4a | 2093 | }\r |
73b4e31a | 2094 | }\r |
ff225cbb | 2095 | \r |
2336382f | 2096 | /**\r |
cb4d97bd | 2097 | This function first order the library instances, then collect\r |
2098 | library instance 's PPI, Protocol, GUID,\r | |
2099 | SetVirtalAddressMapCallBack, ExitBootServiceCallBack, and\r | |
2100 | Destructor, Constructor.\r | |
2101 | \r | |
2102 | @param\r | |
2103 | @return \r | |
5f907e4a | 2104 | **/\r |
892b0e7a | 2105 | private void collectLibInstanceInfo() throws EdkException{\r |
5f907e4a | 2106 | int index;\r |
2107 | \r | |
700279a9 | 2108 | String moduleType = moduleId.getModuleType();\r |
5f907e4a | 2109 | String libConstructName = null;\r |
2110 | String libDestructName = null;\r | |
a387de3b | 2111 | String libModuleType = null;\r |
5f907e4a | 2112 | String[] setVirtuals = null;\r |
2113 | String[] exitBoots = null;\r | |
2114 | \r | |
83fba802 | 2115 | ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r |
700279a9 | 2116 | if (libraryIdList.length <= 0) {\r |
2117 | return;\r | |
2118 | }\r | |
2119 | //\r | |
2120 | // Reorder library instance sequence.\r | |
2121 | //\r | |
2122 | AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch);\r | |
2123 | List<ModuleIdentification> orderList = libOrder.orderLibInstance();\r | |
2124 | //\r | |
2125 | // Process library instance one by one.\r | |
2126 | //\r | |
2127 | for (int i = 0; i < orderList.size(); i++) {\r | |
2128 | //\r | |
2129 | // Get library instance basename.\r | |
2130 | //\r | |
2131 | ModuleIdentification libInstanceId = orderList.get(i);\r | |
5f907e4a | 2132 | \r |
a387de3b | 2133 | //\r |
700279a9 | 2134 | // Get override map\r |
a387de3b | 2135 | //\r |
a387de3b | 2136 | \r |
700279a9 | 2137 | Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r |
2138 | saq.push(libDoc);\r | |
2139 | //\r | |
2140 | // check if the library instance support current module\r | |
2141 | // \r | |
2142 | String[] libraryClassList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED,\r | |
2143 | this.arch,\r | |
2144 | moduleType\r | |
2145 | );\r | |
2146 | if (libraryClassList.length <= 0) {\r | |
2147 | throw new EdkException("Library instance " + libInstanceId.getName() \r | |
2148 | + " doesn't support module type " + moduleType);\r | |
2149 | }\r | |
2150 | //\r | |
2151 | // Get <PPis>, <Protocols>, <Guids> list of this library\r | |
2152 | // instance.\r | |
2153 | //\r | |
2154 | String[] ppiList = saq.getPpiArray(this.arch);\r | |
2155 | String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r | |
2156 | String[] protocolList = saq.getProtocolArray(this.arch);\r | |
2157 | String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r | |
2158 | String[] guidList = saq.getGuidEntryArray(this.arch);\r | |
2159 | PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r | |
a387de3b | 2160 | \r |
700279a9 | 2161 | //\r |
2162 | // Add those ppi, protocol, guid in global ppi,\r | |
2163 | // protocol, guid\r | |
2164 | // list.\r | |
2165 | //\r | |
2166 | for (index = 0; index < ppiList.length; index++) {\r | |
2167 | this.mPpiList.add(ppiList[index]);\r | |
2168 | }\r | |
a387de3b | 2169 | \r |
700279a9 | 2170 | for (index = 0; index < ppiNotifyList.length; index++) {\r |
2171 | this.mPpiList.add(ppiNotifyList[index]);\r | |
2172 | }\r | |
a387de3b | 2173 | \r |
700279a9 | 2174 | for (index = 0; index < protocolList.length; index++) {\r |
2175 | this.mProtocolList.add(protocolList[index]);\r | |
2176 | }\r | |
a387de3b | 2177 | \r |
700279a9 | 2178 | for (index = 0; index < protocolNotifyList.length; index++) {\r |
2179 | this.mProtocolList.add(protocolNotifyList[index]);\r | |
2180 | }\r | |
a387de3b | 2181 | \r |
700279a9 | 2182 | for (index = 0; index < guidList.length; index++) {\r |
2183 | this.mGuidList.add(guidList[index]);\r | |
2184 | }\r | |
2185 | for (index = 0; index < pkgList.length; index++) {\r | |
2186 | if (!this.mDepPkgList.contains(pkgList[index])) {\r | |
2187 | this.mDepPkgList.add(pkgList[index]);\r | |
2188 | }\r | |
2189 | }\r | |
2190 | \r | |
2191 | //\r | |
2192 | // If not yet parse this library instance's constructor\r | |
2193 | // element,parse it.\r | |
2194 | //\r | |
2195 | libConstructName = saq.getLibConstructorName();\r | |
2196 | libDestructName = saq.getLibDestructorName();\r | |
2197 | libModuleType = saq.getModuleType();\r | |
2198 | \r | |
2199 | //\r | |
2200 | // Collect SetVirtualAddressMapCallBack and\r | |
2201 | // ExitBootServiceCallBack.\r | |
2202 | //\r | |
2203 | setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r | |
2204 | exitBoots = saq.getExitBootServicesCallBackArray();\r | |
2205 | if (setVirtuals != null) {\r | |
2206 | for (int j = 0; j < setVirtuals.length; j++) {\r | |
2207 | this.setVirtalAddList.add(setVirtuals[j]);\r | |
2208 | }\r | |
2209 | }\r | |
2210 | if (exitBoots != null) {\r | |
2211 | for (int k = 0; k < exitBoots.length; k++) {\r | |
2212 | this.exitBootServiceList.add(exitBoots[k]);\r | |
a387de3b | 2213 | }\r |
2214 | }\r | |
700279a9 | 2215 | saq.pop();\r |
2216 | //\r | |
2217 | // Add dependent library instance constructor function.\r | |
2218 | //\r | |
2219 | if (libConstructName != null) {\r | |
2220 | this.libConstructList.add(new String[] {libConstructName, libModuleType});\r | |
2221 | }\r | |
2222 | //\r | |
2223 | // Add dependent library instance destructor fuction.\r | |
2224 | //\r | |
2225 | if (libDestructName != null) {\r | |
2226 | this.libDestructList.add(new String[] {libDestructName, libModuleType});\r | |
2227 | }\r | |
a387de3b | 2228 | }\r |
5f907e4a | 2229 | }\r |
aacce761 | 2230 | \r |
e425f073 | 2231 | private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r |
c60019f6 | 2232 | //\r |
2233 | // Entry point lib for these module types needs to know the count\r | |
2234 | // of entryPoint.\r | |
2235 | //\r | |
aacce761 | 2236 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverSetVirtualAddressMapEventCount = ");\r |
a387de3b | 2237 | \r |
2238 | //\r | |
2239 | // If the list is not valid or has no entries set count to zero else\r | |
2240 | // set count to the number of valid entries\r | |
2241 | //\r | |
2242 | int Count = 0;\r | |
2243 | int i = 0;\r | |
2244 | if (this.setVirtalAddList != null) {\r | |
2245 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r | |
2246 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2247 | break;\r | |
2248 | }\r | |
2249 | }\r | |
2250 | Count = i;\r | |
2251 | }\r | |
2252 | \r | |
2253 | fileBuffer.append(Integer.toString(Count));\r | |
aacce761 | 2254 | fileBuffer.append(";\r\n\r\n");\r |
a387de3b | 2255 | if (this.setVirtalAddList == null || this.setVirtalAddList.size() == 0) {\r |
2256 | //\r | |
2257 | // No data so make a NULL list\r | |
2258 | //\r | |
aacce761 | 2259 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {\r\n");\r |
2260 | fileBuffer.append(" NULL\r\n");\r | |
2261 | fileBuffer.append("};\r\n\r\n");\r | |
a387de3b | 2262 | } else {\r |
2263 | //\r | |
2264 | // Write SetVirtualAddressMap function definition.\r | |
2265 | //\r | |
2266 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r | |
2267 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2268 | break;\r | |
2269 | }\r | |
aacce761 | 2270 | functionDeclarations.append("VOID\r\n");\r |
2271 | functionDeclarations.append("EFIAPI\r\n");\r | |
2272 | functionDeclarations.append(this.setVirtalAddList.get(i));\r | |
2273 | functionDeclarations.append(" (\r\n");\r | |
2274 | functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r | |
2275 | functionDeclarations.append(" IN VOID *Context\r\n");\r | |
2276 | functionDeclarations.append(" );\r\n\r\n");\r | |
a387de3b | 2277 | }\r |
2278 | \r | |
2279 | //\r | |
2280 | // Write SetVirtualAddressMap entry point array.\r | |
2281 | //\r | |
aacce761 | 2282 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverSetVirtualAddressMapEvent[] = {");\r |
a387de3b | 2283 | for (i = 0; i < this.setVirtalAddList.size(); i++) {\r |
2284 | if (this.setVirtalAddList.get(i).equalsIgnoreCase("")) {\r | |
2285 | break;\r | |
2286 | }\r | |
2287 | \r | |
2288 | if (i == 0) {\r | |
aacce761 | 2289 | fileBuffer.append("\r\n ");\r |
a387de3b | 2290 | } else {\r |
aacce761 | 2291 | fileBuffer.append(",\r\n ");\r |
a387de3b | 2292 | }\r |
2293 | \r | |
2294 | fileBuffer.append(this.setVirtalAddList.get(i));\r | |
2295 | }\r | |
2296 | //\r | |
2297 | // add the NULL at the end of _gDriverSetVirtualAddressMapEvent list.\r | |
2298 | //\r | |
aacce761 | 2299 | fileBuffer.append(",\r\n NULL");\r |
2300 | fileBuffer.append("\r\n};\r\n\r\n");\r | |
a387de3b | 2301 | }\r |
2302 | }\r | |
2303 | \r | |
2304 | \r | |
2305 | private void setExitBootServiceToAutogenC(StringBuffer fileBuffer){\r | |
2306 | //\r | |
2307 | // Entry point lib for these module types needs to know the count.\r | |
2308 | //\r | |
aacce761 | 2309 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const UINTN _gDriverExitBootServicesEventCount = ");\r |
a387de3b | 2310 | \r |
2311 | //\r | |
2312 | // If the list is not valid or has no entries set count to zero else\r | |
2313 | // set count to the number of valid entries.\r | |
2314 | //\r | |
2315 | int Count = 0;\r | |
2316 | int i = 0; \r | |
2317 | if (this.exitBootServiceList != null) {\r | |
2318 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r | |
2319 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2320 | break;\r | |
2321 | }\r | |
2322 | }\r | |
2323 | Count = i;\r | |
2324 | }\r | |
2325 | fileBuffer.append(Integer.toString(Count));\r | |
aacce761 | 2326 | fileBuffer.append(";\r\n\r\n");\r |
a387de3b | 2327 | \r |
2328 | if (this.exitBootServiceList == null || this.exitBootServiceList.size() == 0) {\r | |
2329 | // \r | |
2330 | // No data so make a NULL list.\r | |
2331 | //\r | |
aacce761 | 2332 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {\r\n");\r |
2333 | fileBuffer.append(" NULL\r\n");\r | |
2334 | fileBuffer.append("};\r\n\r\n");\r | |
a387de3b | 2335 | } else {\r |
2336 | //\r | |
2337 | // Write DriverExitBootServices function definition.\r | |
2338 | //\r | |
2339 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r | |
2340 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2341 | break;\r | |
2342 | }\r | |
2343 | \r | |
aacce761 | 2344 | functionDeclarations.append("VOID\r\n");\r |
2345 | functionDeclarations.append("EFIAPI\r\n");\r | |
2346 | functionDeclarations.append(this.exitBootServiceList.get(i));\r | |
2347 | functionDeclarations.append(" (\r\n");\r | |
2348 | functionDeclarations.append(" IN EFI_EVENT Event,\r\n");\r | |
2349 | functionDeclarations.append(" IN VOID *Context\r\n");\r | |
2350 | functionDeclarations.append(" );\r\n\r\n");\r | |
a387de3b | 2351 | }\r |
2352 | \r | |
2353 | //\r | |
2354 | // Write DriverExitBootServices entry point array.\r | |
2355 | //\r | |
aacce761 | 2356 | fileBuffer.append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED const EFI_EVENT_NOTIFY _gDriverExitBootServicesEvent[] = {");\r |
a387de3b | 2357 | for (i = 0; i < this.exitBootServiceList.size(); i++) {\r |
2358 | if (this.exitBootServiceList.get(i).equalsIgnoreCase("")) {\r | |
2359 | break;\r | |
2360 | }\r | |
2361 | \r | |
2362 | if (i == 0) {\r | |
aacce761 | 2363 | fileBuffer.append("\r\n ");\r |
a387de3b | 2364 | } else {\r |
aacce761 | 2365 | fileBuffer.append(",\r\n ");\r |
a387de3b | 2366 | }\r |
2367 | fileBuffer.append(this.exitBootServiceList.get(i));\r | |
2368 | }\r | |
2369 | \r | |
aacce761 | 2370 | fileBuffer.append(",\r\n NULL");\r |
2371 | fileBuffer.append("\r\n};\r\n\r\n");\r | |
a387de3b | 2372 | } \r |
e425f073 | 2373 | }\r |
2374 | /**\r | |
2375 | setPcdComponentName\r | |
2376 | \r | |
2377 | Get the Pcd Value of ComponentName to \r | |
2378 | decide whether need to disable the componentName. \r | |
2379 | \r | |
2380 | **/\r | |
2381 | public void setPcdComponentName (){\r | |
a387de3b | 2382 | String pcdValue = null;\r |
2383 | pcdValue = saq.getPcdValueBycName("PcdComponentNameDisable");\r | |
2384 | if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r | |
e425f073 | 2385 | this.componentNamePcd = true;\r |
a387de3b | 2386 | }\r |
e425f073 | 2387 | }\r |
a387de3b | 2388 | \r |
e425f073 | 2389 | /**\r |
2390 | setPcdDriverDiagnostic \r | |
2391 | \r | |
2392 | Get the Pcd Value of DriverDiagnostic to \r | |
2393 | decide whether need to disable DriverDiagnostic.\r | |
2394 | \r | |
2395 | **/\r | |
2396 | public void setPcdDriverDiagnostic (){\r | |
a387de3b | 2397 | String pcdValue = null;\r |
e425f073 | 2398 | pcdValue = saq.getPcdValueBycName("PcdDriverDiagnosticsDisable");\r |
a387de3b | 2399 | if (pcdValue != null && pcdValue.equalsIgnoreCase("true")) {\r |
e425f073 | 2400 | this.driverDiagnostPcd = true;\r |
a387de3b | 2401 | }\r |
e425f073 | 2402 | } \r |
a387de3b | 2403 | \r |
2336382f | 2404 | }\r |