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