]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
Modify GenFfsTask to make it don't create ORG file.
[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
28 import org.tianocore.common.logger.EdkLog;
29
30 /**
31 PeiReBaseTask class.
32
33 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.
34 **/
35 public class PeiReBaseTask extends Task implements EfiDefine {
36 ///
37 /// tool name
38 ///
39 private String toolName = "PeiReBase";
40 // /
41 // / Input file
42 // /
43 private String inputFile = "";
44 private String inputFileName = "";
45 // /
46 // / Output file
47 // /
48 private String outputFile = "";
49
50 // /
51 // / Output directory, this variable is added by jave wrap
52 // /
53 private String outputDir = "";
54
55 ///
56 /// Base address
57 ///
58 private String baseAddr = "";
59
60 ///
61 /// Architecture
62 ///
63 private String arch = "";
64
65 /**
66 * execute
67 *
68 * PeiReBaseTask execute function is to assemble tool command line & execute
69 * tool command line
70 *
71 * @throws BuidException
72 */
73 public void execute() throws BuildException {
74
75 Project project = this.getOwningTarget().getProject();
76 //
77 // set Logger
78 //
79 FrameworkLogger logger = new FrameworkLogger(project, toolName.toLowerCase());
80 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
81 EdkLog.setLogger(logger);
82
83 //
84 // absolute path of efi tools
85 //
86 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
87 String command;
88 String argument;
89 if (this.arch.equalsIgnoreCase("IA32")){
90 command = toolName + "_IA32";
91 }else if (this.arch.equalsIgnoreCase("X64")){
92 command = toolName + "_X64";
93 }else if (this.arch.equalsIgnoreCase("IPF")){
94 command = toolName + "_IPF";
95 }else {
96 command = toolName + "_IA32";
97 }
98 if (path != null) {
99 command = path + File.separatorChar + command;
100 }
101
102 //
103 // argument of tools
104 //
105 File file = new File(outputFile);
106 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
107 argument = inputFile + " " + "-O " + outputDir + File.separatorChar
108 + outputFile + " " + this.baseAddr + " "
109 + "-M " + outputDir + + File.separatorChar + outputFile + ".map";
110 } else {
111 argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";
112 }
113
114 //
115 // return value of fwimage execution
116 //
117 int revl = -1;
118
119 try {
120 Commandline cmdline = new Commandline();
121 cmdline.setExecutable(command);
122 cmdline.createArgument().setLine(argument);
123
124 LogStreamHandler streamHandler = new LogStreamHandler(this,
125 Project.MSG_INFO, Project.MSG_WARN);
126 Execute runner = new Execute(streamHandler, null);
127
128 runner.setAntRun(project);
129 runner.setCommandline(cmdline.getCommandline());
130 //
131 // Set debug log information.
132 //
133 EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
134 EdkLog.log(EdkLog.EDK_INFO, this.inputFileName);
135
136 revl = runner.execute();
137
138 if (EFI_SUCCESS == revl) {
139 //
140 // command execution success
141 //
142 EdkLog.log(EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");
143 } else {
144 //
145 // command execution fail
146 //
147 EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
148 throw new BuildException("PeiReBase failed!");
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.inputFileName = (new File(inputFile)).getName();
176 this.inputFile = "-I " + inputFile;
177 }
178
179 /**
180 * getOutputFile
181 *
182 * This function is to get class member "outputFile"
183 *
184 * @return outputFile string of output file name.
185 */
186 public String getOutputFile() {
187 return outputFile;
188 }
189
190 /**
191 * setOutputFile
192 *
193 * This function is to set class member "outputFile"
194 *
195 * @param outputFile
196 * string of output file name.
197 */
198 public void setOutputFile(String outputFile) {
199 this.outputFile = outputFile;
200 }
201
202 /**
203 * getOutputDir
204 *
205 * This function is to get class member "outputDir"
206 *
207 * @return outputDir string of output directory.
208 */
209 public String getOutputDir() {
210 return outputDir;
211 }
212
213 /**
214 * setOutputDir
215 *
216 * This function is to set class member "outputDir"
217 *
218 * @param outputDir
219 * string of output directory.
220 */
221 public void setOutputDir(String outputDir) {
222 this.outputDir = outputDir;
223 }
224
225 /**
226 * getBaseAddr
227 *
228 * This function is to get class member "baseAddr"
229 *
230 * @return baseAddr string of base address.
231 */
232 public String getBaseAddr() {
233 return baseAddr;
234 }
235
236 /**
237 * setBaseAddr
238 *
239 * This function is to set class member "baseAddr"
240 *
241 * @param baseAddr string of base address
242 */
243 public void setBaseAddr(String baseAddr) {
244 this.baseAddr = "-B " + baseAddr;
245 }
246
247 /**
248 * getArch
249 *
250 * This function is to get class member "arch".
251 *
252 * @return arch Architecture
253 */
254 public String getArch() {
255 return arch;
256 }
257
258 /**
259 * setArch
260 *
261 * This function is to set class member "arch"
262 *
263 * @param arch Architecture
264 */
265 public void setArch(String arch) {
266 this.arch = arch;
267 }
268 }