]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/GenFv/GenFvInternalLib.h
BaseTools: Remove unused logic from C tools
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFvInternalLib.h
1 /** @file
2 This file contains describes the public interfaces to the GenFvImage Library.
3 The basic purpose of the library is to create Firmware Volume images.
4
5 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _EFI_GEN_FV_INTERNAL_LIB_H
17 #define _EFI_GEN_FV_INTERNAL_LIB_H
18
19 //
20 // Include files
21 //
22 #include <stdlib.h>
23
24 #include <Common/UefiBaseTypes.h>
25 #include <Common/UefiCapsule.h>
26
27 #include <Common/PiFirmwareFile.h>
28 #include <Common/PiFirmwareVolume.h>
29 #include <Guid/PiFirmwareFileSystem.h>
30 #include <IndustryStandard/PeImage.h>
31
32 #include "CommonLib.h"
33 #include "ParseInf.h"
34 #include "EfiUtilityMsgs.h"
35
36 //
37 // Different file separater for Linux and Windows
38 //
39 #define FILE_SEP_CHAR '/'
40
41 //
42 // The maximum number of Pad file guid entries.
43 //
44 #define MAX_NUMBER_OF_PAD_FILE_GUIDS 1024
45
46 //
47 // The maximum number of block map entries supported by the library
48 //
49 #define MAX_NUMBER_OF_FV_BLOCKS 100
50
51 //
52 // The maximum number of files in the FV supported by the library
53 //
54 #define MAX_NUMBER_OF_FILES_IN_FV 1000
55 #define MAX_NUMBER_OF_FILES_IN_CAP 1000
56 #define EFI_FFS_FILE_HEADER_ALIGNMENT 8
57 //
58 // INF file strings
59 //
60 #define OPTIONS_SECTION_STRING "[options]"
61 #define ATTRIBUTES_SECTION_STRING "[attributes]"
62 #define FILES_SECTION_STRING "[files]"
63 #define FV_BASE_ADDRESS_STRING "[FV_BASE_ADDRESS]"
64
65 //
66 // Options section
67 //
68 #define EFI_FV_BASE_ADDRESS_STRING "EFI_BASE_ADDRESS"
69 #define EFI_FV_FILE_NAME_STRING "EFI_FILE_NAME"
70 #define EFI_NUM_BLOCKS_STRING "EFI_NUM_BLOCKS"
71 #define EFI_BLOCK_SIZE_STRING "EFI_BLOCK_SIZE"
72 #define EFI_GUID_STRING "EFI_GUID"
73 #define EFI_FV_FILESYSTEMGUID_STRING "EFI_FV_GUID"
74 #define EFI_FV_NAMEGUID_STRING "EFI_FVNAME_GUID"
75 #define EFI_CAPSULE_GUID_STRING "EFI_CAPSULE_GUID"
76 #define EFI_CAPSULE_HEADER_SIZE_STRING "EFI_CAPSULE_HEADER_SIZE"
77 #define EFI_CAPSULE_FLAGS_STRING "EFI_CAPSULE_FLAGS"
78 #define EFI_OEM_CAPSULE_FLAGS_STRING "EFI_OEM_CAPSULE_FLAGS"
79 #define EFI_CAPSULE_VERSION_STRING "EFI_CAPSULE_VERSION"
80
81 #define EFI_FV_TOTAL_SIZE_STRING "EFI_FV_TOTAL_SIZE"
82 #define EFI_FV_TAKEN_SIZE_STRING "EFI_FV_TAKEN_SIZE"
83 #define EFI_FV_SPACE_SIZE_STRING "EFI_FV_SPACE_SIZE"
84
85 //
86 // Attributes section
87 //
88 #define EFI_FVB2_READ_DISABLED_CAP_STRING "EFI_READ_DISABLED_CAP"
89 #define EFI_FVB2_READ_ENABLED_CAP_STRING "EFI_READ_ENABLED_CAP"
90 #define EFI_FVB2_READ_STATUS_STRING "EFI_READ_STATUS"
91
92 #define EFI_FVB2_WRITE_DISABLED_CAP_STRING "EFI_WRITE_DISABLED_CAP"
93 #define EFI_FVB2_WRITE_ENABLED_CAP_STRING "EFI_WRITE_ENABLED_CAP"
94 #define EFI_FVB2_WRITE_STATUS_STRING "EFI_WRITE_STATUS"
95
96 #define EFI_FVB2_LOCK_CAP_STRING "EFI_LOCK_CAP"
97 #define EFI_FVB2_LOCK_STATUS_STRING "EFI_LOCK_STATUS"
98
99 #define EFI_FVB2_STICKY_WRITE_STRING "EFI_STICKY_WRITE"
100 #define EFI_FVB2_MEMORY_MAPPED_STRING "EFI_MEMORY_MAPPED"
101 #define EFI_FVB2_ERASE_POLARITY_STRING "EFI_ERASE_POLARITY"
102
103 #define EFI_FVB2_READ_LOCK_CAP_STRING "EFI_READ_LOCK_CAP"
104 #define EFI_FVB2_READ_LOCK_STATUS_STRING "EFI_READ_LOCK_STATUS"
105 #define EFI_FVB2_WRITE_LOCK_CAP_STRING "EFI_WRITE_LOCK_CAP"
106 #define EFI_FVB2_WRITE_LOCK_STATUS_STRING "EFI_WRITE_LOCK_STATUS"
107
108 #define EFI_FVB2_ALIGNMENT_1_STRING "EFI_FVB2_ALIGNMENT_1"
109 #define EFI_FVB2_ALIGNMENT_2_STRING "EFI_FVB2_ALIGNMENT_2"
110 #define EFI_FVB2_ALIGNMENT_4_STRING "EFI_FVB2_ALIGNMENT_4"
111 #define EFI_FVB2_ALIGNMENT_8_STRING "EFI_FVB2_ALIGNMENT_8"
112 #define EFI_FVB2_ALIGNMENT_16_STRING "EFI_FVB2_ALIGNMENT_16"
113 #define EFI_FVB2_ALIGNMENT_32_STRING "EFI_FVB2_ALIGNMENT_32"
114 #define EFI_FVB2_ALIGNMENT_64_STRING "EFI_FVB2_ALIGNMENT_64"
115 #define EFI_FVB2_ALIGNMENT_128_STRING "EFI_FVB2_ALIGNMENT_128"
116 #define EFI_FVB2_ALIGNMENT_256_STRING "EFI_FVB2_ALIGNMENT_256"
117 #define EFI_FVB2_ALIGNMENT_512_STRING "EFI_FVB2_ALIGNMENT_512"
118 #define EFI_FVB2_ALIGNMENT_1K_STRING "EFI_FVB2_ALIGNMENT_1K"
119 #define EFI_FVB2_ALIGNMENT_2K_STRING "EFI_FVB2_ALIGNMENT_2K"
120 #define EFI_FVB2_ALIGNMENT_4K_STRING "EFI_FVB2_ALIGNMENT_4K"
121 #define EFI_FVB2_ALIGNMENT_8K_STRING "EFI_FVB2_ALIGNMENT_8K"
122 #define EFI_FVB2_ALIGNMENT_16K_STRING "EFI_FVB2_ALIGNMENT_16K"
123 #define EFI_FVB2_ALIGNMENT_32K_STRING "EFI_FVB2_ALIGNMENT_32K"
124 #define EFI_FVB2_ALIGNMENT_64K_STRING "EFI_FVB2_ALIGNMENT_64K"
125 #define EFI_FVB2_ALIGNMENT_128K_STRING "EFI_FVB2_ALIGNMENT_128K"
126 #define EFI_FVB2_ALIGNMENT_256K_STRING "EFI_FVB2_ALIGNMENT_256K"
127 #define EFI_FVB2_ALIGNMENT_512K_STRING "EFI_FVB2_ALIGNMENT_512K"
128 #define EFI_FVB2_ALIGNMENT_1M_STRING "EFI_FVB2_ALIGNMENT_1M"
129 #define EFI_FVB2_ALIGNMENT_2M_STRING "EFI_FVB2_ALIGNMENT_2M"
130 #define EFI_FVB2_ALIGNMENT_4M_STRING "EFI_FVB2_ALIGNMENT_4M"
131 #define EFI_FVB2_ALIGNMENT_8M_STRING "EFI_FVB2_ALIGNMENT_8M"
132 #define EFI_FVB2_ALIGNMENT_16M_STRING "EFI_FVB2_ALIGNMENT_16M"
133 #define EFI_FVB2_ALIGNMENT_32M_STRING "EFI_FVB2_ALIGNMENT_32M"
134 #define EFI_FVB2_ALIGNMENT_64M_STRING "EFI_FVB2_ALIGNMENT_64M"
135 #define EFI_FVB2_ALIGNMENT_128M_STRING "EFI_FVB2_ALIGNMENT_128M"
136 #define EFI_FVB2_ALIGNMENT_256M_STRING "EFI_FVB2_ALIGNMENT_256M"
137 #define EFI_FVB2_ALIGNMENT_512M_STRING "EFI_FVB2_ALIGNMENT_512M"
138 #define EFI_FVB2_ALIGNMENT_1G_STRING "EFI_FVB2_ALIGNMENT_1G"
139 #define EFI_FVB2_ALIGNMENT_2G_STRING "EFI_FVB2_ALIGNMENT_2G"
140
141 #define EFI_FV_WEAK_ALIGNMENT_STRING "EFI_WEAK_ALIGNMENT"
142
143 //
144 // File sections
145 //
146 #define EFI_FILE_NAME_STRING "EFI_FILE_NAME"
147
148 #define ONE_STRING "1"
149 #define ZERO_STRING "0"
150 #define TRUE_STRING "TRUE"
151 #define FALSE_STRING "FALSE"
152 #define NULL_STRING "NULL"
153
154 //
155 //
156 //
157 #define EFI_FV_EXT_HEADER_FILE_NAME "EFI_FV_EXT_HEADER_FILE_NAME"
158
159
160 //
161 // VTF (Firmware Volume Top File) signatures
162 //
163 #define IA32_X64_VTF_SIGNATURE_OFFSET 0x14
164 #define IA32_X64_VTF0_SIGNATURE SIGNATURE_32('V','T','F',0)
165
166 //
167 // Defines to calculate the offset for PEI CORE entry points
168 //
169 #define IA32_PEI_CORE_ENTRY_OFFSET 0x20
170
171 //
172 // Defines to calculate the offset for IA32 SEC CORE entry point
173 //
174 #define IA32_SEC_CORE_ENTRY_OFFSET 0xD
175
176 //
177 // Symbol file definitions, current max size if 512K
178 //
179 #define SYMBOL_FILE_SIZE 0x80000
180
181 #define FV_IMAGES_TOP_ADDRESS 0x100000000ULL
182
183 //
184 // Following definition is used for FIT in IPF
185 //
186 #define COMP_TYPE_FIT_PEICORE 0x10
187 #define COMP_TYPE_FIT_UNUSED 0x7F
188
189 #define FIT_TYPE_MASK 0x7F
190 #define CHECKSUM_BIT_MASK 0x80
191
192 //
193 // Private data types
194 //
195 //
196 // Component information
197 //
198 typedef struct {
199 UINTN Size;
200 CHAR8 ComponentName[MAX_LONG_FILE_PATH];
201 } COMPONENT_INFO;
202
203 //
204 // FV and capsule information holder
205 //
206 typedef struct {
207 BOOLEAN BaseAddressSet;
208 EFI_PHYSICAL_ADDRESS BaseAddress;
209 EFI_GUID FvFileSystemGuid;
210 BOOLEAN FvFileSystemGuidSet;
211 EFI_GUID FvNameGuid;
212 BOOLEAN FvNameGuidSet;
213 CHAR8 FvExtHeaderFile[MAX_LONG_FILE_PATH];
214 UINTN Size;
215 EFI_FVB_ATTRIBUTES_2 FvAttributes;
216 CHAR8 FvName[MAX_LONG_FILE_PATH];
217 EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS];
218 CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][MAX_LONG_FILE_PATH];
219 UINT32 SizeofFvFiles[MAX_NUMBER_OF_FILES_IN_FV];
220 BOOLEAN IsPiFvImage;
221 INT8 ForceRebase;
222 } FV_INFO;
223
224 typedef struct {
225 EFI_GUID CapGuid;
226 UINT32 HeaderSize;
227 UINT32 Flags;
228 CHAR8 CapName[MAX_LONG_FILE_PATH];
229 CHAR8 CapFiles[MAX_NUMBER_OF_FILES_IN_CAP][MAX_LONG_FILE_PATH];
230 } CAP_INFO;
231
232 #pragma pack(1)
233
234 typedef struct {
235 UINT64 CompAddress;
236 UINT32 CompSize;
237 UINT16 CompVersion;
238 UINT8 CvAndType;
239 UINT8 CheckSum;
240 } FIT_TABLE;
241
242 #pragma pack()
243
244 #define FV_DEFAULT_ATTRIBUTE 0x0004FEFF
245 extern FV_INFO mFvDataInfo;
246 extern CAP_INFO mCapDataInfo;
247 extern EFI_GUID mEfiFirmwareFileSystem2Guid;
248 extern EFI_GUID mEfiFirmwareFileSystem3Guid;
249 extern UINT32 mFvTotalSize;
250 extern UINT32 mFvTakenSize;
251
252 extern EFI_PHYSICAL_ADDRESS mFvBaseAddress[];
253 extern UINT32 mFvBaseAddressNumber;
254 //
255 // Local function prototypes
256 //
257 EFI_STATUS
258 ParseFvInf (
259 IN MEMORY_FILE *InfFile,
260 OUT FV_INFO *FvInfo
261 )
262 ;
263
264 EFI_STATUS
265 UpdatePeiCoreEntryInFit (
266 IN FIT_TABLE *FitTablePtr,
267 IN UINT64 PeiCorePhysicalAddress
268 )
269 /*++
270
271 Routine Description:
272
273 This function is used to update the Pei Core address in FIT, this can be used by Sec core to pass control from
274 Sec to Pei Core
275
276 Arguments:
277
278 FitTablePtr - The pointer of FIT_TABLE.
279 PeiCorePhysicalAddress - The address of Pei Core entry.
280
281 Returns:
282
283 EFI_SUCCESS - The PEI_CORE FIT entry was updated successfully.
284 EFI_NOT_FOUND - Not found the PEI_CORE FIT entry.
285
286 --*/
287 ;
288
289 VOID
290 UpdateFitCheckSum (
291 IN FIT_TABLE *FitTablePtr
292 )
293 /*++
294
295 Routine Description:
296
297 This function is used to update the checksum for FIT.
298
299
300 Arguments:
301
302 FitTablePtr - The pointer of FIT_TABLE.
303
304 Returns:
305
306 None.
307
308 --*/
309 ;
310
311 EFI_STATUS
312 GetPe32Info (
313 IN UINT8 *Pe32,
314 OUT UINT32 *EntryPoint,
315 OUT UINT32 *BaseOfCode,
316 OUT UINT16 *MachineType
317 );
318
319 EFI_STATUS
320 ParseCapInf (
321 IN MEMORY_FILE *InfFile,
322 OUT CAP_INFO *CapInfo
323 );
324
325 EFI_STATUS
326 FindApResetVectorPosition (
327 IN MEMORY_FILE *FvImage,
328 OUT UINT8 **Pointer
329 );
330
331 EFI_STATUS
332 CalculateFvSize (
333 FV_INFO *FvInfoPtr
334 );
335
336 EFI_STATUS
337 FfsRebase (
338 IN OUT FV_INFO *FvInfo,
339 IN CHAR8 *FileName,
340 IN OUT EFI_FFS_FILE_HEADER *FfsFile,
341 IN UINTN XipOffset,
342 IN FILE *FvMapFile
343 );
344
345 //
346 // Exported function prototypes
347 //
348 EFI_STATUS
349 GenerateCapImage (
350 IN CHAR8 *InfFileImage,
351 IN UINTN InfFileSize,
352 IN CHAR8 *CapFileName
353 )
354 /*++
355
356 Routine Description:
357
358 This is the main function which will be called from application to
359 generate UEFI Capsule image.
360
361 Arguments:
362
363 InfFileImage Buffer containing the INF file contents.
364 InfFileSize Size of the contents of the InfFileImage buffer.
365 CapFileName Requested name for the Cap file.
366
367 Returns:
368
369 EFI_SUCCESS Function completed successfully.
370 EFI_OUT_OF_RESOURCES Could not allocate required resources.
371 EFI_ABORTED Error encountered.
372 EFI_INVALID_PARAMETER A required parameter was NULL.
373
374 --*/
375 ;
376
377 EFI_STATUS
378 GenerateFvImage (
379 IN CHAR8 *InfFileImage,
380 IN UINTN InfFileSize,
381 IN CHAR8 *FvFileName,
382 IN CHAR8 *MapFileName
383 )
384 /*++
385
386 Routine Description:
387
388 This is the main function which will be called from application to
389 generate Firmware Image conforms to PI spec.
390
391 Arguments:
392
393 InfFileImage Buffer containing the INF file contents.
394 InfFileSize Size of the contents of the InfFileImage buffer.
395 FvFileName Requested name for the FV file.
396 MapFileName Fv map file to log fv driver information.
397
398 Returns:
399
400 EFI_SUCCESS Function completed successfully.
401 EFI_OUT_OF_RESOURCES Could not allocate required resources.
402 EFI_ABORTED Error encountered.
403 EFI_INVALID_PARAMETER A required parameter was NULL.
404
405 --*/
406 ;
407
408 #endif