]>
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 | |
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 | |
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 | |
27 | import 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 | |
34 | public 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 | |
219e2247 | 43 | private String inputFileName = "";\r |
a15bb0d3 | 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 | |
219e2247 | 131 | EdkLog.log(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r |
132 | EdkLog.log(EdkLog.EDK_INFO, this.inputFileName);\r | |
a15bb0d3 | 133 | \r |
134 | revl = runner.execute();\r | |
135 | \r | |
136 | if (EFI_SUCCESS == revl) {\r | |
137 | //\r | |
138 | // command execution success\r | |
139 | //\r | |
219e2247 | 140 | EdkLog.log(EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r |
a15bb0d3 | 141 | } else {\r |
142 | //\r | |
143 | // command execution fail\r | |
144 | //\r | |
219e2247 | 145 | EdkLog.log(EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r |
146 | throw new BuildException("PeiReBase failed!");\r | |
a15bb0d3 | 147 | }\r |
148 | } catch (Exception e) {\r | |
149 | throw new BuildException(e.getMessage());\r | |
150 | }\r | |
151 | }\r | |
152 | \r | |
153 | /**\r | |
154 | * getInputFile\r | |
155 | * \r | |
156 | * This function is to get class member "inputFile".\r | |
157 | * \r | |
158 | * @return string of input file name.\r | |
159 | */\r | |
160 | public String getInputFile() {\r | |
161 | return inputFile;\r | |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | * setComponentType\r | |
166 | * \r | |
167 | * This function is to set class member "inputFile".\r | |
168 | * \r | |
169 | * @param inputFile\r | |
170 | * string of input file name.\r | |
171 | */\r | |
172 | public void setInputFile(String inputFile) {\r | |
219e2247 | 173 | this.inputFileName = (new File(inputFile)).getName();\r |
a15bb0d3 | 174 | this.inputFile = "-I " + inputFile;\r |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | * getOutputFile\r | |
179 | * \r | |
180 | * This function is to get class member "outputFile"\r | |
181 | * \r | |
182 | * @return outputFile string of output file name.\r | |
183 | */\r | |
184 | public String getOutputFile() {\r | |
185 | return outputFile;\r | |
186 | }\r | |
187 | \r | |
188 | /**\r | |
189 | * setOutputFile\r | |
190 | * \r | |
191 | * This function is to set class member "outputFile"\r | |
192 | * \r | |
193 | * @param outputFile\r | |
194 | * string of output file name.\r | |
195 | */\r | |
196 | public void setOutputFile(String outputFile) {\r | |
197 | this.outputFile = outputFile;\r | |
198 | }\r | |
199 | \r | |
200 | /**\r | |
201 | * getOutputDir\r | |
202 | * \r | |
203 | * This function is to get class member "outputDir"\r | |
204 | * \r | |
205 | * @return outputDir string of output directory.\r | |
206 | */\r | |
207 | public String getOutputDir() {\r | |
208 | return outputDir;\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | * setOutputDir\r | |
213 | * \r | |
214 | * This function is to set class member "outputDir"\r | |
215 | * \r | |
216 | * @param outputDir\r | |
217 | * string of output directory.\r | |
218 | */\r | |
219 | public void setOutputDir(String outputDir) {\r | |
220 | this.outputDir = outputDir;\r | |
221 | }\r | |
222 | \r | |
223 | /**\r | |
224 | * getBaseAddr\r | |
225 | * \r | |
226 | * This function is to get class member "baseAddr"\r | |
227 | * \r | |
228 | * @return baseAddr string of base address.\r | |
229 | */\r | |
230 | public String getBaseAddr() {\r | |
231 | return baseAddr;\r | |
232 | }\r | |
233 | \r | |
234 | /**\r | |
235 | * setBaseAddr\r | |
236 | * \r | |
237 | * This function is to set class member "baseAddr"\r | |
238 | * \r | |
239 | * @param baseAddr string of base address\r | |
240 | */\r | |
241 | public void setBaseAddr(String baseAddr) {\r | |
242 | this.baseAddr = "-B " + baseAddr;\r | |
243 | }\r | |
244 | \r | |
245 | /**\r | |
246 | * getArch\r | |
247 | * \r | |
248 | * This function is to get class member "arch".\r | |
249 | * \r | |
250 | * @return arch Architecture\r | |
251 | */\r | |
252 | public String getArch() {\r | |
253 | return arch;\r | |
254 | }\r | |
255 | \r | |
256 | /**\r | |
257 | * setArch\r | |
258 | * \r | |
259 | * This function is to set class member "arch" \r | |
260 | * \r | |
261 | * @param arch Architecture\r | |
262 | */\r | |
263 | public void setArch(String arch) {\r | |
264 | this.arch = arch;\r | |
265 | }\r | |
266 | }\r |