]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
Enhance peirebase tool to get base address from the corresponding fv.inf file, which...
[mirror_edk2.git] / Tools / Java / 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 FileArg inputFile = new FileArg();
44 //
45 // Output file
46 //
47 private FileArg outputFile = new FileArg();
48 //
49 // Base address
50 //
51 private ToolArg baseAddr = new ToolArg();
52 //
53 // Fv.inf file
54 //
55 private FileArg fvinfFile = new FileArg();
56 //
57 // map file
58 //
59 private FileArg mapFile = new FileArg();
60 //
61 // Architecture
62 //
63 private String arch = "IA32";
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 if (isUptodate()) {
75 EdkLog.log(this, EdkLog.EDK_VERBOSE, outputFile.toFileList() + " is up-to-date!");
76 return;
77 }
78
79 Project project = this.getOwningTarget().getProject();
80
81 //
82 // absolute path of efi tools
83 //
84 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
85 String command;
86 String argument;
87 if (this.arch.equalsIgnoreCase("IA32")){
88 command = toolName + "_IA32";
89 } else if (this.arch.equalsIgnoreCase("X64")){
90 command = toolName + "_X64";
91 } else if (this.arch.equalsIgnoreCase("IPF")){
92 command = toolName + "_IPF";
93 } else {
94 command = toolName + "_IA32";
95 }
96 if (path != null) {
97 command = path + File.separator + command;
98 }
99
100 //
101 // argument of tools
102 //
103 if (mapFile.getValue().length() == 0) {
104 mapFile.setArg(" -M ", outputFile.getValue() + ".map");
105 }
106 argument = "" + inputFile + outputFile + baseAddr + fvinfFile + mapFile;
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, inputFile.toFileList() + " => "
129 + outputFile.toFileList()
130 + mapFile.toFileList());
131
132 revl = runner.execute();
133
134 if (EFI_SUCCESS == revl) {
135 //
136 // command execution success
137 //
138 EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");
139 } else {
140 //
141 // command execution fail
142 //
143 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
144 throw new BuildException("PeiReBase failed!");
145 }
146 } catch (Exception e) {
147 throw new BuildException(e.getMessage());
148 }
149 }
150
151 /**
152 getInputFile
153
154 This function is to get class member "inputFile".
155
156 @return string of input file name.
157 **/
158 public String getInputFile() {
159 return inputFile.getValue();
160 }
161
162 /**
163 setComponentType
164
165 This function is to set class member "inputFile".
166
167 @param inputFile
168 string of input file name.
169 **/
170 public void setInputFile(String inputFile) {
171 this.inputFile.setArg(" -I ", inputFile);
172 }
173
174 /**
175 getOutputFile
176
177 This function is to get class member "outputFile"
178
179 @return outputFile string of output file name.
180 **/
181 public String getOutputFile() {
182 return outputFile.getValue();
183 }
184
185 /**
186 setOutputFile
187
188 This function is to set class member "outputFile"
189
190 @param outputFile
191 string of output file name.
192 **/
193 public void setOutputFile(String outputFile) {
194 this.outputFile.setArg(" -O ", outputFile);
195 }
196
197 /**
198 getBaseAddr
199
200 This function is to get class member "baseAddr"
201
202 @return baseAddr string of base address.
203 **/
204 public String getBaseAddr() {
205 return baseAddr.getValue();
206 }
207
208 /**
209 setBaseAddr
210
211 This function is to set class member "baseAddr"
212
213 @param baseAddr string of base address
214 **/
215 public void setBaseAddr(String baseAddr) {
216 this.baseAddr.setArg(" -B ", baseAddr);
217 }
218
219 /**
220 getArch
221
222 This function is to get class member "arch".
223
224 @return arch Architecture
225 **/
226 public String getArch() {
227 return arch;
228 }
229
230 /**
231 setArch
232
233 This function is to set class member "arch"
234
235 @param arch Architecture
236 **/
237 public void setArch(String arch) {
238 this.arch = arch;
239 }
240
241 /**
242 Get the value of fv.inf file
243
244 @return String The fv.inf file path
245 **/
246 public String getFvInfFile() {
247 return fvinfFile.getValue();
248 }
249
250 /**
251 Set "-F FvinfFile" argument
252
253 @param fvinfFile The path of fv.inf file
254 **/
255 public void setFvInfFile(String fvinfFile) {
256 this.fvinfFile.setArg(" -F ", fvinfFile);
257 }
258
259 /**
260 Get the value of map file
261
262 @return String The map file path
263 **/
264 public String getMapFile() {
265 return mapFile.getValue();
266 }
267
268 /**
269 Set "-M MapFile" argument
270
271 @param mapFile The path of map file
272 **/
273 public void setMapFile(String mapFile) {
274 this.mapFile.setArg(" -M ", mapFile);
275 }
276
277 //
278 // Dependency check
279 //
280 private boolean isUptodate() {
281 File srcFile = new File(inputFile.getValue());
282 File dstFile = new File(outputFile.getValue());
283
284 if (srcFile.lastModified() > dstFile.lastModified()) {
285 return false;
286 }
287
288 return true;
289 }
290 }