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