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