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