]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
c033c0d199d881f4a0c2cc33f5c874c303e56281
[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
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_INFO, Commandline.toString(cmdline.getCommandline()));
132
133 revl = runner.execute();
134
135 if (EFI_SUCCESS == revl) {
136 //
137 // command execution success
138 //
139 EdkLog.log(EdkLog.EDK_INFO,"PeiBase succeeded!");
140 } else {
141 //
142 // command execution fail
143 //
144 EdkLog.log(EdkLog.EDK_ERROR, "PeiBase failed. (error="
145 + Integer.toHexString(revl) + ")");
146 throw new BuildException("PeiBase failed. (error="
147 + Integer.toHexString(revl) + ")");
148
149 }
150 } catch (Exception e) {
151 throw new BuildException(e.getMessage());
152 }
153 }
154
155 /**
156 * getInputFile
157 *
158 * This function is to get class member "inputFile".
159 *
160 * @return string of input file name.
161 */
162 public String getInputFile() {
163 return inputFile;
164 }
165
166 /**
167 * setComponentType
168 *
169 * This function is to set class member "inputFile".
170 *
171 * @param inputFile
172 * string of input file name.
173 */
174 public void setInputFile(String inputFile) {
175 this.inputFile = "-I " + inputFile;
176 }
177
178 /**
179 * getOutputFile
180 *
181 * This function is to get class member "outputFile"
182 *
183 * @return outputFile string of output file name.
184 */
185 public String getOutputFile() {
186 return outputFile;
187 }
188
189 /**
190 * setOutputFile
191 *
192 * This function is to set class member "outputFile"
193 *
194 * @param outputFile
195 * string of output file name.
196 */
197 public void setOutputFile(String outputFile) {
198 this.outputFile = outputFile;
199 }
200
201 /**
202 * getOutputDir
203 *
204 * This function is to get class member "outputDir"
205 *
206 * @return outputDir string of output directory.
207 */
208 public String getOutputDir() {
209 return outputDir;
210 }
211
212 /**
213 * setOutputDir
214 *
215 * This function is to set class member "outputDir"
216 *
217 * @param outputDir
218 * string of output directory.
219 */
220 public void setOutputDir(String outputDir) {
221 this.outputDir = outputDir;
222 }
223
224 /**
225 * getBaseAddr
226 *
227 * This function is to get class member "baseAddr"
228 *
229 * @return baseAddr string of base address.
230 */
231 public String getBaseAddr() {
232 return baseAddr;
233 }
234
235 /**
236 * setBaseAddr
237 *
238 * This function is to set class member "baseAddr"
239 *
240 * @param baseAddr string of base address
241 */
242 public void setBaseAddr(String baseAddr) {
243 this.baseAddr = "-B " + baseAddr;
244 }
245
246 /**
247 * getArch
248 *
249 * This function is to get class member "arch".
250 *
251 * @return arch Architecture
252 */
253 public String getArch() {
254 return arch;
255 }
256
257 /**
258 * setArch
259 *
260 * This function is to set class member "arch"
261 *
262 * @param arch Architecture
263 */
264 public void setArch(String arch) {
265 this.arch = arch;
266 }
267 }