]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/Fv2ToFvThunk/Fv2ToFvThunk.c
GCC Build Clean: Add doxygen comment and fix build break issue.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / Fv2ToFvThunk / Fv2ToFvThunk.c
CommitLineData
3e5b4527 1/**\r
2Module produce FV2 on top of FV.\r
3\r
4UEFI PI specification supersedes Inte's Framework Specification.\r
5EFI_FIRMWARE_VOLUME_PROTOCOL defined in Intel Framework Pkg is replaced by\r
6EFI_FIRMWARE_VOLUME2_PROTOCOL in MdePkg.\r
7This module produces FV2 on top of FV. This module is used on platform when both of\r
8these two conditions are true:\r
91) Framework module producing FV is present\r
102) And the rest of modules on the platform consume FV2\r
4259256b 11\r
12Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
13All rights reserved. This program and the accompanying materials\r
14are licensed and made available under the terms and conditions of the BSD License\r
15which accompanies this distribution. The full text of the license may be found at\r
16http://opensource.org/licenses/bsd-license.php\r
17\r
18THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
19WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
20Module Name:\r
21\r
3e5b4527 22**/\r
4259256b 23\r
24#include <PiDxe.h>\r
25#include <Protocol/FirmwareVolume2.h>\r
26#include <Protocol/FirmwareVolume.h>\r
27#include <Library/BaseLib.h>\r
28#include <Library/DebugLib.h>\r
29#include <Library/UefiBootServicesTableLib.h>\r
30#include <Library/UefiDriverEntryPoint.h>\r
31#include <Library/UefiLib.h>\r
32#include <Library/MemoryAllocationLib.h>\r
33\r
34/**\r
35 \r
36 Because of constraints imposed by the underlying firmware\r
37 storage, an instance of the Firmware Volume Protocol may not\r
38 be to able to support all possible variations of this\r
39 architecture. These constraints and the current state of the\r
40 firmware volume are exposed to the caller using the\r
41 GetVolumeAttributes() function. GetVolumeAttributes() is\r
42 callable only from TPL_NOTIFY and below. Behavior of\r
43 GetVolumeAttributes() at any EFI_TPL above TPL_NOTIFY is\r
44 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
45 2.0 specification.\r
46 \r
47 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
48 instance.\r
49 \r
50 @param FvAttributes Pointer to an EFI_FV_ATTRIBUTES in which\r
51 the attributes and current settings are\r
52 returned.\r
53\r
54\r
55 @retval EFI_SUCCESS The firmware volume attributes were\r
56 returned.\r
57\r
58**/\r
59EFI_STATUS\r
60EFIAPI\r
61Fv2GetVolumeAttributes (\r
62 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
63 OUT EFI_FV_ATTRIBUTES *FvAttributes\r
64 );\r
65\r
66\r
67/**\r
68 The SetVolumeAttributes() function is used to set configurable\r
69 firmware volume attributes. Only EFI_FV_READ_STATUS,\r
70 EFI_FV_WRITE_STATUS, and EFI_FV_LOCK_STATUS may be modified, and\r
71 then only in accordance with the declared capabilities. All\r
72 other bits of FvAttributes are ignored on input. On successful\r
73 return, all bits of *FvAttributes are valid and it contains the\r
74 completed EFI_FV_ATTRIBUTES for the volume. To modify an\r
75 attribute, the corresponding status bit in the EFI_FV_ATTRIBUTES\r
76 is set to the desired value on input. The EFI_FV_LOCK_STATUS bit\r
77 does not affect the ability to read or write the firmware\r
78 volume. Rather, once the EFI_FV_LOCK_STATUS bit is set, it\r
79 prevents further modification to all the attribute bits.\r
80 SetVolumeAttributes() is callable only from TPL_NOTIFY and\r
81 below. Behavior of SetVolumeAttributes() at any EFI_TPL above\r
82 TPL_NOTIFY is undefined. Type EFI_TPL is defined in\r
83 RaiseTPL() in the UEFI 2.0 specification.\r
84\r
85\r
86 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
87 instance.\r
88 \r
89 @param FvAttributes On input, FvAttributes is a pointer to\r
90 an EFI_FV_ATTRIBUTES containing the\r
91 desired firmware volume settings. On\r
92 successful return, it contains the new\r
93 settings of the firmware volume. On\r
94 unsuccessful return, FvAttributes is not\r
95 modified and the firmware volume\r
96 settings are not changed.\r
97 \r
98 @retval EFI_SUCCESS The requested firmware volume attributes\r
99 were set and the resulting\r
100 EFI_FV_ATTRIBUTES is returned in\r
101 FvAttributes.\r
102\r
103 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_READ_STATUS\r
104 is set to 1 on input, but the\r
105 device does not support enabling\r
106 reads\r
107 (FvAttributes:EFI_FV_READ_ENABLE\r
108 is clear on return from\r
109 GetVolumeAttributes()). Actual\r
110 volume attributes are unchanged.\r
111\r
112 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_READ_STATUS\r
113 is cleared to 0 on input, but\r
114 the device does not support\r
115 disabling reads\r
116 (FvAttributes:EFI_FV_READ_DISABL\r
117 is clear on return from\r
118 GetVolumeAttributes()). Actual\r
119 volume attributes are unchanged.\r
120\r
121 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_WRITE_STATUS\r
122 is set to 1 on input, but the\r
123 device does not support enabling\r
124 writes\r
125 (FvAttributes:EFI_FV_WRITE_ENABL\r
126 is clear on return from\r
127 GetVolumeAttributes()). Actual\r
128 volume attributes are unchanged.\r
129\r
130 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_WRITE_STATUS\r
131 is cleared to 0 on input, but\r
132 the device does not support\r
133 disabling writes\r
134 (FvAttributes:EFI_FV_WRITE_DISAB\r
135 is clear on return from\r
136 GetVolumeAttributes()). Actual\r
137 volume attributes are unchanged.\r
138\r
139 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_LOCK_STATUS\r
140 is set on input, but the device\r
141 does not support locking\r
142 (FvAttributes:EFI_FV_LOCK_CAP is\r
143 clear on return from\r
144 GetVolumeAttributes()). Actual\r
145 volume attributes are unchanged.\r
146\r
147 @retval EFI_ACCESS_DENIED Device is locked and does not\r
148 allow attribute modification\r
149 (FvAttributes:EFI_FV_LOCK_STATUS\r
150 is set on return from\r
151 GetVolumeAttributes()). Actual\r
152 volume attributes are unchanged.\r
153\r
154**/\r
155EFI_STATUS\r
156EFIAPI\r
157Fv2SetVolumeAttributes (\r
158 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
159 IN OUT EFI_FV_ATTRIBUTES *FvAttributes\r
160 );\r
161\r
162\r
163/**\r
164 ReadFile() is used to retrieve any file from a firmware volume\r
165 during the DXE phase. The actual binary encoding of the file in\r
166 the firmware volume media may be in any arbitrary format as long\r
167 as it does the following: ?It is accessed using the Firmware\r
168 Volume Protocol. ?The image that is returned follows the image\r
169 format defined in Code Definitions: PI Firmware File Format.\r
170 If the input value of Buffer==NULL, it indicates the caller is\r
171 requesting only that the type, attributes, and size of the\r
172 file be returned and that there is no output buffer. In this\r
173 case, the following occurs:\r
174 - BufferSize is returned with the size that is required to\r
175 successfully complete the read.\r
176 - The output parameters FoundType and *FileAttributes are\r
177 returned with valid values.\r
178 - The returned value of *AuthenticationStatus is undefined.\r
179\r
180 If the input value of Buffer!=NULL, the output buffer is\r
181 specified by a double indirection of the Buffer parameter. The\r
182 input value of *Buffer is used to determine if the output\r
183 buffer is caller allocated or is dynamically allocated by\r
184 ReadFile(). If the input value of *Buffer!=NULL, it indicates\r
185 the output buffer is caller allocated. In this case, the input\r
186 value of *BufferSize indicates the size of the\r
187 caller-allocated output buffer. If the output buffer is not\r
188 large enough to contain the entire requested output, it is\r
189 filled up to the point that the output buffer is exhausted and\r
190 EFI_WARN_BUFFER_TOO_SMALL is returned, and then BufferSize is\r
191 returned with the size required to successfully complete the\r
192 read. All other output parameters are returned with valid\r
193 values. If the input value of *Buffer==NULL, it indicates the\r
194 output buffer is to be allocated by ReadFile(). In this case,\r
195 ReadFile() will allocate an appropriately sized buffer from\r
196 boot services pool memory, which will be returned in Buffer.\r
197 The size of the new buffer is returned in BufferSize and all\r
198 other output parameters are returned with valid values.\r
199 ReadFile() is callable only from TPL_NOTIFY and below.\r
200 Behavior of ReadFile() at any EFI_TPL above TPL_NOTIFY is\r
201 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
202 2.0 specification.\r
203 \r
204 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
205 instance.\r
206 \r
207 @param NameGuid Pointer to an EFI_GUID, which is the file\r
208 name. All firmware file names are EFI_GUIDs.\r
209 A single firmware volume must not have two\r
210 valid files with the same file name\r
211 EFI_GUID.\r
212 \r
213 @param Buffer Pointer to a pointer to a buffer in which the\r
214 file contents are returned, not including the\r
215 file header.\r
216 @param BufferSize Pointer to a caller-allocated UINTN. It\r
217 indicates the size of the memory\r
218 represented by Buffer.\r
219 \r
220 @param FoundType Pointer to a caller-allocated\r
221 EFI_FV_FILETYPE.\r
222 \r
223 @param FileAttributes Pointer to a caller-allocated\r
224 EFI_FV_FILE_ATTRIBUTES.\r
225 \r
226 @param AuthenticationStatus Pointer to a caller-allocated\r
227 UINT32 in which the\r
228 authentication status is\r
229 returned.\r
230 \r
231 @retval EFI_SUCCESS The call completed successfully.\r
232 \r
233 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to\r
234 contain the requested\r
235 output. The buffer is\r
236 filled and the output is\r
237 truncated.\r
238\r
239 @retval EFI_OUT_OF_RESOURCES An allocation failure occurred.\r
240\r
241 @retavl EFI_NOT_FOUND Name was not found in the firmware\r
242 volume.\r
243\r
244 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
245 attempting to access the firmware\r
246 volume.\r
247\r
248 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
249 isallow reads.\r
250\r
251**/\r
252EFI_STATUS\r
253EFIAPI\r
254Fv2ReadFile (\r
255 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
256 IN CONST EFI_GUID *NameGuid,\r
257 IN OUT VOID **Buffer,\r
258 IN OUT UINTN *BufferSize,\r
259 OUT EFI_FV_FILETYPE *FoundType,\r
260 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
261 OUT UINT32 *AuthenticationStatus\r
262 );\r
263\r
264/**\r
265 ReadSection() is used to retrieve a specific section from a file\r
266 within a firmware volume. The section returned is determined\r
267 using a depth-first, left-to-right search algorithm through all\r
268 sections found in the specified file. See\r
269 ????Firmware File Sections???? on page 9 for more details about\r
270 sections. The output buffer is specified by a double indirection\r
271 of the Buffer parameter. The input value of Buffer is used to\r
272 determine if the output buffer is caller allocated or is\r
273 dynamically allocated by ReadSection(). If the input value of\r
274 Buffer!=NULL, it indicates that the output buffer is caller\r
275 allocated. In this case, the input value of *BufferSize\r
276 indicates the size of the caller-allocated output buffer. If\r
277 the output buffer is not large enough to contain the entire\r
278 requested output, it is filled up to the point that the output\r
279 buffer is exhausted and EFI_WARN_BUFFER_TOO_SMALL is returned,\r
280 and then BufferSize is returned with the size that is required\r
281 to successfully complete the read. All other\r
282 output parameters are returned with valid values. If the input\r
283 value of *Buffer==NULL, it indicates the output buffer is to\r
284 be allocated by ReadSection(). In this case, ReadSection()\r
285 will allocate an appropriately sized buffer from boot services\r
286 pool memory, which will be returned in *Buffer. The size of\r
287 the new buffer is returned in *BufferSize and all other output\r
288 parameters are returned with valid values. ReadSection() is\r
289 callable only from TPL_NOTIFY and below. Behavior of\r
290 ReadSection() at any EFI_TPL above TPL_NOTIFY is\r
291 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
292 2.0 specification.\r
293\r
294\r
295 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
296 instance.\r
297 \r
298 @param NameGuid Pointer to an EFI_GUID, which indicates the\r
299 file name from which the requested section\r
300 will be read.\r
301 \r
302 @param SectionType Indicates the section type to return.\r
303 SectionType in conjunction with\r
304 SectionInstance indicates which section to\r
305 return.\r
306 \r
307 @param SectionInstance Indicates which instance of sections\r
308 with a type of SectionType to return.\r
309 SectionType in conjunction with\r
310 SectionInstance indicates which\r
311 section to return. SectionInstance is\r
312 zero based.\r
313 \r
314 @param Buffer Pointer to a pointer to a buffer in which the\r
315 section contents are returned, not including\r
316 the section header.\r
317 \r
318 @param BufferSize Pointer to a caller-allocated UINTN. It\r
319 indicates the size of the memory\r
320 represented by Buffer.\r
321 \r
322 @param AuthenticationStatus Pointer to a caller-allocated\r
323 UINT32 in which the authentication\r
324 status is returned.\r
325 \r
326 \r
327 @retval EFI_SUCCESS The call completed successfully.\r
328 \r
329 @retval EFI_WARN_BUFFER_TOO_SMALL The caller-allocated\r
330 buffer is too small to\r
331 contain the requested\r
332 output. The buffer is\r
333 filled and the output is\r
334 truncated.\r
335 \r
336 @retval EFI_OUT_OF_RESOURCES An allocation failure occurred.\r
337 \r
338 @retval EFI_NOT_FOUND The requested file was not found in\r
339 the firmware volume. EFI_NOT_FOUND The\r
340 requested section was not found in the\r
341 specified file.\r
342 \r
343 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
344 attempting to access the firmware\r
345 volume.\r
346 \r
347 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
348 disallow reads. EFI_PROTOCOL_ERROR\r
349 The requested section was not found,\r
350 but the file could not be fully\r
351 parsed because a required\r
352 GUIDED_SECTION_EXTRACTION_PROTOCOL\r
353 was not found. It is possible the\r
354 requested section exists within the\r
355 file and could be successfully\r
356 extracted once the required\r
357 GUIDED_SECTION_EXTRACTION_PROTOCOL\r
358 is published.\r
359\r
360**/\r
361EFI_STATUS\r
362EFIAPI\r
363Fv2ReadSection (\r
364 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
365 IN CONST EFI_GUID *NameGuid,\r
366 IN EFI_SECTION_TYPE SectionType,\r
367 IN UINTN SectionInstance,\r
368 IN OUT VOID **Buffer,\r
369 IN OUT UINTN *BufferSize,\r
370 OUT UINT32 *AuthenticationStatus\r
371 );\r
372\r
373/**\r
374 WriteFile() is used to write one or more files to a firmware\r
375 volume. Each file to be written is described by an\r
376 EFI_FV_WRITE_FILE_DATA structure. The caller must ensure that\r
377 any required alignment for all files listed in the FileData\r
378 array is compatible with the firmware volume. Firmware volume\r
379 capabilities can be determined using the GetVolumeAttributes()\r
380 call. Similarly, if the WritePolicy is set to\r
381 EFI_FV_RELIABLE_WRITE, the caller must check the firmware volume\r
382 capabilities to ensure EFI_FV_RELIABLE_WRITE is supported by the\r
383 firmware volume. EFI_FV_UNRELIABLE_WRITE must always be\r
384 supported. Writing a file with a size of zero\r
385 (FileData[n].BufferSize == 0) deletes the file from the firmware\r
386 volume if it exists. Deleting a file must be done one at a time.\r
387 Deleting a file as part of a multiple file write is not allowed.\r
388 Platform Initialization Specification VOLUME 3 Shared\r
389 Architectural Elements 84 August 21, 2006 Version 1.0\r
390 WriteFile() is callable only from TPL_NOTIFY and below.\r
391 Behavior of WriteFile() at any EFI_TPL above TPL_NOTIFY is\r
392 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI 2.0\r
393 specification.\r
394\r
395 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
396 instance. NumberOfFiles Indicates the number of\r
397 elements in the array pointed to by FileData.\r
398\r
399\r
400 @param WritePolicy Indicates the level of reliability for the\r
401 write in the event of a power failure or\r
402 other system failure during the write\r
403 operation.\r
404\r
405 @param FileData Pointer to an array of\r
406 EFI_FV_WRITE_FILE_DATA. Each element of\r
407 FileData[] represents a file to be written.\r
408\r
409\r
410 @retval EFI_SUCCESS The write completed successfully.\r
411 \r
412 @retval EFI_OUT_OF_RESOURCES The firmware volume does not\r
413 have enough free space to\r
414 storefile(s).\r
415 \r
416 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
417 attempting to access the firmware volume.\r
418 \r
419 @retval EFI_WRITE_PROTECTED The firmware volume is\r
420 configured to disallow writes.\r
421 \r
422 @retval EFI_NOT_FOUND A delete was requested, but the\r
423 requested file was not found in the\r
424 firmware volume.\r
425 \r
426 @retval EFI_INVALID_PARAMETER A delete was requested with a\r
427 multiple file write.\r
428 \r
429 @retval EFI_INVALID_PARAMETER An unsupported WritePolicy was\r
430 requested.\r
431\r
432 @retval EFI_INVALID_PARAMETER An unknown file type was\r
433 specified.\r
434\r
435 @retval EFI_INVALID_PARAMETER A file system specific error\r
436 has occurred.\r
437 \r
438**/\r
439EFI_STATUS \r
440EFIAPI\r
441Fv2WriteFile (\r
442 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
443 IN UINT32 NumberOfFiles,\r
444 IN EFI_FV_WRITE_POLICY WritePolicy,\r
445 IN EFI_FV_WRITE_FILE_DATA *FileData\r
446 );\r
447\r
448/**\r
449 GetNextFile() is the interface that is used to search a firmware\r
450 volume for a particular file. It is called successively until\r
451 the desired file is located or the function returns\r
452 EFI_NOT_FOUND. To filter uninteresting files from the output,\r
453 the type of file to search for may be specified in FileType. For\r
454 example, if *FileType is EFI_FV_FILETYPE_DRIVER, only files of\r
455 this type will be returned in the output. If *FileType is\r
456 EFI_FV_FILETYPE_ALL, no filtering of file types is done. The Key\r
457 parameter is used to indicate a starting point of the search. If\r
458 the buffer *Key is completely initialized to zero, the search\r
459 re-initialized and starts at the beginning. Subsequent calls to\r
460 GetNextFile() must maintain the value of *Key returned by the\r
461 immediately previous call. The actual contents of *Key are\r
462 implementation specific and no semantic content is implied.\r
463 GetNextFile() is callable only from TPL_NOTIFY and below.\r
464 Behavior of GetNextFile() at any EFI_TPL above TPL_NOTIFY is\r
465 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI 2.0\r
466 specification. Status Codes Returned\r
467\r
468\r
469 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
470 instance. Key Pointer to a caller-allocated buffer\r
471 that contains implementation-specific data that is\r
472 used to track where to begin the search for the\r
473 next file. The size of the buffer must be at least\r
474 This->KeySize bytes long. To re-initialize the\r
475 search and begin from the beginning of the\r
476 firmware volume, the entire buffer must be cleared\r
477 to zero. Other than clearing the buffer to\r
478 initiate a new search, the caller must not modify\r
479 the data in the buffer between calls to\r
480 GetNextFile().\r
481\r
482 @param FileType Pointer to a caller-allocated\r
483 EFI_FV_FILETYPE. The GetNextFile() API can\r
484 filter its search for files based on the\r
485 value of the FileType input. A *FileType\r
486 input of EFI_FV_FILETYPE_ALL causes\r
487 GetNextFile() to search for files of all\r
488 types. If a file is found, the file's type\r
489 is returned in FileType. *FileType is not\r
490 modified if no file is found.\r
491\r
492 @param NameGuid Pointer to a caller-allocated EFI_GUID. If a\r
493 matching file is found, the file's name is\r
494 returned in NameGuid. If no matching file is\r
495 found, *NameGuid is not modified.\r
496\r
497 @param Attributes Pointer to a caller-allocated\r
498 EFI_FV_FILE_ATTRIBUTES. If a matching file\r
499 is found, the file's attributes are returned\r
500 in Attributes. If no matching file is found,\r
501 Attributes is not modified. Type\r
502 EFI_FV_FILE_ATTRIBUTES is defined in\r
503 ReadFile().\r
504\r
505 @param Size Pointer to a caller-allocated UINTN. If a\r
506 matching file is found, the file's size is\r
507 returned in *Size. If no matching file is found,\r
508 Size is not modified.\r
509\r
510 @retval EFI_SUCCESS The output parameters are filled with data\r
511 obtained from the first matching file that\r
512 was found.\r
513\r
514 @retval FI_NOT_FOUND No files of type FileType were found.\r
515\r
516\r
517 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
518 attempting to access the firmware\r
519 volume.\r
520\r
521 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
522 disallow reads.\r
523\r
524 \r
525**/\r
526EFI_STATUS\r
527EFIAPI\r
528Fv2GetNextFile (\r
529 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
530 IN OUT VOID *Key,\r
531 IN OUT EFI_FV_FILETYPE *FileType,\r
532 OUT EFI_GUID *NameGuid,\r
533 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
534 OUT UINTN *Size\r
535 );\r
536\r
537/**\r
538 The GetInfo() function returns information of type\r
539 InformationType for the requested firmware volume. If the volume\r
540 does not support the requested information type, then\r
541 EFI_UNSUPPORTED is returned. If the buffer is not large enough\r
542 to hold the requested structure, EFI_BUFFER_TOO_SMALL is\r
543 returned and the BufferSize is set to the size of buffer that is\r
544 required to make the request. The information types defined by\r
545 this specification are required information types that all file\r
546 systems must support.\r
547\r
548 @param This A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
549 instance that is the file handle the requested\r
550 information is for.\r
551 \r
552 @param InformationType The type identifier for the\r
553 information being requested.\r
554 \r
555 @param BufferSize On input, the size of Buffer. On output,\r
556 the amount of data returned in Buffer. In\r
557 both cases, the size is measured in bytes.\r
558 \r
559 @param Buffer A pointer to the data buffer to return. The\r
560 buffer's type is indicated by InformationType.\r
561 \r
562 \r
563 @retval EFI_SUCCESS The information was retrieved.\r
564 \r
565 @retval EFI_UNSUPPORTED The InformationType is not known.\r
566 \r
567 @retval EFI_NO_MEDIA The device has no medium.\r
568 \r
569 @retval EFI_DEVICE_ERROR The device reported an error.\r
570 \r
571 @retval EFI_VOLUME_CORRUPTED The file system structures are\r
572 corrupted.\r
573 \r
574 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to\r
575 read the current directory\r
576 entry. BufferSize has been\r
577 updated with the size needed to\r
578 complete the request.\r
579\r
580\r
581**/\r
582EFI_STATUS\r
583EFIAPI\r
584Fv2GetInfo (\r
585 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
586 IN CONST EFI_GUID *InformationType,\r
587 IN OUT UINTN *BufferSize,\r
588 OUT VOID *Buffer\r
589 );\r
590\r
591/**\r
592\r
593 The SetInfo() function sets information of type InformationType\r
594 on the requested firmware volume.\r
595\r
596\r
597 @param This A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
598 instance that is the file handle the information\r
599 is for.\r
600\r
601 @param InformationType The type identifier for the\r
602 information being set.\r
603\r
604 @param BufferSize The size, in bytes, of Buffer.\r
605\r
606 @param Buffer A pointer to the data buffer to write. The\r
607 buffer's type is indicated by InformationType.\r
608\r
609 @retval EFI_SUCCESS The information was set.\r
610\r
611 @retval EFI_UNSUPPORTED The InformationType is not known.\r
612\r
613 @retval EFI_NO_MEDIA The device has no medium.\r
614\r
615 @retval EFI_DEVICE_ERROR The device reported an error.\r
616\r
617 @retval EFI_VOLUME_CORRUPTED The file system structures are\r
618 corrupted.\r
619\r
620\r
621 @retval EFI_WRITE_PROTECTED The media is read only.\r
622\r
623 @retval EFI_VOLUME_FULL The volume is full.\r
624\r
625 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the\r
626 size of the type indicated by\r
627 InformationType.\r
628\r
629**/\r
630EFI_STATUS\r
631EFIAPI\r
632Fv2SetInfo (\r
633 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
634 IN CONST EFI_GUID *InformationType,\r
635 IN UINTN BufferSize,\r
636 IN CONST VOID *Buffer\r
637 );\r
638\r
639//\r
640//\r
641//\r
642#define FIRMWARE_VOLUME2_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('f', 'v', '2', 't')\r
643\r
644typedef struct {\r
645 UINTN Signature;\r
646 EFI_FIRMWARE_VOLUME2_PROTOCOL FirmwareVolume2;\r
647 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
648} FIRMWARE_VOLUME2_PRIVATE_DATA;\r
649\r
650#define FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS(a) CR (a, FIRMWARE_VOLUME2_PRIVATE_DATA, FirmwareVolume2, FIRMWARE_VOLUME2_PRIVATE_DATA_SIGNATURE)\r
651\r
652//\r
653// Firmware Volume Protocol template\r
654//\r
655EFI_EVENT mFv2Registration;\r
656\r
657FIRMWARE_VOLUME2_PRIVATE_DATA gFirmwareVolume2PrivateDataTemplate = {\r
658 FIRMWARE_VOLUME2_PRIVATE_DATA_SIGNATURE,\r
659 {\r
660 Fv2GetVolumeAttributes,\r
661 Fv2SetVolumeAttributes,\r
662 Fv2ReadFile,\r
663 Fv2ReadSection,\r
664 Fv2WriteFile,\r
665 Fv2GetNextFile,\r
666 0,\r
667 NULL,\r
668 Fv2GetInfo,\r
669 Fv2SetInfo\r
670 },\r
671 NULL\r
672};\r
673\r
674//\r
675// Module globals\r
676//\r
677\r
678VOID\r
679EFIAPI\r
680Fv2NotificationEvent (\r
681 IN EFI_EVENT Event,\r
682 IN VOID *Context\r
683 )\r
684{\r
685 EFI_STATUS Status;\r
686 UINTN BufferSize;\r
687 EFI_HANDLE Handle;\r
688 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
689 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
690\r
691 while (TRUE) {\r
692 BufferSize = sizeof (Handle);\r
693 Status = gBS->LocateHandle (\r
694 ByRegisterNotify,\r
695 &gEfiFirmwareVolumeProtocolGuid,\r
696 mFv2Registration,\r
697 &BufferSize,\r
698 &Handle\r
699 );\r
700 if (EFI_ERROR (Status)) {\r
701 //\r
702 // Exit Path of While Loop....\r
703 //\r
704 break;\r
705 }\r
706\r
707 //\r
708 // Skip this handle if the Firmware Volume Protocol is already installed\r
709 //\r
710 Status = gBS->HandleProtocol (\r
711 Handle,\r
712 &gEfiFirmwareVolume2ProtocolGuid,\r
713 (VOID **)&FirmwareVolume2\r
714 );\r
715 if (!EFI_ERROR (Status)) {\r
716 continue;\r
717 }\r
718\r
719 //\r
720 // Allocate private data structure\r
721 //\r
722 Private = AllocateCopyPool (sizeof (FIRMWARE_VOLUME2_PRIVATE_DATA), &gFirmwareVolume2PrivateDataTemplate);\r
723 if (Private == NULL) {\r
724 continue;\r
725 }\r
726\r
727 //\r
728 // Retrieve the Firmware Volume2 Protocol\r
729 //\r
730 Status = gBS->HandleProtocol (\r
731 Handle,\r
732 &gEfiFirmwareVolumeProtocolGuid,\r
733 (VOID **)&Private->FirmwareVolume\r
734 );\r
735 ASSERT_EFI_ERROR (Status);\r
736\r
737 //\r
738 // Fill in rest of private data structure\r
739 //\r
740 Private->FirmwareVolume2.KeySize = Private->FirmwareVolume->KeySize;\r
741 Private->FirmwareVolume2.ParentHandle = Private->FirmwareVolume->ParentHandle;\r
742\r
743 //\r
744 // Install Firmware Volume Protocol onto same handle\r
745 //\r
746 Status = gBS->InstallMultipleProtocolInterfaces (\r
747 &Handle,\r
748 &gEfiFirmwareVolume2ProtocolGuid,\r
749 &Private->FirmwareVolume2,\r
750 NULL\r
751 );\r
752 ASSERT_EFI_ERROR (Status);\r
753 }\r
754}\r
755\r
756\r
757/**\r
758 The user Entry Point for DXE driver. The user code starts with this function\r
759 as the real entry point for the image goes into a library that calls this \r
760 function.\r
761\r
762 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
763 @param[in] SystemTable A pointer to the EFI System Table.\r
764 \r
765 @retval EFI_SUCCESS The entry point is executed successfully.\r
766 @retval other Some error occurs when executing this entry point.\r
767\r
768**/\r
769EFI_STATUS\r
770EFIAPI\r
771InitializeFirmwareVolume (\r
772 IN EFI_HANDLE ImageHandle,\r
773 IN EFI_SYSTEM_TABLE *SystemTable\r
774 )\r
775{\r
776 EfiCreateProtocolNotifyEvent (\r
777 &gEfiFirmwareVolumeProtocolGuid,\r
778 TPL_CALLBACK,\r
779 Fv2NotificationEvent,\r
780 NULL,\r
781 &mFv2Registration\r
782 );\r
783 return EFI_SUCCESS;\r
784}\r
785\r
cae5044b 786/**\r
787 Convert FV attributes defined in Framework Specification\r
788 to FV attributes defined in PI specification.\r
789 \r
790 @param FvAttributes The FV attributes defined in Framework Specification.\r
791 \r
792 @retval The FV attributes defined in PI Specification.\r
793**/\r
9e99ce32 794EFI_FV_ATTRIBUTES\r
795FvAttributesToFv2Attributes (\r
796 EFI_FV_ATTRIBUTES FvAttributes\r
797 )\r
798{\r
799 INTN Alignment;\r
800 \r
801 Alignment = LowBitSet64 (RShiftU64 (FvAttributes, 16) & 0xffff);\r
802 if (Alignment != -1) {\r
803 Alignment = Alignment << 16;\r
804 } else {\r
805 Alignment = 0;\r
806 }\r
807 FvAttributes = (FvAttributes & 0x1ff) | Alignment;\r
808\r
809 return FvAttributes;\r
810}\r
811\r
4259256b 812/**\r
813 \r
814 Because of constraints imposed by the underlying firmware\r
815 storage, an instance of the Firmware Volume Protocol may not\r
816 be to able to support all possible variations of this\r
817 architecture. These constraints and the current state of the\r
818 firmware volume are exposed to the caller using the\r
819 GetVolumeAttributes() function. GetVolumeAttributes() is\r
820 callable only from TPL_NOTIFY and below. Behavior of\r
821 GetVolumeAttributes() at any EFI_TPL above TPL_NOTIFY is\r
822 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
823 2.0 specification.\r
824 \r
825 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
826 instance.\r
827 \r
828 @param FvAttributes Pointer to an EFI_FV_ATTRIBUTES in which\r
829 the attributes and current settings are\r
830 returned.\r
831\r
832\r
833 @retval EFI_SUCCESS The firmware volume attributes were\r
834 returned.\r
835\r
836**/\r
837EFI_STATUS\r
838EFIAPI\r
839Fv2GetVolumeAttributes (\r
840 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
841 OUT EFI_FV_ATTRIBUTES *FvAttributes\r
842 )\r
843{\r
844 EFI_STATUS Status;\r
845 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
846 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
4259256b 847\r
848 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
849 FirmwareVolume = Private->FirmwareVolume;\r
850 Status = FirmwareVolume->GetVolumeAttributes (\r
851 FirmwareVolume,\r
852 (FRAMEWORK_EFI_FV_ATTRIBUTES *)FvAttributes\r
853 );\r
854 if (!EFI_ERROR (Status)) {\r
cae5044b 855 *FvAttributes = FvAttributesToFv2Attributes (*FvAttributes);\r
4259256b 856 }\r
857 return Status;\r
858}\r
859\r
860/**\r
861 The SetVolumeAttributes() function is used to set configurable\r
862 firmware volume attributes. Only EFI_FV_READ_STATUS,\r
863 EFI_FV_WRITE_STATUS, and EFI_FV_LOCK_STATUS may be modified, and\r
864 then only in accordance with the declared capabilities. All\r
865 other bits of FvAttributes are ignored on input. On successful\r
866 return, all bits of *FvAttributes are valid and it contains the\r
867 completed EFI_FV_ATTRIBUTES for the volume. To modify an\r
868 attribute, the corresponding status bit in the EFI_FV_ATTRIBUTES\r
869 is set to the desired value on input. The EFI_FV_LOCK_STATUS bit\r
870 does not affect the ability to read or write the firmware\r
871 volume. Rather, once the EFI_FV_LOCK_STATUS bit is set, it\r
872 prevents further modification to all the attribute bits.\r
873 SetVolumeAttributes() is callable only from TPL_NOTIFY and\r
874 below. Behavior of SetVolumeAttributes() at any EFI_TPL above\r
875 TPL_NOTIFY is undefined. Type EFI_TPL is defined in\r
876 RaiseTPL() in the UEFI 2.0 specification.\r
877\r
878\r
879 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
880 instance.\r
881 \r
882 @param FvAttributes On input, FvAttributes is a pointer to\r
883 an EFI_FV_ATTRIBUTES containing the\r
884 desired firmware volume settings. On\r
885 successful return, it contains the new\r
886 settings of the firmware volume. On\r
887 unsuccessful return, FvAttributes is not\r
888 modified and the firmware volume\r
889 settings are not changed.\r
890 \r
891 @retval EFI_SUCCESS The requested firmware volume attributes\r
892 were set and the resulting\r
893 EFI_FV_ATTRIBUTES is returned in\r
894 FvAttributes.\r
895\r
896 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_READ_STATUS\r
897 is set to 1 on input, but the\r
898 device does not support enabling\r
899 reads\r
900 (FvAttributes:EFI_FV_READ_ENABLE\r
901 is clear on return from\r
902 GetVolumeAttributes()). Actual\r
903 volume attributes are unchanged.\r
904\r
905 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_READ_STATUS\r
906 is cleared to 0 on input, but\r
907 the device does not support\r
908 disabling reads\r
909 (FvAttributes:EFI_FV_READ_DISABL\r
910 is clear on return from\r
911 GetVolumeAttributes()). Actual\r
912 volume attributes are unchanged.\r
913\r
914 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_WRITE_STATUS\r
915 is set to 1 on input, but the\r
916 device does not support enabling\r
917 writes\r
918 (FvAttributes:EFI_FV_WRITE_ENABL\r
919 is clear on return from\r
920 GetVolumeAttributes()). Actual\r
921 volume attributes are unchanged.\r
922\r
923 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_WRITE_STATUS\r
924 is cleared to 0 on input, but\r
925 the device does not support\r
926 disabling writes\r
927 (FvAttributes:EFI_FV_WRITE_DISAB\r
928 is clear on return from\r
929 GetVolumeAttributes()). Actual\r
930 volume attributes are unchanged.\r
931\r
932 @retval EFI_INVALID_PARAMETER FvAttributes:EFI_FV_LOCK_STATUS\r
933 is set on input, but the device\r
934 does not support locking\r
935 (FvAttributes:EFI_FV_LOCK_CAP is\r
936 clear on return from\r
937 GetVolumeAttributes()). Actual\r
938 volume attributes are unchanged.\r
939\r
940 @retval EFI_ACCESS_DENIED Device is locked and does not\r
941 allow attribute modification\r
942 (FvAttributes:EFI_FV_LOCK_STATUS\r
943 is set on return from\r
944 GetVolumeAttributes()). Actual\r
945 volume attributes are unchanged.\r
946\r
947**/\r
948EFI_STATUS\r
949EFIAPI\r
950Fv2SetVolumeAttributes (\r
951 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
952 IN OUT EFI_FV_ATTRIBUTES *FvAttributes\r
953 )\r
954{\r
955 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
956 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
957 FRAMEWORK_EFI_FV_ATTRIBUTES FrameworkFvAttributes; \r
9e99ce32 958 EFI_STATUS Status;\r
3e5b4527 959 UINTN Shift;\r
4259256b 960\r
9e99ce32 961 if (*FvAttributes & (EFI_FV2_READ_LOCK_STATUS | EFI_FV2_WRITE_LOCK_STATUS)) {\r
962 //\r
963 // Framework FV protocol does not support EFI_FV2_READ_LOCK_* | EFI_FV2_WRITE_LOCK_*\r
964 //\r
965 return EFI_INVALID_PARAMETER;\r
966 }\r
967\r
968 *FvAttributes = *FvAttributes & (EFI_FV2_READ_STATUS | EFI_FV2_WRITE_STATUS | EFI_FV2_LOCK_STATUS);\r
969\r
4259256b 970 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
971 FirmwareVolume = Private->FirmwareVolume;\r
972\r
3e5b4527 973 FrameworkFvAttributes = (*FvAttributes & 0x1ff);\r
974 Shift = (UINTN) RShiftU64(*FvAttributes & EFI_FV2_ALIGNMENT, 16);\r
975 FrameworkFvAttributes = FrameworkFvAttributes | LShiftU64 (EFI_FV_ALIGNMENT_2, Shift);\r
4259256b 976\r
9e99ce32 977 Status = FirmwareVolume->SetVolumeAttributes (\r
4259256b 978 FirmwareVolume,\r
979 &FrameworkFvAttributes\r
980 );\r
9e99ce32 981\r
982 if (!EFI_ERROR (Status)) {\r
983 *FvAttributes = FvAttributesToFv2Attributes (FrameworkFvAttributes);\r
984 }\r
985\r
986 return Status;\r
4259256b 987}\r
988\r
989/**\r
990 ReadFile() is used to retrieve any file from a firmware volume\r
991 during the DXE phase. The actual binary encoding of the file in\r
992 the firmware volume media may be in any arbitrary format as long\r
993 as it does the following: ?It is accessed using the Firmware\r
994 Volume Protocol. ?The image that is returned follows the image\r
995 format defined in Code Definitions: PI Firmware File Format.\r
996 If the input value of Buffer==NULL, it indicates the caller is\r
997 requesting only that the type, attributes, and size of the\r
998 file be returned and that there is no output buffer. In this\r
999 case, the following occurs:\r
1000 - BufferSize is returned with the size that is required to\r
1001 successfully complete the read.\r
1002 - The output parameters FoundType and *FileAttributes are\r
1003 returned with valid values.\r
1004 - The returned value of *AuthenticationStatus is undefined.\r
1005\r
1006 If the input value of Buffer!=NULL, the output buffer is\r
1007 specified by a double indirection of the Buffer parameter. The\r
1008 input value of *Buffer is used to determine if the output\r
1009 buffer is caller allocated or is dynamically allocated by\r
1010 ReadFile(). If the input value of *Buffer!=NULL, it indicates\r
1011 the output buffer is caller allocated. In this case, the input\r
1012 value of *BufferSize indicates the size of the\r
1013 caller-allocated output buffer. If the output buffer is not\r
1014 large enough to contain the entire requested output, it is\r
1015 filled up to the point that the output buffer is exhausted and\r
1016 EFI_WARN_BUFFER_TOO_SMALL is returned, and then BufferSize is\r
1017 returned with the size required to successfully complete the\r
1018 read. All other output parameters are returned with valid\r
1019 values. If the input value of *Buffer==NULL, it indicates the\r
1020 output buffer is to be allocated by ReadFile(). In this case,\r
1021 ReadFile() will allocate an appropriately sized buffer from\r
1022 boot services pool memory, which will be returned in Buffer.\r
1023 The size of the new buffer is returned in BufferSize and all\r
1024 other output parameters are returned with valid values.\r
1025 ReadFile() is callable only from TPL_NOTIFY and below.\r
1026 Behavior of ReadFile() at any EFI_TPL above TPL_NOTIFY is\r
1027 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
1028 2.0 specification.\r
1029 \r
1030 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1031 instance.\r
1032 \r
1033 @param NameGuid Pointer to an EFI_GUID, which is the file\r
1034 name. All firmware file names are EFI_GUIDs.\r
1035 A single firmware volume must not have two\r
1036 valid files with the same file name\r
1037 EFI_GUID.\r
1038 \r
1039 @param Buffer Pointer to a pointer to a buffer in which the\r
1040 file contents are returned, not including the\r
1041 file header.\r
1042 @param BufferSize Pointer to a caller-allocated UINTN. It\r
1043 indicates the size of the memory\r
1044 represented by Buffer.\r
1045 \r
1046 @param FoundType Pointer to a caller-allocated\r
1047 EFI_FV_FILETYPE.\r
1048 \r
1049 @param FileAttributes Pointer to a caller-allocated\r
1050 EFI_FV_FILE_ATTRIBUTES.\r
1051 \r
1052 @param AuthenticationStatus Pointer to a caller-allocated\r
1053 UINT32 in which the\r
1054 authentication status is\r
1055 returned.\r
1056 \r
1057 @retval EFI_SUCCESS The call completed successfully.\r
1058 \r
1059 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to\r
1060 contain the requested\r
1061 output. The buffer is\r
1062 filled and the output is\r
1063 truncated.\r
1064\r
1065 @retval EFI_OUT_OF_RESOURCES An allocation failure occurred.\r
1066\r
1067 @retavl EFI_NOT_FOUND Name was not found in the firmware\r
1068 volume.\r
1069\r
1070 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
1071 attempting to access the firmware\r
1072 volume.\r
1073\r
1074 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
1075 isallow reads.\r
1076\r
1077**/\r
1078EFI_STATUS\r
1079EFIAPI\r
1080Fv2ReadFile (\r
1081 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1082 IN CONST EFI_GUID *NameGuid,\r
1083 IN OUT VOID **Buffer,\r
1084 IN OUT UINTN *BufferSize,\r
1085 OUT EFI_FV_FILETYPE *FoundType,\r
1086 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
1087 OUT UINT32 *AuthenticationStatus\r
1088 )\r
1089{\r
1090 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
1091 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
1092\r
1093 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
1094 FirmwareVolume = Private->FirmwareVolume;\r
1095\r
1096 return FirmwareVolume->ReadFile (\r
1097 FirmwareVolume,\r
1098 (EFI_GUID *)NameGuid,\r
1099 Buffer,\r
1100 BufferSize,\r
1101 FoundType,\r
1102 FileAttributes,\r
1103 AuthenticationStatus\r
1104 );\r
1105}\r
1106\r
1107/**\r
1108 ReadSection() is used to retrieve a specific section from a file\r
1109 within a firmware volume. The section returned is determined\r
1110 using a depth-first, left-to-right search algorithm through all\r
1111 sections found in the specified file. See\r
1112 ????Firmware File Sections???? on page 9 for more details about\r
1113 sections. The output buffer is specified by a double indirection\r
1114 of the Buffer parameter. The input value of Buffer is used to\r
1115 determine if the output buffer is caller allocated or is\r
1116 dynamically allocated by ReadSection(). If the input value of\r
1117 Buffer!=NULL, it indicates that the output buffer is caller\r
1118 allocated. In this case, the input value of *BufferSize\r
1119 indicates the size of the caller-allocated output buffer. If\r
1120 the output buffer is not large enough to contain the entire\r
1121 requested output, it is filled up to the point that the output\r
1122 buffer is exhausted and EFI_WARN_BUFFER_TOO_SMALL is returned,\r
1123 and then BufferSize is returned with the size that is required\r
1124 to successfully complete the read. All other\r
1125 output parameters are returned with valid values. If the input\r
1126 value of *Buffer==NULL, it indicates the output buffer is to\r
1127 be allocated by ReadSection(). In this case, ReadSection()\r
1128 will allocate an appropriately sized buffer from boot services\r
1129 pool memory, which will be returned in *Buffer. The size of\r
1130 the new buffer is returned in *BufferSize and all other output\r
1131 parameters are returned with valid values. ReadSection() is\r
1132 callable only from TPL_NOTIFY and below. Behavior of\r
1133 ReadSection() at any EFI_TPL above TPL_NOTIFY is\r
1134 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI\r
1135 2.0 specification.\r
1136\r
1137\r
1138 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1139 instance.\r
1140 \r
1141 @param NameGuid Pointer to an EFI_GUID, which indicates the\r
1142 file name from which the requested section\r
1143 will be read.\r
1144 \r
1145 @param SectionType Indicates the section type to return.\r
1146 SectionType in conjunction with\r
1147 SectionInstance indicates which section to\r
1148 return.\r
1149 \r
1150 @param SectionInstance Indicates which instance of sections\r
1151 with a type of SectionType to return.\r
1152 SectionType in conjunction with\r
1153 SectionInstance indicates which\r
1154 section to return. SectionInstance is\r
1155 zero based.\r
1156 \r
1157 @param Buffer Pointer to a pointer to a buffer in which the\r
1158 section contents are returned, not including\r
1159 the section header.\r
1160 \r
1161 @param BufferSize Pointer to a caller-allocated UINTN. It\r
1162 indicates the size of the memory\r
1163 represented by Buffer.\r
1164 \r
1165 @param AuthenticationStatus Pointer to a caller-allocated\r
1166 UINT32 in which the authentication\r
1167 status is returned.\r
1168 \r
1169 \r
1170 @retval EFI_SUCCESS The call completed successfully.\r
1171 \r
1172 @retval EFI_WARN_BUFFER_TOO_SMALL The caller-allocated\r
1173 buffer is too small to\r
1174 contain the requested\r
1175 output. The buffer is\r
1176 filled and the output is\r
1177 truncated.\r
1178 \r
1179 @retval EFI_OUT_OF_RESOURCES An allocation failure occurred.\r
1180 \r
1181 @retval EFI_NOT_FOUND The requested file was not found in\r
1182 the firmware volume. EFI_NOT_FOUND The\r
1183 requested section was not found in the\r
1184 specified file.\r
1185 \r
1186 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
1187 attempting to access the firmware\r
1188 volume.\r
1189 \r
1190 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
1191 disallow reads. EFI_PROTOCOL_ERROR\r
1192 The requested section was not found,\r
1193 but the file could not be fully\r
1194 parsed because a required\r
1195 GUIDED_SECTION_EXTRACTION_PROTOCOL\r
1196 was not found. It is possible the\r
1197 requested section exists within the\r
1198 file and could be successfully\r
1199 extracted once the required\r
1200 GUIDED_SECTION_EXTRACTION_PROTOCOL\r
1201 is published.\r
1202\r
1203**/\r
1204EFI_STATUS\r
1205EFIAPI\r
1206Fv2ReadSection (\r
1207 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1208 IN CONST EFI_GUID *NameGuid,\r
1209 IN EFI_SECTION_TYPE SectionType,\r
1210 IN UINTN SectionInstance,\r
1211 IN OUT VOID **Buffer,\r
1212 IN OUT UINTN *BufferSize,\r
1213 OUT UINT32 *AuthenticationStatus\r
1214 )\r
1215{\r
1216 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
1217 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
1218\r
1219 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
1220 FirmwareVolume = Private->FirmwareVolume;\r
1221\r
1222 return FirmwareVolume->ReadSection (\r
1223 FirmwareVolume,\r
1224 (EFI_GUID *)NameGuid,\r
1225 SectionType,\r
1226 SectionInstance,\r
1227 Buffer,\r
1228 BufferSize,\r
1229 AuthenticationStatus\r
1230 );\r
1231}\r
1232\r
1233/**\r
1234 WriteFile() is used to write one or more files to a firmware\r
1235 volume. Each file to be written is described by an\r
1236 EFI_FV_WRITE_FILE_DATA structure. The caller must ensure that\r
1237 any required alignment for all files listed in the FileData\r
1238 array is compatible with the firmware volume. Firmware volume\r
1239 capabilities can be determined using the GetVolumeAttributes()\r
1240 call. Similarly, if the WritePolicy is set to\r
1241 EFI_FV_RELIABLE_WRITE, the caller must check the firmware volume\r
1242 capabilities to ensure EFI_FV_RELIABLE_WRITE is supported by the\r
1243 firmware volume. EFI_FV_UNRELIABLE_WRITE must always be\r
1244 supported. Writing a file with a size of zero\r
1245 (FileData[n].BufferSize == 0) deletes the file from the firmware\r
1246 volume if it exists. Deleting a file must be done one at a time.\r
1247 Deleting a file as part of a multiple file write is not allowed.\r
1248 Platform Initialization Specification VOLUME 3 Shared\r
1249 Architectural Elements 84 August 21, 2006 Version 1.0\r
1250 WriteFile() is callable only from TPL_NOTIFY and below.\r
1251 Behavior of WriteFile() at any EFI_TPL above TPL_NOTIFY is\r
1252 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI 2.0\r
1253 specification.\r
1254\r
1255 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1256 instance. NumberOfFiles Indicates the number of\r
1257 elements in the array pointed to by FileData.\r
1258\r
1259\r
1260 @param WritePolicy Indicates the level of reliability for the\r
1261 write in the event of a power failure or\r
1262 other system failure during the write\r
1263 operation.\r
1264\r
1265 @param FileData Pointer to an array of\r
1266 EFI_FV_WRITE_FILE_DATA. Each element of\r
1267 FileData[] represents a file to be written.\r
1268\r
1269\r
1270 @retval EFI_SUCCESS The write completed successfully.\r
1271 \r
1272 @retval EFI_OUT_OF_RESOURCES The firmware volume does not\r
1273 have enough free space to\r
1274 storefile(s).\r
1275 \r
1276 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
1277 attempting to access the firmware volume.\r
1278 \r
1279 @retval EFI_WRITE_PROTECTED The firmware volume is\r
1280 configured to disallow writes.\r
1281 \r
1282 @retval EFI_NOT_FOUND A delete was requested, but the\r
1283 requested file was not found in the\r
1284 firmware volume.\r
1285 \r
1286 @retval EFI_INVALID_PARAMETER A delete was requested with a\r
1287 multiple file write.\r
1288 \r
1289 @retval EFI_INVALID_PARAMETER An unsupported WritePolicy was\r
1290 requested.\r
1291\r
1292 @retval EFI_INVALID_PARAMETER An unknown file type was\r
1293 specified.\r
1294\r
1295 @retval EFI_INVALID_PARAMETER A file system specific error\r
1296 has occurred.\r
1297 \r
1298**/\r
1299EFI_STATUS \r
1300EFIAPI\r
1301Fv2WriteFile (\r
1302 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1303 IN UINT32 NumberOfFiles,\r
1304 IN EFI_FV_WRITE_POLICY WritePolicy,\r
1305 IN EFI_FV_WRITE_FILE_DATA *FileData\r
1306 )\r
1307{\r
1308 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
1309 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
1310\r
1311 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
1312 FirmwareVolume = Private->FirmwareVolume;\r
1313\r
1314 return FirmwareVolume->WriteFile (\r
1315 FirmwareVolume,\r
1316 NumberOfFiles,\r
1317 WritePolicy,\r
1318 (FRAMEWORK_EFI_FV_WRITE_FILE_DATA *)FileData\r
1319 );\r
1320}\r
1321\r
1322/**\r
1323 GetNextFile() is the interface that is used to search a firmware\r
1324 volume for a particular file. It is called successively until\r
1325 the desired file is located or the function returns\r
1326 EFI_NOT_FOUND. To filter uninteresting files from the output,\r
1327 the type of file to search for may be specified in FileType. For\r
1328 example, if *FileType is EFI_FV_FILETYPE_DRIVER, only files of\r
1329 this type will be returned in the output. If *FileType is\r
1330 EFI_FV_FILETYPE_ALL, no filtering of file types is done. The Key\r
1331 parameter is used to indicate a starting point of the search. If\r
1332 the buffer *Key is completely initialized to zero, the search\r
1333 re-initialized and starts at the beginning. Subsequent calls to\r
1334 GetNextFile() must maintain the value of *Key returned by the\r
1335 immediately previous call. The actual contents of *Key are\r
1336 implementation specific and no semantic content is implied.\r
1337 GetNextFile() is callable only from TPL_NOTIFY and below.\r
1338 Behavior of GetNextFile() at any EFI_TPL above TPL_NOTIFY is\r
1339 undefined. Type EFI_TPL is defined in RaiseTPL() in the UEFI 2.0\r
1340 specification. Status Codes Returned\r
1341\r
1342\r
1343 @param This Indicates the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1344 instance. Key Pointer to a caller-allocated buffer\r
1345 that contains implementation-specific data that is\r
1346 used to track where to begin the search for the\r
1347 next file. The size of the buffer must be at least\r
1348 This->KeySize bytes long. To re-initialize the\r
1349 search and begin from the beginning of the\r
1350 firmware volume, the entire buffer must be cleared\r
1351 to zero. Other than clearing the buffer to\r
1352 initiate a new search, the caller must not modify\r
1353 the data in the buffer between calls to\r
1354 GetNextFile().\r
1355\r
1356 @param FileType Pointer to a caller-allocated\r
1357 EFI_FV_FILETYPE. The GetNextFile() API can\r
1358 filter its search for files based on the\r
1359 value of the FileType input. A *FileType\r
1360 input of EFI_FV_FILETYPE_ALL causes\r
1361 GetNextFile() to search for files of all\r
1362 types. If a file is found, the file's type\r
1363 is returned in FileType. *FileType is not\r
1364 modified if no file is found.\r
1365\r
1366 @param NameGuid Pointer to a caller-allocated EFI_GUID. If a\r
1367 matching file is found, the file's name is\r
1368 returned in NameGuid. If no matching file is\r
1369 found, *NameGuid is not modified.\r
1370\r
1371 @param Attributes Pointer to a caller-allocated\r
1372 EFI_FV_FILE_ATTRIBUTES. If a matching file\r
1373 is found, the file's attributes are returned\r
1374 in Attributes. If no matching file is found,\r
1375 Attributes is not modified. Type\r
1376 EFI_FV_FILE_ATTRIBUTES is defined in\r
1377 ReadFile().\r
1378\r
1379 @param Size Pointer to a caller-allocated UINTN. If a\r
1380 matching file is found, the file's size is\r
1381 returned in *Size. If no matching file is found,\r
1382 Size is not modified.\r
1383\r
1384 @retval EFI_SUCCESS The output parameters are filled with data\r
1385 obtained from the first matching file that\r
1386 was found.\r
1387\r
1388 @retval FI_NOT_FOUND No files of type FileType were found.\r
1389\r
1390\r
1391 @retval EFI_DEVICE_ERROR A hardware error occurred when\r
1392 attempting to access the firmware\r
1393 volume.\r
1394\r
1395 @retval EFI_ACCESS_DENIED The firmware volume is configured to\r
1396 disallow reads.\r
1397\r
1398 \r
1399**/\r
1400EFI_STATUS\r
1401EFIAPI\r
1402Fv2GetNextFile (\r
1403 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1404 IN OUT VOID *Key,\r
1405 IN OUT EFI_FV_FILETYPE *FileType,\r
1406 OUT EFI_GUID *NameGuid,\r
1407 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
1408 OUT UINTN *Size\r
1409 )\r
1410{\r
1411 FIRMWARE_VOLUME2_PRIVATE_DATA *Private;\r
1412 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
1413\r
1414 Private = FIRMWARE_VOLUME2_PRIVATE_DATA_FROM_THIS (This);\r
1415 FirmwareVolume = Private->FirmwareVolume;\r
1416\r
1417 return FirmwareVolume->GetNextFile (\r
1418 FirmwareVolume,\r
1419 Key,\r
1420 FileType,\r
1421 NameGuid,\r
1422 Attributes,\r
1423 Size\r
1424 );\r
1425}\r
1426\r
1427/**\r
1428 The GetInfo() function returns information of type\r
1429 InformationType for the requested firmware volume. If the volume\r
1430 does not support the requested information type, then\r
1431 EFI_UNSUPPORTED is returned. If the buffer is not large enough\r
1432 to hold the requested structure, EFI_BUFFER_TOO_SMALL is\r
1433 returned and the BufferSize is set to the size of buffer that is\r
1434 required to make the request. The information types defined by\r
1435 this specification are required information types that all file\r
1436 systems must support.\r
1437\r
1438 @param This A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1439 instance that is the file handle the requested\r
1440 information is for.\r
1441 \r
1442 @param InformationType The type identifier for the\r
1443 information being requested.\r
1444 \r
1445 @param BufferSize On input, the size of Buffer. On output,\r
1446 the amount of data returned in Buffer. In\r
1447 both cases, the size is measured in bytes.\r
1448 \r
1449 @param Buffer A pointer to the data buffer to return. The\r
1450 buffer's type is indicated by InformationType.\r
1451 \r
1452 \r
1453 @retval EFI_SUCCESS The information was retrieved.\r
1454 \r
1455 @retval EFI_UNSUPPORTED The InformationType is not known.\r
1456 \r
1457 @retval EFI_NO_MEDIA The device has no medium.\r
1458 \r
1459 @retval EFI_DEVICE_ERROR The device reported an error.\r
1460 \r
1461 @retval EFI_VOLUME_CORRUPTED The file system structures are\r
1462 corrupted.\r
1463 \r
1464 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to\r
1465 read the current directory\r
1466 entry. BufferSize has been\r
1467 updated with the size needed to\r
1468 complete the request.\r
1469\r
1470\r
1471**/\r
1472EFI_STATUS\r
1473EFIAPI\r
1474Fv2GetInfo (\r
1475 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1476 IN CONST EFI_GUID *InformationType,\r
1477 IN OUT UINTN *BufferSize,\r
1478 OUT VOID *Buffer\r
1479 )\r
1480{\r
1481 return EFI_UNSUPPORTED;\r
1482}\r
1483\r
1484/**\r
1485\r
1486 The SetInfo() function sets information of type InformationType\r
1487 on the requested firmware volume.\r
1488\r
1489\r
1490 @param This A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL\r
1491 instance that is the file handle the information\r
1492 is for.\r
1493\r
1494 @param InformationType The type identifier for the\r
1495 information being set.\r
1496\r
1497 @param BufferSize The size, in bytes, of Buffer.\r
1498\r
1499 @param Buffer A pointer to the data buffer to write. The\r
1500 buffer's type is indicated by InformationType.\r
1501\r
1502 @retval EFI_SUCCESS The information was set.\r
1503\r
1504 @retval EFI_UNSUPPORTED The InformationType is not known.\r
1505\r
1506 @retval EFI_NO_MEDIA The device has no medium.\r
1507\r
1508 @retval EFI_DEVICE_ERROR The device reported an error.\r
1509\r
1510 @retval EFI_VOLUME_CORRUPTED The file system structures are\r
1511 corrupted.\r
1512\r
1513\r
1514 @retval EFI_WRITE_PROTECTED The media is read only.\r
1515\r
1516 @retval EFI_VOLUME_FULL The volume is full.\r
1517\r
1518 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the\r
1519 size of the type indicated by\r
1520 InformationType.\r
1521\r
1522**/\r
1523EFI_STATUS\r
1524EFIAPI\r
1525Fv2SetInfo (\r
1526 IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r
1527 IN CONST EFI_GUID *InformationType,\r
1528 IN UINTN BufferSize,\r
1529 IN CONST VOID *Buffer\r
1530 )\r
1531{\r
1532 return EFI_UNSUPPORTED;\r
1533}\r