]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/GenFv/GenFvInternalLib.h
Sync BaseTool trunk (version r2610) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFvInternalLib.h
1 /** @file
2
3 Copyright (c) 2004 - 2013, 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_OEM_CAPSULE_FLAGS_STRING "EFI_OEM_CAPSULE_FLAGS"
86 #define EFI_CAPSULE_VERSION_STRING "EFI_CAPSULE_VERSION"
87
88 #define EFI_FV_TOTAL_SIZE_STRING "EFI_FV_TOTAL_SIZE"
89 #define EFI_FV_TAKEN_SIZE_STRING "EFI_FV_TAKEN_SIZE"
90 #define EFI_FV_SPACE_SIZE_STRING "EFI_FV_SPACE_SIZE"
91
92 //
93 // Attributes section
94 //
95 #define EFI_FVB2_READ_DISABLED_CAP_STRING "EFI_READ_DISABLED_CAP"
96 #define EFI_FVB2_READ_ENABLED_CAP_STRING "EFI_READ_ENABLED_CAP"
97 #define EFI_FVB2_READ_STATUS_STRING "EFI_READ_STATUS"
98
99 #define EFI_FVB2_WRITE_DISABLED_CAP_STRING "EFI_WRITE_DISABLED_CAP"
100 #define EFI_FVB2_WRITE_ENABLED_CAP_STRING "EFI_WRITE_ENABLED_CAP"
101 #define EFI_FVB2_WRITE_STATUS_STRING "EFI_WRITE_STATUS"
102
103 #define EFI_FVB2_LOCK_CAP_STRING "EFI_LOCK_CAP"
104 #define EFI_FVB2_LOCK_STATUS_STRING "EFI_LOCK_STATUS"
105
106 #define EFI_FVB2_STICKY_WRITE_STRING "EFI_STICKY_WRITE"
107 #define EFI_FVB2_MEMORY_MAPPED_STRING "EFI_MEMORY_MAPPED"
108 #define EFI_FVB2_ERASE_POLARITY_STRING "EFI_ERASE_POLARITY"
109
110 #define EFI_FVB2_READ_LOCK_CAP_STRING "EFI_READ_LOCK_CAP"
111 #define EFI_FVB2_READ_LOCK_STATUS_STRING "EFI_READ_LOCK_STATUS"
112 #define EFI_FVB2_WRITE_LOCK_CAP_STRING "EFI_WRITE_LOCK_CAP"
113 #define EFI_FVB2_WRITE_LOCK_STATUS_STRING "EFI_WRITE_LOCK_STATUS"
114
115 #define EFI_FVB2_ALIGNMENT_1_STRING "EFI_FVB2_ALIGNMENT_1"
116 #define EFI_FVB2_ALIGNMENT_2_STRING "EFI_FVB2_ALIGNMENT_2"
117 #define EFI_FVB2_ALIGNMENT_4_STRING "EFI_FVB2_ALIGNMENT_4"
118 #define EFI_FVB2_ALIGNMENT_8_STRING "EFI_FVB2_ALIGNMENT_8"
119 #define EFI_FVB2_ALIGNMENT_16_STRING "EFI_FVB2_ALIGNMENT_16"
120 #define EFI_FVB2_ALIGNMENT_32_STRING "EFI_FVB2_ALIGNMENT_32"
121 #define EFI_FVB2_ALIGNMENT_64_STRING "EFI_FVB2_ALIGNMENT_64"
122 #define EFI_FVB2_ALIGNMENT_128_STRING "EFI_FVB2_ALIGNMENT_128"
123 #define EFI_FVB2_ALIGNMENT_256_STRING "EFI_FVB2_ALIGNMENT_256"
124 #define EFI_FVB2_ALIGNMENT_512_STRING "EFI_FVB2_ALIGNMENT_512"
125 #define EFI_FVB2_ALIGNMENT_1K_STRING "EFI_FVB2_ALIGNMENT_1K"
126 #define EFI_FVB2_ALIGNMENT_2K_STRING "EFI_FVB2_ALIGNMENT_2K"
127 #define EFI_FVB2_ALIGNMENT_4K_STRING "EFI_FVB2_ALIGNMENT_4K"
128 #define EFI_FVB2_ALIGNMENT_8K_STRING "EFI_FVB2_ALIGNMENT_8K"
129 #define EFI_FVB2_ALIGNMENT_16K_STRING "EFI_FVB2_ALIGNMENT_16K"
130 #define EFI_FVB2_ALIGNMENT_32K_STRING "EFI_FVB2_ALIGNMENT_32K"
131 #define EFI_FVB2_ALIGNMENT_64K_STRING "EFI_FVB2_ALIGNMENT_64K"
132 #define EFI_FVB2_ALIGNMENT_128K_STRING "EFI_FVB2_ALIGNMENT_128K"
133 #define EFI_FVB2_ALIGNMENT_256K_STRING "EFI_FVB2_ALIGNMENT_256K"
134 #define EFI_FVB2_ALIGNMENT_512K_STRING "EFI_FVB2_ALIGNMENT_512K"
135 #define EFI_FVB2_ALIGNMENT_1M_STRING "EFI_FVB2_ALIGNMENT_1M"
136 #define EFI_FVB2_ALIGNMENT_2M_STRING "EFI_FVB2_ALIGNMENT_2M"
137 #define EFI_FVB2_ALIGNMENT_4M_STRING "EFI_FVB2_ALIGNMENT_4M"
138 #define EFI_FVB2_ALIGNMENT_8M_STRING "EFI_FVB2_ALIGNMENT_8M"
139 #define EFI_FVB2_ALIGNMENT_16M_STRING "EFI_FVB2_ALIGNMENT_16M"
140 #define EFI_FVB2_ALIGNMENT_32M_STRING "EFI_FVB2_ALIGNMENT_32M"
141 #define EFI_FVB2_ALIGNMENT_64M_STRING "EFI_FVB2_ALIGNMENT_64M"
142 #define EFI_FVB2_ALIGNMENT_128M_STRING "EFI_FVB2_ALIGNMENT_128M"
143 #define EFI_FVB2_ALIGNMENT_256M_STRING "EFI_FVB2_ALIGNMENT_256M"
144 #define EFI_FVB2_ALIGNMENT_512M_STRING "EFI_FVB2_ALIGNMENT_512M"
145 #define EFI_FVB2_ALIGNMENT_1G_STRING "EFI_FVB2_ALIGNMENT_1G"
146 #define EFI_FVB2_ALIGNMENT_2G_STRING "EFI_FVB2_ALIGNMENT_2G"
147
148 #define EFI_FV_WEAK_ALIGNMENT_STRING "EFI_WEAK_ALIGNMENT"
149
150 //
151 // File sections
152 //
153 #define EFI_FILE_NAME_STRING "EFI_FILE_NAME"
154
155 #define ONE_STRING "1"
156 #define ZERO_STRING "0"
157 #define TRUE_STRING "TRUE"
158 #define FALSE_STRING "FALSE"
159 #define NULL_STRING "NULL"
160
161 //
162 //
163 //
164 #define EFI_FV_EXT_HEADER_FILE_NAME "EFI_FV_EXT_HEADER_FILE_NAME"
165
166
167 //
168 // VTF (Firmware Volume Top File) signatures
169 //
170 #define IA32_X64_VTF_SIGNATURE_OFFSET 0x14
171 #define IA32_X64_VTF0_SIGNATURE EFI_SIGNATURE_32('V','T','F',0)
172
173 //
174 // Defines to calculate the offset for PEI CORE entry points
175 //
176 #define IA32_PEI_CORE_ENTRY_OFFSET 0x20
177
178 //
179 // Defines to calculate the offset for IA32 SEC CORE entry point
180 //
181 #define IA32_SEC_CORE_ENTRY_OFFSET 0xD
182
183 //
184 // Defines to calculate the FIT table
185 //
186 #define IPF_FIT_ADDRESS_OFFSET 0x20
187
188 //
189 // Defines to calculate the offset for SALE_ENTRY
190 //
191 #define IPF_SALE_ENTRY_ADDRESS_OFFSET 0x18
192
193 //
194 // Symbol file definitions, current max size if 512K
195 //
196 #define SYMBOL_FILE_SIZE 0x80000
197
198 #define FV_IMAGES_TOP_ADDRESS 0x100000000ULL
199
200 //
201 // Following definition is used for FIT in IPF
202 //
203 #define COMP_TYPE_FIT_PEICORE 0x10
204 #define COMP_TYPE_FIT_UNUSED 0x7F
205
206 #define FIT_TYPE_MASK 0x7F
207 #define CHECKSUM_BIT_MASK 0x80
208
209 //
210 // Private data types
211 //
212 //
213 // Component information
214 //
215 typedef struct {
216 UINTN Size;
217 CHAR8 ComponentName[_MAX_PATH];
218 } COMPONENT_INFO;
219
220 //
221 // FV and capsule information holder
222 //
223 typedef struct {
224 BOOLEAN BaseAddressSet;
225 EFI_PHYSICAL_ADDRESS BaseAddress;
226 EFI_GUID FvFileSystemGuid;
227 BOOLEAN FvFileSystemGuidSet;
228 EFI_GUID FvNameGuid;
229 BOOLEAN FvNameGuidSet;
230 CHAR8 FvExtHeaderFile[_MAX_PATH];
231 UINTN Size;
232 EFI_FVB_ATTRIBUTES_2 FvAttributes;
233 CHAR8 FvName[_MAX_PATH];
234 EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS];
235 CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][_MAX_PATH];
236 UINT32 SizeofFvFiles[MAX_NUMBER_OF_FILES_IN_FV];
237 BOOLEAN IsPiFvImage;
238 INT8 ForceRebase;
239 } FV_INFO;
240
241 typedef struct {
242 EFI_GUID CapGuid;
243 UINT32 HeaderSize;
244 UINT32 Flags;
245 CHAR8 CapName[_MAX_PATH];
246 CHAR8 CapFiles[MAX_NUMBER_OF_FILES_IN_CAP][_MAX_PATH];
247 } CAP_INFO;
248
249 #pragma pack(1)
250
251 typedef struct {
252 UINT64 CompAddress;
253 UINT32 CompSize;
254 UINT16 CompVersion;
255 UINT8 CvAndType;
256 UINT8 CheckSum;
257 } FIT_TABLE;
258
259 #pragma pack()
260
261 #define FV_DEFAULT_ATTRIBUTE 0x0004FEFF
262 extern FV_INFO mFvDataInfo;
263 extern CAP_INFO mCapDataInfo;
264 extern EFI_GUID mEfiFirmwareFileSystem2Guid;
265 extern EFI_GUID mEfiFirmwareFileSystem3Guid;
266 extern UINT32 mFvTotalSize;
267 extern UINT32 mFvTakenSize;
268
269 extern EFI_PHYSICAL_ADDRESS mFvBaseAddress[];
270 extern UINT32 mFvBaseAddressNumber;
271 //
272 // Local function prototypes
273 //
274 EFI_STATUS
275 ParseFvInf (
276 IN MEMORY_FILE *InfFile,
277 OUT FV_INFO *FvInfo
278 )
279 ;
280
281 EFI_STATUS
282 UpdatePeiCoreEntryInFit (
283 IN FIT_TABLE *FitTablePtr,
284 IN UINT64 PeiCorePhysicalAddress
285 )
286 /*++
287
288 Routine Description:
289
290 This function is used to update the Pei Core address in FIT, this can be used by Sec core to pass control from
291 Sec to Pei Core
292
293 Arguments:
294
295 FitTablePtr - The pointer of FIT_TABLE.
296 PeiCorePhysicalAddress - The address of Pei Core entry.
297
298 Returns:
299
300 EFI_SUCCESS - The PEI_CORE FIT entry was updated successfully.
301 EFI_NOT_FOUND - Not found the PEI_CORE FIT entry.
302
303 --*/
304 ;
305
306 VOID
307 UpdateFitCheckSum (
308 IN FIT_TABLE *FitTablePtr
309 )
310 /*++
311
312 Routine Description:
313
314 This function is used to update the checksum for FIT.
315
316
317 Arguments:
318
319 FitTablePtr - The pointer of FIT_TABLE.
320
321 Returns:
322
323 None.
324
325 --*/
326 ;
327
328 EFI_STATUS
329 GetPe32Info (
330 IN UINT8 *Pe32,
331 OUT UINT32 *EntryPoint,
332 OUT UINT32 *BaseOfCode,
333 OUT UINT16 *MachineType
334 );
335
336 EFI_STATUS
337 ParseCapInf (
338 IN MEMORY_FILE *InfFile,
339 OUT CAP_INFO *CapInfo
340 );
341
342 EFI_STATUS
343 FindApResetVectorPosition (
344 IN MEMORY_FILE *FvImage,
345 OUT UINT8 **Pointer
346 );
347
348 EFI_STATUS
349 CalculateFvSize (
350 FV_INFO *FvInfoPtr
351 );
352
353 EFI_STATUS
354 FfsRebase (
355 IN OUT FV_INFO *FvInfo,
356 IN CHAR8 *FileName,
357 IN OUT EFI_FFS_FILE_HEADER *FfsFile,
358 IN UINTN XipOffset,
359 IN FILE *FvMapFile
360 );
361
362 //
363 // Exported function prototypes
364 //
365 EFI_STATUS
366 GenerateCapImage (
367 IN CHAR8 *InfFileImage,
368 IN UINTN InfFileSize,
369 IN CHAR8 *CapFileName
370 )
371 /*++
372
373 Routine Description:
374
375 This is the main function which will be called from application to
376 generate UEFI Capsule image.
377
378 Arguments:
379
380 InfFileImage Buffer containing the INF file contents.
381 InfFileSize Size of the contents of the InfFileImage buffer.
382 CapFileName Requested name for the Cap file.
383
384 Returns:
385
386 EFI_SUCCESS Function completed successfully.
387 EFI_OUT_OF_RESOURCES Could not allocate required resources.
388 EFI_ABORTED Error encountered.
389 EFI_INVALID_PARAMETER A required parameter was NULL.
390
391 --*/
392 ;
393
394 EFI_STATUS
395 GenerateFvImage (
396 IN CHAR8 *InfFileImage,
397 IN UINTN InfFileSize,
398 IN CHAR8 *FvFileName,
399 IN CHAR8 *MapFileName
400 )
401 /*++
402
403 Routine Description:
404
405 This is the main function which will be called from application to
406 generate Firmware Image conforms to PI spec.
407
408 Arguments:
409
410 InfFileImage Buffer containing the INF file contents.
411 InfFileSize Size of the contents of the InfFileImage buffer.
412 FvFileName Requested name for the FV file.
413 MapFileName Fv map file to log fv driver information.
414
415 Returns:
416
417 EFI_SUCCESS Function completed successfully.
418 EFI_OUT_OF_RESOURCES Could not allocate required resources.
419 EFI_ABORTED Error encountered.
420 EFI_INVALID_PARAMETER A required parameter was NULL.
421
422 --*/
423 ;
424
425 #endif