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