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