]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/SecFixupTask.java
38c6d1e0a1dd9df76de9e4dc51ca8a6400d2a6bb
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / SecFixupTask.java
1 /** @file
2 SecFixupTask class.
3
4 SecFixupTask is used to call SecFixup.exe to fix up sec image.
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 import org.tianocore.logger.EdkLog;
28
29 /**
30 * SecFixupTask class.
31 *
32 * SecFixupTask is used to call SecFixup.exe to fix up sec image.
33 */
34 public class SecFixupTask extends Task implements EfiDefine {
35 // /
36 // / tool name
37 // /
38 private String toolName = "SecFixup";
39
40 // /
41 // / input file
42 // /
43 private String secExeFile = "";
44
45 // /
46 // / output file
47 // /
48 private String resetVectorDataFile = "";
49
50 // /
51 // / output directory, this variable is added by jave wrap
52 // /
53 private String outputFile = "";
54
55 // /
56 // / output directory
57 // /
58 private String outputDir = "";
59
60 /**
61 * execute
62 *
63 * SecFixupTask execute function is to assemble tool command line & execute
64 * tool command line
65 *
66 * @throws BuidException
67 */
68 public void execute() throws BuildException {
69
70 Project project = this.getOwningTarget().getProject();
71 //
72 // set Logger
73 //
74 FrameworkLogger logger = new FrameworkLogger(project, toolName
75 .toLowerCase());
76 EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
77 EdkLog.setLogger(logger);
78 //
79 // absolute path of efi tools
80 //
81 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
82 String command;
83 String argument;
84 if (path == null) {
85 command = toolName;
86 } else {
87 command = path + File.separatorChar + toolName;
88 }
89 //
90 // argument of tools
91 //
92 if (!this.outputDir.equalsIgnoreCase("")) {
93 argument = this.secExeFile + " " + this.resetVectorDataFile + " "
94 + this.outputDir + File.separatorChar + this.outputFile;
95 } else {
96 argument = this.secExeFile + " " + this.resetVectorDataFile + " "
97 + this.outputFile;
98 }
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(EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
120
121 revl = runner.execute();
122
123 if (EFI_SUCCESS == revl) {
124 //
125 // command execution success
126 //
127 EdkLog.log(EdkLog.EDK_VERBOSE, "SecFixup succeeded!");
128 } else {
129 //
130 // command execution fail
131 //
132 EdkLog.log(EdkLog.EDK_INFO, "ERROR = "+ Integer.toHexString(revl));
133 throw new BuildException("SecFixup failed!");
134 }
135 } catch (Exception e) {
136 throw new BuildException(e.getMessage());
137 }
138 }
139
140 /**
141 * getSecExeFile
142 *
143 * This function is to get class member "secExeFile".
144 *
145 * @return string of sectExe file name.
146 */
147 public String getSecExeFile() {
148 return this.secExeFile;
149 }
150
151 /**
152 * setSecExeFile
153 *
154 * This function is to set class member "secExeFile".
155 *
156 * @param secExeFile
157 * string of secExe file name.
158 */
159 public void setSecExeFile(String secExeFile) {
160 this.secExeFile = secExeFile;
161 }
162
163 /**
164 * getResetVectorDataFile
165 *
166 * This function is to get class member "resetVectorDataFile"
167 *
168 * @return resetVectorDataFile string of resetVectorData file name.
169 */
170 public String getResetVectorDataFile() {
171 return this.resetVectorDataFile;
172 }
173
174 /**
175 * setResetVectorDataFile
176 *
177 * This function is to set class member "resetVectorDataFile"
178 *
179 * @param resetVectorDataFile
180 * string of resetVectorData file name.
181 */
182 public void setResetVectorDataFile(String resetVectorDataFile) {
183 this.resetVectorDataFile = resetVectorDataFile;
184 }
185
186 /**
187 * getOutputFile
188 *
189 * This function is to get class member "outputFile"
190 *
191 * @return outputFile string of output file name.
192 */
193 public String getOutputFile() {
194 return outputFile;
195 }
196
197 /**
198 * setOutputFile
199 *
200 * This function is to set class member "outputFile"
201 *
202 * @param outputFile
203 * string of output file name.
204 */
205 public void setOutputFile(String outputFile) {
206 this.outputFile = outputFile;
207 }
208
209 /**
210 * getOutputDir
211 *
212 * This function is to get class member "outputDir"
213 *
214 * @return outputDir name of output directory
215 */
216 public String getOutputDir() {
217 return outputDir;
218 }
219
220 /**
221 * setOutputDir
222 *
223 * This function is to set class member "outputDir"
224 *
225 * @param outputDir
226 * name of output directory
227 */
228 public void setOutputDir(String outputDir) {
229 this.outputDir = outputDir;
230 }
231 }