]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
Adjust Nt32 SecMain user-defined build file to use OBJECTS.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / PeiReBaseTask.java
CommitLineData
a15bb0d3 1/** @file\r
2 PeiReBaseTask class.\r
3\r
4 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.\r
5 \r
6 \r
7 Copyright (c) 2006, Intel Corporation\r
8 All rights reserved. This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12 \r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16 **/\r
17package org.tianocore.framework.tasks;\r
18\r
19import java.io.File;\r
20\r
21import org.apache.tools.ant.Task;\r
22import org.apache.tools.ant.Project;\r
23import org.apache.tools.ant.BuildException;\r
24import org.apache.tools.ant.taskdefs.Execute;\r
25import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
26import org.apache.tools.ant.types.Commandline;\r
27import org.tianocore.logger.EdkLog;\r
28\r
29/**\r
30 PeiReBaseTask class.\r
31\r
32 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.\r
33**/\r
34public class PeiReBaseTask extends Task implements EfiDefine {\r
35 ///\r
36 /// tool name\r
37 ///\r
38 private String toolName = "PeiReBase";\r
39 // /\r
40 // / Input file\r
41 // /\r
42 private String inputFile = "";\r
219e2247 43 private String inputFileName = "";\r
a15bb0d3 44 // /\r
45 // / Output file\r
46 // /\r
47 private String outputFile = "";\r
48\r
49 // /\r
50 // / Output directory, this variable is added by jave wrap\r
51 // /\r
52 private String outputDir = "";\r
53 \r
54 ///\r
55 /// Base address\r
56 ///\r
57 private String baseAddr = "";\r
58 \r
59 ///\r
60 /// Architecture \r
61 ///\r
62 private String arch = "";\r
63 \r
64 /**\r
65 * execute\r
66 * \r
67 * PeiReBaseTask execute function is to assemble tool command line & execute\r
68 * tool command line\r
69 * \r
70 * @throws BuidException\r
71 */\r
72 public void execute() throws BuildException {\r
73\r
74 Project project = this.getOwningTarget().getProject();\r
75 //\r
76 // set Logger\r
77 //\r
78 FrameworkLogger logger = new FrameworkLogger(project, toolName.toLowerCase());\r
79 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r
80 EdkLog.setLogger(logger);\r
81 \r
82 //\r
83 // absolute path of efi tools\r
84 //\r
85 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
86 String command;\r
87 String argument;\r
88 if (this.arch.equalsIgnoreCase("IA32")){\r
89 command = toolName + "_IA32";\r
90 }else if (this.arch.equalsIgnoreCase("X64")){\r
91 command = toolName + "_X64";\r
92 }else if (this.arch.equalsIgnoreCase("IPF")){\r
93 command = toolName + "_IPF";\r
94 }else {\r
95 command = toolName + "_IA32";\r
96 }\r
97 if (path != null) {\r
98 command = path + File.separatorChar + command;\r
99 }\r
100 \r
101 //\r
102 // argument of tools\r
103 //\r
104 File file = new File(outputFile);\r
105 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r
106 argument = inputFile + " " + "-O " + outputDir + File.separatorChar\r
d7506e11 107 + outputFile + " " + this.baseAddr + " "\r
108 + "-M " + outputDir + + File.separatorChar + outputFile + ".map";\r
a15bb0d3 109 } else {\r
d7506e11 110 argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";\r
a15bb0d3 111 }\r
112 \r
113 //\r
114 // return value of fwimage execution\r
115 //\r
116 int revl = -1;\r
117\r
118 try {\r
119 Commandline cmdline = new Commandline();\r
120 cmdline.setExecutable(command);\r
121 cmdline.createArgument().setLine(argument);\r
122\r
123 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
124 Project.MSG_INFO, Project.MSG_WARN);\r
125 Execute runner = new Execute(streamHandler, null);\r
126\r
127 runner.setAntRun(project);\r
128 runner.setCommandline(cmdline.getCommandline());\r
129 //\r
130 // Set debug log information.\r
131 //\r
219e2247 132 EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
133 EdkLog.log(EdkLog.EDK_INFO, this.inputFileName);\r
a15bb0d3 134 \r
135 revl = runner.execute();\r
136 \r
137 if (EFI_SUCCESS == revl) {\r
138 //\r
139 // command execution success\r
140 //\r
219e2247 141 EdkLog.log(EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r
a15bb0d3 142 } else {\r
143 //\r
144 // command execution fail\r
145 //\r
219e2247 146 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r
147 throw new BuildException("PeiReBase failed!");\r
a15bb0d3 148 }\r
149 } catch (Exception e) {\r
150 throw new BuildException(e.getMessage());\r
151 }\r
152 }\r
153\r
154 /**\r
155 * getInputFile\r
156 * \r
157 * This function is to get class member "inputFile".\r
158 * \r
159 * @return string of input file name.\r
160 */\r
161 public String getInputFile() {\r
162 return inputFile;\r
163 }\r
164\r
165 /**\r
166 * setComponentType\r
167 * \r
168 * This function is to set class member "inputFile".\r
169 * \r
170 * @param inputFile\r
171 * string of input file name.\r
172 */\r
173 public void setInputFile(String inputFile) {\r
219e2247 174 this.inputFileName = (new File(inputFile)).getName();\r
a15bb0d3 175 this.inputFile = "-I " + inputFile;\r
176 }\r
177\r
178 /**\r
179 * getOutputFile\r
180 * \r
181 * This function is to get class member "outputFile"\r
182 * \r
183 * @return outputFile string of output file name.\r
184 */\r
185 public String getOutputFile() {\r
186 return outputFile;\r
187 }\r
188\r
189 /**\r
190 * setOutputFile\r
191 * \r
192 * This function is to set class member "outputFile"\r
193 * \r
194 * @param outputFile\r
195 * string of output file name.\r
196 */\r
197 public void setOutputFile(String outputFile) {\r
198 this.outputFile = outputFile;\r
199 }\r
200\r
201 /**\r
202 * getOutputDir\r
203 * \r
204 * This function is to get class member "outputDir"\r
205 * \r
206 * @return outputDir string of output directory.\r
207 */\r
208 public String getOutputDir() {\r
209 return outputDir;\r
210 }\r
211\r
212 /**\r
213 * setOutputDir\r
214 * \r
215 * This function is to set class member "outputDir"\r
216 * \r
217 * @param outputDir\r
218 * string of output directory.\r
219 */\r
220 public void setOutputDir(String outputDir) {\r
221 this.outputDir = outputDir;\r
222 }\r
223\r
224 /**\r
225 * getBaseAddr\r
226 * \r
227 * This function is to get class member "baseAddr"\r
228 * \r
229 * @return baseAddr string of base address.\r
230 */\r
231 public String getBaseAddr() {\r
232 return baseAddr;\r
233 }\r
234\r
235 /**\r
236 * setBaseAddr\r
237 * \r
238 * This function is to set class member "baseAddr"\r
239 * \r
240 * @param baseAddr string of base address\r
241 */\r
242 public void setBaseAddr(String baseAddr) {\r
243 this.baseAddr = "-B " + baseAddr;\r
244 }\r
245\r
246 /**\r
247 * getArch\r
248 * \r
249 * This function is to get class member "arch".\r
250 * \r
251 * @return arch Architecture\r
252 */\r
253 public String getArch() {\r
254 return arch;\r
255 }\r
256\r
257 /**\r
258 * setArch\r
259 * \r
260 * This function is to set class member "arch" \r
261 * \r
262 * @param arch Architecture\r
263 */\r
264 public void setArch(String arch) {\r
265 this.arch = arch;\r
266 }\r
267}\r