]>
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 | |
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 | |
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 | |
ff225cbb | 95 | \r |
a15bb0d3 | 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 | |
d7506e11 | 102 | + outputFile + " " + this.baseAddr + " "\r |
103 | + "-M " + outputDir + + File.separatorChar + outputFile + ".map";\r | |
a15bb0d3 | 104 | } else {\r |
d7506e11 | 105 | argument = inputFile + " " + "-O " + outputFile + " " + this.baseAddr+ " " + "-M " + outputFile + ".map";\r |
a15bb0d3 | 106 | }\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 |
128 | EdkLog.log(this, EdkLog.EDK_INFO, this.inputFileName);\r | |
ff225cbb | 129 | \r |
a15bb0d3 | 130 | revl = runner.execute();\r |
ff225cbb | 131 | \r |
a15bb0d3 | 132 | if (EFI_SUCCESS == revl) {\r |
133 | //\r | |
134 | // command execution success\r | |
135 | //\r | |
91f7d582 | 136 | EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");\r |
a15bb0d3 | 137 | } else {\r |
138 | //\r | |
139 | // command execution fail\r | |
140 | //\r | |
91f7d582 | 141 | EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r |
219e2247 | 142 | throw new BuildException("PeiReBase failed!");\r |
a15bb0d3 | 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 | |
ff225cbb | 151 | *\r |
a15bb0d3 | 152 | * This function is to get class member "inputFile".\r |
ff225cbb | 153 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 162 | *\r |
a15bb0d3 | 163 | * This function is to set class member "inputFile".\r |
ff225cbb | 164 | *\r |
a15bb0d3 | 165 | * @param inputFile\r |
166 | * string of input file name.\r | |
167 | */\r | |
168 | public void setInputFile(String inputFile) {\r | |
219e2247 | 169 | this.inputFileName = (new File(inputFile)).getName();\r |
a15bb0d3 | 170 | this.inputFile = "-I " + inputFile;\r |
171 | }\r | |
172 | \r | |
173 | /**\r | |
174 | * getOutputFile\r | |
ff225cbb | 175 | *\r |
a15bb0d3 | 176 | * This function is to get class member "outputFile"\r |
ff225cbb | 177 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 186 | *\r |
a15bb0d3 | 187 | * This function is to set class member "outputFile"\r |
ff225cbb | 188 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 198 | *\r |
a15bb0d3 | 199 | * This function is to get class member "outputDir"\r |
ff225cbb | 200 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 209 | *\r |
a15bb0d3 | 210 | * This function is to set class member "outputDir"\r |
ff225cbb | 211 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 221 | *\r |
a15bb0d3 | 222 | * This function is to get class member "baseAddr"\r |
ff225cbb | 223 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 232 | *\r |
a15bb0d3 | 233 | * This function is to set class member "baseAddr"\r |
ff225cbb | 234 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 243 | *\r |
a15bb0d3 | 244 | * This function is to get class member "arch".\r |
ff225cbb | 245 | *\r |
a15bb0d3 | 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 | |
ff225cbb | 254 | *\r |
255 | * This function is to set class member "arch"\r | |
256 | *\r | |
a15bb0d3 | 257 | * @param arch Architecture\r |
258 | */\r | |
259 | public void setArch(String arch) {\r | |
260 | this.arch = arch;\r | |
261 | }\r | |
262 | }\r |