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