]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
Remove FrameworkLogger in FrameworkTasks and EdkException in GenBuild. Update EdkLog...
[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 //
78 // absolute path of efi tools
79 //
80 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
81 String command;
82 String argument;
83 if (this.arch.equalsIgnoreCase("IA32")){
84 command = toolName + "_IA32";
85 }else if (this.arch.equalsIgnoreCase("X64")){
86 command = toolName + "_X64";
87 }else if (this.arch.equalsIgnoreCase("IPF")){
88 command = toolName + "_IPF";
89 }else {
90 command = toolName + "_IA32";
91 }
92 if (path != null) {
93 command = path + File.separatorChar + command;
94 }
95
96 //
97 // argument of tools
98 //
99 File file = new File(outputFile);
100 if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {
101 argument = inputFile + " " + "-O " + outputDir + File.separatorChar
102 + outputFile + " " + this.baseAddr + " "
103 + "-M " + outputDir + + File.separatorChar + outputFile + ".map";
104 } else {
105 argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";
106 }
107
108 //
109 // return value of fwimage execution
110 //
111 int revl = -1;
112
113 try {
114 Commandline cmdline = new Commandline();
115 cmdline.setExecutable(command);
116 cmdline.createArgument().setLine(argument);
117
118 LogStreamHandler streamHandler = new LogStreamHandler(this,
119 Project.MSG_INFO, Project.MSG_WARN);
120 Execute runner = new Execute(streamHandler, null);
121
122 runner.setAntRun(project);
123 runner.setCommandline(cmdline.getCommandline());
124 //
125 // Set debug log information.
126 //
127 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
128 EdkLog.log(this, EdkLog.EDK_INFO, this.inputFileName);
129
130 revl = runner.execute();
131
132 if (EFI_SUCCESS == revl) {
133 //
134 // command execution success
135 //
136 EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");
137 } else {
138 //
139 // command execution fail
140 //
141 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
142 throw new BuildException("PeiReBase failed!");
143 }
144 } catch (Exception e) {
145 throw new BuildException(e.getMessage());
146 }
147 }
148
149 /**
150 * getInputFile
151 *
152 * This function is to get class member "inputFile".
153 *
154 * @return string of input file name.
155 */
156 public String getInputFile() {
157 return inputFile;
158 }
159
160 /**
161 * setComponentType
162 *
163 * This function is to set class member "inputFile".
164 *
165 * @param inputFile
166 * string of input file name.
167 */
168 public void setInputFile(String inputFile) {
169 this.inputFileName = (new File(inputFile)).getName();
170 this.inputFile = "-I " + inputFile;
171 }
172
173 /**
174 * getOutputFile
175 *
176 * This function is to get class member "outputFile"
177 *
178 * @return outputFile string of output file name.
179 */
180 public String getOutputFile() {
181 return outputFile;
182 }
183
184 /**
185 * setOutputFile
186 *
187 * This function is to set class member "outputFile"
188 *
189 * @param outputFile
190 * string of output file name.
191 */
192 public void setOutputFile(String outputFile) {
193 this.outputFile = outputFile;
194 }
195
196 /**
197 * getOutputDir
198 *
199 * This function is to get class member "outputDir"
200 *
201 * @return outputDir string of output directory.
202 */
203 public String getOutputDir() {
204 return outputDir;
205 }
206
207 /**
208 * setOutputDir
209 *
210 * This function is to set class member "outputDir"
211 *
212 * @param outputDir
213 * string of output directory.
214 */
215 public void setOutputDir(String outputDir) {
216 this.outputDir = outputDir;
217 }
218
219 /**
220 * getBaseAddr
221 *
222 * This function is to get class member "baseAddr"
223 *
224 * @return baseAddr string of base address.
225 */
226 public String getBaseAddr() {
227 return baseAddr;
228 }
229
230 /**
231 * setBaseAddr
232 *
233 * This function is to set class member "baseAddr"
234 *
235 * @param baseAddr string of base address
236 */
237 public void setBaseAddr(String baseAddr) {
238 this.baseAddr = "-B " + baseAddr;
239 }
240
241 /**
242 * getArch
243 *
244 * This function is to get class member "arch".
245 *
246 * @return arch Architecture
247 */
248 public String getArch() {
249 return arch;
250 }
251
252 /**
253 * setArch
254 *
255 * This function is to set class member "arch"
256 *
257 * @param arch Architecture
258 */
259 public void setArch(String arch) {
260 this.arch = arch;
261 }
262 }