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