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