3 Structures and functions declaration.
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _BIN_FILE_MANAGER_
11 #define _BIN_FILE_MANAGER_
23 #include <Common/UefiBaseTypes.h>
24 #include <Common/PiFirmwareVolume.h>
25 #include <Common/PiFirmwareFile.h>
26 #include <Protocol/GuidedSectionExtraction.h>
28 #include "CommonLib.h"
29 #include "EfiUtilityMsgs.h"
31 #include "ParseGuidedSectionTools.h"
32 #include "StringFuncs.h"
34 #include "Decompress.h"
40 #if defined(_MSC_VER) && _MSC_VER < 1900
41 #define snprintf _snprintf
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"
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"
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)
65 // The maximum number of Pad file guid entries.
67 #define MAX_NUMBER_OF_PAD_FILE_GUIDS 1024
70 // The maximum number of block map entries supported by the library
72 #define MAX_NUMBER_OF_FV_BLOCKS 100
76 // The maximum number of sections in an FFS file.
78 #define MAX_NUMBER_OF_SECTION_IN_FFS 100
81 // The maximum number of files in the FV supported by the library
83 #define MAX_NUMBER_OF_FILES_IN_FV 1000
84 #define MAX_NUMBER_OF_FILES_IN_CAP 1000
89 /// If present, this must be the first and only opcode,
90 /// EFI_DEP_BEFORE is only used by DXE driver.
92 #define EFI_DEP_BEFORE 0x00
95 /// If present, this must be the first and only opcode,
96 /// EFI_DEP_AFTER is only used by DXE driver.
98 #define EFI_DEP_AFTER 0x01
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
110 /// If present, this must be the first opcode,
111 /// EFI_DEP_SOR is only used by DXE driver.
113 #define EFI_DEP_SOR 0x09
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]"
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"
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"
143 typedef UINT32 FMMT_ENCAP_TYPE
;
145 #define MAX_LEVEL_IN_FV_FILE 32
148 // Types of FMMT_ENCAP_TREENODE_TYPE
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
156 extern EFI_HANDLE mParsedGuidedSectionTools
;
159 #define TEMP_DIR_NAME "FmmtTemp"
162 // Structure to keep a list of GUID-To-BaseNames
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
];
171 typedef struct _GUID_SEC_TOOL_ENTRY
{
175 struct _GUID_SEC_TOOL_ENTRY
*Next
;
176 } GUID_SEC_TOOL_ENTRY
;
180 // Private data types
183 // Component information
187 CHAR8 ComponentName
[_MAX_PATH
];
191 CHAR8 FfsName
[_MAX_PATH
];
194 // UI Name for this FFS file, if has.
196 CHAR16 UiName
[_MAX_PATH
];
199 // Total section number in this FFS.
201 UINT32 TotalSectionNum
;
204 // Describe the position of the FFS file.
208 // If this FFS has no encapsulate section, this flag will set to True.
212 // Section type for each section in FFS.
214 EFI_SECTION_TYPE SectionType
[MAX_NUMBER_OF_SECTION_IN_FFS
];
216 // Offset relative to current FV
229 typedef struct __ENCAP_INFO_DATA
{
238 FMMT_ENCAP_TYPE Type
;
241 // Data, if it's FV, should be FV header.
246 //FvId, match FvId with FvGuidName.
251 // if FV ExtHeaderOffset not to zero, should also have FvExtHeader information
253 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FvExtHeader
;
255 CHAR16 UiName
[_MAX_PATH
];
263 struct __ENCAP_INFO_DATA
*NextNode
;
268 struct __ENCAP_INFO_DATA
*RightNode
;
271 typedef struct _FFS_INFOMATION
{
276 CHAR16 UiName
[_MAX_PATH
];
280 BOOLEAN FfsFoundFlag
;
281 struct _FFS_INFOMATION
*Next
;
285 // FV and capsule information holder
287 typedef struct _FV_INFOMATION
{
288 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
289 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FvExtHeader
;
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
;
301 CHAR8 AlignmentStr
[16];
302 FFS_INFORMATION
*ChildFvFFS
;
305 typedef struct _FIRMWARE_DEVICE
{
313 typedef struct _FILENode
{
316 struct _FILENode
*Next
;
323 FIRMWARE_DEVICE
*FdData
;
325 FV_INFORMATION
*FvInFd
;
331 IN OUT FIRMWARE_DEVICE
**FdData
336 TODO: Add function description
338 @param[in] Fv - Firmware Volume to get information from
346 IN OUT FV_INFORMATION
*CurrentFv
,
349 IN ENCAP_INFO_DATA
**CurrentFvEncapData
,
351 IN OUT UINT8
*FvCount
,
357 Get size info from FV file.
373 This function returns the next larger size that meets the alignment
374 requirement specified.
376 @param[in] ActualSize The size.
377 @param[in] Alignment The desired alignment.
379 @retval EFI_SUCCESS Function completed successfully.
380 @retval EFI_ABORTED The function encountered an error.
385 IN UINT32 ActualSize
,
390 Converts ASCII characters to Unicode.
391 Assumes that the Unicode characters are only these defined in the ASCII set.
393 String - Pointer to string that is written to FILE.
394 UniString - Pointer to unicode string
396 The address to the ASCII string - same as AsciiStr.
402 OUT CHAR16
*UniString
406 Delete a directory and files in it.
408 @param[in] DirName Name of the directory need to be deleted.
410 @return EFI_INVALID_PARAMETER
421 @param[in] FileName Name of the file need to be deleted.
423 @return EFI_INVALID_PARAMETER
434 Free the whole Fd data structure.
436 @param[in] Fd The pointer point to the Fd data structure.
447 IN FV_INFORMATION
*FvInFd
,
449 IN ENCAP_INFO_DATA
*CurrentEncapData
,
450 IN UINT32 Level_Break
,
451 OUT FFS_INFORMATION
**OutputFile
457 IN FIRMWARE_DEVICE
*FdData
,
459 IN OUT FV_INFORMATION
**FvInFd
463 LibPreDefinedGuidedTools (