]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDriver.h
Optimize the log entry search algorithm to save boot performance.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / FirmwareVolume / FwVolDxe / FwVolDriver.h
CommitLineData
c2df8e13 1/** @file\r
2 Common defines and definitions for a FwVolDxe driver.\r
3\r
23491d5c 4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
c2df8e13 5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions\r
8 of the BSD License which accompanies this distribution. The\r
9 full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _FWVOL_DRIVER_H_\r
18#define _FWVOL_DRIVER_H_\r
19\r
20#include <PiDxe.h>\r
21\r
22#include <Guid/FirmwareFileSystem2.h>\r
23491d5c 23#include <Guid/FirmwareFileSystem3.h>\r
c2df8e13 24#include <Protocol/SectionExtraction.h>\r
25#include <Protocol/FaultTolerantWrite.h>\r
26#include <Protocol/FirmwareVolume2.h>\r
27#include <Protocol/FirmwareVolumeBlock.h>\r
28\r
29#include <Library/DebugLib.h>\r
30#include <Library/UefiDriverEntryPoint.h>\r
31#include <Library/UefiLib.h>\r
32#include <Library/BaseLib.h>\r
33#include <Library/BaseMemoryLib.h>\r
34#include <Library/MemoryAllocationLib.h>\r
35#include <Library/UefiBootServicesTableLib.h>\r
36\r
37#define FV_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '_')\r
38\r
39//\r
40// Define two helper macro to extract the Capability field or Status field in FVB\r
41// bit fields\r
42//\r
43#define EFI_FVB2_CAPABILITIES (EFI_FVB2_READ_DISABLED_CAP | \\r
44 EFI_FVB2_READ_ENABLED_CAP | \\r
45 EFI_FVB2_WRITE_DISABLED_CAP | \\r
46 EFI_FVB2_WRITE_ENABLED_CAP | \\r
47 EFI_FVB2_LOCK_CAP \\r
48 )\r
49\r
50#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)\r
51\r
52#define MAX_FILES 32\r
53\r
54//\r
55// Used to caculate from address -> Lba\r
56//\r
57typedef struct {\r
58 LIST_ENTRY Link;\r
59 EFI_LBA LbaIndex;\r
60 UINT8 *StartingAddress;\r
61 UINTN BlockLength;\r
62} LBA_ENTRY;\r
63\r
64//\r
65// Used to track free space in the Fv\r
66//\r
67typedef struct {\r
68 LIST_ENTRY Link;\r
69 UINT8 *StartingAddress;\r
70 UINTN Length;\r
71} FREE_SPACE_ENTRY;\r
72\r
73//\r
74// Used to track all non-deleted files\r
75//\r
76typedef struct {\r
77 LIST_ENTRY Link;\r
78 UINT8 *FfsHeader;\r
79} FFS_FILE_LIST_ENTRY;\r
80\r
81typedef struct {\r
82 UINTN Signature;\r
83 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
84 EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;\r
85 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
86 UINT8 *Key;\r
87 EFI_HANDLE Handle;\r
88\r
89 UINT8 ErasePolarity;\r
90 EFI_PHYSICAL_ADDRESS CachedFv;\r
91 LIST_ENTRY LbaHeader;\r
92 LIST_ENTRY FreeSpaceHeader;\r
93 LIST_ENTRY FfsFileListHeader;\r
94\r
95 FFS_FILE_LIST_ENTRY *CurrentFfsFile;\r
23491d5c 96 BOOLEAN IsFfs3Fv;\r
c2df8e13 97} FV_DEVICE;\r
98\r
99#define FV_DEVICE_FROM_THIS(a) CR (a, FV_DEVICE, Fv, FV_DEVICE_SIGNATURE)\r
100\r
101/**\r
102 Retrieves attributes, insures positive polarity of attribute bits, returns\r
103 resulting attributes in output parameter.\r
104\r
105 @param This Calling context\r
106 @param Attributes output buffer which contains attributes\r
107\r
108 @retval EFI_SUCCESS Successfully got volume attributes\r
109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113FvGetVolumeAttributes (\r
114 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
115 OUT EFI_FV_ATTRIBUTES *Attributes\r
116 );\r
117\r
118/**\r
119 Sets current attributes for volume.\r
120\r
121 @param This Calling context\r
122 @param Attributes On input, FvAttributes is a pointer to\r
123 an EFI_FV_ATTRIBUTES containing the\r
124 desired firmware volume settings. On\r
125 successful return, it contains the new\r
126 settings of the firmware volume. On\r
127 unsuccessful return, FvAttributes is not\r
128 modified and the firmware volume\r
129 settings are not changed.\r
130 \r
131 @retval EFI_SUCCESS The requested firmware volume attributes\r
132 were set and the resulting\r
133 EFI_FV_ATTRIBUTES is returned in\r
134 FvAttributes.\r
135 @retval EFI_ACCESS_DENIED Atrribute is locked down.\r
136 @retval EFI_INVALID_PARAMETER Atrribute is not valid.\r
137\r
138**/\r
139EFI_STATUS\r
140EFIAPI\r
141FvSetVolumeAttributes (\r
142 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
143 IN OUT EFI_FV_ATTRIBUTES *Attributes\r
144 );\r
145\r
146/**\r
147 Given the input key, search for the next matching file in the volume.\r
148\r
149 @param This Indicates the calling context.\r
150 @param Key Key is a pointer to a caller allocated\r
151 buffer that contains implementation specific\r
152 data that is used to track where to begin\r
153 the search for the next file. The size of\r
154 the buffer must be at least This->KeySize\r
155 bytes long. To reinitialize the search and\r
156 begin from the beginning of the firmware\r
157 volume, the entire buffer must be cleared to\r
158 zero. Other than clearing the buffer to\r
159 initiate a new search, the caller must not\r
160 modify the data in the buffer between calls\r
161 to GetNextFile().\r
162 @param FileType FileType is a pointer to a caller allocated\r
163 EFI_FV_FILETYPE. The GetNextFile() API can\r
164 filter it's search for files based on the\r
165 value of *FileType input. A *FileType input\r
166 of 0 causes GetNextFile() to search for\r
167 files of all types. If a file is found, the\r
168 file's type is returned in *FileType.\r
169 *FileType is not modified if no file is\r
170 found.\r
171 @param NameGuid NameGuid is a pointer to a caller allocated\r
172 EFI_GUID. If a file is found, the file's\r
173 name is returned in *NameGuid. *NameGuid is\r
174 not modified if no file is found.\r
175 @param Attributes Attributes is a pointer to a caller\r
176 allocated EFI_FV_FILE_ATTRIBUTES. If a file\r
177 is found, the file's attributes are returned\r
178 in *Attributes. *Attributes is not modified\r
179 if no file is found.\r
180 @param Size Size is a pointer to a caller allocated\r
181 UINTN. If a file is found, the file's size\r
182 is returned in *Size. *Size is not modified\r
183 if no file is found.\r
184\r
185 @retval EFI_SUCCESS Successfully find the file.\r
186 @retval EFI_DEVICE_ERROR Device error.\r
187 @retval EFI_ACCESS_DENIED Fv could not read.\r
188 @retval EFI_NOT_FOUND No matching file found.\r
189 @retval EFI_INVALID_PARAMETER Invalid parameter\r
190\r
191**/\r
192EFI_STATUS\r
193EFIAPI\r
194FvGetNextFile (\r
195 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
196 IN OUT VOID *Key,\r
197 IN OUT EFI_FV_FILETYPE *FileType,\r
198 OUT EFI_GUID *NameGuid,\r
199 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
200 OUT UINTN *Size\r
201 );\r
202\r
203/**\r
204 Locates a file in the firmware volume and\r
205 copies it to the supplied buffer.\r
206\r
207 @param This Indicates the calling context.\r
208 @param NameGuid Pointer to an EFI_GUID, which is the\r
209 filename.\r
210 @param Buffer Buffer is a pointer to pointer to a buffer\r
211 in which the file or section contents or are\r
212 returned.\r
213 @param BufferSize BufferSize is a pointer to caller allocated\r
214 UINTN. On input *BufferSize indicates the\r
215 size in bytes of the memory region pointed\r
216 to by Buffer. On output, *BufferSize\r
217 contains the number of bytes required to\r
218 read the file.\r
219 @param FoundType FoundType is a pointer to a caller allocated\r
220 EFI_FV_FILETYPE that on successful return\r
221 from Read() contains the type of file read.\r
222 This output reflects the file type\r
223 irrespective of the value of the SectionType\r
224 input.\r
225 @param FileAttributes FileAttributes is a pointer to a caller\r
226 allocated EFI_FV_FILE_ATTRIBUTES. On\r
227 successful return from Read(),\r
228 *FileAttributes contains the attributes of\r
229 the file read.\r
230 @param AuthenticationStatus AuthenticationStatus is a pointer to a\r
231 caller allocated UINTN in which the\r
232 authentication status is returned.\r
233\r
234 @retval EFI_SUCCESS Successfully read to memory buffer.\r
235 @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.\r
236 @retval EFI_NOT_FOUND Not found.\r
237 @retval EFI_DEVICE_ERROR Device error.\r
238 @retval EFI_ACCESS_DENIED Could not read.\r
239 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
240 @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r
241\r
242**/\r
243EFI_STATUS\r
244EFIAPI\r
245FvReadFile (\r
246 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
247 IN CONST EFI_GUID *NameGuid,\r
248 IN OUT VOID **Buffer,\r
249 IN OUT UINTN *BufferSize,\r
250 OUT EFI_FV_FILETYPE *FoundType,\r
251 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
252 OUT UINT32 *AuthenticationStatus\r
253 );\r
254\r
255/**\r
256 Locates a section in a given FFS File and\r
257 copies it to the supplied buffer (not including section header).\r
258\r
259 @param This Indicates the calling context.\r
260 @param NameGuid Pointer to an EFI_GUID, which is the\r
261 filename.\r
262 @param SectionType Indicates the section type to return.\r
263 @param SectionInstance Indicates which instance of sections with a\r
264 type of SectionType to return.\r
265 @param Buffer Buffer is a pointer to pointer to a buffer\r
266 in which the file or section contents or are\r
267 returned.\r
268 @param BufferSize BufferSize is a pointer to caller allocated\r
269 UINTN.\r
270 @param AuthenticationStatus AuthenticationStatus is a pointer to a\r
271 caller allocated UINT32 in which the\r
272 authentication status is returned.\r
273\r
274 @retval EFI_SUCCESS Successfully read the file section into\r
275 buffer.\r
276 @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small.\r
277 @retval EFI_NOT_FOUND Section not found.\r
278 @retval EFI_DEVICE_ERROR Device error.\r
279 @retval EFI_ACCESS_DENIED Could not read.\r
280 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
281\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285FvReadFileSection (\r
286 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
287 IN CONST EFI_GUID *NameGuid,\r
288 IN EFI_SECTION_TYPE SectionType,\r
289 IN UINTN SectionInstance,\r
290 IN OUT VOID **Buffer,\r
291 IN OUT UINTN *BufferSize,\r
292 OUT UINT32 *AuthenticationStatus\r
293 );\r
294\r
295/**\r
296 Writes one or more files to the firmware volume.\r
297\r
298 @param This Indicates the calling context.\r
299 @param NumberOfFiles Number of files.\r
300 @param WritePolicy WritePolicy indicates the level of reliability\r
301 for the write in the event of a power failure or\r
302 other system failure during the write operation.\r
303 @param FileData FileData is an pointer to an array of\r
304 EFI_FV_WRITE_DATA. Each element of array\r
305 FileData represents a file to be written.\r
306\r
307 @retval EFI_SUCCESS Files successfully written to firmware volume\r
308 @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r
309 @retval EFI_DEVICE_ERROR Device error.\r
310 @retval EFI_WRITE_PROTECTED Write protected.\r
311 @retval EFI_NOT_FOUND Not found.\r
312 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
313 @retval EFI_UNSUPPORTED This function not supported.\r
314\r
315**/\r
316EFI_STATUS\r
317EFIAPI\r
318FvWriteFile (\r
319 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
320 IN UINT32 NumberOfFiles,\r
321 IN EFI_FV_WRITE_POLICY WritePolicy,\r
322 IN EFI_FV_WRITE_FILE_DATA *FileData\r
323 );\r
324\r
325/**\r
326 Return information of type InformationType for the requested firmware\r
327 volume.\r
328\r
329 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
330 @param InformationType InformationType for requested.\r
331 @param BufferSize On input, size of Buffer.On output, the amount of\r
332 data returned in Buffer.\r
333 @param Buffer A poniter to the data buffer to return.\r
334\r
335 @return EFI_UNSUPPORTED Could not get.\r
336\r
337**/\r
338EFI_STATUS\r
339EFIAPI\r
340FvGetVolumeInfo (\r
341 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
342 IN CONST EFI_GUID *InformationType,\r
343 IN OUT UINTN *BufferSize,\r
344 OUT VOID *Buffer\r
345 );\r
346\r
347\r
348/**\r
349 Set information with InformationType into the requested firmware volume.\r
350\r
351 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
352 @param InformationType InformationType for requested.\r
353 @param BufferSize Size of Buffer data.\r
354 @param Buffer A poniter to the data buffer to be set.\r
355\r
356 @retval EFI_UNSUPPORTED Could not set.\r
357\r
358**/\r
359EFI_STATUS\r
360EFIAPI\r
361FvSetVolumeInfo (\r
362 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
363 IN CONST EFI_GUID *InformationType,\r
364 IN UINTN BufferSize,\r
365 IN CONST VOID *Buffer\r
366 );\r
367\r
368/**\r
369 Writes data beginning at Lba:Offset from FV. The write terminates either\r
370 when *NumBytes of data have been written, or when the firmware end is\r
371 reached. *NumBytes is updated to reflect the actual number of bytes\r
372 written.\r
373\r
374 @param FvDevice Cached Firmware Volume\r
375 @param Offset Offset in the block at which to begin write\r
376 @param NumBytes At input, indicates the requested write size.\r
377 At output, indicates the actual number of bytes written.\r
378 @param Buffer Buffer containing source data for the write.\r
379\r
380 @retval EFI_SUCCESS Data is successfully written into FV.\r
381 @return error Data is failed written.\r
382\r
383**/\r
384EFI_STATUS\r
385FvcWrite (\r
386 IN FV_DEVICE *FvDevice,\r
387 IN UINTN Offset,\r
388 IN OUT UINTN *NumBytes,\r
389 IN UINT8 *Buffer\r
390 );\r
391\r
392\r
393/**\r
394 Check if a block of buffer is erased.\r
395\r
396 @param ErasePolarity Erase polarity attribute of the firmware volume\r
397 @param Buffer The buffer to be checked\r
398 @param BufferSize Size of the buffer in bytes\r
399\r
400 @retval TRUE The block of buffer is erased\r
401 @retval FALSE The block of buffer is not erased\r
402\r
403**/\r
404BOOLEAN\r
405IsBufferErased (\r
406 IN UINT8 ErasePolarity,\r
407 IN UINT8 *Buffer,\r
408 IN UINTN BufferSize\r
409 );\r
410\r
411/**\r
412 Get the FFS file state by checking the highest bit set in the header's state field.\r
413\r
414 @param ErasePolarity Erase polarity attribute of the firmware volume\r
415 @param FfsHeader Points to the FFS file header\r
416\r
417 @return FFS File state\r
418\r
419**/\r
420EFI_FFS_FILE_STATE\r
421GetFileState (\r
422 IN UINT8 ErasePolarity,\r
423 IN EFI_FFS_FILE_HEADER *FfsHeader\r
424 );\r
425\r
426/**\r
427 Verify checksum of the firmware volume header.\r
428\r
429 @param FvHeader Points to the firmware volume header to be checked\r
430\r
431 @retval TRUE Checksum verification passed\r
432 @retval FALSE Checksum verification failed\r
433\r
434**/\r
435BOOLEAN\r
436VerifyFvHeaderChecksum (\r
437 IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r
438 );\r
439\r
440/**\r
441 Check if it's a valid FFS file header.\r
442\r
443 @param ErasePolarity Erase polarity attribute of the firmware volume\r
444 @param FfsHeader Points to the FFS file header to be checked\r
445\r
446 @retval TRUE Valid FFS file header\r
447 @retval FALSE Invalid FFS file header\r
448\r
449**/\r
450BOOLEAN\r
451IsValidFFSHeader (\r
452 IN UINT8 ErasePolarity,\r
453 IN EFI_FFS_FILE_HEADER *FfsHeader\r
454 );\r
455\r
456/**\r
457 Check if it's a valid FFS file.\r
458 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.\r
459\r
460 @param FvDevice Cached FV image.\r
461 @param FfsHeader Points to the FFS file to be checked\r
462\r
463 @retval TRUE Valid FFS file\r
464 @retval FALSE Invalid FFS file\r
465\r
466**/\r
467BOOLEAN\r
468IsValidFFSFile (\r
469 IN FV_DEVICE *FvDevice,\r
470 IN EFI_FFS_FILE_HEADER *FfsHeader\r
471 );\r
472\r
473/**\r
474 Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and\r
475 copy the real length volume header into it.\r
476\r
477 @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to\r
478 read the volume header\r
479 @param FwVolHeader Pointer to pointer to allocated buffer in which\r
480 the volume header is returned.\r
481\r
482 @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.\r
483 @retval EFI_SUCCESS Successfully read volume header to the allocated\r
484 buffer.\r
485 @retval EFI_ACCESS_DENIED Read status of FV is not enabled.\r
486**/\r
487EFI_STATUS\r
488GetFwVolHeader (\r
489 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r
490 OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r
491 );\r
492\r
c2df8e13 493/**\r
494 Convert the Buffer Address to LBA Entry Address.\r
495\r
496 @param FvDevice Cached FvDevice\r
497 @param BufferAddress Address of Buffer\r
498 @param LbaListEntry Pointer to the got LBA entry that contains the address.\r
499\r
500 @retval EFI_NOT_FOUND Buffer address is out of FvDevice.\r
501 @retval EFI_SUCCESS LBA entry is found for Buffer address.\r
502\r
503**/\r
504EFI_STATUS\r
505Buffer2LbaEntry (\r
506 IN FV_DEVICE *FvDevice,\r
507 IN EFI_PHYSICAL_ADDRESS BufferAddress,\r
508 OUT LBA_ENTRY **LbaListEntry\r
509 );\r
510\r
511/**\r
512 Convert the Buffer Address to LBA Address & Offset.\r
513\r
514 @param FvDevice Cached FvDevice\r
515 @param BufferAddress Address of Buffer\r
516 @param Lba Pointer to the gob Lba value\r
517 @param Offset Pointer to the got Offset\r
518\r
519 @retval EFI_NOT_FOUND Buffer address is out of FvDevice.\r
520 @retval EFI_SUCCESS LBA and Offset is found for Buffer address.\r
521\r
522**/\r
523EFI_STATUS\r
524Buffer2Lba (\r
525 IN FV_DEVICE *FvDevice,\r
526 IN EFI_PHYSICAL_ADDRESS BufferAddress,\r
527 OUT EFI_LBA *Lba,\r
528 OUT UINTN *Offset\r
529 );\r
530\r
531/**\r
532 Set File State in the FfsHeader.\r
533\r
534 @param State File state to be set into FFS header.\r
535 @param FfsHeader Points to the FFS file header\r
536\r
537**/\r
538VOID\r
539SetFileState (\r
540 IN UINT8 State,\r
541 IN EFI_FFS_FILE_HEADER *FfsHeader\r
542 );\r
543\r
544/**\r
545 Create a PAD File in the Free Space.\r
546\r
547 @param FvDevice Firmware Volume Device.\r
548 @param FreeSpaceEntry Indicating in which Free Space(Cache) the Pad file will be inserted.\r
549 @param Size Pad file Size, not include the header.\r
550 @param PadFileEntry The Ffs File Entry that points to this Pad File.\r
551\r
552 @retval EFI_SUCCESS Successfully create a PAD file.\r
553 @retval EFI_OUT_OF_RESOURCES No enough free space to create a PAD file.\r
554 @retval EFI_INVALID_PARAMETER Size is not 8 byte alignment.\r
555 @retval EFI_DEVICE_ERROR Free space is not erased.\r
556**/\r
557EFI_STATUS\r
558FvCreatePadFileInFreeSpace (\r
559 IN FV_DEVICE *FvDevice,\r
560 IN FREE_SPACE_ENTRY *FreeSpaceEntry,\r
561 IN UINTN Size,\r
562 OUT FFS_FILE_LIST_ENTRY **PadFileEntry\r
563 );\r
564\r
565/**\r
566 Create a new file within a PAD file area.\r
567\r
568 @param FvDevice Firmware Volume Device.\r
569 @param FfsFileBuffer A buffer that holds an FFS file,(it contains a File Header which is in init state).\r
570 @param BufferSize The size of FfsFileBuffer.\r
571 @param ActualFileSize The actual file length, it may not be multiples of 8.\r
572 @param FileName The FFS File Name.\r
573 @param FileType The FFS File Type.\r
574 @param FileAttributes The Attributes of the FFS File to be created.\r
575\r
576 @retval EFI_SUCCESS Successfully create a new file within the found PAD file area.\r
577 @retval EFI_OUT_OF_RESOURCES No suitable PAD file is found.\r
578 @retval other errors New file is created failed.\r
579\r
580**/\r
581EFI_STATUS\r
582FvCreateNewFileInsidePadFile (\r
583 IN FV_DEVICE *FvDevice,\r
584 IN UINT8 *FfsFileBuffer,\r
585 IN UINTN BufferSize,\r
586 IN UINTN ActualFileSize,\r
587 IN EFI_GUID *FileName,\r
588 IN EFI_FV_FILETYPE FileType,\r
589 IN EFI_FV_FILE_ATTRIBUTES FileAttributes\r
590 );\r
591\r
592/**\r
593 Write multiple files into FV in reliable method.\r
594\r
595 @param FvDevice Firmware Volume Device.\r
596 @param NumOfFiles Total File number to be written.\r
597 @param FileData The array of EFI_FV_WRITE_FILE_DATA structure, \r
598 used to get name, attributes, type, etc\r
599 @param FileOperation The array of operation for each file.\r
600\r
601 @retval EFI_SUCCESS Files are added into FV.\r
602 @retval EFI_OUT_OF_RESOURCES No enough free PAD files to add the input files.\r
603 @retval EFI_INVALID_PARAMETER File number is less than or equal to 1.\r
604 @retval EFI_UNSUPPORTED File number exceeds the supported max numbers of files.\r
605\r
606**/\r
607EFI_STATUS\r
608FvCreateMultipleFiles (\r
609 IN FV_DEVICE *FvDevice,\r
610 IN UINTN NumOfFiles,\r
611 IN EFI_FV_WRITE_FILE_DATA *FileData,\r
612 IN BOOLEAN *FileOperation\r
613 );\r
614\r
615/**\r
616 Caculate the checksum for the FFS header.\r
617\r
618 @param FfsHeader FFS File Header which needs to caculate the checksum\r
619\r
620**/\r
621VOID\r
622SetHeaderChecksum (\r
623 IN EFI_FFS_FILE_HEADER *FfsHeader\r
624 );\r
625\r
626/**\r
627 Caculate the checksum for the FFS File.\r
628\r
629 @param FfsHeader FFS File Header which needs to caculate the checksum\r
630 @param ActualFileSize The whole Ffs File Length.\r
631\r
632**/\r
633VOID\r
634SetFileChecksum (\r
635 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
636 IN UINTN ActualFileSize\r
637 );\r
638\r
639/**\r
640 Get the alignment value from File Attributes.\r
641\r
642 @param FfsAttributes FFS attribute\r
643\r
644 @return Alignment value.\r
645\r
646**/\r
647UINTN\r
648GetRequiredAlignment (\r
649 IN EFI_FV_FILE_ATTRIBUTES FfsAttributes\r
650 );\r
651\r
652/**\r
653 Locate Pad File for writing, this is got from FV Cache.\r
654\r
655 @param FvDevice Cached Firmware Volume.\r
656 @param Size The required FFS file size.\r
657 @param RequiredAlignment FFS File Data alignment requirement.\r
658 @param PadSize Pointer to the size of leading Pad File.\r
659 @param PadFileEntry Pointer to the Pad File Entry that meets the requirement.\r
660\r
661 @retval EFI_SUCCESS The required pad file is found.\r
662 @retval EFI_NOT_FOUND The required pad file can't be found.\r
663\r
664**/\r
665EFI_STATUS\r
666FvLocatePadFile (\r
667 IN FV_DEVICE *FvDevice,\r
668 IN UINTN Size,\r
669 IN UINTN RequiredAlignment,\r
670 OUT UINTN *PadSize,\r
671 OUT FFS_FILE_LIST_ENTRY **PadFileEntry\r
672 );\r
673\r
674/**\r
675 Locate a suitable pad file for multiple file writing.\r
676\r
677 @param FvDevice Cached Firmware Volume.\r
678 @param NumOfFiles The number of Files that needed updating\r
679 @param BufferSize The array of each file size.\r
680 @param RequiredAlignment The array of of FFS File Data alignment requirement.\r
681 @param PadSize The array of size of each leading Pad File.\r
682 @param TotalSizeNeeded The totalsize that can hold these files.\r
683 @param PadFileEntry Pointer to the Pad File Entry that meets the requirement.\r
684\r
685 @retval EFI_SUCCESS The required pad file is found.\r
686 @retval EFI_NOT_FOUND The required pad file can't be found.\r
687\r
688**/\r
689EFI_STATUS\r
690FvSearchSuitablePadFile (\r
691 IN FV_DEVICE *FvDevice,\r
692 IN UINTN NumOfFiles,\r
693 IN UINTN *BufferSize,\r
694 IN UINTN *RequiredAlignment,\r
695 OUT UINTN *PadSize,\r
696 OUT UINTN *TotalSizeNeeded,\r
697 OUT FFS_FILE_LIST_ENTRY **PadFileEntry\r
698 );\r
699\r
700/**\r
701 Locate a Free Space entry which can hold these files, including\r
702 meeting the alignment requirements.\r
703\r
704 @param FvDevice Cached Firmware Volume.\r
705 @param NumOfFiles The number of Files that needed updating\r
706 @param BufferSize The array of each file size.\r
707 @param RequiredAlignment The array of of FFS File Data alignment requirement.\r
708 @param PadSize The array of size of each leading Pad File.\r
709 @param TotalSizeNeeded The got total size that can hold these files.\r
710 @param FreeSpaceEntry The Free Space Entry that can hold these files.\r
711\r
712 @retval EFI_SUCCESS The free space entry is found.\r
713 @retval EFI_NOT_FOUND The free space entry can't be found.\r
714\r
715**/\r
716EFI_STATUS\r
717FvSearchSuitableFreeSpace (\r
718 IN FV_DEVICE *FvDevice,\r
719 IN UINTN NumOfFiles,\r
720 IN UINTN *BufferSize,\r
721 IN UINTN *RequiredAlignment,\r
722 OUT UINTN *PadSize,\r
723 OUT UINTN *TotalSizeNeeded,\r
724 OUT FREE_SPACE_ENTRY **FreeSpaceEntry\r
725 );\r
726\r
727/**\r
728 Change FFS file header state and write to FV.\r
729\r
730 @param FvDevice Cached FV image.\r
731 @param FfsHeader Points to the FFS file header to be updated.\r
732 @param State FFS file state to be set.\r
733\r
734 @retval EFI_SUCCESS File state is writen into FV.\r
735 @retval others File state can't be writen into FV.\r
736\r
737**/\r
738EFI_STATUS\r
739UpdateHeaderBit (\r
740 IN FV_DEVICE *FvDevice,\r
741 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
742 IN EFI_FFS_FILE_STATE State\r
743 );\r
744\r
745/**\r
746 Convert EFI_FV_FILE_ATTRIBUTES to FFS_FILE_ATTRIBUTES.\r
747\r
748 @param FvFileAttrib The value of EFI_FV_FILE_ATTRIBUTES\r
749 @param FfsFileAttrib Pointer to the got FFS_FILE_ATTRIBUTES value.\r
750\r
751**/\r
752VOID\r
753FvFileAttrib2FfsFileAttrib (\r
754 IN EFI_FV_FILE_ATTRIBUTES FvFileAttrib,\r
755 OUT UINT8 *FfsFileAttrib\r
756 );\r
757\r
758#endif\r