summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
blob: acfb2ba5720815c8a321da934d184943783a42b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/** @file
 EfiRomTask class.

 EfiRomTask is used to call FlashMap.exe to lay out the flash.


 Copyright (c) 2006, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php

 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

 **/
package org.tianocore.framework.tasks;

import java.io.File;
import java.util.LinkedList;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.tianocore.common.logger.EdkLog;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.types.Commandline;

/**
  SecFixupTask class.
 
  SecFixupTask is used to call SecFixup.exe to fix up sec image.
 **/
public class EfiRomTask extends Task implements EfiDefine {
    //
    // tool name
    //
    private final static String toolName = "EfiRom";

    //
    // Flash default file
    //
    private ToolArg verbose = new ToolArg();

    //
    // Flash device
    //
    private ToolArg venderId = new ToolArg();

    //
    // Flash device Image
    //
    private ToolArg deviceId = new ToolArg();

    //
    // output file
    //
    private FileArg outputFile = new FileArg();

    //
    // binary file
    //
    private Input binaryFileList = new Input();

    //
    // Efi PE32 image file
    //
    private Input pe32FileList = new Input();

    //
    // Compress efi PE32 image file
    //
    private Input pe32ComprFileList = new Input();

    //
    // Hex class code in the PCI data strutor header
    //
    private ToolArg classCode = new ToolArg();

    //
    // Hex revision in the PCI data header.
    //
    private ToolArg revision = new ToolArg();

    //
    // Dump the headers of an existing option rom image.
    //
    private ToolArg dump = new ToolArg();

    //
    // output directory
    //
    private String outputDir = ".";

    //
    // command and argument list
    //
    LinkedList<String> argList = new LinkedList<String>();

    /**
      execute
     
      EfiRomTask execute function is to assemble tool command line & execute
      tool command line
     
      @throws BuidException
     **/
    public void execute() throws BuildException {

        Project project = this.getOwningTarget().getProject();

        //
        // absolute path of efi tools
        //
        String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
        String command;
        if (path == null) {
            command = toolName;
        } else {
            command = path + File.separator + toolName;
        }

        String argument = "" + verbose + venderId + deviceId + dump + revision + classCode 
                             + binaryFileList.toStringWithSinglepPrefix(" -b ")
                             + pe32FileList.toStringWithSinglepPrefix(" -e ")
                             + pe32ComprFileList.toStringWithSinglepPrefix(" -ec ")
                             + outputFile;

        try {
            Commandline cmdline = new Commandline();
            cmdline.setExecutable(command);
            cmdline.createArgument().setLine(argument);

            LogStreamHandler streamHandler = new LogStreamHandler(this,
                    Project.MSG_INFO, Project.MSG_WARN);
            Execute runner = new Execute(streamHandler, null);

            runner.setAntRun(project);
            runner.setCommandline(cmdline.getCommandline());
            runner.setWorkingDirectory(new File(outputDir));

            EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
            EdkLog.log(this, EdkLog.EDK_INFO, binaryFileList.toFileList() 
                       + pe32FileList.toFileList() + pe32ComprFileList.toFileList()
                       + " => " + outputFile.toFileList());

            int exitCode = runner.execute();
            if (exitCode != 0) {
                //
                // command execution fail
                //
                EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));
                throw new BuildException(toolName + " failed!");
            } else {
                EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
            }
        } catch (Exception e) {
            throw new BuildException(e.getMessage());
        }
    }

    /**
      getVerbose
     
      This function is to get class member "verbose"
     
      @return verbose   for verbose output.
     **/
    public String getVerbose() {
        return verbose.getValue();
    }

    /**
      setVerbose
     
      This function is to set class member "verbose"
     
      @param verbose    for verbose output.
     **/
    public void setVerbose(boolean verbose) {
        if (verbose){
            this.verbose.setArg(" -", "p");
        }
    }

    /**
      getVenderId
     
      This function is to get class member "venderId"
     
      @return venderId     String of venderId.
     **/
    public String getVenderId() {
        return venderId.getValue();
    }

    /**
      setVenderId
     
      This function is to set class member "venderId"
     
      @param venderId      String of venderId.
     **/
    public void setVenderId(String venderId) {
        this.venderId.setArg(" -v ", venderId);
    }

    /**
      getDeviceId
     
      This function is to get class member "deviceId"
     
      @return deviceId   String of device ID.
     **/
    public String getDeviceId() {
        return this.deviceId.getValue();
    }

    /**
      setDeviceId
     
      This function is to set class member "deviceId"
     
      @param deviceId   String of device ID.
     **/
    public void setDeviceId(String deviceId) {
        this.deviceId.setArg(" -d ", deviceId);
    }


    /**
      getOutputFile
     
      This function is to get class member "outputFile"
     
      @return outputFile     name of output directory.
     **/
    public String getOutputFile() {
        return outputFile.getValue();
    }

    /**
      setOutputFile
     
      This function is to set class member "dscFile"
     
      @param outputFile      name of DSC file
     **/
    public void setOutputFile(String outputFile) {
        this.outputFile.setArg(" -o ", outputFile);
    }

    /**
      getClassCode
     
      This function is to get class member "classCode"
     
      @return fdImage       name of class code file.
     **/
    public String getClassCode() {
        return classCode.getValue();
    }

    /**
      setclassCode
     
      This function is to set class member "classCode"
     
      @param fdImage        name of class code file.
     **/
    public void setclassCode(String classCode) {
        this.classCode.setArg(" -cc ", classCode);
    }

    /**
      getRevision
     
      This function is to get class member "revision".
     
      @return revision     hex revision in the PDI data header.
     **/
    public String getRevision() {
        return revision.getValue();
    }

    /**
      setRevision
     
      This function is to set class member "revision"
     
      @param revision     hex revision in the PDI data header.
     **/
    public void setRevision(String revision) {
        this.revision.setArg(" -rev ", revision);
    }

    /**
      getFlashDeviceImage
     
      This function is to get class member "dump"
     
      @return flashDeviceImage      name of flash device image
     **/
    public String getDump() {
        return dump.getValue();
    }

    /**
      setFlashDeviceImage
     
      This function is to set class member "dump"
     
      @param flashDeviceImage        name of flash device image
     **/
    public void setDump(boolean dump) {
        if (dump) {
            this.dump.setArg(" -", "dump");
        }
    }

    /**
      getOutputDir
     
      This function is to get class member "outputDir"
     
      @return outputDir       string of output directory
     **/
    public String getOutputDir() {
        return outputDir;
    }

    /**
      setOutputDir
     
      This function is to set class member "outputDir"
     
      @param outputDir         string of output directory
     **/
    public void setOutputDir(String outputDir) {
        this.outputDir = outputDir;
    }

    /**
      addBinaryFile
     
      This function is to add binary file to binaryFile list.
     
      @param binaryFile         name of binary file.
     **/
    public void addConfiguredBinaryFile(Input binaryFile){
        this.binaryFileList.insert(binaryFile);
    }

    /**
      addPe32File
     
      This function is to add pe32 file to pe32File list.
     
      @param pe32File            name of pe32 file.
     **/
    public void addConfiguredPe32File(Input pe32File){
        this.pe32FileList.insert(pe32File);
    }

    /**
      addPe32ComprFile
     
      This function os to add compressed pe32 file to pe32ComprFile list.
     
      @param pe32ComprFile        name of compressed pe32 file.
     **/
    public void addConfiguredPe32ComprFile(Input pe32ComprFile){
        this.pe32ComprFileList.insert(pe32ComprFile);
    }
}