]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/FMMT/FirmwareModuleManagement.h
Revert "BaseTools: fix FCE build when edksetup not executed"
[mirror_edk2.git] / BaseTools / Source / C / FMMT / FirmwareModuleManagement.h
1 /** @file
2
3 Structures and functions declaration.
4
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _BIN_FILE_MANAGER_
11 #define _BIN_FILE_MANAGER_
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #ifdef __GNUC__
17 #include <unistd.h>
18 #else
19 #include <io.h>
20 #include <direct.h>
21 #endif
22 #include <FvLib.h>
23 #include <Common/UefiBaseTypes.h>
24 #include <Common/PiFirmwareVolume.h>
25 #include <Common/PiFirmwareFile.h>
26 #include <Protocol/GuidedSectionExtraction.h>
27
28 #include "CommonLib.h"
29 #include "EfiUtilityMsgs.h"
30 #include "ParseInf.h"
31 #include "ParseGuidedSectionTools.h"
32 #include "StringFuncs.h"
33 #include "Compress.h"
34 #include "Decompress.h"
35
36 #ifndef _MAX_PATH
37 #define _MAX_PATH 500
38 #endif
39
40 #if defined(_MSC_VER) && _MSC_VER < 1900
41 #define snprintf _snprintf
42 #endif
43
44 #ifdef __GNUC__
45 #define OS_SEP '/'
46 #define OS_SEP_STR "/"
47 #define COPY_STR "cp \"%s\" \"%s\" > /dev/null"
48 #define RMDIR_STR "rm -r \"%s\" > /dev/null"
49 #define DEL_STR "rm \"%s\" > /dev/null"
50 #else
51 #define OS_SEP '\\'
52 #define OS_SEP_STR "\\"
53 #define COPY_STR "copy \"%s\" \"%s\" > NUL"
54 #define RMDIR_STR "rmdir /S /Q \"%s\" > NUL"
55 #define DEL_STR "del \"%s\" > NUL"
56 #endif
57
58 #define UTILITY_NAME "Firmware Module Management Tool(FMMT)"
59 #define UTILITY_SHORT_NAME "FMMT"
60 #define UTILITY_MAJOR_VERSION 0
61 #define UTILITY_MINOR_VERSION 23
62 #define MAX_BASENAME_LEN 60 // not good to HardCode, but let's be reasonable
63 #define EFI_SECTION_ERROR EFIERR (100)
64 //
65 // The maximum number of Pad file guid entries.
66 //
67 #define MAX_NUMBER_OF_PAD_FILE_GUIDS 1024
68
69 //
70 // The maximum number of block map entries supported by the library
71 //
72 #define MAX_NUMBER_OF_FV_BLOCKS 100
73
74
75 //
76 // The maximum number of sections in an FFS file.
77 //
78 #define MAX_NUMBER_OF_SECTION_IN_FFS 100
79
80 //
81 // The maximum number of files in the FV supported by the library
82 //
83 #define MAX_NUMBER_OF_FILES_IN_FV 1000
84 #define MAX_NUMBER_OF_FILES_IN_CAP 1000
85
86
87
88 ///
89 /// If present, this must be the first and only opcode,
90 /// EFI_DEP_BEFORE is only used by DXE driver.
91 ///
92 #define EFI_DEP_BEFORE 0x00
93
94 ///
95 /// If present, this must be the first and only opcode,
96 /// EFI_DEP_AFTER is only used by DXE driver.
97 ///
98 #define EFI_DEP_AFTER 0x01
99
100 #define EFI_DEP_PUSH 0x02
101 #define EFI_DEP_AND 0x03
102 #define EFI_DEP_OR 0x04
103 #define EFI_DEP_NOT 0x05
104 #define EFI_DEP_TRUE 0x06
105 #define EFI_DEP_FALSE 0x07
106 #define EFI_DEP_END 0x08
107
108
109 ///
110 /// If present, this must be the first opcode,
111 /// EFI_DEP_SOR is only used by DXE driver.
112 ///
113 #define EFI_DEP_SOR 0x09
114
115 //
116 // INF file strings
117 //
118 #define OPTIONS_SECTION_STRING "[options]"
119 #define ATTRIBUTES_SECTION_STRING "[attributes]"
120 #define FILES_SECTION_STRING "[files]"
121 #define FV_BASE_ADDRESS_STRING "[FV_BASE_ADDRESS]"
122
123 //
124 // Options section
125 //
126 #define EFI_FV_BASE_ADDRESS_STRING "EFI_BASE_ADDRESS"
127 #define EFI_FV_FILE_NAME_STRING "EFI_FILE_NAME"
128 #define EFI_NUM_BLOCKS_STRING "EFI_NUM_BLOCKS"
129 #define EFI_BLOCK_SIZE_STRING "EFI_BLOCK_SIZE"
130 #define EFI_GUID_STRING "EFI_GUID"
131 #define EFI_FV_FILESYSTEMGUID_STRING "EFI_FV_GUID"
132 #define EFI_FV_NAMEGUID_STRING "EFI_FVNAME_GUID"
133 #define EFI_CAPSULE_GUID_STRING "EFI_CAPSULE_GUID"
134 #define EFI_CAPSULE_HEADER_SIZE_STRING "EFI_CAPSULE_HEADER_SIZE"
135 #define EFI_CAPSULE_FLAGS_STRING "EFI_CAPSULE_FLAGS"
136 #define EFI_CAPSULE_VERSION_STRING "EFI_CAPSULE_VERSION"
137
138 #define EFI_FV_TOTAL_SIZE_STRING "EFI_FV_TOTAL_SIZE"
139 #define EFI_FV_TAKEN_SIZE_STRING "EFI_FV_TAKEN_SIZE"
140 #define EFI_FV_SPACE_SIZE_STRING "EFI_FV_SPACE_SIZE"
141
142
143 typedef UINT32 FMMT_ENCAP_TYPE;
144
145 #define MAX_LEVEL_IN_FV_FILE 32
146
147 //
148 // Types of FMMT_ENCAP_TREENODE_TYPE
149 //
150 #define FMMT_ENCAP_TREE_FV 0x1
151 #define FMMT_ENCAP_TREE_FFS 0x2
152 #define FMMT_ENCAP_TREE_GUIDED_SECTION 0x3
153 #define FMMT_ENCAP_TREE_COMPRESS_SECTION 0x4
154 #define FMMT_ENCAP_TREE_FV_SECTION 0x5
155
156 extern EFI_HANDLE mParsedGuidedSectionTools;
157
158
159 #define TEMP_DIR_NAME "FmmtTemp"
160
161 //
162 // Structure to keep a list of GUID-To-BaseNames
163 //
164 typedef struct _GUID_TO_BASENAME {
165 struct _GUID_TO_BASENAME *Next;
166 INT8 Guid[PRINTED_GUID_BUFFER_SIZE];
167 INT8 BaseName[MAX_BASENAME_LEN];
168 } GUID_TO_BASENAME;
169
170
171 typedef struct _GUID_SEC_TOOL_ENTRY {
172 EFI_GUID Guid;
173 CHAR8* Name;
174 CHAR8* Path;
175 struct _GUID_SEC_TOOL_ENTRY *Next;
176 } GUID_SEC_TOOL_ENTRY;
177
178
179 //
180 // Private data types
181 //
182 //
183 // Component information
184 //
185 typedef struct {
186 UINTN Size;
187 CHAR8 ComponentName[_MAX_PATH];
188 } COMPONENT_INFO;
189
190 typedef struct {
191 CHAR8 FfsName[_MAX_PATH];
192
193 //
194 // UI Name for this FFS file, if has.
195 //
196 CHAR16 UiName[_MAX_PATH];
197 UINT32 UiNameSize;
198 //
199 // Total section number in this FFS.
200 //
201 UINT32 TotalSectionNum;
202
203 //
204 // Describe the position of the FFS file.
205 //
206 UINT8 Level;
207 //
208 // If this FFS has no encapsulate section, this flag will set to True.
209 //
210 BOOLEAN IsLeaf;
211 //
212 // Section type for each section in FFS.
213 //
214 EFI_SECTION_TYPE SectionType[MAX_NUMBER_OF_SECTION_IN_FFS];
215 //
216 // Offset relative to current FV
217 //
218 UINT32 Offset;
219 UINT8 FvLevel;
220 EFI_GUID GuidName;
221 UINT8 *Depex;
222 UINT32 DepexLen;
223 BOOLEAN IsHandle;
224 BOOLEAN IsFvStart;
225 BOOLEAN IsFvEnd;
226 }FFS_ATTRIBUTES;
227
228
229 typedef struct __ENCAP_INFO_DATA{
230 //
231 // Now Level
232 //
233 UINT8 Level;
234
235 //
236 // Encapsulate type.
237 //
238 FMMT_ENCAP_TYPE Type;
239
240 //
241 // Data, if it's FV, should be FV header.
242 //
243 VOID *Data;
244
245 //
246 //FvId, match FvId with FvGuidName.
247 //
248 UINT8 FvId;
249
250 //
251 // if FV ExtHeaderOffset not to zero, should also have FvExtHeader information
252 //
253 EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
254
255 CHAR16 UiName[_MAX_PATH];
256 UINT32 UiNameSize;
257 UINT8 *Depex;
258 UINT32 DepexLen;
259
260 //
261 // Next node.
262 //
263 struct __ENCAP_INFO_DATA *NextNode;
264
265 //
266 // Right node.
267 //
268 struct __ENCAP_INFO_DATA *RightNode;
269 } ENCAP_INFO_DATA;
270
271 typedef struct _FFS_INFOMATION{
272 CHAR8 *FFSName;
273 UINT32 InFvId;
274 UINT8 ParentLevel;
275 BOOLEAN IsFFS;
276 CHAR16 UiName[_MAX_PATH];
277 UINT32 UiNameSize;
278 UINT8 *Depex;
279 UINT32 DepexLen;
280 BOOLEAN FfsFoundFlag;
281 struct _FFS_INFOMATION *Next;
282 } FFS_INFORMATION;
283
284 //
285 // FV and capsule information holder
286 //
287 typedef struct _FV_INFOMATION{
288 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
289 EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
290 UINT32 ImageAddress;
291 UINT32 FfsNumbers;
292 CHAR8 FvName[_MAX_PATH];
293 EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS];
294 FFS_ATTRIBUTES FfsAttuibutes[MAX_NUMBER_OF_FILES_IN_FV];
295 EFI_FFS_FILE_HEADER2 FfsHeader[MAX_NUMBER_OF_FILES_IN_FV];
296 struct _FV_INFOMATION *FvNext;
297 ENCAP_INFO_DATA *EncapData;
298 UINT8 FvLevel;
299 CHAR8 *FvUiName;
300 UINT8 MulFvLevel;
301 CHAR8 AlignmentStr[16];
302 FFS_INFORMATION *ChildFvFFS;
303 } FV_INFORMATION;
304
305 typedef struct _FIRMWARE_DEVICE {
306 ///
307 /// Size of FD file
308 ///
309 UINT32 Size;
310 FV_INFORMATION *Fv;
311 } FIRMWARE_DEVICE;
312
313 typedef struct _FILENode {
314 CHAR8 *FileName;
315 UINT8 SubLevel;
316 struct _FILENode *Next;
317 } FILENode;
318
319 typedef struct {
320 CHAR8 *FvId;
321 FILENode *NewFile;
322 FILENode *OldFile;
323 FIRMWARE_DEVICE *FdData;
324 UINT8 FvLevel;
325 FV_INFORMATION *FvInFd;
326 } Data;
327
328 EFI_STATUS
329 LibFindFvInFd (
330 IN FILE *InputFile,
331 IN OUT FIRMWARE_DEVICE **FdData
332 );
333
334 /**
335
336 TODO: Add function description
337
338 @param[in] Fv - Firmware Volume to get information from
339
340 @return EFI_STATUS
341
342 **/
343 EFI_STATUS
344 LibGetFvInfo (
345 IN VOID *Fv,
346 IN OUT FV_INFORMATION *CurrentFv,
347 IN CHAR8 *FvName,
348 IN UINT8 Level,
349 IN ENCAP_INFO_DATA **CurrentFvEncapData,
350 IN UINT32 *FfsCount,
351 IN OUT UINT8 *FvCount,
352 IN BOOLEAN ViewFlag,
353 IN BOOLEAN IsChildFv
354 );
355
356 /*
357 Get size info from FV file.
358
359 @param[in]
360 @param[out]
361
362 @retval
363
364 */
365 EFI_STATUS
366 LibGetFvSize (
367 IN FILE *InputFile,
368 OUT UINT32 *FvSize
369 );
370
371 /**
372
373 This function returns the next larger size that meets the alignment
374 requirement specified.
375
376 @param[in] ActualSize The size.
377 @param[in] Alignment The desired alignment.
378
379 @retval EFI_SUCCESS Function completed successfully.
380 @retval EFI_ABORTED The function encountered an error.
381
382 **/
383 UINT32
384 GetOccupiedSize (
385 IN UINT32 ActualSize,
386 IN UINT32 Alignment
387 );
388
389 /**
390 Converts ASCII characters to Unicode.
391 Assumes that the Unicode characters are only these defined in the ASCII set.
392
393 String - Pointer to string that is written to FILE.
394 UniString - Pointer to unicode string
395
396 The address to the ASCII string - same as AsciiStr.
397
398 **/
399 VOID
400 LibAscii2Unicode (
401 IN CHAR8 *String,
402 OUT CHAR16 *UniString
403 );
404
405 /**
406 Delete a directory and files in it.
407
408 @param[in] DirName Name of the directory need to be deleted.
409
410 @return EFI_INVALID_PARAMETER
411 @return EFI_SUCCESS
412 **/
413 EFI_STATUS
414 LibRmDir (
415 IN CHAR8* DirName
416 );
417
418 /**
419 Delete a file.
420
421 @param[in] FileName Name of the file need to be deleted.
422
423 @return EFI_INVALID_PARAMETER
424 @return EFI_SUCCESS
425 **/
426 EFI_STATUS
427 LibFmmtDeleteFile(
428 IN CHAR8 *FileName
429 );
430
431
432 /**
433
434 Free the whole Fd data structure.
435
436 @param[in] Fd The pointer point to the Fd data structure.
437
438 **/
439 VOID
440 LibFmmtFreeFd (
441 FIRMWARE_DEVICE *Fd
442 );
443
444
445 EFI_STATUS
446 LibEncapNewFvFile(
447 IN FV_INFORMATION *FvInFd,
448 IN CHAR8 *TemDir,
449 IN ENCAP_INFO_DATA *CurrentEncapData,
450 IN UINT32 Level_Break,
451 OUT FFS_INFORMATION **OutputFile
452 );
453
454
455 EFI_STATUS
456 LibLocateFvViaFvId (
457 IN FIRMWARE_DEVICE *FdData,
458 IN CHAR8 *FvId,
459 IN OUT FV_INFORMATION **FvInFd
460 );
461
462 EFI_HANDLE
463 LibPreDefinedGuidedTools (
464 VOID
465 );
466
467 EFI_STATUS
468 FvBufGetSize(
469 IN VOID *Fv,
470 OUT UINTN *Size
471 );
472
473 EFI_STATUS
474 FvBufFindNextFile(
475 IN VOID *Fv,
476 IN OUT UINTN *Key,
477 OUT VOID **File
478 );
479 #endif