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