]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/FlashMap/FlashMap.c
1. Removed the unnecessary #include statements and include files
[mirror_edk2.git] / Tools / Source / TianoTools / FlashMap / FlashMap.c
CommitLineData
d25c4bf0 1/*++\r
2\r
3Copyright (c) 2004-2005 Intel Corporation. All rights reserved\r
4This software and associated documentation (if any) is furnished\r
5under a license and may only be used or copied in accordance\r
6with the terms of the license. Except as permitted by such\r
7license, no part of this software or documentation may be\r
8reproduced, stored in a retrieval system, or transmitted in any\r
9form or by any means without the express written consent of\r
10Intel Corporation.\r
11\r
12Module Name:\r
13\r
14 FlashMap.c\r
15\r
16Abstract:\r
17\r
18 Utility for flash management in the Intel Platform Innovation Framework\r
19 for EFI build environment.\r
20\r
21--*/\r
22\r
23#include <stdio.h>\r
24#include <string.h>\r
25#include <stdlib.h>\r
26#include <ctype.h>\r
51d48c26 27#include <UefiBaseTypes.h>\r
28#include <Base.h>\r
d25c4bf0 29\r
30#include "EfiUtilityMsgs.h"\r
31#include "Microcode.h"\r
32#include "FlashDefFile.h"\r
33#include "Symbols.h"\r
34\r
35#define UTILITY_NAME "FlashMap"\r
36\r
37typedef struct _STRING_LIST {\r
38 struct _STRING_LIST *Next;\r
39 char *Str;\r
40} STRING_LIST;\r
41\r
42//\r
43// Keep our globals in one of these structures\r
44//\r
45static struct {\r
46 char *CIncludeFileName;\r
47 char *FlashDevice;\r
48 char *FlashDeviceImage;\r
49 char *MCIFileName;\r
50 char *MCOFileName;\r
51 char *ImageOutFileName;\r
52 char *DscFileName;\r
53 char *AsmIncludeFileName;\r
54 char *FlashDefinitionFileName;\r
55 char *StringReplaceInFileName;\r
56 char *StringReplaceOutFileName;\r
57 char *DiscoverFDImageName;\r
58 char MicrocodePadByteValue;\r
59 unsigned int MicrocodeAlignment;\r
60 STRING_LIST *MCIFileNames;\r
61 STRING_LIST *LastMCIFileNames;\r
62 unsigned int BaseAddress;\r
63} mGlobals;\r
64\r
65#define DEFAULT_MC_PAD_BYTE_VALUE 0xFF\r
66#define DEFAULT_MC_ALIGNMENT 16\r
67\r
68static\r
69STATUS\r
70ProcessCommandLine (\r
71 int argc,\r
72 char *argv[]\r
73 );\r
74\r
75static\r
76STATUS\r
77MergeMicrocodeFiles (\r
78 char *OutFileName,\r
79 STRING_LIST *FileNames,\r
80 unsigned int Alignment,\r
81 char PadByteValue\r
82 );\r
83\r
84static\r
85void\r
86Usage (\r
87 VOID\r
88 );\r
89\r
90int\r
91main (\r
92 int argc,\r
93 char *argv[]\r
94 )\r
95/*++\r
96\r
97Routine Description:\r
98 Parse the command line arguments and then call worker functions to do the work\r
99 \r
100Arguments:\r
101 argc - number of elements in argv\r
102 argv - array of command-line arguments\r
103\r
104Returns:\r
105 STATUS_SUCCESS - no problems encountered while processing\r
106 STATUS_WARNING - warnings, but no errors, were encountered while processing\r
107 STATUS_ERROR - errors were encountered while processing\r
108 \r
109--*/\r
110{\r
111 STATUS Status;\r
112\r
113 SetUtilityName (UTILITY_NAME);\r
114 Status = ProcessCommandLine (argc, argv);\r
115 if (Status != STATUS_SUCCESS) {\r
116 return Status;\r
117 }\r
118 //\r
119 // Check for discovery of an FD (command line option)\r
120 //\r
121 if (mGlobals.DiscoverFDImageName != NULL) {\r
122 Status = FDDiscover (mGlobals.DiscoverFDImageName, mGlobals.BaseAddress);\r
123 goto Done;\r
124 }\r
125 //\r
126 // If they're doing microcode file parsing, then do that\r
127 //\r
128 if (mGlobals.MCIFileName != NULL) {\r
129 MicrocodeConstructor ();\r
130 MicrocodeParseFile (mGlobals.MCIFileName, mGlobals.MCOFileName);\r
131 MicrocodeDestructor ();\r
132 }\r
133 //\r
134 // If they're doing microcode file merging, then do that now\r
135 //\r
136 if (mGlobals.MCIFileNames != NULL) {\r
137 MergeMicrocodeFiles (\r
138 mGlobals.MCOFileName,\r
139 mGlobals.MCIFileNames,\r
140 mGlobals.MicrocodeAlignment,\r
141 mGlobals.MicrocodePadByteValue\r
142 );\r
143 }\r
144 //\r
145 // If using a flash definition file, then process that and return\r
146 //\r
147 if (mGlobals.FlashDefinitionFileName != NULL) {\r
148 FDFConstructor ();\r
149 SymbolsConstructor ();\r
150 Status = FDFParseFile (mGlobals.FlashDefinitionFileName);\r
151 if (GetUtilityStatus () != STATUS_ERROR) {\r
152 //\r
153 // If they want us to do a string-replace on a file, then add the symbol definitions to\r
154 // the symbol table, and then do the string replace.\r
155 //\r
156 if (mGlobals.StringReplaceInFileName != NULL) {\r
157 Status = FDFCreateSymbols (mGlobals.FlashDevice);\r
158 Status = SymbolsFileStringsReplace (mGlobals.StringReplaceInFileName, mGlobals.StringReplaceOutFileName);\r
159 }\r
160 //\r
161 // If they want us to create a .h defines file or .c flashmap data file, then do so now\r
162 //\r
163 if (mGlobals.CIncludeFileName != NULL) {\r
164 Status = FDFCreateCIncludeFile (mGlobals.FlashDevice, mGlobals.CIncludeFileName);\r
165 }\r
166 if (mGlobals.AsmIncludeFileName != NULL) {\r
167 Status = FDFCreateAsmIncludeFile (mGlobals.FlashDevice, mGlobals.AsmIncludeFileName);\r
168 }\r
169 //\r
170 // If they want us to create an image, do that now\r
171 //\r
172 if (mGlobals.ImageOutFileName != NULL) {\r
173 Status = FDFCreateImage (mGlobals.FlashDevice, mGlobals.FlashDeviceImage, mGlobals.ImageOutFileName);\r
174 }\r
175 //\r
176 // If they want to create an output DSC file, do that now\r
177 //\r
178 if (mGlobals.DscFileName != NULL) {\r
179 Status = FDFCreateDscFile (mGlobals.FlashDevice, mGlobals.DscFileName);\r
180 }\r
181 }\r
182 SymbolsDestructor ();\r
183 FDFDestructor ();\r
184 }\r
185Done:\r
186 //\r
187 // Free up memory\r
188 //\r
189 while (mGlobals.MCIFileNames != NULL) {\r
190 mGlobals.LastMCIFileNames = mGlobals.MCIFileNames->Next;\r
191 _free (mGlobals.MCIFileNames);\r
192 mGlobals.MCIFileNames = mGlobals.LastMCIFileNames;\r
193 }\r
194 return GetUtilityStatus ();\r
195}\r
196\r
197static\r
198STATUS\r
199MergeMicrocodeFiles (\r
200 char *OutFileName,\r
201 STRING_LIST *FileNames,\r
202 unsigned int Alignment,\r
203 char PadByteValue\r
204 )\r
205/*++\r
206\r
207Routine Description:\r
208\r
209 Merge binary microcode files into a single file, taking into consideration\r
210 the alignment and pad value.\r
211\r
212Arguments:\r
213\r
214 OutFileName - name of the output file to create\r
215 FileNames - linked list of input microcode files to merge\r
216 Alignment - alignment for each microcode file in the output image\r
217 PadByteValue - value to use when padding to meet alignment requirements\r
218\r
219Returns:\r
220\r
221 STATUS_SUCCESS - merge completed successfully or with acceptable warnings\r
222 STATUS_ERROR - merge failed, output file not created\r
223\r
224--*/\r
225{\r
226 long FileSize;\r
227 long TotalFileSize;\r
228 FILE *InFptr;\r
229 FILE *OutFptr;\r
230 char *Buffer;\r
231 STATUS Status;\r
232\r
233 //\r
234 // Open the output file\r
235 //\r
236 if ((OutFptr = fopen (OutFileName, "wb")) == NULL) {\r
237 Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");\r
238 return STATUS_ERROR;\r
239 }\r
240 //\r
241 // Walk the list of files\r
242 //\r
243 Status = STATUS_ERROR;\r
244 Buffer = NULL;\r
245 InFptr = NULL;\r
246 TotalFileSize = 0;\r
247 while (FileNames != NULL) {\r
248 //\r
249 // Open the file, determine the size, then read it in and write\r
250 // it back out.\r
251 //\r
252 if ((InFptr = fopen (FileNames->Str, "rb")) == NULL) {\r
253 Error (NULL, 0, 0, FileNames->Str, "failed to open input file for reading");\r
254 goto Done;\r
255 }\r
256 fseek (InFptr, 0, SEEK_END);\r
257 FileSize = ftell (InFptr);\r
258 fseek (InFptr, 0, SEEK_SET);\r
259 if (FileSize != 0) {\r
260 Buffer = (char *) _malloc (FileSize);\r
261 if (Buffer == NULL) {\r
262 Error (NULL, 0, 0, "memory allocation failure", NULL);\r
263 goto Done;\r
264 }\r
265 if (fread (Buffer, FileSize, 1, InFptr) != 1) {\r
266 Error (NULL, 0, 0, FileNames->Str, "failed to read file contents");\r
267 goto Done;\r
268 }\r
269 //\r
270 // Align\r
271 //\r
272 if (Alignment != 0) {\r
273 while ((TotalFileSize % Alignment) != 0) {\r
274 if (fwrite (&PadByteValue, 1, 1, OutFptr) != 1) {\r
275 Error (NULL, 0, 0, OutFileName, "failed to write pad bytes to output file");\r
276 goto Done;\r
277 }\r
278 TotalFileSize++;\r
279 }\r
280 }\r
281 TotalFileSize += FileSize;\r
282 if (fwrite (Buffer, FileSize, 1, OutFptr) != 1) {\r
283 Error (NULL, 0, 0, OutFileName, "failed to write to output file");\r
284 goto Done;\r
285 }\r
286 _free (Buffer);\r
287 Buffer = NULL;\r
288 } else {\r
289 Warning (NULL, 0, 0, FileNames->Str, "0-size file encountered");\r
290 }\r
291 fclose (InFptr);\r
292 InFptr = NULL;\r
293 FileNames = FileNames->Next;\r
294 }\r
295 Status = STATUS_SUCCESS;\r
296Done:\r
297 fclose (OutFptr);\r
298 if (InFptr != NULL) {\r
299 fclose (InFptr);\r
300 }\r
301 if (Buffer != NULL) {\r
302 _free (Buffer);\r
303 }\r
304 if (Status == STATUS_ERROR) {\r
305 remove (OutFileName);\r
306 }\r
307 return Status;\r
308}\r
309\r
310static\r
311STATUS\r
312ProcessCommandLine (\r
313 int argc,\r
314 char *argv[]\r
315 )\r
316/*++\r
317\r
318Routine Description:\r
319 Process the command line arguments\r
320 \r
321Arguments:\r
322 argc - Standard C entry point arguments\r
323 argv[] - Standard C entry point arguments\r
324\r
325Returns:\r
326 STATUS_SUCCESS - no problems encountered while processing\r
327 STATUS_WARNING - warnings, but no errors, were encountered while processing\r
328 STATUS_ERROR - errors were encountered while processing\r
329 \r
330--*/\r
331{\r
332 int ThingsToDo;\r
333 unsigned int Temp;\r
334 STRING_LIST *Str;\r
335 //\r
336 // Skip program name arg, process others\r
337 //\r
338 argc--;\r
339 argv++;\r
340 if (argc == 0) {\r
341 Usage ();\r
342 return STATUS_ERROR;\r
343 }\r
344 //\r
345 // Clear out our globals, then start walking the arguments\r
346 //\r
347 memset ((void *) &mGlobals, 0, sizeof (mGlobals));\r
348 mGlobals.MicrocodePadByteValue = DEFAULT_MC_PAD_BYTE_VALUE;\r
349 mGlobals.MicrocodeAlignment = DEFAULT_MC_ALIGNMENT;\r
350 ThingsToDo = 0;\r
351 while (argc > 0) {\r
352 if (strcmp (argv[0], "-?") == 0) {\r
353 Usage ();\r
354 return STATUS_ERROR;\r
355 } else if (strcmp (argv[0], "-hfile") == 0) {\r
356 //\r
357 // -hfile FileName\r
358 //\r
359 // Used to specify an output C #include file to create that contains\r
360 // #define statements for all the flashmap region offsets and sizes.\r
361 // Check for additional argument.\r
362 //\r
363 if (argc < 2) {\r
364 Error (NULL, 0, 0, argv[0], "option requires an output file name");\r
365 return STATUS_ERROR;\r
366 }\r
367 argc--;\r
368 argv++;\r
369 mGlobals.CIncludeFileName = argv[0];\r
370 ThingsToDo++;\r
371 } else if (strcmp (argv[0], "-flashdevice") == 0) {\r
372 //\r
373 // -flashdevice FLASH_DEVICE_NAME\r
374 //\r
375 // Used to select which flash device definition to operate on.\r
376 // Check for additional argument\r
377 //\r
378 if (argc < 2) {\r
379 Error (NULL, 0, 0, argv[0], "option requires a flash device name to use");\r
380 return STATUS_ERROR;\r
381 }\r
382 argc--;\r
383 argv++;\r
384 mGlobals.FlashDevice = argv[0];\r
385 } else if (strcmp (argv[0], "-mco") == 0) {\r
386 //\r
387 // -mco OutFileName\r
388 //\r
389 // Used to specify a microcode output binary file to create.\r
390 // Check for additional argument.\r
391 //\r
392 if (argc < 2) {\r
393 Error (NULL, 0, 0, (INT8 *) argv[0], (INT8 *) "option requires an output microcode file name to create");\r
394 return STATUS_ERROR;\r
395 }\r
396 argc--;\r
397 argv++;\r
398 mGlobals.MCOFileName = argv[0];\r
399 ThingsToDo++;\r
400 } else if (strcmp (argv[0], "-asmincfile") == 0) {\r
401 //\r
402 // -asmincfile FileName\r
403 //\r
404 // Used to specify the name of the output assembly include file that contains\r
405 // equates for the flash region addresses and sizes.\r
406 // Check for additional argument.\r
407 //\r
408 if (argc < 2) {\r
409 Error (NULL, 0, 0, argv[0], "option requires an output ASM include file name to create");\r
410 return STATUS_ERROR;\r
411 }\r
412 argc--;\r
413 argv++;\r
414 mGlobals.AsmIncludeFileName = argv[0];\r
415 ThingsToDo++;\r
416 } else if (strcmp (argv[0], "-mci") == 0) {\r
417 //\r
418 // -mci FileName\r
419 //\r
420 // Used to specify an input microcode text file to parse.\r
421 // Check for additional argument\r
422 //\r
423 if (argc < 2) {\r
424 Error (NULL, 0, 0, (INT8 *) argv[0], (INT8 *) "option requires an input microcode text file name to parse");\r
425 return STATUS_ERROR;\r
426 }\r
427 argc--;\r
428 argv++;\r
429 mGlobals.MCIFileName = argv[0];\r
430 } else if (strcmp (argv[0], "-flashdeviceimage") == 0) {\r
431 //\r
432 // -flashdeviceimage FlashDeviceImage\r
433 //\r
434 // Used to specify which flash device image definition from the input flash definition file\r
435 // to create.\r
436 // Check for additional argument.\r
437 //\r
438 if (argc < 2) {\r
439 Error (NULL, 0, 0, argv[0], "option requires the name of a flash definition image to use");\r
440 return STATUS_ERROR;\r
441 }\r
442 argc--;\r
443 argv++;\r
444 mGlobals.FlashDeviceImage = argv[0];\r
445 } else if (strcmp (argv[0], "-imageout") == 0) {\r
446 //\r
447 // -imageout FileName\r
448 //\r
449 // Used to specify the name of the output FD image file to create.\r
450 // Check for additional argument.\r
451 //\r
452 if (argc < 2) {\r
453 Error (NULL, 0, 0, argv[0], "option requires an output image filename to create");\r
454 return STATUS_ERROR;\r
455 }\r
456 argc--;\r
457 argv++;\r
458 mGlobals.ImageOutFileName = argv[0];\r
459 ThingsToDo++;\r
460 } else if (strcmp (argv[0], "-dsc") == 0) {\r
461 //\r
462 // -dsc FileName\r
463 //\r
464 // Used to specify the name of the output DSC file to create.\r
465 // Check for additional argument.\r
466 //\r
467 if (argc < 2) {\r
468 Error (NULL, 0, 0, argv[0], "option requires an output DSC filename to create");\r
469 return STATUS_ERROR;\r
470 }\r
471 argc--;\r
472 argv++;\r
473 mGlobals.DscFileName = argv[0];\r
474 ThingsToDo++;\r
475 } else if (strcmp (argv[0], "-fdf") == 0) {\r
476 //\r
477 // -fdf FileName\r
478 //\r
479 // Used to specify the name of the input flash definition file.\r
480 // Check for additional argument.\r
481 //\r
482 if (argc < 2) {\r
483 Error (NULL, 0, 0, argv[0], "option requires an input flash definition file name");\r
484 return STATUS_ERROR;\r
485 }\r
486 argc--;\r
487 argv++;\r
488 mGlobals.FlashDefinitionFileName = argv[0];\r
489 } else if (strcmp (argv[0], "-discover") == 0) {\r
490 //\r
491 // -discover FDFileName\r
492 //\r
493 // Debug functionality used to scan an existing FD image, trying to find\r
494 // firmware volumes at 64K boundaries.\r
495 // Check for additional argument.\r
496 //\r
497 if (argc < 2) {\r
498 Error (NULL, 0, 0, argv[0], "option requires an input FD image file name");\r
499 return STATUS_ERROR;\r
500 }\r
501 argc--;\r
502 argv++;\r
503 mGlobals.DiscoverFDImageName = argv[0];\r
504 ThingsToDo++;\r
505 } else if (strcmp (argv[0], "-baseaddr") == 0) {\r
506 //\r
507 // -baseaddr Addr\r
508 //\r
509 // Used to specify a base address when doing a discover of an FD image.\r
510 // Check for additional argument.\r
511 //\r
512 if (argc < 2) {\r
513 Error (NULL, 0, 0, argv[0], "option requires a base address");\r
514 return STATUS_ERROR;\r
515 }\r
516 argc--;\r
517 argv++;\r
518 if (tolower (argv[0][1]) == 'x') {\r
519 sscanf (argv[0] + 2, "%x", &mGlobals.BaseAddress);\r
520 } else {\r
521 sscanf (argv[0], "%d", &mGlobals.BaseAddress);\r
522 }\r
523 } else if (strcmp (argv[0], "-padvalue") == 0) {\r
524 //\r
525 // -padvalue Value\r
526 //\r
527 // Used to specify the value to pad with when aligning data while\r
528 // creating an FD image. Check for additional argument.\r
529 //\r
530 if (argc < 2) {\r
531 Error (NULL, 0, 0, argv[0], "option requires a byte value");\r
532 return STATUS_ERROR;\r
533 }\r
534 argc--;\r
535 argv++;\r
536 if (tolower (argv[0][1]) == 'x') {\r
537 sscanf (argv[0] + 2, "%x", &Temp);\r
538 mGlobals.MicrocodePadByteValue = (char) Temp;\r
539 } else {\r
540 sscanf (argv[0], "%d", &Temp);\r
541 mGlobals.MicrocodePadByteValue = (char) Temp;\r
542 }\r
543 } else if (strcmp (argv[0], "-align") == 0) {\r
544 //\r
545 // -align Alignment\r
546 //\r
547 // Used to specify how each data file is aligned in the region\r
548 // when creating an FD image. Check for additional argument.\r
549 //\r
550 if (argc < 2) {\r
551 Error (NULL, 0, 0, argv[0], "option requires an alignment");\r
552 return STATUS_ERROR;\r
553 }\r
554 argc--;\r
555 argv++;\r
556 if (tolower (argv[0][1]) == 'x') {\r
557 sscanf (argv[0] + 2, "%x", &mGlobals.MicrocodeAlignment);\r
558 } else {\r
559 sscanf (argv[0], "%d", &mGlobals.MicrocodeAlignment);\r
560 }\r
561 } else if (strcmp (argv[0], "-mcmerge") == 0) {\r
562 //\r
563 // -mcmerge FileName(s)\r
564 //\r
565 // Used to concatenate multiple microde binary files. Can specify\r
566 // multiple file names with the one -mcmerge flag. Check for additional argument.\r
567 //\r
568 if ((argc < 2) || (argv[1][0] == '-')) {\r
569 Error (NULL, 0, 0, argv[0], "option requires one or more input file names");\r
570 return STATUS_ERROR;\r
571 }\r
572 //\r
573 // Take input files until another option or end of list\r
574 //\r
575 ThingsToDo++;\r
576 while ((argc > 1) && (argv[1][0] != '-')) {\r
577 Str = (STRING_LIST *) _malloc (sizeof (STRING_LIST));\r
578 if (Str == NULL) {\r
579 Error (NULL, 0, 0, "memory allocation failure", NULL);\r
580 return STATUS_ERROR;\r
581 }\r
582 memset (Str, 0, sizeof (STRING_LIST));\r
583 Str->Str = argv[1];\r
584 if (mGlobals.MCIFileNames == NULL) {\r
585 mGlobals.MCIFileNames = Str;\r
586 } else {\r
587 mGlobals.LastMCIFileNames->Next = Str;\r
588 }\r
589 mGlobals.LastMCIFileNames = Str;\r
590 argc--;\r
591 argv++;\r
592 }\r
593 } else if (strcmp (argv[0], "-strsub") == 0) {\r
594 //\r
595 // -strsub SrcFile DestFile\r
596 //\r
597 // Used to perform string substitutions on a file, writing the result to a new\r
598 // file. Check for two additional arguments.\r
599 //\r
600 if (argc < 3) {\r
601 Error (NULL, 0, 0, argv[0], "option requires input and output file names for string substitution");\r
602 return STATUS_ERROR;\r
603 }\r
604 argc--;\r
605 argv++;\r
606 mGlobals.StringReplaceInFileName = argv[0];\r
607 argc--;\r
608 argv++;\r
609 mGlobals.StringReplaceOutFileName = argv[0];\r
610 ThingsToDo++;\r
611 } else {\r
612 Error (NULL, 0, 0, argv[0], "invalid option");\r
613 return STATUS_ERROR;\r
614 }\r
615 argc--;\r
616 argv++;\r
617 }\r
618 //\r
619 // If no outputs requested, then report an error\r
620 //\r
621 if (ThingsToDo == 0) {\r
622 Error (NULL, 0, 0, "nothing to do", NULL);\r
623 return STATUS_ERROR;\r
624 }\r
625 //\r
626 // If they want an asm file, #include file, or C file to be created, then they have to specify a\r
627 // flash device name and flash definition file name.\r
628 //\r
629 if ((mGlobals.CIncludeFileName != NULL) &&\r
630 ((mGlobals.FlashDevice == NULL) || (mGlobals.FlashDefinitionFileName == NULL))) {\r
631 Error (NULL, 0, 0, "must specify -flashdevice and -fdf with -hfile", NULL);\r
632 return STATUS_ERROR;\r
633 }\r
634 if ((mGlobals.AsmIncludeFileName != NULL) &&\r
635 ((mGlobals.FlashDevice == NULL) || (mGlobals.FlashDefinitionFileName == NULL))) {\r
636 Error (NULL, 0, 0, "must specify -flashdevice and -fdf with -asmincfile", NULL);\r
637 return STATUS_ERROR;\r
638 }\r
639 //\r
640 // If they want a dsc file to be created, then they have to specify a\r
641 // flash device name and a flash definition file name\r
642 //\r
643 if (mGlobals.DscFileName != NULL) {\r
644 if (mGlobals.FlashDevice == NULL) {\r
645 Error (NULL, 0, 0, "must specify -flashdevice with -dsc", NULL);\r
646 return STATUS_ERROR;\r
647 }\r
648 if (mGlobals.FlashDefinitionFileName == NULL) {\r
649 Error (NULL, 0, 0, "must specify -fdf with -dsc", NULL);\r
650 return STATUS_ERROR;\r
651 }\r
652 }\r
653 //\r
654 // If they specified an output microcode file name, then they have to specify an input\r
655 // file name, and vice versa.\r
656 //\r
657 if ((mGlobals.MCIFileName != NULL) && (mGlobals.MCOFileName == NULL)) {\r
658 Error (NULL, 0, 0, "must specify output microcode file name", NULL);\r
659 return STATUS_ERROR;\r
660 }\r
661 if ((mGlobals.MCOFileName != NULL) && (mGlobals.MCIFileName == NULL) && (mGlobals.MCIFileNames == NULL)) {\r
662 Error (NULL, 0, 0, "must specify input microcode file name", NULL);\r
663 return STATUS_ERROR;\r
664 }\r
665 //\r
666 // If doing merge, then have to specify output file name\r
667 //\r
668 if ((mGlobals.MCIFileNames != NULL) && (mGlobals.MCOFileName == NULL)) {\r
669 Error (NULL, 0, 0, "must specify output microcode file name", NULL);\r
670 return STATUS_ERROR;\r
671 }\r
672 //\r
673 // If they want an output image to be created, then they have to specify\r
674 // the flash device and the flash device image to use.\r
675 //\r
676 if (mGlobals.ImageOutFileName != NULL) {\r
677 if (mGlobals.FlashDevice == NULL) {\r
678 Error (NULL, 0, 0, "must specify -flashdevice with -imageout", NULL);\r
679 return STATUS_ERROR;\r
680 }\r
681 if (mGlobals.FlashDeviceImage == NULL) {\r
682 Error (NULL, 0, 0, "must specify -flashdeviceimage with -imageout", NULL);\r
683 return STATUS_ERROR;\r
684 }\r
685 if (mGlobals.FlashDefinitionFileName == NULL) {\r
686 Error (NULL, 0, 0, "must specify -c or -fdf with -imageout", NULL);\r
687 return STATUS_ERROR;\r
688 }\r
689 }\r
690 return STATUS_SUCCESS;\r
691}\r
692\r
693static\r
694void\r
695Usage (\r
696 VOID\r
697 )\r
698/*++\r
699\r
700Routine Description:\r
701 Print utility command line help\r
702 \r
703Arguments:\r
704 None\r
705\r
706Returns:\r
707 NA\r
708\r
709--*/\r
710{\r
711 int i;\r
712 char *Msg[] = {\r
713 "Usage: FlashTool -fdf FlashDefFile -flashdevice FlashDevice",\r
714 " -flashdeviceimage FlashDeviceImage -mci MCIFile -mco MCOFile",\r
715 " -discover FDImage -dsc DscFile -asmincfile AsmIncFile",\r
716 " -imageOut ImageOutFile -hfile HFile -strsub InStrFile OutStrFile",\r
717 " -baseaddr BaseAddr -align Alignment -padvalue PadValue",\r
718 " -mcmerge MCIFile(s)",\r
719 " where",\r
720 " FlashDefFile - input Flash Definition File",\r
721 " FlashDevice - flash device to use (from flash definition file)",\r
722 " FlashDeviceImage - flash device image to use (from flash definition file)",\r
723 " MCIFile - input microcode file to parse",\r
724 " MCOFile - output binary microcode image to create from MCIFile",\r
725 " HFile - output #include file to create",\r
726 " FDImage - name of input FDImage file to scan",\r
727 " ImageOutFile - output image file to create",\r
728 " DscFile - output DSC file to create",\r
729 " AsmIncFile - output ASM include file to create",\r
730 " InStrFile - input file to replace symbol names, writing result to OutStrFile",\r
731 " BaseAddr - base address of FDImage (used with -discover)",\r
732 " Alignment - alignment to use when merging microcode binaries",\r
733 " PadValue - byte value to use as pad value when aligning microcode binaries",\r
734 " MCIFile(s) - one or more microcode binary files to merge/concatenate",\r
735 "",\r
736 NULL\r
737 };\r
738 for (i = 0; Msg[i] != NULL; i++) {\r
739 fprintf (stdout, "%s\n", Msg[i]);\r
740 }\r
741}\r