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