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