]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/PeiReBaseTask.java
76a396c2b53cad4c1ed23aa1d689b20bfce58b1b
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / PeiReBaseTask.java
1 /** @file
2 PeiReBaseTask class.
3
4 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.
5
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17 package org.tianocore.framework.tasks;
18
19 import java.io.File;
20
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.taskdefs.Execute;
25 import org.apache.tools.ant.taskdefs.LogStreamHandler;
26 import org.apache.tools.ant.types.Commandline;
27
28 import org.tianocore.common.logger.EdkLog;
29
30 /**
31 PeiReBaseTask class.
32
33 PeiReBaseTask is used to call PeiReBase.exe to rebase efi fv file.
34 **/
35 public class PeiReBaseTask extends Task implements EfiDefine {
36 //
37 // tool name
38 //
39 private String toolName = "PeiReBase";
40 //
41 // Input file
42 //
43 private FileArg inputFile = new FileArg();
44 //
45 // Output file
46 //
47 private FileArg outputFile = new FileArg();
48 //
49 // Base address
50 //
51 private ToolArg baseAddr = new ToolArg();
52 //
53 //
54 //
55 private FileArg mapFile = new FileArg();
56 //
57 // Architecture
58 //
59 private String arch = "IA32";
60
61 /**
62 execute
63
64 PeiReBaseTask execute function is to assemble tool command line & execute
65 tool command line
66
67 @throws BuidException
68 **/
69 public void execute() throws BuildException {
70
71 Project project = this.getOwningTarget().getProject();
72
73 //
74 // absolute path of efi tools
75 //
76 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
77 String command;
78 String argument;
79 if (this.arch.equalsIgnoreCase("IA32")){
80 command = toolName + "_IA32";
81 } else if (this.arch.equalsIgnoreCase("X64")){
82 command = toolName + "_X64";
83 } else if (this.arch.equalsIgnoreCase("IPF")){
84 command = toolName + "_IPF";
85 } else {
86 command = toolName + "_IA32";
87 }
88 if (path != null) {
89 command = path + File.separator + command;
90 }
91
92 //
93 // argument of tools
94 //
95 if (mapFile.getValue().length() == 0) {
96 mapFile.setArg(" -M ", outputFile.getValue() + ".map");
97 }
98 argument = "" + inputFile + outputFile + baseAddr + mapFile;
99
100 //
101 // return value of fwimage execution
102 //
103 int revl = -1;
104
105 try {
106 Commandline cmdline = new Commandline();
107 cmdline.setExecutable(command);
108 cmdline.createArgument().setLine(argument);
109
110 LogStreamHandler streamHandler = new LogStreamHandler(this,
111 Project.MSG_INFO, Project.MSG_WARN);
112 Execute runner = new Execute(streamHandler, null);
113
114 runner.setAntRun(project);
115 runner.setCommandline(cmdline.getCommandline());
116 //
117 // Set debug log information.
118 //
119 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
120 EdkLog.log(this, EdkLog.EDK_INFO, inputFile.toFileList() + " => "
121 + outputFile.toFileList()
122 + mapFile.toFileList());
123
124 revl = runner.execute();
125
126 if (EFI_SUCCESS == revl) {
127 //
128 // command execution success
129 //
130 EdkLog.log(this, EdkLog.EDK_VERBOSE, "PeiReBase succeeded!");
131 } else {
132 //
133 // command execution fail
134 //
135 EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));
136 throw new BuildException("PeiReBase failed!");
137 }
138 } catch (Exception e) {
139 throw new BuildException(e.getMessage());
140 }
141 }
142
143 /**
144 getInputFile
145
146 This function is to get class member "inputFile".
147
148 @return string of input file name.
149 **/
150 public String getInputFile() {
151 return inputFile.getValue();
152 }
153
154 /**
155 setComponentType
156
157 This function is to set class member "inputFile".
158
159 @param inputFile
160 string of input file name.
161 **/
162 public void setInputFile(String inputFile) {
163 this.inputFile.setArg(" -I ", inputFile);
164 }
165
166 /**
167 getOutputFile
168
169 This function is to get class member "outputFile"
170
171 @return outputFile string of output file name.
172 **/
173 public String getOutputFile() {
174 return outputFile.getValue();
175 }
176
177 /**
178 setOutputFile
179
180 This function is to set class member "outputFile"
181
182 @param outputFile
183 string of output file name.
184 **/
185 public void setOutputFile(String outputFile) {
186 this.outputFile.setArg(" -O ", outputFile);
187 }
188
189 /**
190 getBaseAddr
191
192 This function is to get class member "baseAddr"
193
194 @return baseAddr string of base address.
195 **/
196 public String getBaseAddr() {
197 return baseAddr.getValue();
198 }
199
200 /**
201 setBaseAddr
202
203 This function is to set class member "baseAddr"
204
205 @param baseAddr string of base address
206 **/
207 public void setBaseAddr(String baseAddr) {
208 this.baseAddr.setArg(" -B ", baseAddr);
209 }
210
211 /**
212 getArch
213
214 This function is to get class member "arch".
215
216 @return arch Architecture
217 **/
218 public String getArch() {
219 return arch;
220 }
221
222 /**
223 setArch
224
225 This function is to set class member "arch"
226
227 @param arch Architecture
228 **/
229 public void setArch(String arch) {
230 this.arch = arch;
231 }
232
233 /**
234 Get the value of map file
235
236 @return String The map file path
237 **/
238 public String getMapFile() {
239 return mapFile.getValue();
240 }
241
242 /**
243 Set "-M MapFile" argument
244
245 @param mapFile The path of map file
246 **/
247 public void setMapFile(String mapFile) {
248 this.mapFile.setArg(" -M ", mapFile);
249 }
250 }