]>
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 | |
36 | ///\r | |
37 | /// tool name\r | |
38 | ///\r | |
39 | private String toolName = "PeiReBase";\r | |
40 | // /\r | |
41 | // / Input file\r | |
42 | // /\r | |
43 | private String inputFile = "";\r | |
219e2247 | 44 | private String inputFileName = "";\r |
a15bb0d3 | 45 | // /\r |
46 | // / Output file\r | |
47 | // /\r | |
48 | private String outputFile = "";\r | |
49 | \r | |
50 | // /\r | |
51 | // / Output directory, this variable is added by jave wrap\r | |
52 | // /\r | |
53 | private String outputDir = "";\r | |
ff225cbb | 54 | \r |
a15bb0d3 | 55 | ///\r |
56 | /// Base address\r | |
57 | ///\r | |
58 | private String baseAddr = "";\r | |
ff225cbb | 59 | \r |
a15bb0d3 | 60 | ///\r |
ff225cbb | 61 | /// Architecture\r |
a15bb0d3 | 62 | ///\r |
63 | private String arch = "";\r | |
ff225cbb | 64 | \r |
a15bb0d3 | 65 | /**\r |
66 | * execute\r | |
ff225cbb | 67 | *\r |
a15bb0d3 | 68 | * PeiReBaseTask execute function is to assemble tool command line & execute\r |
69 | * tool command line\r | |
ff225cbb | 70 | *\r |
a15bb0d3 | 71 | * @throws BuidException\r |
72 | */\r | |
73 | public void execute() throws BuildException {\r | |
74 | \r | |
75 | Project project = this.getOwningTarget().getProject();\r | |
76 | //\r | |
77 | // set Logger\r | |
78 | //\r | |
79 | FrameworkLogger logger = new FrameworkLogger(project, toolName.toLowerCase());\r | |
80 | EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r | |
81 | EdkLog.setLogger(logger);\r | |
ff225cbb | 82 | \r |
a15bb0d3 | 83 | //\r |
84 | // absolute path of efi tools\r | |
85 | //\r | |
86 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
87 | String command;\r | |
88 | String argument;\r | |
89 | if (this.arch.equalsIgnoreCase("IA32")){\r | |
90 | command = toolName + "_IA32";\r | |
91 | }else if (this.arch.equalsIgnoreCase("X64")){\r | |
92 | command = toolName + "_X64";\r | |
93 | }else if (this.arch.equalsIgnoreCase("IPF")){\r | |
94 | command = toolName + "_IPF";\r | |
95 | }else {\r | |
96 | command = toolName + "_IA32";\r | |
97 | }\r | |
98 | if (path != null) {\r | |
99 | command = path + File.separatorChar + command;\r | |
100 | }\r | |
ff225cbb | 101 | \r |
a15bb0d3 | 102 | //\r |
103 | // argument of tools\r | |
104 | //\r | |
105 | File file = new File(outputFile);\r | |
106 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
107 | argument = inputFile + " " + "-O " + outputDir + File.separatorChar\r | |
d7506e11 | 108 | + outputFile + " " + this.baseAddr + " "\r |
109 | + "-M " + outputDir + + File.separatorChar + outputFile + ".map";\r | |
a15bb0d3 | 110 | } else {\r |
d7506e11 | 111 | argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";\r |
a15bb0d3 | 112 | }\r |
ff225cbb | 113 | \r |
a15bb0d3 | 114 | //\r |
115 | // return value of fwimage execution\r | |
116 | //\r | |
117 | int revl = -1;\r | |
118 | \r | |
119 | try {\r | |
120 | Commandline cmdline = new Commandline();\r | |
121 | cmdline.setExecutable(command);\r | |
122 | cmdline.createArgument().setLine(argument);\r | |
123 | \r | |
124 | LogStreamHandler streamHandler = new LogStreamHandler(this,\r | |
125 | Project.MSG_INFO, Project.MSG_WARN);\r | |
126 | Execute runner = new Execute(streamHandler, null);\r | |
127 | \r | |
128 | runner.setAntRun(project);\r | |
129 | runner.setCommandline(cmdline.getCommandline());\r | |
130 | //\r | |
131 | // Set debug log information.\r | |
132 | //\r | |
219e2247 | 133 | EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r |
134 | EdkLog.log(EdkLog.EDK_INFO, this.inputFileName);\r | |
ff225cbb | 135 | \r |
a15bb0d3 | 136 | revl = runner.execute();\r |
ff225cbb | 137 | \r |
a15bb0d3 | 138 | if (EFI_SUCCESS == revl) {\r |
139 | //\r | |
140 | // command execution success\r | |
141 | //\r | |
219e2247 | 142 | EdkLog.log(EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r |
a15bb0d3 | 143 | } else {\r |
144 | //\r | |
145 | // command execution fail\r | |
146 | //\r | |
219e2247 | 147 | EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r |
148 | throw new BuildException("PeiReBase failed!");\r | |
a15bb0d3 | 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 | |
ff225cbb | 157 | *\r |
a15bb0d3 | 158 | * This function is to get class member "inputFile".\r |
ff225cbb | 159 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 168 | *\r |
a15bb0d3 | 169 | * This function is to set class member "inputFile".\r |
ff225cbb | 170 | *\r |
a15bb0d3 | 171 | * @param inputFile\r |
172 | * string of input file name.\r | |
173 | */\r | |
174 | public void setInputFile(String inputFile) {\r | |
219e2247 | 175 | this.inputFileName = (new File(inputFile)).getName();\r |
a15bb0d3 | 176 | this.inputFile = "-I " + inputFile;\r |
177 | }\r | |
178 | \r | |
179 | /**\r | |
180 | * getOutputFile\r | |
ff225cbb | 181 | *\r |
a15bb0d3 | 182 | * This function is to get class member "outputFile"\r |
ff225cbb | 183 | *\r |
a15bb0d3 | 184 | * @return outputFile string of output file name.\r |
185 | */\r | |
186 | public String getOutputFile() {\r | |
187 | return outputFile;\r | |
188 | }\r | |
189 | \r | |
190 | /**\r | |
191 | * setOutputFile\r | |
ff225cbb | 192 | *\r |
a15bb0d3 | 193 | * This function is to set class member "outputFile"\r |
ff225cbb | 194 | *\r |
a15bb0d3 | 195 | * @param outputFile\r |
196 | * string of output file name.\r | |
197 | */\r | |
198 | public void setOutputFile(String outputFile) {\r | |
199 | this.outputFile = outputFile;\r | |
200 | }\r | |
201 | \r | |
202 | /**\r | |
203 | * getOutputDir\r | |
ff225cbb | 204 | *\r |
a15bb0d3 | 205 | * This function is to get class member "outputDir"\r |
ff225cbb | 206 | *\r |
a15bb0d3 | 207 | * @return outputDir string of output directory.\r |
208 | */\r | |
209 | public String getOutputDir() {\r | |
210 | return outputDir;\r | |
211 | }\r | |
212 | \r | |
213 | /**\r | |
214 | * setOutputDir\r | |
ff225cbb | 215 | *\r |
a15bb0d3 | 216 | * This function is to set class member "outputDir"\r |
ff225cbb | 217 | *\r |
a15bb0d3 | 218 | * @param outputDir\r |
219 | * string of output directory.\r | |
220 | */\r | |
221 | public void setOutputDir(String outputDir) {\r | |
222 | this.outputDir = outputDir;\r | |
223 | }\r | |
224 | \r | |
225 | /**\r | |
226 | * getBaseAddr\r | |
ff225cbb | 227 | *\r |
a15bb0d3 | 228 | * This function is to get class member "baseAddr"\r |
ff225cbb | 229 | *\r |
a15bb0d3 | 230 | * @return baseAddr string of base address.\r |
231 | */\r | |
232 | public String getBaseAddr() {\r | |
233 | return baseAddr;\r | |
234 | }\r | |
235 | \r | |
236 | /**\r | |
237 | * setBaseAddr\r | |
ff225cbb | 238 | *\r |
a15bb0d3 | 239 | * This function is to set class member "baseAddr"\r |
ff225cbb | 240 | *\r |
a15bb0d3 | 241 | * @param baseAddr string of base address\r |
242 | */\r | |
243 | public void setBaseAddr(String baseAddr) {\r | |
244 | this.baseAddr = "-B " + baseAddr;\r | |
245 | }\r | |
246 | \r | |
247 | /**\r | |
248 | * getArch\r | |
ff225cbb | 249 | *\r |
a15bb0d3 | 250 | * This function is to get class member "arch".\r |
ff225cbb | 251 | *\r |
a15bb0d3 | 252 | * @return arch Architecture\r |
253 | */\r | |
254 | public String getArch() {\r | |
255 | return arch;\r | |
256 | }\r | |
257 | \r | |
258 | /**\r | |
259 | * setArch\r | |
ff225cbb | 260 | *\r |
261 | * This function is to set class member "arch"\r | |
262 | *\r | |
a15bb0d3 | 263 | * @param arch Architecture\r |
264 | */\r | |
265 | public void setArch(String arch) {\r | |
266 | this.arch = arch;\r | |
267 | }\r | |
268 | }\r |