]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/GenFv/GenFv.c
fa86d009da28a831eb52d1b6a1ad8d8973aae617
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFv.c
1 /** @file
2
3 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 GenFv.c
15
16 Abstract:
17
18 This contains all code necessary to build the GenFvImage.exe utility.
19 This utility relies heavily on the GenFvImage Lib. Definitions for both
20 can be found in the Tiano Firmware Volume Generation Utility
21 Specification, review draft.
22
23 **/
24
25 //
26 // File included in build
27 //
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include "GenFvInternalLib.h"
32
33 //
34 // Utility Name
35 //
36 #define UTILITY_NAME "GenFv"
37
38 //
39 // Utility version information
40 //
41 #define UTILITY_MAJOR_VERSION 0
42 #define UTILITY_MINOR_VERSION 1
43
44 EFI_GUID mEfiFirmwareFileSystem2Guid = EFI_FIRMWARE_FILE_SYSTEM2_GUID;
45
46 STATIC
47 VOID
48 Version (
49 VOID
50 )
51 /*++
52
53 Routine Description:
54
55 Displays the standard utility information to SDTOUT
56
57 Arguments:
58
59 None
60
61 Returns:
62
63 None
64
65 --*/
66 {
67 fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
68 }
69
70 STATIC
71 VOID
72 Usage (
73 VOID
74 )
75 /*++
76
77 Routine Description:
78
79 Displays the utility usage syntax to STDOUT
80
81 Arguments:
82
83 None
84
85 Returns:
86
87 None
88
89 --*/
90 {
91 //
92 // Summary usage
93 //
94 fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);
95
96 //
97 // Copyright declaration
98 //
99 fprintf (stdout, "Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.\n\n");
100
101 //
102 // Details Option
103 //
104 fprintf (stdout, "Options:\n");
105 fprintf (stdout, " -o FileName, --outputfile FileName\n\
106 File is the FvImage or CapImage to be created.\n");
107 fprintf (stdout, " -i FileName, --inputfile FileName\n\
108 File is the input FV.inf or Cap.inf to specify\n\
109 how to construct FvImage or CapImage.\n");
110 fprintf (stdout, " -b BlockSize, --blocksize BlockSize\n\
111 BlockSize is one HEX or DEC format value\n\
112 BlockSize is required by Fv Image.\n");
113 fprintf (stdout, " -n NumberBlock, --numberblock NumberBlock\n\
114 NumberBlock is one HEX or DEC format value\n\
115 NumberBlock is one optional parameter.\n");
116 fprintf (stdout, " -f FfsFile, --ffsfile FfsFile\n\
117 FfsFile is placed into Fv Image\n\
118 multi files can input one by one\n");
119 fprintf (stdout, " -s FileTakenSize, --filetakensize FileTakenSize\n\
120 FileTakenSize specifies the size of the required\n\
121 space that the input file is placed in Fvimage.\n\
122 It is specified together with the input file.\n");
123 fprintf (stdout, " -r Address, --baseaddr Address\n\
124 Address is the rebase start address for drivers that\n\
125 run in Flash. It supports DEC or HEX digital format.\n\
126 If it is set to zero, no rebase action will be taken\n");
127 fprintf (stdout, " -F ForceRebase, --force-rebase ForceRebase\n\
128 If value is TRUE, will always take rebase action\n\
129 If value is FALSE, will always not take reabse action\n\
130 If not specified, will take rebase action if rebase address greater than zero, \n\
131 will not take rebase action if rebase address is zero.\n");
132 fprintf (stdout, " -a AddressFile, --addrfile AddressFile\n\
133 AddressFile is one file used to record the child\n\
134 FV base address when current FV base address is set.\n");
135 fprintf (stdout, " -m logfile, --map logfile\n\
136 Logfile is the output fv map file name. if it is not\n\
137 given, the FvName.map will be the default map file name\n");
138 fprintf (stdout, " -g Guid, --guid Guid\n\
139 GuidValue is one specific capsule guid value\n\
140 or fv file system guid value.\n\
141 Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");
142 fprintf (stdout, " --FvNameGuid Guid Guid is used to specify Fv Name.\n\
143 Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");
144 fprintf (stdout, " --capflag CapFlag Capsule Reset Flag can be PersistAcrossReset,\n\
145 or PopulateSystemTable or InitiateReset or not set\n");
146 fprintf (stdout, " --capheadsize HeadSize\n\
147 HeadSize is one HEX or DEC format value\n\
148 HeadSize is required by Capsule Image.\n");
149 fprintf (stdout, " -c, --capsule Create Capsule Image.\n");
150 fprintf (stdout, " -p, --dump Dump Capsule Image header.\n");
151 fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n");
152 fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n");
153 fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n");
154 fprintf (stdout, " --version Show program's version number and exit.\n");
155 fprintf (stdout, " -h, --help Show this help message and exit.\n");
156 }
157
158 UINT32 mFvTotalSize;
159 UINT32 mFvTakenSize;
160
161 int
162 main (
163 IN int argc,
164 IN char **argv
165 )
166 /*++
167
168 Routine Description:
169
170 This utility uses GenFvImage.Lib to build a firmware volume image.
171
172 Arguments:
173
174 FvInfFileName The name of an FV image description file or Capsule Image.
175
176 Arguments come in pair in any order.
177 -I FvInfFileName
178
179 Returns:
180
181 EFI_SUCCESS No error conditions detected.
182 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
183 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
184 Most commonly this will be memory allocation
185 or file creation.
186 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
187 EFI_ABORTED Error executing the GenFvImage lib.
188
189 --*/
190 {
191 EFI_STATUS Status;
192 CHAR8 *InfFileName;
193 CHAR8 *AddrFileName;
194 CHAR8 *MapFileName;
195 CHAR8 *InfFileImage;
196 UINT32 InfFileSize;
197 CHAR8 *OutFileName;
198 BOOLEAN CapsuleFlag;
199 BOOLEAN DumpCapsule;
200 FILE *FpFile;
201 EFI_CAPSULE_HEADER *CapsuleHeader;
202 UINT64 LogLevel, TempNumber;
203 UINT32 Index;
204
205 InfFileName = NULL;
206 AddrFileName = NULL;
207 InfFileImage = NULL;
208 OutFileName = NULL;
209 MapFileName = NULL;
210 InfFileSize = 0;
211 CapsuleFlag = FALSE;
212 DumpCapsule = FALSE;
213 FpFile = NULL;
214 CapsuleHeader = NULL;
215 LogLevel = 0;
216 TempNumber = 0;
217 Index = 0;
218 mFvTotalSize = 0;
219 mFvTakenSize = 0;
220 Status = EFI_SUCCESS;
221
222 SetUtilityName (UTILITY_NAME);
223
224 if (argc == 1) {
225 Error (NULL, 0, 1001, "Missing options", "No input options specified.");
226 Usage ();
227 return STATUS_ERROR;
228 }
229
230 //
231 // Init global data to Zero
232 //
233 memset (&mFvDataInfo, 0, sizeof (FV_INFO));
234 memset (&mCapDataInfo, 0, sizeof (CAP_INFO));
235 //
236 // Set the default FvGuid
237 //
238 memcpy (&mFvDataInfo.FvFileSystemGuid, &mEfiFirmwareFileSystem2Guid, sizeof (EFI_GUID));
239 mFvDataInfo.ForceRebase = -1;
240
241 //
242 // Parse command line
243 //
244 argc --;
245 argv ++;
246
247 if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
248 Version ();
249 Usage ();
250 return STATUS_SUCCESS;
251 }
252
253 if (stricmp (argv[0], "--version") == 0) {
254 Version ();
255 return STATUS_SUCCESS;
256 }
257
258 while (argc > 0) {
259 if ((stricmp (argv[0], "-i") == 0) || (stricmp (argv[0], "--inputfile") == 0)) {
260 InfFileName = argv[1];
261 if (InfFileName == NULL) {
262 Error (NULL, 0, 1003, "Invalid option value", "Input file can't be null");
263 return STATUS_ERROR;
264 }
265 argc -= 2;
266 argv += 2;
267 continue;
268 }
269
270 if ((stricmp (argv[0], "-a") == 0) || (stricmp (argv[0], "--addrfile") == 0)) {
271 AddrFileName = argv[1];
272 if (AddrFileName == NULL) {
273 Error (NULL, 0, 1003, "Invalid option value", "Address file can't be null");
274 return STATUS_ERROR;
275 }
276 argc -= 2;
277 argv += 2;
278 continue;
279 }
280
281 if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--outputfile") == 0)) {
282 OutFileName = argv[1];
283 if (OutFileName == NULL) {
284 Error (NULL, 0, 1003, "Invalid option value", "Output file can't be null");
285 return STATUS_ERROR;
286 }
287 argc -= 2;
288 argv += 2;
289 continue;
290 }
291
292 if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--baseaddr") == 0)) {
293 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
294 if (EFI_ERROR (Status)) {
295 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
296 return STATUS_ERROR;
297 }
298 mFvDataInfo.BaseAddress = TempNumber;
299 mFvDataInfo.BaseAddressSet = TRUE;
300 argc -= 2;
301 argv += 2;
302 continue;
303 }
304
305 if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--blocksize") == 0)) {
306 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
307 if (EFI_ERROR (Status)) {
308 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
309 return STATUS_ERROR;
310 }
311 if (TempNumber == 0) {
312 Error (NULL, 0, 1003, "Invalid option value", "Fv block size can't be be set to zero");
313 return STATUS_ERROR;
314 }
315 mFvDataInfo.FvBlocks[0].Length = (UINT32) TempNumber;
316 DebugMsg (NULL, 0, 9, "FV Block Size", "%s = 0x%llx", EFI_BLOCK_SIZE_STRING, (unsigned long long) TempNumber);
317 argc -= 2;
318 argv += 2;
319 continue;
320 }
321
322 if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--numberblock") == 0)) {
323 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
324 if (EFI_ERROR (Status)) {
325 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
326 return STATUS_ERROR;
327 }
328 if (TempNumber == 0) {
329 Error (NULL, 0, 1003, "Invalid option value", "Fv block number can't be set to zero");
330 return STATUS_ERROR;
331 }
332 mFvDataInfo.FvBlocks[0].NumBlocks = (UINT32) TempNumber;
333 DebugMsg (NULL, 0, 9, "FV Number Block", "%s = 0x%llx", EFI_NUM_BLOCKS_STRING, (unsigned long long) TempNumber);
334 argc -= 2;
335 argv += 2;
336 continue;
337 }
338
339 if ((strcmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {
340 if (argv[1] == NULL) {
341 Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");
342 return STATUS_ERROR;
343 }
344 strcpy (mFvDataInfo.FvFiles[Index], argv[1]);
345 DebugMsg (NULL, 0, 9, "FV component file", "the %uth name is %s", (unsigned) Index + 1, argv[1]);
346 argc -= 2;
347 argv += 2;
348
349 if (argc > 0) {
350 if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {
351 if (argv[1] == NULL) {
352 Error (NULL, 0, 1003, "Invalid option value", "Ffsfile Size can't be null");
353 return STATUS_ERROR;
354 }
355 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
356 if (EFI_ERROR (Status)) {
357 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
358 return STATUS_ERROR;
359 }
360 mFvDataInfo.SizeofFvFiles[Index] = (UINT32) TempNumber;
361 DebugMsg (NULL, 0, 9, "FV component file size", "the %uth size is %s", (unsigned) Index + 1, argv[1]);
362 argc -= 2;
363 argv += 2;
364 }
365 }
366 Index ++;
367 continue;
368 }
369
370 if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {
371 Error (NULL, 0, 1003, "Invalid option", "It must be specified together with -f option to specify the file size.");
372 return STATUS_ERROR;
373 }
374
375 if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--capsule") == 0)) {
376 CapsuleFlag = TRUE;
377 argc --;
378 argv ++;
379 continue;
380 }
381
382 if ((strcmp (argv[0], "-F") == 0) || (stricmp (argv[0], "--force-rebase") == 0)) {
383 if (argv[1] == NULL) {
384 Error (NULL, 0, 1003, "Invalid option value", "Froce rebase flag can't be null");
385 return STATUS_ERROR;
386 }
387
388 if (stricmp (argv[1], "TRUE") == 0) {
389 mFvDataInfo.ForceRebase = 1;
390 } else if (stricmp (argv[1], "FALSE") == 0) {
391 mFvDataInfo.ForceRebase = 0;
392 } else {
393 Error (NULL, 0, 1003, "Invalid option value", "froce rebase flag value must be \"TRUE\" or \"FALSE\"");
394 return STATUS_ERROR;
395 }
396
397 argc -= 2;
398 argv += 2;
399 continue;
400 }
401
402 if (stricmp (argv[0], "--capheadsize") == 0) {
403 //
404 // Get Capsule Image Header Size
405 //
406 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
407 if (EFI_ERROR (Status)) {
408 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
409 return STATUS_ERROR;
410 }
411 mCapDataInfo.HeaderSize = (UINT32) TempNumber;
412 DebugMsg (NULL, 0, 9, "Capsule Header size", "%s = 0x%llx", EFI_CAPSULE_HEADER_SIZE_STRING, (unsigned long long) TempNumber);
413 argc -= 2;
414 argv += 2;
415 continue;
416 }
417
418 if (stricmp (argv[0], "--capflag") == 0) {
419 //
420 // Get Capsule Header
421 //
422 if (argv[1] == NULL) {
423 Error (NULL, 0, 1003, "Option value is not set", "%s = %s", argv[0], argv[1]);
424 return STATUS_ERROR;
425 }
426 if (strcmp (argv[1], "PopulateSystemTable") == 0) {
427 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE;
428 } else if (strcmp (argv[1], "PersistAcrossReset") == 0) {
429 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
430 } else if (strcmp (argv[1], "InitiateReset") == 0) {
431 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET;
432 } else {
433 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
434 return STATUS_ERROR;
435 }
436 DebugMsg (NULL, 0, 9, "Capsule Flag", argv[1]);
437 argc -= 2;
438 argv += 2;
439 continue;
440 }
441
442 if (stricmp (argv[0], "--capguid") == 0) {
443 //
444 // Get the Capsule Guid
445 //
446 Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);
447 if (EFI_ERROR (Status)) {
448 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
449 return STATUS_ERROR;
450 }
451 DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
452 argc -= 2;
453 argv += 2;
454 continue;
455 }
456
457 if ((stricmp (argv[0], "-g") == 0) || (stricmp (argv[0], "--guid") == 0)) {
458 //
459 // Get the Capsule or Fv Guid
460 //
461 Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);
462 if (EFI_ERROR (Status)) {
463 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);
464 return STATUS_ERROR;
465 }
466 memcpy (&mFvDataInfo.FvFileSystemGuid, &mCapDataInfo.CapGuid, sizeof (EFI_GUID));
467 mFvDataInfo.FvFileSystemGuidSet = TRUE;
468 DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
469 DebugMsg (NULL, 0, 9, "FV Guid", "%s = %s", EFI_FV_FILESYSTEMGUID_STRING, argv[1]);
470 argc -= 2;
471 argv += 2;
472 continue;
473 }
474
475 if (stricmp (argv[0], "--FvNameGuid") == 0) {
476 //
477 // Get Fv Name Guid
478 //
479 Status = StringToGuid (argv[1], &mFvDataInfo.FvNameGuid);
480 if (EFI_ERROR (Status)) {
481 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);
482 return STATUS_ERROR;
483 }
484 mFvDataInfo.FvNameGuidSet = TRUE;
485 DebugMsg (NULL, 0, 9, "FV Name Guid", "%s = %s", EFI_FV_NAMEGUID_STRING, argv[1]);
486 argc -= 2;
487 argv += 2;
488 continue;
489 }
490
491 if ((stricmp (argv[0], "-p") == 0) || (stricmp (argv[0], "--dump") == 0)) {
492 DumpCapsule = TRUE;
493 argc --;
494 argv ++;
495 continue;
496 }
497
498 if ((stricmp (argv[0], "-m") == 0) || (stricmp (argv[0], "--map") == 0)) {
499 MapFileName = argv[1];
500 if (MapFileName == NULL) {
501 Error (NULL, 0, 1003, "Invalid option value", "Map file can't be null");
502 return STATUS_ERROR;
503 }
504 argc -= 2;
505 argv += 2;
506 continue;
507 }
508
509 if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {
510 SetPrintLevel (VERBOSE_LOG_LEVEL);
511 VerboseMsg ("Verbose output Mode Set!");
512 argc --;
513 argv ++;
514 continue;
515 }
516
517 if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
518 SetPrintLevel (KEY_LOG_LEVEL);
519 KeyMsg ("Quiet output Mode Set!");
520 argc --;
521 argv ++;
522 continue;
523 }
524
525 if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
526 Status = AsciiStringToUint64 (argv[1], FALSE, &LogLevel);
527 if (EFI_ERROR (Status)) {
528 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
529 return STATUS_ERROR;
530 }
531 if (LogLevel > 9) {
532 Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel);
533 return STATUS_ERROR;
534 }
535 SetPrintLevel (LogLevel);
536 DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[1]);
537 argc -= 2;
538 argv += 2;
539 continue;
540 }
541
542 //
543 // Don't recognize the parameter.
544 //
545 Error (NULL, 0, 1000, "Unknown option", "%s", argv[0]);
546 return STATUS_ERROR;
547 }
548
549 VerboseMsg ("%s tool start.", UTILITY_NAME);
550
551 //
552 // check input parameter, InfFileName can be NULL
553 //
554 if (InfFileName == NULL && DumpCapsule) {
555 Error (NULL, 0, 1001, "Missing option", "Input Capsule Image");
556 return STATUS_ERROR;
557 }
558 VerboseMsg ("the input FvInf or CapInf file name is %s", InfFileName);
559
560 if (!DumpCapsule && OutFileName == NULL) {
561 Error (NULL, 0, 1001, "Missing option", "Output File");
562 return STATUS_ERROR;
563 }
564 if (OutFileName != NULL) {
565 VerboseMsg ("the output file name is %s", OutFileName);
566 }
567
568 //
569 // Read the INF file image
570 //
571 if (InfFileName != NULL) {
572 Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);
573 if (EFI_ERROR (Status)) {
574 return STATUS_ERROR;
575 }
576 }
577
578 if (DumpCapsule) {
579 VerboseMsg ("Dump the capsule header information for the input capsule image %s", InfFileName);
580 //
581 // Dump Capsule Image Header Information
582 //
583 CapsuleHeader = (EFI_CAPSULE_HEADER *) InfFileImage;
584 if (OutFileName == NULL) {
585 FpFile = stdout;
586 } else {
587 FpFile = fopen (OutFileName, "w");
588 if (FpFile == NULL) {
589 Error (NULL, 0, 0001, "Error opening file", OutFileName);
590 return STATUS_ERROR;
591 }
592 }
593 fprintf (FpFile, "Capsule %s Image Header Information\n", InfFileName);
594 fprintf (FpFile, " GUID %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
595 (unsigned) CapsuleHeader->CapsuleGuid.Data1,
596 (unsigned) CapsuleHeader->CapsuleGuid.Data2,
597 (unsigned) CapsuleHeader->CapsuleGuid.Data3,
598 (unsigned) CapsuleHeader->CapsuleGuid.Data4[0],
599 (unsigned) CapsuleHeader->CapsuleGuid.Data4[1],
600 (unsigned) CapsuleHeader->CapsuleGuid.Data4[2],
601 (unsigned) CapsuleHeader->CapsuleGuid.Data4[3],
602 (unsigned) CapsuleHeader->CapsuleGuid.Data4[4],
603 (unsigned) CapsuleHeader->CapsuleGuid.Data4[5],
604 (unsigned) CapsuleHeader->CapsuleGuid.Data4[6],
605 (unsigned) CapsuleHeader->CapsuleGuid.Data4[7]);
606 fprintf (FpFile, " Header size 0x%08X\n", (unsigned) CapsuleHeader->HeaderSize);
607 fprintf (FpFile, " Flags 0x%08X\n", (unsigned) CapsuleHeader->Flags);
608 fprintf (FpFile, " Capsule image size 0x%08X\n", (unsigned) CapsuleHeader->CapsuleImageSize);
609 fclose (FpFile);
610 } else if (CapsuleFlag) {
611 VerboseMsg ("Create capsule image");
612 //
613 // Call the GenerateCapImage to generate Capsule Image
614 //
615 for (Index = 0; mFvDataInfo.FvFiles[Index][0] != '\0'; Index ++) {
616 strcpy (mCapDataInfo.CapFiles[Index], mFvDataInfo.FvFiles[Index]);
617 }
618
619 Status = GenerateCapImage (
620 InfFileImage,
621 InfFileSize,
622 OutFileName
623 );
624 } else {
625 VerboseMsg ("Create Fv image and its map file");
626 //
627 // Will take rebase action at below situation:
628 // 1. ForceRebase Flag specified to TRUE;
629 // 2. ForceRebase Flag not specified, BaseAddress greater than zero.
630 //
631 if (((mFvDataInfo.BaseAddress > 0) && (mFvDataInfo.ForceRebase == -1)) || (mFvDataInfo.ForceRebase == 1)) {
632 VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);
633 }
634 //
635 // Call the GenerateFvImage to generate Fv Image
636 //
637 Status = GenerateFvImage (
638 InfFileImage,
639 InfFileSize,
640 OutFileName,
641 MapFileName
642 );
643 }
644
645 //
646 // free InfFileImage memory
647 //
648 if (InfFileImage != NULL) {
649 free (InfFileImage);
650 }
651
652 //
653 // update boot driver address and runtime driver address in address file
654 //
655 if (Status == EFI_SUCCESS && AddrFileName != NULL && mFvBaseAddressNumber > 0) {
656 FpFile = fopen (AddrFileName, "w");
657 if (FpFile == NULL) {
658 Error (NULL, 0, 0001, "Error opening file", AddrFileName);
659 return STATUS_ERROR;
660 }
661 fprintf (FpFile, FV_BASE_ADDRESS_STRING);
662 fprintf (FpFile, "\n");
663 for (Index = 0; Index < mFvBaseAddressNumber; Index ++) {
664 fprintf (
665 FpFile,
666 "0x%llx\n",
667 (unsigned long long)mFvBaseAddress[Index]
668 );
669 }
670 fflush (FpFile);
671 fclose (FpFile);
672 }
673
674 if (Status == EFI_SUCCESS) {
675 DebugMsg (NULL, 0, 9, "The Total Fv Size", "%s = 0x%x", EFI_FV_TOTAL_SIZE_STRING, (unsigned) mFvTotalSize);
676 DebugMsg (NULL, 0, 9, "The used Fv Size", "%s = 0x%x", EFI_FV_TAKEN_SIZE_STRING, (unsigned) mFvTakenSize);
677 DebugMsg (NULL, 0, 9, "The space Fv size", "%s = 0x%x", EFI_FV_SPACE_SIZE_STRING, (unsigned) (mFvTotalSize - mFvTakenSize));
678 }
679
680 VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ());
681
682 return GetUtilityStatus ();
683 }