3 The API to parse the binary.
5 Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _BINARY_PARSE_H_
10 #define _BINARY_PARSE_H_ 1
14 #include "Decompress.h"
15 #include "CommonLib.h"
16 #include "EfiUtilityMsgs.h"
17 #include "FirmwareVolumeBufferLib.h"
19 #include "ParseGuidedSectionTools.h"
20 #include "StringFuncs.h"
22 #include <Common/UefiBaseTypes.h>
23 #include <Common/UefiInternalFormRepresentation.h>
24 #include <Common/UefiCapsule.h>
25 #include <Common/PiFirmwareFile.h>
26 #include <Common/PiFirmwareVolume.h>
27 #include <Guid/PiFirmwareFileSystem.h>
28 #include <IndustryStandard/PeImage.h>
29 #include <Protocol/GuidedSectionExtraction.h>
33 #define OS_SEP_STR "/"
36 #define OS_SEP_STR "\\"
39 #if defined(_MSC_VER) && _MSC_VER < 1900
40 #define snprintf _snprintf
43 #define TEMP_DIR_NAME "Temp"
44 #define MAX_FILENAME_LEN 200
45 #define MAX_MATCH_GUID_NUM 100
46 #define MAX_EFI_IN_FFS_NUM 100
51 UINTN EfiVariableAddr
;
52 UINTN Length
[MAX_EFI_IN_FFS_NUM
];
53 VOID
*FfsArray
[MAX_EFI_IN_FFS_NUM
];
54 VOID
*StorageFfsInBfv
;
55 VOID
*NvStoreDatabase
;
56 BOOLEAN ExistNvStoreDatabase
;
60 ///Define the structure for th sections
64 UINTN UncompressedBuffer
[MAX_EFI_IN_FFS_NUM
];
66 UINT8 UnCompressIndex
;
69 // {d0bc7cb4-6a47-495f-aa11-710746da06a2}
70 #define EFI_VFR_ATTRACT_GUID \
71 { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }
73 // {8913C5E0-33F6-4d86-9BF1-43EF89FC0666}
74 #define EFI_UNI_STR_ATTRACT_GUID \
75 { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
77 // {FFF12B8D-7696-4C8B-A985-2747075B4F50}
78 #define EFI_SYSTEM_NVDATA_FV_GUID \
79 { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}
82 Parses FFS Sections, and remove the FFS headers. Tis function olny handle one efi in this FFS.
84 @param SectionBuffer The section base address
85 @param BufferLength The length of FFS.
86 @param EfiBufferHeader The structure dual pointer to the efi informations
88 @retval EFI_SUCCESS The application exited normally.
89 @retval EFI_ABORTED An error occurred.
94 IN BOOLEAN IsFfsOrEfi
,
95 IN OUT UINT8
*SectionBuffer
,
96 IN UINT32 BufferLength
,
97 IN OUT EFI_SECTION_STRUCT
**EfiBufferHeader
101 Search the VfrBin Base address.
103 According the known GUID gVfrArrayAttractGuid to get the base address from FFS.
105 @param Fv the Pointer to the FFS
106 @param EfiAddr the Pointer to the EFI in FFS
107 @param Length the length of Fv
108 @param Offset the Pointer to the Addr (Offset)
109 @param NumOfMachingOffset the number of Addr (Offset)
111 @retval EFI_SUCCESS Get the address successfully.
119 OUT UINT8
*NumOfMachingOffset
123 Search the UniBin Base address.
125 According the known GUID gUniStrArrayAttractGuid to get the base address from FFS.
127 @param Fv the Pointer to the FFS
128 @param EfiAddr the Pointer to the EFI in FFS
129 @param Length the length of Fv
130 @param Offset the Pointer to the Addr (Offset)
132 @retval Base address Get the address successfully.
143 Read the file to memory.
145 @param InputFile The file that contains the FV image.
146 @param Size The size of the file.
148 @retval The pointer to the begining position of memory.
157 Search the EFI variables address in Fd.
159 Open and read the *.fd to the memory, initialize the global structure.
160 Update the EFI variables addr and the begining position of memory.
162 @retval EFI_SUCCESS Get the address successfully.
165 GetEfiVariablesAddr (
170 Pick up the FFS which includes IFR section.
172 Parse all FFS extracted by BfmLib, and save all which includes IFR
173 Binary to gEfiFdInfo structure.
175 @retval EFI_SUCCESS Get the address successfully.
176 @retval EFI_BUFFER_TOO_SMALL Memory can't be allocated.
177 @retval EFI_ABORTED Read FFS Failed.
181 IN CHAR8
*FolderName
,
182 OUT BOOLEAN
*ExistStorageInBfv
,
183 OUT BOOLEAN
*SizeOptimized