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