2 The tool dumps the contents of a firmware volume
4 Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Common/UefiBaseTypes.h>
26 #include <Common/UefiCapsule.h>
27 #include <Common/PiFirmwareFile.h>
28 #include <Common/PiFirmwareVolume.h>
29 #include <Guid/PiFirmwareFileSystem.h>
30 #include <IndustryStandard/PeImage.h>
31 #include <Protocol/GuidedSectionExtraction.h>
34 #include "Decompress.h"
36 #include "CommonLib.h"
37 #include "EfiUtilityMsgs.h"
38 #include "FirmwareVolumeBufferLib.h"
40 #include "ParseGuidedSectionTools.h"
41 #include "StringFuncs.h"
45 // Utility global variables
48 EFI_GUID gEfiCrc32GuidedSectionExtractionProtocolGuid
= EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID
;
50 #define UTILITY_MAJOR_VERSION 1
51 #define UTILITY_MINOR_VERSION 0
53 #define UTILITY_NAME "VolInfo"
55 #define EFI_SECTION_ERROR EFIERR (100)
57 #define MAX_BASENAME_LEN 60 // not good to hardcode, but let's be reasonable
60 // Structure to keep a list of guid-to-basenames
62 typedef struct _GUID_TO_BASENAME
{
63 struct _GUID_TO_BASENAME
*Next
;
64 INT8 Guid
[PRINTED_GUID_BUFFER_SIZE
];
65 INT8 BaseName
[MAX_BASENAME_LEN
];
68 static GUID_TO_BASENAME
*mGuidBaseNameList
= NULL
;
71 // Store GUIDed Section guid->tool mapping
73 EFI_HANDLE mParsedGuidedSectionTools
= NULL
;
75 CHAR8
* mUtilityFilename
= NULL
;
78 ParseGuidBaseNameFile (
83 FreeGuidBaseNameList (
94 IN UINT8
*SectionBuffer
,
95 IN UINT32 BufferLength
101 IN UINT32 SectionLength
109 OUT BOOLEAN
*ErasePolarity
115 EFI_FIRMWARE_VOLUME_HEADER
*FvImage
,
116 EFI_FFS_FILE_HEADER
*FileHeader
,
117 BOOLEAN ErasePolarity
129 LoadGuidedSectionToolsTxt (
130 IN CHAR8
* FirmwareVolumeFilename
147 GC_TODO: Add function description
151 argc - GC_TODO: add argument description
152 ] - GC_TODO: add argument description
156 GC_TODO: add return values
162 EFI_FIRMWARE_VOLUME_HEADER
*FvImage
;
166 BOOLEAN ErasePolarity
;
169 SetUtilityName (UTILITY_NAME
);
171 // Print utility header
173 printf ("%s Version %d.%d Build %s\n",
175 UTILITY_MAJOR_VERSION
,
176 UTILITY_MINOR_VERSION
,
191 // Look for help options
193 if ((strcmp(argv
[0], "-h") == 0) || (strcmp(argv
[0], "--help") == 0) ||
194 (strcmp(argv
[0], "-?") == 0) || (strcmp(argv
[0], "/?") == 0)) {
196 return STATUS_SUCCESS
;
199 // Version has already be printed, so just return success
201 if (strcmp(argv
[0], "--version") == 0) {
202 return STATUS_SUCCESS
;
206 // If they specified -x xref guid/basename cross-reference files, process it.
207 // This will print the basename beside each file guid. To use it, specify
208 // -x xref_filename to processdsc, then use xref_filename as a parameter
212 if ((strcmp(argv
[0], "-x") == 0) || (strcmp(argv
[0], "--xref") == 0)) {
213 ParseGuidBaseNameFile (argv
[1]);
214 printf("ParseGuidBaseNameFile: %s\n", argv
[1]);
219 if (strcmp(argv
[0], "--offset") == 0) {
223 if ((argv
[1][0] == '0') && (tolower ((int)argv
[1][1]) == 'x')) {
224 if (sscanf (argv
[1], "%x", &Offset
) != 1) {
225 Error (NULL
, 0, 1003, "Invalid option value", "Offset = %s", argv
[1]);
226 return GetUtilityStatus ();
229 if (sscanf (argv
[1], "%d", &Offset
) != 1) {
230 Error (NULL
, 0, 1003, "Invalid option value", "Offset = %s", argv
[1]);
231 return GetUtilityStatus ();
234 // See if they said something like "64K"
236 if (tolower ((int)argv
[1][strlen (argv
[1]) - 1]) == 'k') {
246 if ((stricmp (argv
[0], "-v") == 0) || (stricmp (argv
[0], "--verbose") == 0)) {
247 SetPrintLevel (VERBOSE_LOG_LEVEL
);
253 if ((stricmp (argv
[0], "-q") == 0) || (stricmp (argv
[0], "--quiet") == 0)) {
254 SetPrintLevel (KEY_LOG_LEVEL
);
260 if ((stricmp (argv
[0], "-d") == 0) || (stricmp (argv
[0], "--debug") == 0)) {
261 Status
= AsciiStringToUint64 (argv
[1], FALSE
, &LogLevel
);
262 if (EFI_ERROR (Status
)) {
263 Error (NULL
, 0, 1003, "Invalid option value", "%s = %s", argv
[0], argv
[1]);
267 Error (NULL
, 0, 1003, "Invalid option value", "Debug Level range is 0-9, current input level is %d", (int) LogLevel
);
270 SetPrintLevel (LogLevel
);
271 DebugMsg (NULL
, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", argv
[1]);
277 mUtilityFilename
= argv
[0];
283 // Open the file containing the FV
285 if (mUtilityFilename
== NULL
) {
286 Error (NULL
, 0, 1001, "Missing option", "Input files are not specified");
287 return GetUtilityStatus ();
289 InputFile
= fopen (LongFilePath (mUtilityFilename
), "rb");
290 if (InputFile
== NULL
) {
291 Error (NULL
, 0, 0001, "Error opening the input file", mUtilityFilename
);
292 return GetUtilityStatus ();
295 // Skip over pad bytes if specified. This is used if they prepend 0xff
296 // data to the FV image binary.
299 fseek (InputFile
, Offset
, SEEK_SET
);
302 // Determine size of FV
304 Status
= ReadHeader (InputFile
, &FvSize
, &ErasePolarity
);
305 if (EFI_ERROR (Status
)) {
306 Error (NULL
, 0, 0003, "error parsing FV image", "%s Header is invalid", mUtilityFilename
);
308 return GetUtilityStatus ();
311 // Allocate a buffer for the FV image
313 FvImage
= malloc (FvSize
);
314 if (FvImage
== NULL
) {
315 Error (NULL
, 0, 4001, "Resource: Memory can't be allocated", NULL
);
317 return GetUtilityStatus ();
320 // Seek to the start of the image, then read the entire FV to the buffer
322 fseek (InputFile
, Offset
, SEEK_SET
);
323 BytesRead
= fread (FvImage
, 1, FvSize
, InputFile
);
325 if ((unsigned int) BytesRead
!= FvSize
) {
326 Error (NULL
, 0, 0004, "error reading FvImage from", mUtilityFilename
);
328 return GetUtilityStatus ();
331 LoadGuidedSectionToolsTxt (mUtilityFilename
);
333 PrintFvInfo (FvImage
, FALSE
);
339 FreeGuidBaseNameList ();
340 return GetUtilityStatus ();
354 GC_TODO: Add function description
358 Fv - Firmware Volume to print information about
359 IsChildFv - Flag specifies whether the input FV is a child FV.
369 BOOLEAN ErasePolarity
;
371 EFI_FFS_FILE_HEADER
*CurrentFile
;
374 Status
= FvBufGetSize (Fv
, &FvSize
);
378 (((EFI_FIRMWARE_VOLUME_HEADER
*)Fv
)->Attributes
& EFI_FVB2_ERASE_POLARITY
) ?
382 // Get the first file
385 Status
= FvBufFindNextFile (Fv
, &Key
, (VOID
**) &CurrentFile
);
386 if (EFI_ERROR (Status
)) {
387 Error (NULL
, 0, 0003, "error parsing FV image", "cannot find the first file in the FV image");
388 return GetUtilityStatus ();
391 // Display information about files found
393 while (CurrentFile
!= NULL
) {
395 // Increment the number of files counter
400 // Display info about this file
402 Status
= PrintFileInfo (Fv
, CurrentFile
, ErasePolarity
);
403 if (EFI_ERROR (Status
)) {
404 Error (NULL
, 0, 0003, "error parsing FV image", "failed to parse a file in the FV");
405 return GetUtilityStatus ();
410 Status
= FvBufFindNextFile (Fv
, &Key
, (VOID
**) &CurrentFile
);
411 if (Status
== EFI_NOT_FOUND
) {
413 } else if (EFI_ERROR (Status
)) {
414 Error (NULL
, 0, 0003, "error parsing FV image", "cannot find the next file in the FV image");
415 return GetUtilityStatus ();
420 printf ("There are a total of %d files in the child FV\n", (int) NumberOfFiles
);
422 printf ("There are a total of %d files in this FV\n", (int) NumberOfFiles
);
430 IN UINT32 ActualSize
,
437 This function returns the next larger size that meets the alignment
438 requirement specified.
443 Alignment The desired alignment.
447 EFI_SUCCESS Function completed successfully.
448 EFI_ABORTED The function encountered an error.
454 OccupiedSize
= ActualSize
;
455 while ((OccupiedSize
& (Alignment
- 1)) != 0) {
465 IN EFI_SECTION_TYPE Type
471 Converts EFI Section names to Strings
475 Type - The EFI Section type
479 CHAR8* - Pointer to the String containing the section name.
484 CHAR8
*SectionTypeStringTable
[] = {
492 "EFI_SECTION_COMPRESSION",
496 "EFI_SECTION_GUID_DEFINED",
500 "Unknown section type - Reserved 0x03",
504 "Unknown section type - Reserved 0x04",
508 "Unknown section type - Reserved 0x05",
512 "Unknown section type - Reserved 0x06",
516 "Unknown section type - Reserved 0x07",
520 "Unknown section type - Reserved 0x08",
524 "Unknown section type - Reserved 0x09",
528 "Unknown section type - Reserved 0x0A",
532 "Unknown section type - Reserved 0x0B",
536 "Unknown section type - Reserved 0x0C",
540 "Unknown section type - Reserved 0x0D",
544 "Unknown section type - Reserved 0x0E",
548 "Unknown section type - Reserved 0x0E",
564 "EFI_SECTION_DXE_DEPEX",
568 "EFI_SECTION_VERSION",
572 "EFI_SECTION_USER_INTERFACE",
576 "EFI_SECTION_COMPATIBILITY16",
580 "EFI_SECTION_FIRMWARE_VOLUME_IMAGE ",
584 "EFI_SECTION_FREEFORM_SUBTYPE_GUID ",
592 "Unknown section type - 0x1A",
596 "EFI_SECTION_PEI_DEPEX",
600 "EFI_SECTION_SMM_DEPEX",
604 "Unknown section type - Reserved - beyond last defined section"
607 if (Type
> EFI_SECTION_LAST_SECTION_TYPE
) {
608 Type
= EFI_SECTION_LAST_SECTION_TYPE
+ 1;
611 SectionStr
= malloc (100);
612 if (SectionStr
== NULL
) {
613 printf ("Error: Out of memory resources.\n");
616 strcpy (SectionStr
, SectionTypeStringTable
[Type
]);
625 OUT BOOLEAN
*ErasePolarity
631 This function determines the size of the FV and the erase polarity. The
632 erase polarity is the FALSE value for file state.
636 InputFile The file that contains the FV image.
637 FvSize The size of the FV.
638 ErasePolarity The FV erase polarity.
642 EFI_SUCCESS Function completed successfully.
643 EFI_INVALID_PARAMETER A required parameter was NULL or is out of range.
644 EFI_ABORTED The function encountered an error.
648 EFI_FIRMWARE_VOLUME_HEADER VolumeHeader
;
649 EFI_FV_BLOCK_MAP_ENTRY BlockMap
;
657 // Check input parameters
659 if (InputFile
== NULL
|| FvSize
== NULL
|| ErasePolarity
== NULL
) {
660 Error (__FILE__
, __LINE__
, 0, "application error", "invalid parameter to function");
661 return EFI_INVALID_PARAMETER
;
666 fread (&VolumeHeader
, sizeof (EFI_FIRMWARE_VOLUME_HEADER
) - sizeof (EFI_FV_BLOCK_MAP_ENTRY
), 1, InputFile
);
667 BytesRead
= sizeof (EFI_FIRMWARE_VOLUME_HEADER
) - sizeof (EFI_FV_BLOCK_MAP_ENTRY
);
668 Signature
[0] = VolumeHeader
.Signature
;
672 // Print FV header information
674 printf ("Signature: %s (%X)\n", (char *) Signature
, (unsigned) VolumeHeader
.Signature
);
675 printf ("Attributes: %X\n", (unsigned) VolumeHeader
.Attributes
);
677 if (VolumeHeader
.Attributes
& EFI_FVB2_READ_DISABLED_CAP
) {
678 printf (" EFI_FVB2_READ_DISABLED_CAP\n");
681 if (VolumeHeader
.Attributes
& EFI_FVB2_READ_ENABLED_CAP
) {
682 printf (" EFI_FVB2_READ_ENABLED_CAP\n");
685 if (VolumeHeader
.Attributes
& EFI_FVB2_READ_STATUS
) {
686 printf (" EFI_FVB2_READ_STATUS\n");
689 if (VolumeHeader
.Attributes
& EFI_FVB2_WRITE_DISABLED_CAP
) {
690 printf (" EFI_FVB2_WRITE_DISABLED_CAP\n");
693 if (VolumeHeader
.Attributes
& EFI_FVB2_WRITE_ENABLED_CAP
) {
694 printf (" EFI_FVB2_WRITE_ENABLED_CAP\n");
697 if (VolumeHeader
.Attributes
& EFI_FVB2_WRITE_STATUS
) {
698 printf (" EFI_FVB2_WRITE_STATUS\n");
701 if (VolumeHeader
.Attributes
& EFI_FVB2_LOCK_CAP
) {
702 printf (" EFI_FVB2_LOCK_CAP\n");
705 if (VolumeHeader
.Attributes
& EFI_FVB2_LOCK_STATUS
) {
706 printf (" EFI_FVB2_LOCK_STATUS\n");
709 if (VolumeHeader
.Attributes
& EFI_FVB2_STICKY_WRITE
) {
710 printf (" EFI_FVB2_STICKY_WRITE\n");
713 if (VolumeHeader
.Attributes
& EFI_FVB2_MEMORY_MAPPED
) {
714 printf (" EFI_FVB2_MEMORY_MAPPED\n");
717 if (VolumeHeader
.Attributes
& EFI_FVB2_ERASE_POLARITY
) {
718 printf (" EFI_FVB2_ERASE_POLARITY\n");
719 *ErasePolarity
= TRUE
;
722 #if (PI_SPECIFICATION_VERSION < 0x00010000)
723 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT
) {
724 printf (" EFI_FVB2_ALIGNMENT\n");
727 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2
) {
728 printf (" EFI_FVB2_ALIGNMENT_2\n");
731 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_4
) {
732 printf (" EFI_FVB2_ALIGNMENT_4\n");
735 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_8
) {
736 printf (" EFI_FVB2_ALIGNMENT_8\n");
739 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_16
) {
740 printf (" EFI_FVB2_ALIGNMENT_16\n");
743 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_32
) {
744 printf (" EFI_FVB2_ALIGNMENT_32\n");
747 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64
) {
748 printf (" EFI_FVB2_ALIGNMENT_64\n");
751 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_128
) {
752 printf (" EFI_FVB2_ALIGNMENT_128\n");
755 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_256
) {
756 printf (" EFI_FVB2_ALIGNMENT_256\n");
759 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_512
) {
760 printf (" EFI_FVB2_ALIGNMENT_512\n");
763 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_1K
) {
764 printf (" EFI_FVB2_ALIGNMENT_1K\n");
767 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2K
) {
768 printf (" EFI_FVB2_ALIGNMENT_2K\n");
771 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_4K
) {
772 printf (" EFI_FVB2_ALIGNMENT_4K\n");
775 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_8K
) {
776 printf (" EFI_FVB2_ALIGNMENT_8K\n");
779 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_16K
) {
780 printf (" EFI_FVB2_ALIGNMENT_16K\n");
783 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_32K
) {
784 printf (" EFI_FVB2_ALIGNMENT_32K\n");
787 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64K
) {
788 printf (" EFI_FVB2_ALIGNMENT_64K\n");
793 if (VolumeHeader
.Attributes
& EFI_FVB2_READ_LOCK_CAP
) {
794 printf (" EFI_FVB2_READ_LOCK_CAP\n");
797 if (VolumeHeader
.Attributes
& EFI_FVB2_READ_LOCK_STATUS
) {
798 printf (" EFI_FVB2_READ_LOCK_STATUS\n");
801 if (VolumeHeader
.Attributes
& EFI_FVB2_WRITE_LOCK_CAP
) {
802 printf (" EFI_FVB2_WRITE_LOCK_CAP\n");
805 if (VolumeHeader
.Attributes
& EFI_FVB2_WRITE_LOCK_STATUS
) {
806 printf (" EFI_FVB2_WRITE_LOCK_STATUS\n");
809 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_1
) {
810 printf (" EFI_FVB2_ALIGNMENT_1\n");
813 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2
) {
814 printf (" EFI_FVB2_ALIGNMENT_2\n");
817 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_4
) {
818 printf (" EFI_FVB2_ALIGNMENT_4\n");
821 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_8
) {
822 printf (" EFI_FVB2_ALIGNMENT_8\n");
825 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_16
) {
826 printf (" EFI_FVB2_ALIGNMENT_16\n");
829 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_32
) {
830 printf (" EFI_FVB2_ALIGNMENT_32\n");
833 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64
) {
834 printf (" EFI_FVB2_ALIGNMENT_64\n");
837 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_128
) {
838 printf (" EFI_FVB2_ALIGNMENT_128\n");
841 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_256
) {
842 printf (" EFI_FVB2_ALIGNMENT_256\n");
845 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_512
) {
846 printf (" EFI_FVB2_ALIGNMENT_512\n");
849 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_1K
) {
850 printf (" EFI_FVB2_ALIGNMENT_1K\n");
853 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2K
) {
854 printf (" EFI_FVB2_ALIGNMENT_2K\n");
857 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_4K
) {
858 printf (" EFI_FVB2_ALIGNMENT_4K\n");
861 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_8K
) {
862 printf (" EFI_FVB2_ALIGNMENT_8K\n");
865 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_16K
) {
866 printf (" EFI_FVB2_ALIGNMENT_16K\n");
869 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_32K
) {
870 printf (" EFI_FVB2_ALIGNMENT_32K\n");
873 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64K
) {
874 printf (" EFI_FVB2_ALIGNMENT_64K\n");
877 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_128K
) {
878 printf (" EFI_FVB2_ALIGNMENT_128K\n");
881 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_256K
) {
882 printf (" EFI_FVB2_ALIGNMENT_256K\n");
885 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_512K
) {
886 printf (" EFI_FVB2_ALIGNMENT_512K\n");
889 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_1M
) {
890 printf (" EFI_FVB2_ALIGNMENT_1M\n");
893 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2M
) {
894 printf (" EFI_FVB2_ALIGNMENT_2M\n");
897 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_4M
) {
898 printf (" EFI_FVB2_ALIGNMENT_4M\n");
901 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_8M
) {
902 printf (" EFI_FVB2_ALIGNMENT_8M\n");
905 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_16M
) {
906 printf (" EFI_FVB2_ALIGNMENT_16M\n");
909 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_32M
) {
910 printf (" EFI_FVB2_ALIGNMENT_32M\n");
913 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64M
) {
914 printf (" EFI_FVB2_ALIGNMENT_64M\n");
917 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_128M
) {
918 printf (" EFI_FVB2_ALIGNMENT_128M\n");
921 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_64M
) {
922 printf (" EFI_FVB2_ALIGNMENT_64M\n");
925 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_128M
) {
926 printf (" EFI_FVB2_ALIGNMENT_128M\n");
929 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_256M
) {
930 printf (" EFI_FVB2_ALIGNMENT_256M\n");
933 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_512M
) {
934 printf (" EFI_FVB2_ALIGNMENT_512M\n");
937 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_1G
) {
938 printf (" EFI_FVB2_ALIGNMENT_1G\n");
941 if (VolumeHeader
.Attributes
& EFI_FVB2_ALIGNMENT_2G
) {
942 printf (" EFI_FVB2_ALIGNMENT_2G\n");
946 printf ("Header Length: 0x%08X\n", VolumeHeader
.HeaderLength
);
947 printf ("File System ID: ");
948 PrintGuid (&VolumeHeader
.FileSystemGuid
);
952 printf ("Revision: 0x%04X\n", VolumeHeader
.Revision
);
955 fread (&BlockMap
, sizeof (EFI_FV_BLOCK_MAP_ENTRY
), 1, InputFile
);
956 BytesRead
+= sizeof (EFI_FV_BLOCK_MAP_ENTRY
);
958 if (BlockMap
.NumBlocks
!= 0) {
959 printf ("Number of Blocks: 0x%08X\n", (unsigned) BlockMap
.NumBlocks
);
960 printf ("Block Length: 0x%08X\n", (unsigned) BlockMap
.Length
);
961 Size
+= BlockMap
.NumBlocks
* BlockMap
.Length
;
964 } while (!(BlockMap
.NumBlocks
== 0 && BlockMap
.Length
== 0));
966 if (BytesRead
!= VolumeHeader
.HeaderLength
) {
967 printf ("ERROR: Header length not consistent with Block Maps!\n");
971 if (VolumeHeader
.FvLength
!= Size
) {
972 printf ("ERROR: Volume Size not consistant with Block Maps!\n");
976 printf ("Total Volume Size: 0x%08X\n", (unsigned) Size
);
981 // rewind (InputFile);
989 EFI_FIRMWARE_VOLUME_HEADER
*FvImage
,
990 EFI_FFS_FILE_HEADER
*FileHeader
,
991 BOOLEAN ErasePolarity
997 GC_TODO: Add function description
1001 FvImage - GC_TODO: add argument description
1002 FileHeader - GC_TODO: add argument description
1003 ErasePolarity - GC_TODO: add argument description
1007 EFI_SUCCESS - GC_TODO: Add description for return value
1008 EFI_ABORTED - GC_TODO: Add description for return value
1015 EFI_FFS_FILE_HEADER2 BlankHeader
;
1017 UINT8 GuidBuffer
[PRINTED_GUID_BUFFER_SIZE
];
1019 #if (PI_SPECIFICATION_VERSION < 0x00010000)
1023 // Check if we have free space
1025 HeaderSize
= FvBufGetFfsHeaderSize(FileHeader
);
1026 if (ErasePolarity
) {
1027 memset (&BlankHeader
, -1, HeaderSize
);
1029 memset (&BlankHeader
, 0, HeaderSize
);
1032 if (memcmp (&BlankHeader
, FileHeader
, HeaderSize
) == 0) {
1036 // Print file information.
1038 printf ("============================================================\n");
1040 printf ("File Name: ");
1041 PrintGuidToBuffer (&FileHeader
->Name
, GuidBuffer
, sizeof (GuidBuffer
), TRUE
);
1042 printf ("%s ", GuidBuffer
);
1043 PrintGuidName (GuidBuffer
);
1047 // PrintGuid (&FileHeader->Name);
1050 FileLength
= FvBufGetFfsFileSize (FileHeader
);
1051 printf ("File Offset: 0x%08X\n", (unsigned) ((UINTN
) FileHeader
- (UINTN
) FvImage
));
1052 printf ("File Length: 0x%08X\n", (unsigned) FileLength
);
1053 printf ("File Attributes: 0x%02X\n", FileHeader
->Attributes
);
1054 printf ("File State: 0x%02X\n", FileHeader
->State
);
1059 FileState
= GetFileState (ErasePolarity
, FileHeader
);
1061 switch (FileState
) {
1063 case EFI_FILE_HEADER_CONSTRUCTION
:
1064 printf (" EFI_FILE_HEADER_CONSTRUCTION\n");
1067 case EFI_FILE_HEADER_INVALID
:
1068 printf (" EFI_FILE_HEADER_INVALID\n");
1071 case EFI_FILE_HEADER_VALID
:
1072 printf (" EFI_FILE_HEADER_VALID\n");
1073 Checksum
= CalculateSum8 ((UINT8
*) FileHeader
, HeaderSize
);
1074 Checksum
= (UINT8
) (Checksum
- FileHeader
->IntegrityCheck
.Checksum
.File
);
1075 Checksum
= (UINT8
) (Checksum
- FileHeader
->State
);
1076 if (Checksum
!= 0) {
1077 printf ("ERROR: Header checksum invalid.\n");
1083 case EFI_FILE_DELETED
:
1084 printf (" EFI_FILE_DELETED\n");
1086 case EFI_FILE_MARKED_FOR_UPDATE
:
1087 printf (" EFI_FILE_MARKED_FOR_UPDATE\n");
1089 case EFI_FILE_DATA_VALID
:
1090 printf (" EFI_FILE_DATA_VALID\n");
1093 // Calculate header checksum
1095 Checksum
= CalculateSum8 ((UINT8
*) FileHeader
, HeaderSize
);
1096 Checksum
= (UINT8
) (Checksum
- FileHeader
->IntegrityCheck
.Checksum
.File
);
1097 Checksum
= (UINT8
) (Checksum
- FileHeader
->State
);
1098 if (Checksum
!= 0) {
1099 Error (NULL
, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid header checksum", GuidBuffer
);
1103 FileLength
= FvBufGetFfsFileSize (FileHeader
);
1105 if (FileHeader
->Attributes
& FFS_ATTRIB_CHECKSUM
) {
1107 // Calculate file checksum
1109 Checksum
= CalculateSum8 ((UINT8
*)FileHeader
+ HeaderSize
, FileLength
- HeaderSize
);
1110 Checksum
= Checksum
+ FileHeader
->IntegrityCheck
.Checksum
.File
;
1111 if (Checksum
!= 0) {
1112 Error (NULL
, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid file checksum", GuidBuffer
);
1116 if (FileHeader
->IntegrityCheck
.Checksum
.File
!= FFS_FIXED_CHECKSUM
) {
1117 Error (NULL
, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has invalid header checksum -- not set to fixed value of 0xAA", GuidBuffer
);
1121 #if (PI_SPECIFICATION_VERSION < 0x00010000)
1123 // Verify tail if present
1125 if (FileHeader
->Attributes
& FFS_ATTRIB_TAIL_PRESENT
) {
1127 // Verify tail is complement of integrity check field in the header.
1129 Tail
= (UINT16
*) ((UINTN
) FileHeader
+ GetLength (FileHeader
->Size
) - sizeof (EFI_FFS_INTEGRITY_CHECK
));
1130 if (FileHeader
->IntegrityCheck
.TailReference
!= (UINT16
)~(*Tail
)) {
1131 Error (NULL
, 0, 0003, "error parsing FFS file", \
1132 "FFS file with Guid %s failed in the integrity check, tail is not the complement of the header field", GuidBuffer
);
1140 Error (NULL
, 0, 0003, "error parsing FFS file", "FFS file with Guid %s has the invalid/unrecognized file state bits", GuidBuffer
);
1144 printf ("File Type: 0x%02X ", FileHeader
->Type
);
1146 switch (FileHeader
->Type
) {
1148 case EFI_FV_FILETYPE_RAW
:
1149 printf ("EFI_FV_FILETYPE_RAW\n");
1152 case EFI_FV_FILETYPE_FREEFORM
:
1153 printf ("EFI_FV_FILETYPE_FREEFORM\n");
1156 case EFI_FV_FILETYPE_SECURITY_CORE
:
1157 printf ("EFI_FV_FILETYPE_SECURITY_CORE\n");
1160 case EFI_FV_FILETYPE_PEI_CORE
:
1161 printf ("EFI_FV_FILETYPE_PEI_CORE\n");
1164 case EFI_FV_FILETYPE_DXE_CORE
:
1165 printf ("EFI_FV_FILETYPE_DXE_CORE\n");
1168 case EFI_FV_FILETYPE_PEIM
:
1169 printf ("EFI_FV_FILETYPE_PEIM\n");
1172 case EFI_FV_FILETYPE_DRIVER
:
1173 printf ("EFI_FV_FILETYPE_DRIVER\n");
1176 case EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
:
1177 printf ("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER\n");
1180 case EFI_FV_FILETYPE_APPLICATION
:
1181 printf ("EFI_FV_FILETYPE_APPLICATION\n");
1184 case EFI_FV_FILETYPE_SMM
:
1185 printf ("EFI_FV_FILETYPE_SMM\n");
1188 case EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
:
1189 printf ("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\n");
1192 case EFI_FV_FILETYPE_COMBINED_SMM_DXE
:
1193 printf ("EFI_FV_FILETYPE_COMBINED_SMM_DXE\n");
1196 case EFI_FV_FILETYPE_SMM_CORE
:
1197 printf ("EFI_FV_FILETYPE_SMM_CORE\n");
1200 case EFI_FV_FILETYPE_FFS_PAD
:
1201 printf ("EFI_FV_FILETYPE_FFS_PAD\n");
1205 printf ("\nERROR: Unrecognized file type %X.\n", FileHeader
->Type
);
1210 switch (FileHeader
->Type
) {
1212 case EFI_FV_FILETYPE_ALL
:
1213 case EFI_FV_FILETYPE_RAW
:
1214 case EFI_FV_FILETYPE_FFS_PAD
:
1219 // All other files have sections
1221 Status
= ParseSection (
1222 (UINT8
*) ((UINTN
) FileHeader
+ HeaderSize
),
1223 FvBufGetFfsFileSize (FileHeader
) - HeaderSize
1225 if (EFI_ERROR (Status
)) {
1227 // printf ("ERROR: Parsing the FFS file.\n");
1239 IN UINT8
*SectionBuffer
,
1240 IN UINT32 BufferLength
1244 Routine Description:
1250 SectionBuffer - Buffer containing the section to parse.
1251 BufferLength - Length of SectionBuffer
1255 EFI_SECTION_ERROR - Problem with section parsing.
1256 (a) compression errors
1257 (b) unrecognized section
1258 EFI_UNSUPPORTED - Do not know how to parse the section.
1259 EFI_SUCCESS - Section successfully parsed.
1260 EFI_OUT_OF_RESOURCES - Memory allocation failed.
1264 EFI_SECTION_TYPE Type
;
1266 UINT32 SectionLength
;
1267 UINT32 SectionHeaderLen
;
1270 UINT32 ParsedLength
;
1271 UINT8
*CompressedBuffer
;
1272 UINT32 CompressedLength
;
1273 UINT8
*UncompressedBuffer
;
1274 UINT32 UncompressedLength
;
1275 UINT8
*ToolOutputBuffer
;
1276 UINT32 ToolOutputLength
;
1277 UINT8 CompressionType
;
1280 UINT8
*ScratchBuffer
;
1281 DECOMPRESS_FUNCTION DecompressFunction
;
1282 GETINFO_FUNCTION GetInfoFunction
;
1284 CHAR8
*ExtractionTool
;
1285 CHAR8
*ToolInputFile
;
1286 CHAR8
*ToolOutputFile
;
1287 CHAR8
*SystemCommandFormatString
;
1288 CHAR8
*SystemCommand
;
1295 while (ParsedLength
< BufferLength
) {
1296 Ptr
= SectionBuffer
+ ParsedLength
;
1298 SectionLength
= GetLength (((EFI_COMMON_SECTION_HEADER
*) Ptr
)->Size
);
1299 Type
= ((EFI_COMMON_SECTION_HEADER
*) Ptr
)->Type
;
1302 // This is sort of an odd check, but is necessary because FFS files are
1303 // padded to a QWORD boundary, meaning there is potentially a whole section
1304 // header worth of 0xFF bytes.
1306 if (SectionLength
== 0xffffff && Type
== 0xff) {
1312 // Get real section file size
1314 SectionLength
= GetSectionFileLength ((EFI_COMMON_SECTION_HEADER
*) Ptr
);
1315 SectionHeaderLen
= GetSectionHeaderLength((EFI_COMMON_SECTION_HEADER
*)Ptr
);
1317 SectionName
= SectionNameToStr (Type
);
1318 printf ("------------------------------------------------------------\n");
1319 printf (" Type: %s\n Size: 0x%08X\n", SectionName
, (unsigned) SectionLength
);
1323 case EFI_SECTION_RAW
:
1324 case EFI_SECTION_PE32
:
1325 case EFI_SECTION_PIC
:
1326 case EFI_SECTION_TE
:
1327 // default is no more information
1330 case EFI_SECTION_USER_INTERFACE
:
1331 printf (" String: %ls\n", (CHAR16
*) &((EFI_USER_INTERFACE_SECTION
*) Ptr
)->FileNameString
);
1334 case EFI_SECTION_FIRMWARE_VOLUME_IMAGE
:
1335 Status
= PrintFvInfo (Ptr
+ SectionHeaderLen
, TRUE
);
1336 if (EFI_ERROR (Status
)) {
1337 Error (NULL
, 0, 0003, "printing of FV section contents failed", NULL
);
1338 return EFI_SECTION_ERROR
;
1342 case EFI_SECTION_COMPATIBILITY16
:
1343 case EFI_SECTION_FREEFORM_SUBTYPE_GUID
:
1345 // Section does not contain any further header information.
1349 case EFI_SECTION_PEI_DEPEX
:
1350 case EFI_SECTION_DXE_DEPEX
:
1351 case EFI_SECTION_SMM_DEPEX
:
1352 DumpDepexSection (Ptr
, SectionLength
);
1355 case EFI_SECTION_VERSION
:
1356 printf (" Build Number: 0x%02X\n", *(UINT16
*)(Ptr
+ SectionHeaderLen
));
1357 printf (" Version Strg: %s\n", (char*) (Ptr
+ SectionHeaderLen
+ sizeof (UINT16
)));
1360 case EFI_SECTION_COMPRESSION
:
1361 UncompressedBuffer
= NULL
;
1362 if (SectionHeaderLen
== sizeof (EFI_COMMON_SECTION_HEADER
)) {
1363 RealHdrLen
= sizeof(EFI_COMPRESSION_SECTION
);
1364 UncompressedLength
= ((EFI_COMPRESSION_SECTION
*)Ptr
)->UncompressedLength
;
1365 CompressionType
= ((EFI_COMPRESSION_SECTION
*)Ptr
)->CompressionType
;
1367 RealHdrLen
= sizeof(EFI_COMPRESSION_SECTION2
);
1368 UncompressedLength
= ((EFI_COMPRESSION_SECTION2
*)Ptr
)->UncompressedLength
;
1369 CompressionType
= ((EFI_COMPRESSION_SECTION2
*)Ptr
)->CompressionType
;
1371 CompressedLength
= SectionLength
- RealHdrLen
;
1372 printf (" Uncompressed Length: 0x%08X\n", (unsigned) UncompressedLength
);
1374 if (CompressionType
== EFI_NOT_COMPRESSED
) {
1375 printf (" Compression Type: EFI_NOT_COMPRESSED\n");
1376 if (CompressedLength
!= UncompressedLength
) {
1381 "file is not compressed, but the compressed length does not match the uncompressed length",
1384 return EFI_SECTION_ERROR
;
1387 UncompressedBuffer
= Ptr
+ RealHdrLen
;
1388 } else if (CompressionType
== EFI_STANDARD_COMPRESSION
) {
1389 GetInfoFunction
= EfiGetInfo
;
1390 DecompressFunction
= EfiDecompress
;
1391 printf (" Compression Type: EFI_STANDARD_COMPRESSION\n");
1393 CompressedBuffer
= Ptr
+ RealHdrLen
;
1395 Status
= GetInfoFunction (CompressedBuffer
, CompressedLength
, &DstSize
, &ScratchSize
);
1396 if (EFI_ERROR (Status
)) {
1397 Error (NULL
, 0, 0003, "error getting compression info from compression section", NULL
);
1398 return EFI_SECTION_ERROR
;
1401 if (DstSize
!= UncompressedLength
) {
1402 Error (NULL
, 0, 0003, "compression error in the compression section", NULL
);
1403 return EFI_SECTION_ERROR
;
1406 ScratchBuffer
= malloc (ScratchSize
);
1407 UncompressedBuffer
= malloc (UncompressedLength
);
1408 if ((ScratchBuffer
== NULL
) || (UncompressedBuffer
== NULL
)) {
1409 return EFI_OUT_OF_RESOURCES
;
1411 Status
= DecompressFunction (
1419 free (ScratchBuffer
);
1420 if (EFI_ERROR (Status
)) {
1421 Error (NULL
, 0, 0003, "decompress failed", NULL
);
1422 free (UncompressedBuffer
);
1423 return EFI_SECTION_ERROR
;
1426 Error (NULL
, 0, 0003, "unrecognized compression type", "type 0x%X", CompressionType
);
1427 return EFI_SECTION_ERROR
;
1430 Status
= ParseSection (UncompressedBuffer
, UncompressedLength
);
1432 if (CompressionType
== EFI_STANDARD_COMPRESSION
) {
1434 // We need to deallocate Buffer
1436 free (UncompressedBuffer
);
1439 if (EFI_ERROR (Status
)) {
1440 Error (NULL
, 0, 0003, "failed to parse section", NULL
);
1441 return EFI_SECTION_ERROR
;
1445 case EFI_SECTION_GUID_DEFINED
:
1446 if (SectionHeaderLen
== sizeof(EFI_COMMON_SECTION_HEADER
)) {
1447 EfiGuid
= &((EFI_GUID_DEFINED_SECTION
*) Ptr
)->SectionDefinitionGuid
;
1448 DataOffset
= ((EFI_GUID_DEFINED_SECTION
*) Ptr
)->DataOffset
;
1449 Attributes
= ((EFI_GUID_DEFINED_SECTION
*) Ptr
)->Attributes
;
1451 EfiGuid
= &((EFI_GUID_DEFINED_SECTION2
*) Ptr
)->SectionDefinitionGuid
;
1452 DataOffset
= ((EFI_GUID_DEFINED_SECTION2
*) Ptr
)->DataOffset
;
1453 Attributes
= ((EFI_GUID_DEFINED_SECTION2
*) Ptr
)->Attributes
;
1455 printf (" SectionDefinitionGuid: ");
1456 PrintGuid (EfiGuid
);
1458 printf (" DataOffset: 0x%04X\n", (unsigned) DataOffset
);
1459 printf (" Attributes: 0x%04X\n", (unsigned) Attributes
);
1462 LookupGuidedSectionToolPath (
1463 mParsedGuidedSectionTools
,
1467 if (ExtractionTool
!= NULL
) {
1469 ToolInputFile
= CloneString (tmpnam (NULL
));
1470 ToolOutputFile
= CloneString (tmpnam (NULL
));
1472 char tmp1
[] = "/tmp/fileXXXXXX";
1473 char tmp2
[] = "/tmp/fileXXXXXX";
1476 fd1
= mkstemp(tmp1
);
1477 fd2
= mkstemp(tmp2
);
1478 ToolInputFile
= CloneString(tmp1
);
1479 ToolOutputFile
= CloneString(tmp2
);
1485 // Construction 'system' command string
1487 SystemCommandFormatString
= "%s -d -o %s %s";
1488 SystemCommand
= malloc (
1489 strlen (SystemCommandFormatString
) +
1490 strlen (ExtractionTool
) +
1491 strlen (ToolInputFile
) +
1492 strlen (ToolOutputFile
) +
1497 SystemCommandFormatString
,
1502 free (ExtractionTool
);
1507 (CHAR8
*) SectionBuffer
+ DataOffset
,
1508 BufferLength
- DataOffset
1511 system (SystemCommand
);
1512 remove (ToolInputFile
);
1513 free (ToolInputFile
);
1518 (CHAR8
**)&ToolOutputBuffer
,
1521 remove (ToolOutputFile
);
1522 free (ToolOutputFile
);
1523 if (EFI_ERROR (Status
)) {
1524 Error (NULL
, 0, 0004, "unable to read decoded GUIDED section", NULL
);
1525 return EFI_SECTION_ERROR
;
1528 Status
= ParseSection (
1532 if (EFI_ERROR (Status
)) {
1533 Error (NULL
, 0, 0003, "parse of decoded GUIDED section failed", NULL
);
1534 return EFI_SECTION_ERROR
;
1538 // Check for CRC32 sections which we can handle internally if needed.
1540 } else if (!CompareGuid (
1542 &gEfiCrc32GuidedSectionExtractionProtocolGuid
1546 // CRC32 guided section
1548 Status
= ParseSection (
1549 SectionBuffer
+ DataOffset
,
1550 BufferLength
- DataOffset
1552 if (EFI_ERROR (Status
)) {
1553 Error (NULL
, 0, 0003, "parse of CRC32 GUIDED section failed", NULL
);
1554 return EFI_SECTION_ERROR
;
1558 // We don't know how to parse it now.
1560 Error (NULL
, 0, 0003, "Error parsing section", \
1561 "EFI_SECTION_GUID_DEFINED cannot be parsed at this time. Tool to decode this section should have been defined in GuidedSectionTools.txt (built in the FV directory).");
1562 return EFI_UNSUPPORTED
;
1568 // Unknown section, return error
1570 Error (NULL
, 0, 0003, "unrecognized section type found", "section type = 0x%X", Type
);
1571 return EFI_SECTION_ERROR
;
1574 ParsedLength
+= SectionLength
;
1576 // We make then next section begin on a 4-byte boundary
1578 ParsedLength
= GetOccupiedSize (ParsedLength
, 4);
1581 if (ParsedLength
< BufferLength
) {
1582 Error (NULL
, 0, 0003, "sections do not completely fill the sectioned buffer being parsed", NULL
);
1583 return EFI_SECTION_ERROR
;
1592 IN UINT32 SectionLength
1596 Routine Description:
1598 GC_TODO: Add function description
1602 Ptr - GC_TODO: add argument description
1603 SectionLength - GC_TODO: add argument description
1607 EFI_SUCCESS - GC_TODO: Add description for return value
1611 UINT8 GuidBuffer
[PRINTED_GUID_BUFFER_SIZE
];
1614 // Need at least a section header + data
1616 if (SectionLength
<= sizeof (EFI_COMMON_SECTION_HEADER
)) {
1620 Ptr
+= GetSectionHeaderLength((EFI_COMMON_SECTION_HEADER
*)Ptr
);
1621 SectionLength
-= GetSectionHeaderLength((EFI_COMMON_SECTION_HEADER
*)Ptr
);
1622 while (SectionLength
> 0) {
1625 case EFI_DEP_BEFORE
:
1626 printf ("BEFORE\n");
1639 PrintGuidToBuffer ((EFI_GUID
*) (Ptr
+ 1), GuidBuffer
, sizeof (GuidBuffer
), TRUE
);
1640 printf ("%s ", GuidBuffer
);
1641 PrintGuidName (GuidBuffer
);
1644 // PrintGuid ((EFI_GUID *)(Ptr + 1));
1647 SectionLength
-= 17;
1681 printf ("END DEPEX\n");
1693 printf ("Unrecognized byte in depex: 0x%X\n", *Ptr
);
1707 Routine Description:
1709 GC_TODO: Add function description
1713 GuidStr - GC_TODO: add argument description
1717 EFI_SUCCESS - GC_TODO: Add description for return value
1718 EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
1722 GUID_TO_BASENAME
*GPtr
;
1724 // If we have a list of guid-to-basenames, then go through the list to
1725 // look for a guid string match. If found, print the basename to stdout,
1726 // otherwise return a failure.
1728 GPtr
= mGuidBaseNameList
;
1729 while (GPtr
!= NULL
) {
1730 if (_stricmp ((CHAR8
*) GuidStr
, (CHAR8
*) GPtr
->Guid
) == 0) {
1731 printf ("%s", GPtr
->BaseName
);
1738 return EFI_INVALID_PARAMETER
;
1742 ParseGuidBaseNameFile (
1747 Routine Description:
1749 GC_TODO: Add function description
1753 FileName - GC_TODO: add argument description
1757 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
1758 EFI_OUT_OF_RESOURCES - GC_TODO: Add description for return value
1759 EFI_SUCCESS - GC_TODO: Add description for return value
1764 CHAR8 Line
[MAX_LINE_LEN
];
1765 GUID_TO_BASENAME
*GPtr
;
1767 if ((Fptr
= fopen (LongFilePath (FileName
), "r")) == NULL
) {
1768 printf ("ERROR: Failed to open input cross-reference file '%s'\n", FileName
);
1769 return EFI_DEVICE_ERROR
;
1772 while (fgets (Line
, sizeof (Line
), Fptr
) != NULL
) {
1774 // Allocate space for another guid/basename element
1776 GPtr
= malloc (sizeof (GUID_TO_BASENAME
));
1778 return EFI_OUT_OF_RESOURCES
;
1781 memset ((char *) GPtr
, 0, sizeof (GUID_TO_BASENAME
));
1782 if (sscanf (Line
, "%s %s", GPtr
->Guid
, GPtr
->BaseName
) == 2) {
1783 GPtr
->Next
= mGuidBaseNameList
;
1784 mGuidBaseNameList
= GPtr
;
1787 // Some sort of error. Just continue.
1798 FreeGuidBaseNameList (
1803 Routine Description:
1805 GC_TODO: Add function description
1813 EFI_SUCCESS - GC_TODO: Add description for return value
1817 GUID_TO_BASENAME
*Next
;
1819 while (mGuidBaseNameList
!= NULL
) {
1820 Next
= mGuidBaseNameList
->Next
;
1821 free (mGuidBaseNameList
);
1822 mGuidBaseNameList
= Next
;
1831 LoadGuidedSectionToolsTxt (
1832 IN CHAR8
* FirmwareVolumeFilename
1835 CHAR8
* PeerFilename
;
1842 Places
[0] = FirmwareVolumeFilename
;
1843 //Places[1] = mUtilityFilename;
1845 mParsedGuidedSectionTools
= NULL
;
1847 for (Index
= 0; Index
< (sizeof(Places
)/sizeof(Places
[0])); Index
++) {
1848 PeerFilename
= OsPathPeerFilePath (Places
[Index
], "GuidedSectionTools.txt");
1849 //printf("Loading %s...\n", PeerFilename);
1850 if (OsPathExists (PeerFilename
)) {
1851 mParsedGuidedSectionTools
= ParseGuidedSectionToolsFile (PeerFilename
);
1853 free (PeerFilename
);
1854 if (mParsedGuidedSectionTools
!= NULL
) {
1867 Routine Description:
1869 GC_TODO: Add function description
1877 GC_TODO: add return values
1884 fprintf (stdout
, "Usage: %s [options] <input_file>\n\n", UTILITY_NAME
);
1887 // Copyright declaration
1889 fprintf (stdout
, "Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.\n\n");
1890 fprintf (stdout
, " Display Tiano Firmware Volume FFS image information\n\n");
1895 fprintf (stdout
, "optional arguments:\n");
1896 fprintf (stdout
, " -h, --help\n\
1897 Show this help message and exit\n");
1898 fprintf (stdout
, " --version\n\
1899 Show program's version number and exit\n");
1900 fprintf (stdout
, " -d [DEBUG], --debug [DEBUG]\n\
1901 Output DEBUG statements, where DEBUG_LEVEL is 0 (min) - 9 (max)\n");
1902 fprintf (stdout
, " -v, --verbose\n\
1903 Print informational statements\n");
1904 fprintf (stdout
, " -q, --quiet\n\
1905 Returns the exit code, error messages will be displayed\n");
1906 fprintf (stdout
, " -s, --silent\n\
1907 Returns only the exit code; informational and error\n\
1908 messages are not displayed\n");
1909 fprintf (stdout
, " -x XREF_FILENAME, --xref XREF_FILENAME\n\
1910 Parse the basename to file-guid cross reference file(s)\n");
1911 fprintf (stdout
, " -f OFFSET, --offset OFFSET\n\
1912 The offset from the start of the input file to start \n\
1913 processing an FV\n");
1914 fprintf (stdout
, " --sfo\n\
1915 Reserved for future use\n");