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