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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
/** @file
FlashMapTask class.
FlashMapTask 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.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.tianocore.logger.EdkLog;
/**
* SecFixupTask class.
*
* SecFixupTask is used to call SecFixup.exe to fix up sec image.
*/
public class FlashMapTask extends Task implements EfiDefine {
// /
// / tool name
// /
private final String toolName = "FlashMap";
// /
// / Flash default file
// /
private String flashDefFile = "";
// /
// / Flash device
// /
private String flashDevice = "";
// /
// / Flash device Image
// /
private String flashDeviceImage = "";
// /
// / MCI file
// /
private String mciFile = "";
// /
// / MCO file
// /
private String mcoFile = "";
// /
// / Discover FD image
// /
private String fdImage = "";
// /
// / Dsc file
// /
private String dscFile = "";
// /
// / Asm INC file
// /
private String asmIncFile = "";
// /
// / Image out file
// /
private String imageOutFile = "";
// /
// / Header file
// /
private String headerFile = "";
// /
// / Input string file
// /
private String inStrFile = "";
// /
// / Output string file
// /
private String outStrFile = "";
// /
// / Base address
// /
private String baseAddr = "";
// /
// / Aligment
// /
private String aligment = "";
// /
// / Padding value
// /
private String padValue = "";
// /
// / output directory
// /
private String outputDir = "";
// /
// / MCI file array
// /
List<Input> mciFileArray = new ArrayList<Input>();
// /
// / command and argument list
// /
LinkedList<String> argList = new LinkedList<String>();
/**
* execute
*
* FlashMapTask execute function is to assemble tool command line & execute
* tool command line
*
* @throws BuidException
*/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
//
// set Logger
//
FrameworkLogger logger = new FrameworkLogger(project, "flashmap");
EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));
EdkLog.setLogger(logger);
//
// absolute path of efi tools
//
String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
String command;
if (path == null) {
command = toolName;
} else {
command = path + File.separatorChar + toolName;
}
argList.addFirst(command);
//
// add substituted input file and output file
//
if (this.inStrFile != null && this.outStrFile != null
&& !this.inStrFile.equalsIgnoreCase("")
&& !this.inStrFile.equalsIgnoreCase("")) {
argList.add("-strsub");
argList.add(this.inStrFile);
argList.add(this.outStrFile);
}
//
// add microcode binary files
//
if (mciFileArray.size() > 0) {
argList.add("-mcmerge");
Iterator mciList = mciFileArray.iterator();
while (mciList.hasNext()) {
argList.add(((Input) mciList.next()).getFile());
}
}
EdkLog.log(EdkLog.EDK_INFO, argList.toString().replace(",",""));
//
// lauch the program
//
ProcessBuilder pb = new ProcessBuilder(argList);
pb.directory(new File(outputDir));
int exitCode = 0;
try {
Process cmdProc = pb.start();
InputStreamReader cmdOut = new InputStreamReader(cmdProc
.getInputStream());
char[] buf = new char[1024];
exitCode = cmdProc.waitFor();
//
// log command line string.
//
EdkLog.log(EdkLog.EDK_INFO, cmdProc.getOutputStream().toString());
if (exitCode != 0) {
int len = cmdOut.read(buf, 0, 1024);
EdkLog.log(EdkLog.EDK_ERROR, new String(buf, 0, len));
} else {
EdkLog.log(EdkLog.EDK_INFO, "FlashMap succeed!");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
} finally {
if (exitCode != 0) {
// throw new BuildException("GenFvImage: failed to generate FV
// file!");
}
}
}
/**
* getFlashDefFile
*
* This function is to get class member "flashDefFile"
*
* @return flashDeFile Name of flash definition file.
*/
public String getFlashDefFile() {
return flashDefFile;
}
/**
* setFlashDefFile
*
* This function is to set class member "flashDefFile"
*
* @param flashDefFile
* Name of flash definition file.
*/
public void setFlashDefFile(String flashDefFile) {
this.flashDefFile = flashDefFile;
argList.add("-fdf");
argList.add(this.flashDefFile);
}
/**
* getAligment
*
* This function is to get class member "aligment"
*
* @return aligment String of aligment value.
*/
public String getAligment() {
return aligment;
}
/**
* setAligment
*
* This function is to set class member "aligment"
*
* @param aligment
* String of aligment value.
*/
public void setAligment(String aligment) {
this.aligment = aligment;
argList.add("-align");
argList.add(this.aligment);
}
/**
* getAsmIncFile
*
* This function is to get class member "asmIncFile"
*
* @return asmIncFile String of ASM include file.
*/
public String getAsmIncFile() {
return asmIncFile;
}
/**
* setAsmIncFile
*
* This function is to set class member "asmIncFile"
*
* @param asmIncFile
* String of ASM include file.
*/
public void setAsmIncFile(String asmIncFile) {
this.asmIncFile = asmIncFile;
argList.add("-asmincfile");
argList.add(this.asmIncFile);
}
/**
* getBaseAddr
*
* This function is to get class member "baseAddr"
*
* @return baseAddr String of base address value.
*/
public String getBaseAddr() {
return baseAddr;
}
/**
* setBaseAddr
*
* This function is to set class member "baseAddr"
*
* @param baseAddr
* String of base address value.
*/
public void setBaseAddr(String baseAddr) {
this.baseAddr = baseAddr;
argList.add("-baseaddr");
argList.add(this.baseAddr);
}
/**
* getDscFile
*
* This function is to get class member "dscFile"
*
* @return dscFile name of DSC file
*/
public String getDscFile() {
return dscFile;
}
/**
* setDscFile
*
* This function is to set class member "dscFile"
*
* @param dscFile
* name of DSC file
*/
public void setDscFile(String dscFile) {
this.dscFile = dscFile;
argList.add("-dsc");
argList.add(this.dscFile);
}
/**
* getFdImage
*
* This function is to get class member "fdImage"
*
* @return fdImage name of input FDI image file.
*/
public String getFdImage() {
return fdImage;
}
/**
* setFdImage
*
* This function is to set class member "fdImage"
*
* @param fdImage
* name of input FDI image file.
*/
public void setFdImage(String fdImage) {
this.fdImage = fdImage;
argList.add("-discover");
argList.add(this.fdImage);
}
/**
* getFlashDevice
*
* This function is to get class member "flashDevice".
*
* @return flashDevice name of flash device.
*/
public String getFlashDevice() {
return flashDevice;
}
/**
* setFlashDevice
*
* This function is to set class member "flashDevice"
*
* @param flashDevice
* name of flash device.
*/
public void setFlashDevice(String flashDevice) {
this.flashDevice = flashDevice;
argList.add("-flashdevice");
argList.add(this.flashDevice);
}
/**
* getFlashDeviceImage
*
* This function is to get class member "flashDeviceImage"
*
* @return flashDeviceImage name of flash device image
*/
public String getFlashDeviceImage() {
return flashDeviceImage;
}
/**
* setFlashDeviceImage
*
* This function is to set class member "flashDeviceImage"
*
* @param flashDeviceImage
* name of flash device image
*/
public void setFlashDeviceImage(String flashDeviceImage) {
this.flashDeviceImage = flashDeviceImage;
argList.add("-flashdeviceimage");
argList.add(this.flashDeviceImage);
}
/**
* getHeaderFile
*
* This function is to get class member "headerFile"
*
* @return headerFile name of include file
*/
public String getHeaderFile() {
return headerFile;
}
/**
* setHeaderFile
*
* This function is to set class member "headerFile"
*
* @param headerFile
* name of include file
*/
public void setHeaderFile(String headerFile) {
this.headerFile = headerFile;
argList.add("-hfile");
argList.add(this.headerFile);
}
/**
* getImageOutFile
*
* This function is to get class member "imageOutFile"
*
* @return imageOutFile name of output image file
*/
public String getImageOutFile() {
return imageOutFile;
}
/**
* setImageOutFile
*
* This function is to set class member "ImageOutFile"
*
* @param imageOutFile
* name of output image file
*/
public void setImageOutFile(String imageOutFile) {
this.imageOutFile = imageOutFile;
argList.add("-imageout");
argList.add(this.imageOutFile);
}
/**
* getInStrFile
*
* This function is to get class member "inStrFile"
*
* @return inStrFile name of input file which used to replace symbol names.
*/
public String getInStrFile() {
return inStrFile;
}
/**
* setInStrFile
*
* This function is to set class member "inStrFile"
*
* @param inStrFile
* name of input file which used to replace symbol names.
*/
public void setInStrFile(String inStrFile) {
this.inStrFile = inStrFile;
}
/**
* getMciFile
*
* This function is to get class member "mciFile"
*
* @return mciFile name of input microcode file
*/
public String getMciFile() {
return mciFile;
}
/**
* setMciFile
*
* This function is to set class member "mciFile"
*
* @param mciFile
* name of input microcode file
*/
public void setMciFile(String mciFile) {
this.mciFile = mciFile;
argList.add("-mci");
argList.add(this.mciFile);
}
/**
* getMcoFile
*
* This function is to get class member "mcoFile"
*
* @return mcoFile name of output binary microcode image
*/
public String getMcoFile() {
return mcoFile;
}
/**
* setMcoFile
*
* This function is to set class member "mcoFile"
*
* @param mcoFile
* name of output binary microcode image
*/
public void setMcoFile(String mcoFile) {
this.mcoFile = mcoFile;
argList.add("-mco");
argList.add(this.mcoFile);
}
/**
* getOutStrFile
*
* This function is to get class member "outStrFile"
*
* @return outStrFile name of output string substitution file
*/
public String getOutStrFile() {
return outStrFile;
}
/**
* setOutStrFile
*
* This function is to set class member "outStrFile"
*
* @param outStrFile
* name of output string substitution file
*/
public void setOutStrFile(String outStrFile) {
this.outStrFile = outStrFile;
}
/**
* getPadValue
*
* This function is to get class member "padValue"
*
* @return padValue string of byte value to use as padding
*/
public String getPadValue() {
return padValue;
}
/**
* setPadValue
*
* This function is to set class member "padValue"
*
* @param padValue
* string of byte value to use as padding
*/
public void setPadValue(String padValue) {
this.padValue = padValue;
argList.add("-padvalue");
argList.add(this.padValue);
}
/**
* addMciFile
*
* This function is to add Microcode binary file
*
* @param mciFile
* instance of input class
*/
public void addMciFile(Input mciFile) {
this.mciFileArray.add(mciFile);
}
/**
* 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;
}
}
|