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
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
ff225cbb 5\r
6\r
a15bb0d3 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
ff225cbb 12\r
a15bb0d3 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
ff225cbb 27\r
28import org.tianocore.common.logger.EdkLog;\r
a15bb0d3 29\r
30/**\r
31 PeiReBaseTask class.\r
32\r
33 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.\r
34**/\r
35public class PeiReBaseTask extends Task implements EfiDefine {\r
93f5dd0a 36 //\r
37 // tool name\r
38 //\r
a15bb0d3 39 private String toolName = "PeiReBase";\r
93f5dd0a 40 //\r
41 // Input file\r
42 //\r
43 private FileArg inputFile = new FileArg();\r
44 //\r
45 // Output file\r
46 //\r
47 private FileArg outputFile = new FileArg();\r
48 //\r
49 // Base address\r
50 //\r
51 private ToolArg baseAddr = new ToolArg();\r
52 //\r
4c50c885 53 // Fv.inf file\r
93f5dd0a 54 // \r
4c50c885
LG
55 private FileArg fvinfFile = new FileArg();\r
56 //\r
57 // map file\r
93f5dd0a 58 // \r
59 private FileArg mapFile = new FileArg();\r
60 //\r
61 // Architecture\r
62 //\r
63 private String arch = "IA32";\r
ff225cbb 64\r
a15bb0d3 65 /**\r
93f5dd0a 66 execute\r
67 \r
68 PeiReBaseTask execute function is to assemble tool command line & execute\r
69 tool command line\r
70 \r
71 @throws BuidException\r
72 **/\r
a15bb0d3 73 public void execute() throws BuildException {\r
d946661a 74 if (isUptodate()) {\r
75 EdkLog.log(this, EdkLog.EDK_VERBOSE, outputFile.toFileList() + " is up-to-date!");\r
76 return;\r
77 }\r
a15bb0d3 78\r
79 Project project = this.getOwningTarget().getProject();\r
ff225cbb 80\r
a15bb0d3 81 //\r
82 // absolute path of efi tools\r
83 //\r
84 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
85 String command;\r
86 String argument;\r
87 if (this.arch.equalsIgnoreCase("IA32")){\r
88 command = toolName + "_IA32";\r
93f5dd0a 89 } else if (this.arch.equalsIgnoreCase("X64")){\r
a15bb0d3 90 command = toolName + "_X64";\r
93f5dd0a 91 } else if (this.arch.equalsIgnoreCase("IPF")){\r
a15bb0d3 92 command = toolName + "_IPF";\r
93f5dd0a 93 } else {\r
a15bb0d3 94 command = toolName + "_IA32";\r
95 }\r
96 if (path != null) {\r
93f5dd0a 97 command = path + File.separator + command;\r
a15bb0d3 98 }\r
ff225cbb 99\r
a15bb0d3 100 //\r
101 // argument of tools\r
102 //\r
93f5dd0a 103 if (mapFile.getValue().length() == 0) {\r
104 mapFile.setArg(" -M ", outputFile.getValue() + ".map");\r
a15bb0d3 105 }\r
4c50c885 106 argument = "" + inputFile + outputFile + baseAddr + fvinfFile + mapFile;\r
ff225cbb 107\r
a15bb0d3 108 //\r
109 // return value of fwimage execution\r
110 //\r
111 int revl = -1;\r
112\r
113 try {\r
114 Commandline cmdline = new Commandline();\r
115 cmdline.setExecutable(command);\r
116 cmdline.createArgument().setLine(argument);\r
117\r
118 LogStreamHandler streamHandler = new LogStreamHandler(this,\r
119 Project.MSG_INFO, Project.MSG_WARN);\r
120 Execute runner = new Execute(streamHandler, null);\r
121\r
122 runner.setAntRun(project);\r
123 runner.setCommandline(cmdline.getCommandline());\r
124 //\r
125 // Set debug log information.\r
126 //\r
91f7d582 127 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
93f5dd0a 128 EdkLog.log(this, EdkLog.EDK_INFO, inputFile.toFileList() + " => " \r
129 + outputFile.toFileList()\r
130 + mapFile.toFileList());\r
ff225cbb 131\r
a15bb0d3 132 revl = runner.execute();\r
ff225cbb 133\r
a15bb0d3 134 if (EFI_SUCCESS == revl) {\r
135 //\r
136 // command execution success\r
137 //\r
91f7d582 138 EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r
a15bb0d3 139 } else {\r
140 //\r
141 // command execution fail\r
142 //\r
91f7d582 143 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r
219e2247 144 throw new BuildException("PeiReBase failed!");\r
a15bb0d3 145 }\r
146 } catch (Exception e) {\r
147 throw new BuildException(e.getMessage());\r
148 }\r
149 }\r
150\r
151 /**\r
93f5dd0a 152 getInputFile\r
153 \r
154 This function is to get class member "inputFile".\r
155 \r
156 @return string of input file name.\r
157 **/\r
a15bb0d3 158 public String getInputFile() {\r
93f5dd0a 159 return inputFile.getValue();\r
a15bb0d3 160 }\r
161\r
162 /**\r
93f5dd0a 163 setComponentType\r
164 \r
165 This function is to set class member "inputFile".\r
166 \r
167 @param inputFile\r
168 string of input file name.\r
169 **/\r
a15bb0d3 170 public void setInputFile(String inputFile) {\r
93f5dd0a 171 this.inputFile.setArg(" -I ", inputFile);\r
a15bb0d3 172 }\r
173\r
174 /**\r
93f5dd0a 175 getOutputFile\r
176 \r
177 This function is to get class member "outputFile"\r
178 \r
179 @return outputFile string of output file name.\r
180 **/\r
a15bb0d3 181 public String getOutputFile() {\r
93f5dd0a 182 return outputFile.getValue();\r
a15bb0d3 183 }\r
184\r
185 /**\r
93f5dd0a 186 setOutputFile\r
187 \r
188 This function is to set class member "outputFile"\r
189 \r
190 @param outputFile\r
191 string of output file name.\r
192 **/\r
a15bb0d3 193 public void setOutputFile(String outputFile) {\r
93f5dd0a 194 this.outputFile.setArg(" -O ", outputFile);\r
a15bb0d3 195 }\r
196\r
197 /**\r
93f5dd0a 198 getBaseAddr\r
199 \r
200 This function is to get class member "baseAddr"\r
201 \r
202 @return baseAddr string of base address.\r
203 **/\r
a15bb0d3 204 public String getBaseAddr() {\r
93f5dd0a 205 return baseAddr.getValue();\r
a15bb0d3 206 }\r
207\r
208 /**\r
93f5dd0a 209 setBaseAddr\r
210 \r
211 This function is to set class member "baseAddr"\r
212 \r
213 @param baseAddr string of base address\r
214 **/\r
a15bb0d3 215 public void setBaseAddr(String baseAddr) {\r
93f5dd0a 216 this.baseAddr.setArg(" -B ", baseAddr);\r
a15bb0d3 217 }\r
218\r
219 /**\r
93f5dd0a 220 getArch\r
221 \r
222 This function is to get class member "arch".\r
223 \r
224 @return arch Architecture\r
225 **/\r
a15bb0d3 226 public String getArch() {\r
227 return arch;\r
228 }\r
229\r
230 /**\r
93f5dd0a 231 setArch\r
232 \r
233 This function is to set class member "arch"\r
234 \r
235 @param arch Architecture\r
236 **/\r
a15bb0d3 237 public void setArch(String arch) {\r
238 this.arch = arch;\r
239 }\r
93f5dd0a 240\r
4c50c885
LG
241 /**\r
242 Get the value of fv.inf file\r
243\r
244 @return String The fv.inf file path\r
245 **/\r
246 public String getFvInfFile() {\r
247 return fvinfFile.getValue();\r
248 }\r
249\r
250 /**\r
251 Set "-F FvinfFile" argument\r
252\r
253 @param fvinfFile The path of fv.inf file\r
254 **/\r
255 public void setFvInfFile(String fvinfFile) {\r
256 this.fvinfFile.setArg(" -F ", fvinfFile);\r
257 }\r
258\r
93f5dd0a 259 /**\r
260 Get the value of map file\r
261\r
262 @return String The map file path\r
263 **/\r
264 public String getMapFile() {\r
265 return mapFile.getValue();\r
266 }\r
267\r
268 /**\r
269 Set "-M MapFile" argument\r
270\r
271 @param mapFile The path of map file\r
272 **/\r
273 public void setMapFile(String mapFile) {\r
274 this.mapFile.setArg(" -M ", mapFile);\r
275 }\r
d946661a 276\r
277 //\r
278 // Dependency check\r
279 // \r
280 private boolean isUptodate() {\r
281 File srcFile = new File(inputFile.getValue());\r
282 File dstFile = new File(outputFile.getValue());\r
283\r
284 if (srcFile.lastModified() > dstFile.lastModified()) {\r
285 return false;\r
286 }\r
287\r
288 return true;\r
289 }\r
a15bb0d3 290}\r