]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
c479e0d3344198c81dd91cd5b6d107b908abd769
[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 + "-M " + outputDir + + File.separatorChar + outputFile + ".map";
109 } else {
110 argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";
111 }
112
113 //
114 // return value of fwimage execution
115 //
116 int revl = -1;
117
118 try {
119 Commandline cmdline = new Commandline();
120 cmdline.setExecutable(command);
121 cmdline.createArgument().setLine(argument);
122
123 LogStreamHandler streamHandler = new LogStreamHandler(this,
124 Project.MSG_INFO, Project.MSG_WARN);
125 Execute runner = new Execute(streamHandler, null);
126
127 runner.setAntRun(project);
128 runner.setCommandline(cmdline.getCommandline());
129 //
130 // Set debug log information.
131 //
132 EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
133 EdkLog.log(EdkLog.EDK_INFO, this.inputFileName);
134
135 revl = runner.execute();
136
137 if (EFI_SUCCESS == revl) {
138 //
139 // command execution success
140 //
141 EdkLog.log(EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");
142 } else {
143 //
144 // command execution fail
145 //
146 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
147 throw new BuildException("PeiReBase failed!");
148 }
149 } catch (Exception e) {
150 throw new BuildException(e.getMessage());
151 }
152 }
153
154 /**
155 * getInputFile
156 *
157 * This function is to get class member "inputFile".
158 *
159 * @return string of input file name.
160 */
161 public String getInputFile() {
162 return inputFile;
163 }
164
165 /**
166 * setComponentType
167 *
168 * This function is to set class member "inputFile".
169 *
170 * @param inputFile
171 * string of input file name.
172 */
173 public void setInputFile(String inputFile) {
174 this.inputFileName = (new File(inputFile)).getName();
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 }