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