2 UEFI PI specification supersedes Inte's Framework Specification.
3 EFI_FIRMWARE_VOLUME_PROTOCOL defined in Intel Framework Pkg is replaced by
4 EFI_FIRMWARE_VOLUME2_PROTOCOL in MdePkg.
5 This module produces FV on top of FV2. This module is used on platform when both of
6 these two conditions are true:
7 1) Framework module consuming FV is present
8 2) And the platform only produces FV2
10 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
11 All rights reserved. This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include <Protocol/FirmwareVolume2.h>
24 #include <Protocol/FirmwareVolume.h>
25 #include <Library/BaseLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiLib.h>
30 #include <Library/MemoryAllocationLib.h>
33 Retrieves attributes, insures positive polarity of attribute bits, returns
34 resulting attributes in output parameter
36 @param This Calling context
37 @param Attributes output buffer which contains attributes
39 @retval EFI_INVALID_PARAMETER
45 FvGetVolumeAttributes (
46 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
47 OUT FRAMEWORK_EFI_FV_ATTRIBUTES
*Attributes
51 Sets volume attributes
53 @param This Calling context
54 @param Attributes Buffer which contains attributes
56 @retval EFI_INVALID_PARAMETER
57 @retval EFI_DEVICE_ERROR
63 FvSetVolumeAttributes (
64 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
65 IN OUT FRAMEWORK_EFI_FV_ATTRIBUTES
*Attributes
69 Read the requested file (NameGuid) and returns data in Buffer.
71 @param This Calling context
72 @param NameGuid Filename identifying which file to read
73 @param Buffer Pointer to pointer to buffer in which contents of file are returned.
75 If Buffer is NULL, only type, attributes, and size are returned as
76 there is no output buffer.
78 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated
79 from BS pool by ReadFile
81 If Buffer != NULL and *Buffer != NULL, the output buffer has been
82 allocated by the caller and is being passed in.
83 @param BufferSize Indicates the buffer size passed in, and on output the size
84 required to complete the read
85 @param FoundType Indicates the type of the file who's data is returned
86 @param FileAttributes Indicates the attributes of the file who's data is resturned
87 @param AuthenticationStatus Indicates the authentication status of the data
90 @retval EFI_WARN_BUFFER_TOO_SMALL
92 @retval EFI_DEVICE_ERROR
93 @retval EFI_ACCESS_DENIED
99 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
100 IN EFI_GUID
*NameGuid
,
101 IN OUT VOID
**Buffer
,
102 IN OUT UINTN
*BufferSize
,
103 OUT EFI_FV_FILETYPE
*FoundType
,
104 OUT EFI_FV_FILE_ATTRIBUTES
*FileAttributes
,
105 OUT UINT32
*AuthenticationStatus
109 Read the requested section from the specified file and returns data in Buffer.
111 @param This Calling context
112 @param NameGuid Filename identifying the file from which to read
113 @param SectionType Indicates what section type to retrieve
114 @param SectionInstance Indicates which instance of SectionType to retrieve
115 @param Buffer Pointer to pointer to buffer in which contents of file are returned.
117 If Buffer is NULL, only type, attributes, and size are returned as
118 there is no output buffer.
120 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated
121 from BS pool by ReadFile
123 If Buffer != NULL and *Buffer != NULL, the output buffer has been
124 allocated by the caller and is being passed in.
125 @param BufferSize Indicates the buffer size passed in, and on output the size
126 required to complete the read
127 @param AuthenticationStatus Indicates the authentication status of the data
130 @retval EFI_WARN_BUFFER_TOO_SMALL
131 @retval EFI_OUT_OF_RESOURCES
132 @retval EFI_NOT_FOUND
133 @retval EFI_DEVICE_ERROR
134 @retval EFI_ACCESS_DENIED
140 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
141 IN EFI_GUID
*NameGuid
,
142 IN EFI_SECTION_TYPE SectionType
,
143 IN UINTN SectionInstance
,
144 IN OUT VOID
**Buffer
,
145 IN OUT UINTN
*BufferSize
,
146 OUT UINT32
*AuthenticationStatus
150 Write the supplied file (NameGuid) to the FV.
152 @param This Calling context
153 @param NumberOfFiles Indicates the number of file records pointed to by FileData
154 @param WritePolicy Indicates the level of reliability of the write with respect to
155 things like power failure events.
156 @param FileData A pointer to an array of EFI_FV_WRITE_FILE_DATA structures. Each
157 element in the array indicates a file to write, and there are
158 NumberOfFiles elements in the input array.
161 @retval EFI_OUT_OF_RESOURCES
162 @retval EFI_DEVICE_ERROR
163 @retval EFI_WRITE_PROTECTED
164 @retval EFI_NOT_FOUND
165 @retval EFI_INVALID_PARAMETER
171 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
172 IN UINT32 NumberOfFiles
,
173 IN FRAMEWORK_EFI_FV_WRITE_POLICY WritePolicy
,
174 IN FRAMEWORK_EFI_FV_WRITE_FILE_DATA
*FileData
178 Given the input key, search for the next matching file in the volume.
180 @param This Calling context
181 @param Key Pointer to a caller allocated buffer that contains an implementation
182 specific key that is used to track where to begin searching on
184 @param FileType Indicates the file type to filter for
185 @param NameGuid Guid filename of the file found
186 @param Attributes Attributes of the file found
187 @param Size Size in bytes of the file found
190 @retval EFI_NOT_FOUND
191 @retval EFI_DEVICE_ERROR
192 @retval EFI_ACCESS_DENIED
198 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
200 IN OUT EFI_FV_FILETYPE
*FileType
,
201 OUT EFI_GUID
*NameGuid
,
202 OUT EFI_FV_FILE_ATTRIBUTES
*Attributes
,
206 #define FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('f', 'v', 't', 'h')
210 EFI_FIRMWARE_VOLUME_PROTOCOL FirmwareVolume
;
211 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
212 } FIRMWARE_VOLUME_PRIVATE_DATA
;
214 #define FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS(a) CR (a, FIRMWARE_VOLUME_PRIVATE_DATA, FirmwareVolume, FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE)
217 // Firmware Volume Protocol template
219 EFI_EVENT mFvRegistration
;
221 FIRMWARE_VOLUME_PRIVATE_DATA gFirmwareVolumePrivateDataTemplate
= {
222 FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE
,
224 FvGetVolumeAttributes
,
225 FvSetVolumeAttributes
,
242 FvNotificationEvent (
250 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
251 EFI_FIRMWARE_VOLUME_PROTOCOL
*FirmwareVolume
;
254 BufferSize
= sizeof (Handle
);
255 Status
= gBS
->LocateHandle (
257 &gEfiFirmwareVolume2ProtocolGuid
,
262 if (EFI_ERROR (Status
)) {
264 // Exit Path of While Loop....
270 // Skip this handle if the Firmware Volume Protocol is already installed
272 Status
= gBS
->HandleProtocol (
274 &gEfiFirmwareVolumeProtocolGuid
,
275 (VOID
**)&FirmwareVolume
277 if (!EFI_ERROR (Status
)) {
282 // Allocate private data structure
284 Private
= AllocateCopyPool (sizeof (FIRMWARE_VOLUME_PRIVATE_DATA
), &gFirmwareVolumePrivateDataTemplate
);
285 if (Private
== NULL
) {
290 // Retrieve the Firmware Volume2 Protocol
292 Status
= gBS
->HandleProtocol (
294 &gEfiFirmwareVolume2ProtocolGuid
,
295 (VOID
**)&Private
->FirmwareVolume2
297 ASSERT_EFI_ERROR (Status
);
300 // Fill in rest of private data structure
302 Private
->FirmwareVolume
.KeySize
= Private
->FirmwareVolume2
->KeySize
;
303 Private
->FirmwareVolume
.ParentHandle
= Private
->FirmwareVolume2
->ParentHandle
;
306 // Install Firmware Volume Protocol onto same handle
308 Status
= gBS
->InstallMultipleProtocolInterfaces (
310 &gEfiFirmwareVolumeProtocolGuid
,
311 &Private
->FirmwareVolume
,
314 ASSERT_EFI_ERROR (Status
);
320 The user Entry Point for DXE driver. The user code starts with this function
321 as the real entry point for the image goes into a library that calls this
324 @param[in] ImageHandle The firmware allocated handle for the EFI image.
325 @param[in] SystemTable A pointer to the EFI System Table.
327 @retval EFI_SUCCESS The entry point is executed successfully.
328 @retval other Some error occurs when executing this entry point.
333 InitializeFirmwareVolume2 (
334 IN EFI_HANDLE ImageHandle
,
335 IN EFI_SYSTEM_TABLE
*SystemTable
338 EfiCreateProtocolNotifyEvent (
339 &gEfiFirmwareVolume2ProtocolGuid
,
348 FRAMEWORK_EFI_FV_ATTRIBUTES
349 Fv2AttributesToFvAttributes (
350 EFI_FV_ATTRIBUTES Fv2Attributes
354 // Clear those filed that is not defined in Framework FV spec and Alignment conversion.
356 return (Fv2Attributes
& 0x1ff) | ((UINTN
) EFI_FV_ALIGNMENT_2
<< RShiftU64((Fv2Attributes
& EFI_FV2_ALIGNMENT
), 16));
360 Retrieves attributes, insures positive polarity of attribute bits, returns
361 resulting attributes in output parameter
363 @param This Calling context
364 @param Attributes output buffer which contains attributes
366 @retval EFI_INVALID_PARAMETER
372 FvGetVolumeAttributes (
373 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
374 OUT FRAMEWORK_EFI_FV_ATTRIBUTES
*Attributes
378 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
379 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
381 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
382 FirmwareVolume2
= Private
->FirmwareVolume2
;
384 Status
= FirmwareVolume2
->GetVolumeAttributes (
388 if (!EFI_ERROR (Status
)) {
389 *Attributes
= Fv2AttributesToFvAttributes (*Attributes
);
395 Sets volume attributes
397 @param This Calling context
398 @param Attributes Buffer which contains attributes
400 @retval EFI_INVALID_PARAMETER
401 @retval EFI_DEVICE_ERROR
407 FvSetVolumeAttributes (
408 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
409 IN OUT FRAMEWORK_EFI_FV_ATTRIBUTES
*Attributes
412 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
413 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
414 EFI_FV_ATTRIBUTES Fv2Attributes
;
417 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
418 FirmwareVolume2
= Private
->FirmwareVolume2
;
420 Fv2Attributes
= (*Attributes
& 0x1ff);
421 Status
= FirmwareVolume2
->SetVolumeAttributes (
426 *Attributes
= Fv2AttributesToFvAttributes (Fv2Attributes
);
432 Read the requested file (NameGuid) and returns data in Buffer.
434 @param This Calling context
435 @param NameGuid Filename identifying which file to read
436 @param Buffer Pointer to pointer to buffer in which contents of file are returned.
438 If Buffer is NULL, only type, attributes, and size are returned as
439 there is no output buffer.
441 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated
442 from BS pool by ReadFile
444 If Buffer != NULL and *Buffer != NULL, the output buffer has been
445 allocated by the caller and is being passed in.
446 @param BufferSize Indicates the buffer size passed in, and on output the size
447 required to complete the read
448 @param FoundType Indicates the type of the file who's data is returned
449 @param FileAttributes Indicates the attributes of the file who's data is resturned
450 @param AuthenticationStatus Indicates the authentication status of the data
453 @retval EFI_WARN_BUFFER_TOO_SMALL
454 @retval EFI_NOT_FOUND
455 @retval EFI_DEVICE_ERROR
456 @retval EFI_ACCESS_DENIED
462 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
463 IN EFI_GUID
*NameGuid
,
464 IN OUT VOID
**Buffer
,
465 IN OUT UINTN
*BufferSize
,
466 OUT EFI_FV_FILETYPE
*FoundType
,
467 OUT EFI_FV_FILE_ATTRIBUTES
*FileAttributes
,
468 OUT UINT32
*AuthenticationStatus
471 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
472 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
475 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
476 FirmwareVolume2
= Private
->FirmwareVolume2
;
478 Status
= FirmwareVolume2
->ReadFile (
489 // For Framework FV attrbutes, only alignment fields are valid.
491 *FileAttributes
= *FileAttributes
& EFI_FV_FILE_ATTRIB_ALIGNMENT
;
497 Read the requested section from the specified file and returns data in Buffer.
499 @param This Calling context
500 @param NameGuid Filename identifying the file from which to read
501 @param SectionType Indicates what section type to retrieve
502 @param SectionInstance Indicates which instance of SectionType to retrieve
503 @param Buffer Pointer to pointer to buffer in which contents of file are returned.
505 If Buffer is NULL, only type, attributes, and size are returned as
506 there is no output buffer.
508 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated
509 from BS pool by ReadFile
511 If Buffer != NULL and *Buffer != NULL, the output buffer has been
512 allocated by the caller and is being passed in.
513 @param BufferSize Indicates the buffer size passed in, and on output the size
514 required to complete the read
515 @param AuthenticationStatus Indicates the authentication status of the data
518 @retval EFI_WARN_BUFFER_TOO_SMALL
519 @retval EFI_OUT_OF_RESOURCES
520 @retval EFI_NOT_FOUND
521 @retval EFI_DEVICE_ERROR
522 @retval EFI_ACCESS_DENIED
528 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
529 IN EFI_GUID
*NameGuid
,
530 IN EFI_SECTION_TYPE SectionType
,
531 IN UINTN SectionInstance
,
532 IN OUT VOID
**Buffer
,
533 IN OUT UINTN
*BufferSize
,
534 OUT UINT32
*AuthenticationStatus
537 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
538 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
540 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
541 FirmwareVolume2
= Private
->FirmwareVolume2
;
543 return FirmwareVolume2
->ReadSection (
555 Write the supplied file (NameGuid) to the FV.
557 @param This Calling context
558 @param NumberOfFiles Indicates the number of file records pointed to by FileData
559 @param WritePolicy Indicates the level of reliability of the write with respect to
560 things like power failure events.
561 @param FileData A pointer to an array of EFI_FV_WRITE_FILE_DATA structures. Each
562 element in the array indicates a file to write, and there are
563 NumberOfFiles elements in the input array.
566 @retval EFI_OUT_OF_RESOURCES
567 @retval EFI_DEVICE_ERROR
568 @retval EFI_WRITE_PROTECTED
569 @retval EFI_NOT_FOUND
570 @retval EFI_INVALID_PARAMETER
576 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
577 IN UINT32 NumberOfFiles
,
578 IN FRAMEWORK_EFI_FV_WRITE_POLICY WritePolicy
,
579 IN FRAMEWORK_EFI_FV_WRITE_FILE_DATA
*FileData
582 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
583 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
584 EFI_FV_WRITE_FILE_DATA
*PiFileData
;
588 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
589 FirmwareVolume2
= Private
->FirmwareVolume2
;
591 PiFileData
= AllocateCopyPool (sizeof (EFI_FV_WRITE_FILE_DATA
), FileData
);
594 // Framework Spec assume firmware files are Memory-Mapped.
596 for (Index
= 0; Index
< NumberOfFiles
; Index
++) {
597 PiFileData
[Index
].FileAttributes
|= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED
;
600 Status
= FirmwareVolume2
->WriteFile (
604 (EFI_FV_WRITE_FILE_DATA
*)FileData
607 FreePool (PiFileData
);
612 Given the input key, search for the next matching file in the volume.
614 @param This Calling context
615 @param Key Pointer to a caller allocated buffer that contains an implementation
616 specific key that is used to track where to begin searching on
618 @param FileType Indicates the file type to filter for
619 @param NameGuid Guid filename of the file found
620 @param Attributes Attributes of the file found
621 @param Size Size in bytes of the file found
624 @retval EFI_NOT_FOUND
625 @retval EFI_DEVICE_ERROR
626 @retval EFI_ACCESS_DENIED
632 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*This
,
634 IN OUT EFI_FV_FILETYPE
*FileType
,
635 OUT EFI_GUID
*NameGuid
,
636 OUT EFI_FV_FILE_ATTRIBUTES
*Attributes
,
640 FIRMWARE_VOLUME_PRIVATE_DATA
*Private
;
641 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FirmwareVolume2
;
644 Private
= FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This
);
645 FirmwareVolume2
= Private
->FirmwareVolume2
;
647 Status
= FirmwareVolume2
->GetNextFile (
657 // For Framework FV attrbutes, only alignment fields are valid.
659 *Attributes
= *Attributes
& EFI_FV_FILE_ATTRIB_ALIGNMENT
;