]>
Commit | Line | Data |
---|---|---|
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 | \r | |
28 | import org.tianocore.common.logger.EdkLog;\r | |
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 | |
44 | private String inputFileName = "";\r | |
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 | |
54 | \r | |
55 | ///\r | |
56 | /// Base address\r | |
57 | ///\r | |
58 | private String baseAddr = "";\r | |
59 | \r | |
60 | ///\r | |
61 | /// Architecture\r | |
62 | ///\r | |
63 | private String arch = "";\r | |
64 | \r | |
65 | /**\r | |
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 | |
73 | public void execute() throws BuildException {\r | |
74 | \r | |
75 | Project project = this.getOwningTarget().getProject();\r | |
76 | \r | |
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 | |
85 | }else if (this.arch.equalsIgnoreCase("X64")){\r | |
86 | command = toolName + "_X64";\r | |
87 | }else if (this.arch.equalsIgnoreCase("IPF")){\r | |
88 | command = toolName + "_IPF";\r | |
89 | }else {\r | |
90 | command = toolName + "_IA32";\r | |
91 | }\r | |
92 | if (path != null) {\r | |
93 | command = path + File.separatorChar + command;\r | |
94 | }\r | |
95 | \r | |
96 | //\r | |
97 | // argument of tools\r | |
98 | //\r | |
99 | File file = new File(outputFile);\r | |
100 | if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r | |
101 | argument = inputFile + " " + "-O " + outputDir + File.separatorChar\r | |
102 | + outputFile + " " + this.baseAddr + " "\r | |
103 | + "-M " + outputDir + + File.separatorChar + outputFile + ".map";\r | |
104 | } else {\r | |
105 | argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";\r | |
106 | }\r | |
107 | \r | |
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 | |
127 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r | |
128 | EdkLog.log(this, EdkLog.EDK_INFO, this.inputFileName);\r | |
129 | \r | |
130 | revl = runner.execute();\r | |
131 | \r | |
132 | if (EFI_SUCCESS == revl) {\r | |
133 | //\r | |
134 | // command execution success\r | |
135 | //\r | |
136 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r | |
137 | } else {\r | |
138 | //\r | |
139 | // command execution fail\r | |
140 | //\r | |
141 | EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r | |
142 | throw new BuildException("PeiReBase failed!");\r | |
143 | }\r | |
144 | } catch (Exception e) {\r | |
145 | throw new BuildException(e.getMessage());\r | |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | /**\r | |
150 | * getInputFile\r | |
151 | *\r | |
152 | * This function is to get class member "inputFile".\r | |
153 | *\r | |
154 | * @return string of input file name.\r | |
155 | */\r | |
156 | public String getInputFile() {\r | |
157 | return inputFile;\r | |
158 | }\r | |
159 | \r | |
160 | /**\r | |
161 | * setComponentType\r | |
162 | *\r | |
163 | * This function is to set class member "inputFile".\r | |
164 | *\r | |
165 | * @param inputFile\r | |
166 | * string of input file name.\r | |
167 | */\r | |
168 | public void setInputFile(String inputFile) {\r | |
169 | this.inputFileName = (new File(inputFile)).getName();\r | |
170 | this.inputFile = "-I " + inputFile;\r | |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | * getOutputFile\r | |
175 | *\r | |
176 | * This function is to get class member "outputFile"\r | |
177 | *\r | |
178 | * @return outputFile string of output file name.\r | |
179 | */\r | |
180 | public String getOutputFile() {\r | |
181 | return outputFile;\r | |
182 | }\r | |
183 | \r | |
184 | /**\r | |
185 | * setOutputFile\r | |
186 | *\r | |
187 | * This function is to set class member "outputFile"\r | |
188 | *\r | |
189 | * @param outputFile\r | |
190 | * string of output file name.\r | |
191 | */\r | |
192 | public void setOutputFile(String outputFile) {\r | |
193 | this.outputFile = outputFile;\r | |
194 | }\r | |
195 | \r | |
196 | /**\r | |
197 | * getOutputDir\r | |
198 | *\r | |
199 | * This function is to get class member "outputDir"\r | |
200 | *\r | |
201 | * @return outputDir string of output directory.\r | |
202 | */\r | |
203 | public String getOutputDir() {\r | |
204 | return outputDir;\r | |
205 | }\r | |
206 | \r | |
207 | /**\r | |
208 | * setOutputDir\r | |
209 | *\r | |
210 | * This function is to set class member "outputDir"\r | |
211 | *\r | |
212 | * @param outputDir\r | |
213 | * string of output directory.\r | |
214 | */\r | |
215 | public void setOutputDir(String outputDir) {\r | |
216 | this.outputDir = outputDir;\r | |
217 | }\r | |
218 | \r | |
219 | /**\r | |
220 | * getBaseAddr\r | |
221 | *\r | |
222 | * This function is to get class member "baseAddr"\r | |
223 | *\r | |
224 | * @return baseAddr string of base address.\r | |
225 | */\r | |
226 | public String getBaseAddr() {\r | |
227 | return baseAddr;\r | |
228 | }\r | |
229 | \r | |
230 | /**\r | |
231 | * setBaseAddr\r | |
232 | *\r | |
233 | * This function is to set class member "baseAddr"\r | |
234 | *\r | |
235 | * @param baseAddr string of base address\r | |
236 | */\r | |
237 | public void setBaseAddr(String baseAddr) {\r | |
238 | this.baseAddr = "-B " + baseAddr;\r | |
239 | }\r | |
240 | \r | |
241 | /**\r | |
242 | * getArch\r | |
243 | *\r | |
244 | * This function is to get class member "arch".\r | |
245 | *\r | |
246 | * @return arch Architecture\r | |
247 | */\r | |
248 | public String getArch() {\r | |
249 | return arch;\r | |
250 | }\r | |
251 | \r | |
252 | /**\r | |
253 | * setArch\r | |
254 | *\r | |
255 | * This function is to set class member "arch"\r | |
256 | *\r | |
257 | * @param arch Architecture\r | |
258 | */\r | |
259 | public void setArch(String arch) {\r | |
260 | this.arch = arch;\r | |
261 | }\r | |
262 | }\r |