]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/FCE/BinaryParse.h
BaseTools: Fix various typos
[mirror_edk2.git] / BaseTools / Source / C / FCE / BinaryParse.h
1 /** @file
2
3 The API to parse the binary.
4
5 Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9 #ifndef _BINARY_PARSE_H_
10 #define _BINARY_PARSE_H_ 1
11
12 #include <FvLib.h>
13 #include "Compress.h"
14 #include "Decompress.h"
15 #include "CommonLib.h"
16 #include "EfiUtilityMsgs.h"
17 #include "FirmwareVolumeBufferLib.h"
18 #include "OsPath.h"
19 #include "ParseGuidedSectionTools.h"
20 #include "StringFuncs.h"
21 #include "ParseInf.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>
30
31 #ifdef __GNUC__
32 #define OS_SEP '/'
33 #define OS_SEP_STR "/"
34 #else
35 #define OS_SEP '\\'
36 #define OS_SEP_STR "\\"
37 #endif
38
39 #if defined(_MSC_VER) && _MSC_VER < 1900
40 #define snprintf _snprintf
41 #endif
42
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
47
48 typedef struct {
49 VOID *Fd;
50 UINT32 FdSize;
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;
57 } G_EFI_FD_INFO;
58
59 ///
60 ///Define the structure for th sections
61 ///
62 typedef struct {
63 UINTN BufferBase;
64 UINTN UncompressedBuffer[MAX_EFI_IN_FFS_NUM];
65 UINTN Length;
66 UINT8 UnCompressIndex;
67 } EFI_SECTION_STRUCT;
68
69 // {d0bc7cb4-6a47-495f-aa11-710746da06a2}
70 #define EFI_VFR_ATTRACT_GUID \
71 { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } }
72
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 } }
76
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 }}
80
81 /**
82 Parses FFS Sections, and remove the FFS headers. Tis function olny handle one efi in this FFS.
83
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
87
88 @retval EFI_SUCCESS The application exited normally.
89 @retval EFI_ABORTED An error occurred.
90
91 **/
92 EFI_STATUS
93 ParseSection (
94 IN BOOLEAN IsFfsOrEfi,
95 IN OUT UINT8 *SectionBuffer,
96 IN UINT32 BufferLength,
97 IN OUT EFI_SECTION_STRUCT **EfiBufferHeader
98 );
99
100 /**
101 Search the VfrBin Base address.
102
103 According the known GUID gVfrArrayAttractGuid to get the base address from FFS.
104
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)
110
111 @retval EFI_SUCCESS Get the address successfully.
112 **/
113 EFI_STATUS
114 SearchVfrBinInFFS (
115 IN VOID *Fv,
116 IN VOID *EfiAddr,
117 IN UINTN Length,
118 OUT UINTN **Offset,
119 OUT UINT8 *NumOfMachingOffset
120 );
121
122 /**
123 Search the UniBin Base address.
124
125 According the known GUID gUniStrArrayAttractGuid to get the base address from FFS.
126
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)
131
132 @retval Base address Get the address successfully.
133 **/
134 EFI_STATUS
135 SearchUniBinInFFS (
136 IN VOID *Fv,
137 IN VOID *EfiAddr,
138 IN UINTN Length,
139 OUT UINTN **Offset
140 );
141
142 /**
143 Read the file to memory.
144
145 @param InputFile The file that contains the FV image.
146 @param Size The size of the file.
147
148 @retval The pointer to the begining position of memory.
149 **/
150 VOID *
151 ReadFileToMemory (
152 IN CHAR8 *FileName,
153 OUT UINT32 *Size
154 );
155
156 /**
157 Search the EFI variables address in Fd.
158
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.
161
162 @retval EFI_SUCCESS Get the address successfully.
163 **/
164 EFI_STATUS
165 GetEfiVariablesAddr (
166 BOOLEAN UqiIsSet
167 );
168
169 /**
170 Pick up the FFS which includes IFR section.
171
172 Parse all FFS extracted by BfmLib, and save all which includes IFR
173 Binary to gEfiFdInfo structure.
174
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.
178 **/
179 EFI_STATUS
180 FindFileInFolder (
181 IN CHAR8 *FolderName,
182 OUT BOOLEAN *ExistStorageInBfv,
183 OUT BOOLEAN *SizeOptimized
184 );
185
186 #endif
187