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