Fixed FwImage/fwimage.c to guarantee that the raw size of a section is a multiple...
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / MsaWriter.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17\r
18import org.tianocore.*;\r
19import org.tianocore.SupportedArchitectures.Enum;\r
20import org.apache.xmlbeans.*;\r
21\r
22public class MsaWriter {\r
27e0221a 23 MsaWriter(ModuleInfo moduleinfo) {\r
24 mi = moduleinfo;\r
25 }\r
0dc8c589 26\r
27e0221a 27 private ModuleInfo mi;\r
28 \r
29 private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
30 \r
31 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
32 private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
33 private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
34 private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r
35 private GuidsDocument.Guids guids;\r
36 private ProtocolsDocument.Protocols protocols;\r
37 private PPIsDocument.PPIs ppis;\r
38 private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
39 private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
40 private ExternsDocument.Externs externs = msa.addNewExterns();\r
41 \r
42 private String Query (String requirement) throws Exception {\r
43 String answer;\r
44 BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
45 System.out.println(requirement);\r
46 while ((answer = rd.readLine()).length() == 0) ;\r
47 return answer;\r
48 }\r
49 \r
50 private void addSourceFiles (String name) { // furthur modification needed\r
51 List<Enum> arch = new ArrayList<Enum>();\r
52 FilenameDocument.Filename filename;\r
53 filename = sourcefiles.addNewFilename();\r
54 filename.setStringValue(name);\r
55 \r
56 if (name.contains("x64" + File.separator)) { // filename ???\r
57 arch.add(SupportedArchitectures.X_64);\r
58 System.out.println("x64" + File.separator);\r
59 filename.setSupArchList(arch);\r
60 } else if (name.contains("Ia32" + File.separator)) { // filename ???\r
61 arch.add(SupportedArchitectures.IA_32);\r
62 System.out.println("Ia32" + File.separator);\r
63 filename.setSupArchList(arch);\r
64 } else if (name.contains("Ipf" + File.separator)) { // filename ???\r
65 arch.add(SupportedArchitectures.IPF);\r
66 System.out.println("Ipf" + File.separator);\r
67 filename.setSupArchList(arch);\r
68 } else if (name.contains("Ebc" + File.separator)) { // filename ???\r
69 arch.add(SupportedArchitectures.EBC);\r
70 System.out.println("Ebc" + File.separator);\r
71 filename.setSupArchList(arch);\r
72 }\r
73 }\r
74 \r
75 private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
76 Iterator<String> it;\r
77 String temp;\r
78 \r
79 if (mi.modulename != null) {\r
80 msaheader.setModuleName(mi.modulename);\r
81 } else {\r
82 msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));\r
83 }\r
84 if (mi.guidvalue == null) {\r
85 mi.guidvalue = UUID.randomUUID().toString();\r
86 MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!"); \r
87 } \r
88 msaheader.setGuidValue(mi.guidvalue);\r
89 if (mi.moduletype != null) {\r
90 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r
91 /*\r
92 if (mi.moduletype.contains("PEI")) {\r
93 msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r
94 } else {\r
95 msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r
96 }\r
97 */\r
98 } else {\r
99 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
100 }\r
fb840aa8 101\r
27e0221a 102 msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
103 msaheader.setVersion("1.0");\r
104 msaheader.setAbstract("Component name for module " + mi.modulename);\r
105 msaheader.setDescription("FIX ME!");\r
106 msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
107 " This software and associated documentation (if any) is furnished\n" +\r
108 " under a license and may only be used or copied in accordance\n" +\r
109 " with the terms of the license. Except as permitted by such\n" +\r
110 " license, no part of this software or documentation may be\n" +\r
111 " reproduced, stored in a retrieval system, or transmitted in any\n" +\r
112 " form or by any means without the express written consent of\n" +\r
113 " Intel Corporation.");\r
114 msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r
115 \r
116 List<Enum> arch = new ArrayList<Enum>();\r
117 arch.add(SupportedArchitectures.IA_32);\r
118 arch.add(SupportedArchitectures.X_64);\r
119 arch.add(SupportedArchitectures.IPF);\r
120 arch.add(SupportedArchitectures.EBC);\r
121 md.setSupportedArchitectures(arch);\r
122 md.setBinaryModule(false);\r
123 md.setOutputFileBasename(mi.modulename);\r
124 \r
125 pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
77dd49a7 126 pd.addNewPackage().setPackageGuid("68169ab0-d41b-4009-9060-292c253ac43d");\r
27e0221a 127 externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
128 externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
129 externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
130 \r
131 it = mi.localmodulesources.iterator();\r
132 while (it.hasNext()) {\r
133 addSourceFiles(it.next());\r
134 }\r
135 if (!mi.protocol.isEmpty()) {\r
136 protocols = msa.addNewProtocols();\r
137 it = mi.protocol.iterator();\r
138 while (it.hasNext()) {\r
139 if ((temp = it.next()) != null) {\r
140 ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
141 pr.setProtocolCName(temp);\r
142 pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
143 }\r
144 }\r
145 }\r
146 if (!mi.ppi.isEmpty()) {\r
147 ppis = msa.addNewPPIs();\r
148 it = mi.ppi.iterator();\r
149 while (it.hasNext()) {\r
150 if ((temp = it.next()) != null) {\r
151 PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
152 pp.setPpiCName(temp);\r
153 pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
154 }\r
155 }\r
156 }\r
157 if (!mi.guid.isEmpty()) {\r
158 guids = msa.addNewGuids();\r
159 it = mi.guid.iterator();\r
160 while (it.hasNext()) {\r
161 if ((temp = it.next()) != null) {\r
162 GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
163 gcn.setGuidCName(temp);\r
164 gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
165 }\r
166 }\r
167 }\r
168 it = mi.hashrequiredr9libs.iterator();\r
169 while (it.hasNext()) {\r
170 if ((temp = it.next()) != null && !temp.matches("%")) {\r
171 LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
172 lc.setKeyword(temp);\r
173 lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
174 }\r
175 }\r
176 \r
177 return msadoc;\r
178 }\r
179 \r
180 public void flush() throws Exception {\r
0dc8c589 181 XmlOptions options = new XmlOptions();\r
182\r
183 options.setCharacterEncoding("UTF-8");\r
184 options.setSavePrettyPrint();\r
185 options.setSavePrettyPrintIndent(2);\r
186 options.setUseDefaultNamespace();\r
187 \r
27e0221a 188 BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
189 fulfillMsadoc().save(bw, options);\r
190 //MsaTreeEditor.init(mi, ui, msadoc);\r
191 bw.flush();\r
192 bw.close();\r
193 }\r
6f55be9f 194\r
27e0221a 195 private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
6f55be9f 196 XmlOptions options = new XmlOptions();\r
197\r
198 options.setCharacterEncoding("UTF-8");\r
199 options.setSavePrettyPrint();\r
200 options.setSavePrettyPrintIndent(2);\r
201 options.setUseDefaultNamespace();\r
202\r
27e0221a 203 BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r
204 msadoc.save(bw, options);\r
205 bw.flush();\r
206 bw.close();\r
207 }\r
208 \r
209 public static final void parse(String msafile) throws Exception {\r
210 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);\r
211 flush("c:\\temp.msa", msadoc);\r
212 }\r
0dc8c589 213}\r