]>
Commit | Line | Data |
---|---|---|
3c59d946 SZ |
1 | /** @file\r |
2 | \r | |
3 | The API to parse the binary.\r | |
4 | \r | |
5 | Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>\r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | #ifndef _BINARY_PARSE_H_\r | |
10 | #define _BINARY_PARSE_H_ 1\r | |
11 | \r | |
12 | #include <FvLib.h>\r | |
13 | #include "Compress.h"\r | |
14 | #include "Decompress.h"\r | |
15 | #include "CommonLib.h"\r | |
16 | #include "EfiUtilityMsgs.h"\r | |
17 | #include "FirmwareVolumeBufferLib.h"\r | |
18 | #include "OsPath.h"\r | |
19 | #include "ParseGuidedSectionTools.h"\r | |
20 | #include "StringFuncs.h"\r | |
21 | #include "ParseInf.h"\r | |
22 | #include <Common/UefiBaseTypes.h>\r | |
23 | #include <Common/UefiInternalFormRepresentation.h>\r | |
24 | #include <Common/UefiCapsule.h>\r | |
25 | #include <Common/PiFirmwareFile.h>\r | |
26 | #include <Common/PiFirmwareVolume.h>\r | |
27 | #include <Guid/PiFirmwareFileSystem.h>\r | |
28 | #include <IndustryStandard/PeImage.h>\r | |
29 | #include <Protocol/GuidedSectionExtraction.h>\r | |
30 | \r | |
31 | #ifdef __GNUC__\r | |
32 | #define OS_SEP '/'\r | |
33 | #define OS_SEP_STR "/"\r | |
34 | #else\r | |
35 | #define OS_SEP '\\'\r | |
36 | #define OS_SEP_STR "\\"\r | |
37 | #endif\r | |
38 | \r | |
39 | #if defined(_MSC_VER) && _MSC_VER < 1900\r | |
40 | #define snprintf _snprintf\r | |
41 | #endif\r | |
42 | \r | |
43 | #define TEMP_DIR_NAME "Temp"\r | |
44 | #define MAX_FILENAME_LEN 200\r | |
45 | #define MAX_MATCH_GUID_NUM 100\r | |
46 | #define MAX_EFI_IN_FFS_NUM 100\r | |
47 | \r | |
48 | typedef struct {\r | |
49 | VOID *Fd;\r | |
50 | UINT32 FdSize;\r | |
51 | UINTN EfiVariableAddr;\r | |
52 | UINTN Length[MAX_EFI_IN_FFS_NUM];\r | |
53 | VOID *FfsArray[MAX_EFI_IN_FFS_NUM];\r | |
54 | VOID *StorageFfsInBfv;\r | |
55 | VOID *NvStoreDatabase;\r | |
56 | BOOLEAN ExistNvStoreDatabase;\r | |
57 | } G_EFI_FD_INFO;\r | |
58 | \r | |
59 | ///\r | |
60 | ///Define the structure for th sections\r | |
61 | ///\r | |
62 | typedef struct {\r | |
63 | UINTN BufferBase;\r | |
64 | UINTN UncompressedBuffer[MAX_EFI_IN_FFS_NUM];\r | |
65 | UINTN Length;\r | |
66 | UINT8 UnCompressIndex;\r | |
67 | } EFI_SECTION_STRUCT;\r | |
68 | \r | |
69 | // {d0bc7cb4-6a47-495f-aa11-710746da06a2}\r | |
70 | #define EFI_VFR_ATTRACT_GUID \\r | |
71 | { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }\r | |
72 | \r | |
73 | // {8913C5E0-33F6-4d86-9BF1-43EF89FC0666}\r | |
74 | #define EFI_UNI_STR_ATTRACT_GUID \\r | |
75 | { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r | |
76 | \r | |
77 | // {FFF12B8D-7696-4C8B-A985-2747075B4F50}\r | |
78 | #define EFI_SYSTEM_NVDATA_FV_GUID \\r | |
79 | { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}\r | |
80 | \r | |
81 | /**\r | |
82 | Parses FFS Sections, and remove the FFS headers. Tis function olny handle one efi in this FFS.\r | |
83 | \r | |
84 | @param SectionBuffer The section base address\r | |
85 | @param BufferLength The length of FFS.\r | |
86 | @param EfiBufferHeader The structure dual pointer to the efi informations\r | |
87 | \r | |
88 | @retval EFI_SUCCESS The application exited normally.\r | |
89 | @retval EFI_ABORTED An error occurred.\r | |
90 | \r | |
91 | **/\r | |
92 | EFI_STATUS\r | |
93 | ParseSection (\r | |
94 | IN BOOLEAN IsFfsOrEfi,\r | |
95 | IN OUT UINT8 *SectionBuffer,\r | |
96 | IN UINT32 BufferLength,\r | |
97 | IN OUT EFI_SECTION_STRUCT **EfiBufferHeader\r | |
98 | );\r | |
99 | \r | |
100 | /**\r | |
101 | Search the VfrBin Base address.\r | |
102 | \r | |
103 | According the known GUID gVfrArrayAttractGuid to get the base address from FFS.\r | |
104 | \r | |
105 | @param Fv the Pointer to the FFS\r | |
106 | @param EfiAddr the Pointer to the EFI in FFS\r | |
107 | @param Length the length of Fv\r | |
108 | @param Offset the Pointer to the Addr (Offset)\r | |
109 | @param NumOfMachingOffset the number of Addr (Offset)\r | |
110 | \r | |
111 | @retval EFI_SUCCESS Get the address successfully.\r | |
112 | **/\r | |
113 | EFI_STATUS\r | |
114 | SearchVfrBinInFFS (\r | |
115 | IN VOID *Fv,\r | |
116 | IN VOID *EfiAddr,\r | |
117 | IN UINTN Length,\r | |
118 | OUT UINTN **Offset,\r | |
119 | OUT UINT8 *NumOfMachingOffset\r | |
120 | );\r | |
121 | \r | |
122 | /**\r | |
123 | Search the UniBin Base address.\r | |
124 | \r | |
125 | According the known GUID gUniStrArrayAttractGuid to get the base address from FFS.\r | |
126 | \r | |
127 | @param Fv the Pointer to the FFS\r | |
128 | @param EfiAddr the Pointer to the EFI in FFS\r | |
129 | @param Length the length of Fv\r | |
130 | @param Offset the Pointer to the Addr (Offset)\r | |
131 | \r | |
132 | @retval Base address Get the address successfully.\r | |
133 | **/\r | |
134 | EFI_STATUS\r | |
135 | SearchUniBinInFFS (\r | |
136 | IN VOID *Fv,\r | |
137 | IN VOID *EfiAddr,\r | |
138 | IN UINTN Length,\r | |
139 | OUT UINTN **Offset\r | |
140 | );\r | |
141 | \r | |
142 | /**\r | |
143 | Read the file to memory.\r | |
144 | \r | |
145 | @param InputFile The file that contains the FV image.\r | |
146 | @param Size The size of the file.\r | |
147 | \r | |
148 | @retval The pointer to the begining position of memory.\r | |
149 | **/\r | |
150 | VOID *\r | |
151 | ReadFileToMemory (\r | |
152 | IN CHAR8 *FileName,\r | |
153 | OUT UINT32 *Size\r | |
154 | );\r | |
155 | \r | |
156 | /**\r | |
157 | Search the EFI variables address in Fd.\r | |
158 | \r | |
159 | Open and read the *.fd to the memory, initialize the global structure.\r | |
160 | Update the EFI variables addr and the begining position of memory.\r | |
161 | \r | |
162 | @retval EFI_SUCCESS Get the address successfully.\r | |
163 | **/\r | |
164 | EFI_STATUS\r | |
165 | GetEfiVariablesAddr (\r | |
166 | BOOLEAN UqiIsSet\r | |
167 | );\r | |
168 | \r | |
169 | /**\r | |
170 | Pick up the FFS which includes IFR section.\r | |
171 | \r | |
172 | Parse all FFS extracted by BfmLib, and save all which includes IFR\r | |
173 | Binary to gEfiFdInfo structure.\r | |
174 | \r | |
175 | @retval EFI_SUCCESS Get the address successfully.\r | |
176 | @retval EFI_BUFFER_TOO_SMALL Memory can't be allocated.\r | |
177 | @retval EFI_ABORTED Read FFS Failed.\r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | FindFileInFolder (\r | |
181 | IN CHAR8 *FolderName,\r | |
182 | OUT BOOLEAN *ExistStorageInBfv,\r | |
183 | OUT BOOLEAN *SizeOptimized\r | |
184 | );\r | |
185 | \r | |
186 | #endif\r | |
187 | \r |