]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/GenFv/GenFv.c
8f452c7374f6765a58daabc10316312937d3b2ea
[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, " -a AddressFile, --addrfile AddressFile\n\
128 AddressFile is one file used to record the child\n\
129 FV base address when current FV base address is set.\n");
130 fprintf (stdout, " -m logfile, --map logfile\n\
131 Logfile is the output fv map file name. if it is not\n\
132 given, the FvName.map will be the default map file name\n");
133 fprintf (stdout, " -g Guid, --guid Guid\n\
134 GuidValue is one specific capsule guid value\n\
135 or fv file system guid value.\n\
136 Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");
137 fprintf (stdout, " --FvNameGuid Guid Guid is used to specify Fv Name.\n\
138 Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");
139 fprintf (stdout, " --capflag CapFlag Capsule Reset Flag can be PersistAcrossReset,\n\
140 or PopulateSystemTable or InitiateReset or not set\n");
141 fprintf (stdout, " --capheadsize HeadSize\n\
142 HeadSize is one HEX or DEC format value\n\
143 HeadSize is required by Capsule Image.\n");
144 fprintf (stdout, " -c, --capsule Create Capsule Image.\n");
145 fprintf (stdout, " -p, --dump Dump Capsule Image header.\n");
146 fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n");
147 fprintf (stdout, " -q, --quiet Disable all messages except key message and fatal error\n");
148 fprintf (stdout, " -d, --debug level Enable debug messages, at input debug level.\n");
149 fprintf (stdout, " --version Show program's version number and exit.\n");
150 fprintf (stdout, " -h, --help Show this help message and exit.\n");
151 }
152
153 UINT32 mFvTotalSize;
154 UINT32 mFvTakenSize;
155
156 int
157 main (
158 IN int argc,
159 IN char **argv
160 )
161 /*++
162
163 Routine Description:
164
165 This utility uses GenFvImage.Lib to build a firmware volume image.
166
167 Arguments:
168
169 FvInfFileName The name of an FV image description file or Capsule Image.
170
171 Arguments come in pair in any order.
172 -I FvInfFileName
173
174 Returns:
175
176 EFI_SUCCESS No error conditions detected.
177 EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
178 EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
179 Most commonly this will be memory allocation
180 or file creation.
181 EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
182 EFI_ABORTED Error executing the GenFvImage lib.
183
184 --*/
185 {
186 EFI_STATUS Status;
187 CHAR8 *InfFileName;
188 CHAR8 *AddrFileName;
189 CHAR8 *MapFileName;
190 CHAR8 *InfFileImage;
191 UINT32 InfFileSize;
192 CHAR8 *OutFileName;
193 BOOLEAN CapsuleFlag;
194 BOOLEAN DumpCapsule;
195 FILE *FpFile;
196 EFI_CAPSULE_HEADER *CapsuleHeader;
197 UINT64 LogLevel, TempNumber;
198 UINT32 Index;
199
200 InfFileName = NULL;
201 AddrFileName = NULL;
202 InfFileImage = NULL;
203 OutFileName = NULL;
204 MapFileName = NULL;
205 InfFileSize = 0;
206 CapsuleFlag = FALSE;
207 DumpCapsule = FALSE;
208 FpFile = NULL;
209 CapsuleHeader = NULL;
210 LogLevel = 0;
211 TempNumber = 0;
212 Index = 0;
213 mFvTotalSize = 0;
214 mFvTakenSize = 0;
215 Status = EFI_SUCCESS;
216
217 SetUtilityName (UTILITY_NAME);
218
219 if (argc == 1) {
220 Error (NULL, 0, 1001, "Missing options", "No input options specified.");
221 Usage ();
222 return STATUS_ERROR;
223 }
224
225 //
226 // Init global data to Zero
227 //
228 memset (&mFvDataInfo, 0, sizeof (FV_INFO));
229 memset (&mCapDataInfo, 0, sizeof (CAP_INFO));
230 //
231 // Set the default FvGuid
232 //
233 memcpy (&mFvDataInfo.FvFileSystemGuid, &mEfiFirmwareFileSystem2Guid, sizeof (EFI_GUID));
234
235 //
236 // Parse command line
237 //
238 argc --;
239 argv ++;
240
241 if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
242 Version ();
243 Usage ();
244 return STATUS_SUCCESS;
245 }
246
247 if (stricmp (argv[0], "--version") == 0) {
248 Version ();
249 return STATUS_SUCCESS;
250 }
251
252 while (argc > 0) {
253 if ((stricmp (argv[0], "-i") == 0) || (stricmp (argv[0], "--inputfile") == 0)) {
254 InfFileName = argv[1];
255 if (InfFileName == NULL) {
256 Error (NULL, 0, 1003, "Invalid option value", "Input file can't be null");
257 return STATUS_ERROR;
258 }
259 argc -= 2;
260 argv += 2;
261 continue;
262 }
263
264 if ((stricmp (argv[0], "-a") == 0) || (stricmp (argv[0], "--addrfile") == 0)) {
265 AddrFileName = argv[1];
266 if (AddrFileName == NULL) {
267 Error (NULL, 0, 1003, "Invalid option value", "Address file can't be null");
268 return STATUS_ERROR;
269 }
270 argc -= 2;
271 argv += 2;
272 continue;
273 }
274
275 if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--outputfile") == 0)) {
276 OutFileName = argv[1];
277 if (OutFileName == NULL) {
278 Error (NULL, 0, 1003, "Invalid option value", "Output file can't be null");
279 return STATUS_ERROR;
280 }
281 argc -= 2;
282 argv += 2;
283 continue;
284 }
285
286 if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--baseaddr") == 0)) {
287 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
288 if (EFI_ERROR (Status)) {
289 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
290 return STATUS_ERROR;
291 }
292 mFvDataInfo.BaseAddress = TempNumber;
293 mFvDataInfo.BaseAddressSet = TRUE;
294 argc -= 2;
295 argv += 2;
296 continue;
297 }
298
299 if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--blocksize") == 0)) {
300 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
301 if (EFI_ERROR (Status)) {
302 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
303 return STATUS_ERROR;
304 }
305 if (TempNumber == 0) {
306 Error (NULL, 0, 1003, "Invalid option value", "Fv block size can't be be set to zero");
307 return STATUS_ERROR;
308 }
309 mFvDataInfo.FvBlocks[0].Length = (UINT32) TempNumber;
310 DebugMsg (NULL, 0, 9, "FV Block Size", "%s = 0x%llx", EFI_BLOCK_SIZE_STRING, (unsigned long long) TempNumber);
311 argc -= 2;
312 argv += 2;
313 continue;
314 }
315
316 if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--numberblock") == 0)) {
317 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
318 if (EFI_ERROR (Status)) {
319 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
320 return STATUS_ERROR;
321 }
322 if (TempNumber == 0) {
323 Error (NULL, 0, 1003, "Invalid option value", "Fv block number can't be set to zero");
324 return STATUS_ERROR;
325 }
326 mFvDataInfo.FvBlocks[0].NumBlocks = (UINT32) TempNumber;
327 DebugMsg (NULL, 0, 9, "FV Number Block", "%s = 0x%llx", EFI_NUM_BLOCKS_STRING, (unsigned long long) TempNumber);
328 argc -= 2;
329 argv += 2;
330 continue;
331 }
332
333 if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {
334 if (argv[1] == NULL) {
335 Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");
336 return STATUS_ERROR;
337 }
338 strcpy (mFvDataInfo.FvFiles[Index], argv[1]);
339 DebugMsg (NULL, 0, 9, "FV component file", "the %uth name is %s", (unsigned) Index + 1, argv[1]);
340 argc -= 2;
341 argv += 2;
342
343 if (argc > 0) {
344 if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {
345 if (argv[1] == NULL) {
346 Error (NULL, 0, 1003, "Invalid option value", "Ffsfile Size can't be null");
347 return STATUS_ERROR;
348 }
349 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
350 if (EFI_ERROR (Status)) {
351 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
352 return STATUS_ERROR;
353 }
354 mFvDataInfo.SizeofFvFiles[Index] = (UINT32) TempNumber;
355 DebugMsg (NULL, 0, 9, "FV component file size", "the %uth size is %s", (unsigned) Index + 1, argv[1]);
356 argc -= 2;
357 argv += 2;
358 }
359 }
360 Index ++;
361 continue;
362 }
363
364 if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--filetakensize") == 0)) {
365 Error (NULL, 0, 1003, "Invalid option", "It must be specified together with -f option to specify the file size.");
366 return STATUS_ERROR;
367 }
368
369 if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--capsule") == 0)) {
370 CapsuleFlag = TRUE;
371 argc --;
372 argv ++;
373 continue;
374 }
375
376 if (stricmp (argv[0], "--capheadsize") == 0) {
377 //
378 // Get Capsule Image Header Size
379 //
380 Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);
381 if (EFI_ERROR (Status)) {
382 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
383 return STATUS_ERROR;
384 }
385 mCapDataInfo.HeaderSize = (UINT32) TempNumber;
386 DebugMsg (NULL, 0, 9, "Capsule Header size", "%s = 0x%llx", EFI_CAPSULE_HEADER_SIZE_STRING, (unsigned long long) TempNumber);
387 argc -= 2;
388 argv += 2;
389 continue;
390 }
391
392 if (stricmp (argv[0], "--capflag") == 0) {
393 //
394 // Get Capsule Header
395 //
396 if (argv[1] == NULL) {
397 Error (NULL, 0, 1003, "Option value is not set", "%s = %s", argv[0], argv[1]);
398 return STATUS_ERROR;
399 }
400 if (strcmp (argv[1], "PopulateSystemTable") == 0) {
401 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE;
402 } else if (strcmp (argv[1], "PersistAcrossReset") == 0) {
403 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
404 } else if (strcmp (argv[1], "InitiateReset") == 0) {
405 mCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_INITIATE_RESET;
406 } else {
407 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
408 return STATUS_ERROR;
409 }
410 DebugMsg (NULL, 0, 9, "Capsule Flag", argv[1]);
411 argc -= 2;
412 argv += 2;
413 continue;
414 }
415
416 if (stricmp (argv[0], "--capguid") == 0) {
417 //
418 // Get the Capsule Guid
419 //
420 Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);
421 if (EFI_ERROR (Status)) {
422 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
423 return STATUS_ERROR;
424 }
425 DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
426 argc -= 2;
427 argv += 2;
428 continue;
429 }
430
431 if ((stricmp (argv[0], "-g") == 0) || (stricmp (argv[0], "--guid") == 0)) {
432 //
433 // Get the Capsule or Fv Guid
434 //
435 Status = StringToGuid (argv[1], &mCapDataInfo.CapGuid);
436 if (EFI_ERROR (Status)) {
437 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);
438 return STATUS_ERROR;
439 }
440 memcpy (&mFvDataInfo.FvFileSystemGuid, &mCapDataInfo.CapGuid, sizeof (EFI_GUID));
441 mFvDataInfo.FvFileSystemGuidSet = TRUE;
442 DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);
443 DebugMsg (NULL, 0, 9, "FV Guid", "%s = %s", EFI_FV_FILESYSTEMGUID_STRING, argv[1]);
444 argc -= 2;
445 argv += 2;
446 continue;
447 }
448
449 if (stricmp (argv[0], "--FvNameGuid") == 0) {
450 //
451 // Get Fv Name Guid
452 //
453 Status = StringToGuid (argv[1], &mFvDataInfo.FvNameGuid);
454 if (EFI_ERROR (Status)) {
455 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_GUID_STRING, argv[1]);
456 return STATUS_ERROR;
457 }
458 mFvDataInfo.FvNameGuidSet = TRUE;
459 DebugMsg (NULL, 0, 9, "FV Name Guid", "%s = %s", EFI_FV_NAMEGUID_STRING, argv[1]);
460 argc -= 2;
461 argv += 2;
462 continue;
463 }
464
465 if ((stricmp (argv[0], "-p") == 0) || (stricmp (argv[0], "--dump") == 0)) {
466 DumpCapsule = TRUE;
467 argc --;
468 argv ++;
469 continue;
470 }
471
472 if ((stricmp (argv[0], "-m") == 0) || (stricmp (argv[0], "--map") == 0)) {
473 MapFileName = argv[1];
474 if (MapFileName == NULL) {
475 Error (NULL, 0, 1003, "Invalid option value", "Map file can't be null");
476 return STATUS_ERROR;
477 }
478 argc -= 2;
479 argv += 2;
480 continue;
481 }
482
483 if ((stricmp (argv[0], "-v") == 0) || (stricmp (argv[0], "--verbose") == 0)) {
484 SetPrintLevel (VERBOSE_LOG_LEVEL);
485 VerboseMsg ("Verbose output Mode Set!");
486 argc --;
487 argv ++;
488 continue;
489 }
490
491 if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
492 SetPrintLevel (KEY_LOG_LEVEL);
493 KeyMsg ("Quiet output Mode Set!");
494 argc --;
495 argv ++;
496 continue;
497 }
498
499 if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
500 Status = AsciiStringToUint64 (argv[1], FALSE, &LogLevel);
501 if (EFI_ERROR (Status)) {
502 Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
503 return STATUS_ERROR;
504 }
505 if (LogLevel > 9) {
506 Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel);
507 return STATUS_ERROR;
508 }
509 SetPrintLevel (LogLevel);
510 DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv[1]);
511 argc -= 2;
512 argv += 2;
513 continue;
514 }
515
516 //
517 // Don't recognize the parameter.
518 //
519 Error (NULL, 0, 1000, "Unknown option", "%s", argv[0]);
520 return STATUS_ERROR;
521 }
522
523 VerboseMsg ("%s tool start.", UTILITY_NAME);
524
525 //
526 // check input parameter, InfFileName can be NULL
527 //
528 if (InfFileName == NULL && DumpCapsule) {
529 Error (NULL, 0, 1001, "Missing option", "Input Capsule Image");
530 return STATUS_ERROR;
531 }
532 VerboseMsg ("the input FvInf or CapInf file name is %s", InfFileName);
533
534 if (!DumpCapsule && OutFileName == NULL) {
535 Error (NULL, 0, 1001, "Missing option", "Output File");
536 return STATUS_ERROR;
537 }
538 if (OutFileName != NULL) {
539 VerboseMsg ("the output file name is %s", OutFileName);
540 }
541
542 //
543 // Read the INF file image
544 //
545 if (InfFileName != NULL) {
546 Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);
547 if (EFI_ERROR (Status)) {
548 return STATUS_ERROR;
549 }
550 }
551
552 if (DumpCapsule) {
553 VerboseMsg ("Dump the capsule header information for the input capsule image %s", InfFileName);
554 //
555 // Dump Capsule Image Header Information
556 //
557 CapsuleHeader = (EFI_CAPSULE_HEADER *) InfFileImage;
558 if (OutFileName == NULL) {
559 FpFile = stdout;
560 } else {
561 FpFile = fopen (OutFileName, "w");
562 if (FpFile == NULL) {
563 Error (NULL, 0, 0001, "Error opening file", OutFileName);
564 return STATUS_ERROR;
565 }
566 }
567 fprintf (FpFile, "Capsule %s Image Header Information\n", InfFileName);
568 fprintf (FpFile, " GUID %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
569 (unsigned) CapsuleHeader->CapsuleGuid.Data1,
570 (unsigned) CapsuleHeader->CapsuleGuid.Data2,
571 (unsigned) CapsuleHeader->CapsuleGuid.Data3,
572 (unsigned) CapsuleHeader->CapsuleGuid.Data4[0],
573 (unsigned) CapsuleHeader->CapsuleGuid.Data4[1],
574 (unsigned) CapsuleHeader->CapsuleGuid.Data4[2],
575 (unsigned) CapsuleHeader->CapsuleGuid.Data4[3],
576 (unsigned) CapsuleHeader->CapsuleGuid.Data4[4],
577 (unsigned) CapsuleHeader->CapsuleGuid.Data4[5],
578 (unsigned) CapsuleHeader->CapsuleGuid.Data4[6],
579 (unsigned) CapsuleHeader->CapsuleGuid.Data4[7]);
580 fprintf (FpFile, " Header size 0x%08X\n", (unsigned) CapsuleHeader->HeaderSize);
581 fprintf (FpFile, " Flags 0x%08X\n", (unsigned) CapsuleHeader->Flags);
582 fprintf (FpFile, " Capsule image size 0x%08X\n", (unsigned) CapsuleHeader->CapsuleImageSize);
583 fclose (FpFile);
584 } else if (CapsuleFlag) {
585 VerboseMsg ("Create capsule image");
586 //
587 // Call the GenerateCapImage to generate Capsule Image
588 //
589 for (Index = 0; mFvDataInfo.FvFiles[Index][0] != '\0'; Index ++) {
590 strcpy (mCapDataInfo.CapFiles[Index], mFvDataInfo.FvFiles[Index]);
591 }
592
593 Status = GenerateCapImage (
594 InfFileImage,
595 InfFileSize,
596 OutFileName
597 );
598 } else {
599 VerboseMsg ("Create Fv image and its map file");
600 if (mFvDataInfo.BaseAddress != 0) {
601 VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);
602 }
603 //
604 // Call the GenerateFvImage to generate Fv Image
605 //
606 Status = GenerateFvImage (
607 InfFileImage,
608 InfFileSize,
609 OutFileName,
610 MapFileName
611 );
612 }
613
614 //
615 // free InfFileImage memory
616 //
617 if (InfFileImage != NULL) {
618 free (InfFileImage);
619 }
620
621 //
622 // update boot driver address and runtime driver address in address file
623 //
624 if (Status == EFI_SUCCESS && AddrFileName != NULL && mFvBaseAddressNumber > 0) {
625 FpFile = fopen (AddrFileName, "w");
626 if (FpFile == NULL) {
627 Error (NULL, 0, 0001, "Error opening file", AddrFileName);
628 return STATUS_ERROR;
629 }
630 fprintf (FpFile, FV_BASE_ADDRESS_STRING);
631 fprintf (FpFile, "\n");
632 for (Index = 0; Index < mFvBaseAddressNumber; Index ++) {
633 fprintf (
634 FpFile,
635 "0x%llx\n",
636 (unsigned long long)mFvBaseAddress[Index]
637 );
638 }
639 fflush (FpFile);
640 fclose (FpFile);
641 }
642
643 if (Status == EFI_SUCCESS) {
644 DebugMsg (NULL, 0, 9, "The Total Fv Size", "%s = 0x%x", EFI_FV_TOTAL_SIZE_STRING, (unsigned) mFvTotalSize);
645 DebugMsg (NULL, 0, 9, "The used Fv Size", "%s = 0x%x", EFI_FV_TAKEN_SIZE_STRING, (unsigned) mFvTakenSize);
646 DebugMsg (NULL, 0, 9, "The space Fv size", "%s = 0x%x", EFI_FV_SPACE_SIZE_STRING, (unsigned) (mFvTotalSize - mFvTakenSize));
647 }
648
649 VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetUtilityStatus ());
650
651 return GetUtilityStatus ();
652 }