--- /dev/null
+/** @file\r
+ GenCRC32SectionTask class.\r
+\r
+ GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section.\r
+ \r
+ Copyright (c) 2006, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ \r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ **/\r
+\r
+package org.tianocore.framework.tasks;\r
+\r
+import java.io.File;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+import org.apache.tools.ant.Project;\r
+import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.taskdefs.Execute;\r
+import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
+import org.apache.tools.ant.types.Commandline;\r
+\r
+import org.tianocore.common.logger.EdkLog;\r
+\r
+/**\r
+ GenCRC32SectionTask\r
+ \r
+ GenCRC32SectionTask is to call GenCRC32Section.exe to generate crc32 section. \r
+ \r
+**/\r
+public class GenCRC32SectionTask extends Task implements EfiDefine {\r
+ //\r
+ // Tool name\r
+ //\r
+ private static String toolName = "GenCRC32Section";\r
+ //\r
+ // output file\r
+ //\r
+ private FileArg outputFile = new FileArg();\r
+ //\r
+ // inputFile list\r
+ //\r
+ private InputFile inputFileList = new InputFile();\r
+ \r
+ //\r
+ // Project\r
+ //\r
+ static private Project project;\r
+ \r
+ /**\r
+ execute\r
+ \r
+ GenCRC32SectionTask execute is to assemble tool command line & execute\r
+ tool command line\r
+ \r
+ @throws BuildException\r
+ **/\r
+ public void execute() throws BuildException {\r
+ \r
+ project = this.getOwningTarget().getProject(); \r
+ ///\r
+ /// absolute path of efi tools\r
+ ///\r
+ String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r
+ String command;\r
+ if (path == null) {\r
+ command = toolName;\r
+ } else {\r
+ command = path + File.separator + toolName ;\r
+ }\r
+ // \r
+ // assemble argument \r
+ //\r
+ String argument = "" + inputFileList.toStringWithSinglepPrefix(" -i ") + outputFile; \r
+ // \r
+ // return value of fwimage execution \r
+ //\r
+ int revl = -1; \r
+ \r
+ try {\r
+ Commandline cmdline = new Commandline();\r
+ cmdline.setExecutable(command);\r
+ cmdline.createArgument().setLine(argument);\r
+ \r
+ LogStreamHandler streamHandler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);\r
+ Execute runner = new Execute(streamHandler, null);\r
+ \r
+ runner.setAntRun(project);\r
+ runner.setCommandline(cmdline.getCommandline());\r
+\r
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
+ EdkLog.log(this, inputFileList.toFileList() + " => " + outputFile.toFileList());\r
+\r
+ revl = runner.execute();\r
+ if (EFI_SUCCESS == revl){\r
+ //\r
+ // command execution success \r
+ //\r
+ EdkLog.log(this, toolName + " succeeded!");\r
+ } else {\r
+ // \r
+ // command execution fail\r
+ //\r
+ EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));\r
+ // LAH Added This Line\r
+ throw new BuildException(toolName + " failed!");\r
+ }\r
+ } catch (Exception e) {\r
+ throw new BuildException(e.getMessage());\r
+ } \r
+ }\r
+\r
+ /**\r
+ addInputFile\r
+ \r
+ This function is to add a inputFile element into list\r
+ @param inputFile : inputFile element\r
+ **/\r
+ public void addConfiguredInputfile(InputFile inputFile) {\r
+ inputFileList.insert(inputFile);\r
+ }\r
+ \r
+ /**\r
+ get class member "outputFile"\r
+ @return name of output file\r
+ **/\r
+ public String getOutputFile() {\r
+ return this.outputFile.getValue();\r
+ }\r
+ /**\r
+ set class member "outputFile"\r
+ @param outputFile : outputFile parameter \r
+ **/\r
+ public void setOutputFile(String outputFile) {\r
+ this.outputFile.setArg(" -o ", outputFile);\r
+ }\r
+}\r