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