]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/FvOnFv2Thunk/FvOnFv2Thunk.c
Add the missing check for NULL pointer before use it.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FvOnFv2Thunk / FvOnFv2Thunk.c
CommitLineData
0d694539 1/** @file\r
2UEFI PI specification supersedes Inte's Framework Specification.\r
3EFI_FIRMWARE_VOLUME_PROTOCOL defined in Intel Framework Pkg is replaced by\r
4EFI_FIRMWARE_VOLUME2_PROTOCOL in MdePkg.\r
5This module produces FV on top of FV2. This module is used on platform when both of\r
6these two conditions are true:\r
71) Framework module consuming FV is present\r
82) And the platform only produces FV2\r
4259256b 9\r
771ececd 10Copyright (c) 2006 - 2010 Intel Corporation. <BR>\r
4259256b 11All rights reserved. This program and the accompanying materials\r
12are licensed and made available under the terms and conditions of the BSD License\r
13which accompanies this distribution. The full text of the license may be found at\r
14http://opensource.org/licenses/bsd-license.php\r
15\r
16THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18Module Name:\r
19\r
0d694539 20**/\r
4259256b 21\r
22#include <PiDxe.h>\r
23#include <Protocol/FirmwareVolume2.h>\r
24#include <Protocol/FirmwareVolume.h>\r
25#include <Library/BaseLib.h>\r
26#include <Library/DebugLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/UefiDriverEntryPoint.h>\r
29#include <Library/UefiLib.h>\r
30#include <Library/MemoryAllocationLib.h>\r
31\r
32/**\r
33 Retrieves attributes, insures positive polarity of attribute bits, returns\r
34 resulting attributes in output parameter\r
35\r
36 @param This Calling context\r
37 @param Attributes output buffer which contains attributes\r
38\r
39 @retval EFI_INVALID_PARAMETER\r
40 @retval EFI_SUCCESS\r
41\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45FvGetVolumeAttributes (\r
46 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
47 OUT FRAMEWORK_EFI_FV_ATTRIBUTES *Attributes\r
48 );\r
49\r
50/**\r
51 Sets volume attributes\r
52\r
53 @param This Calling context\r
54 @param Attributes Buffer which contains attributes\r
55\r
56 @retval EFI_INVALID_PARAMETER\r
57 @retval EFI_DEVICE_ERROR\r
58 @retval EFI_SUCCESS\r
59\r
60**/\r
61EFI_STATUS\r
62EFIAPI\r
63FvSetVolumeAttributes (\r
64 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
65 IN OUT FRAMEWORK_EFI_FV_ATTRIBUTES *Attributes\r
66 );\r
67\r
68/**\r
69 Read the requested file (NameGuid) and returns data in Buffer.\r
70\r
71 @param This Calling context\r
72 @param NameGuid Filename identifying which file to read\r
73 @param Buffer Pointer to pointer to buffer in which contents of file are returned.\r
74 <br>\r
75 If Buffer is NULL, only type, attributes, and size are returned as\r
76 there is no output buffer.\r
77 <br>\r
78 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated\r
79 from BS pool by ReadFile\r
80 <br>\r
81 If Buffer != NULL and *Buffer != NULL, the output buffer has been\r
82 allocated by the caller and is being passed in.\r
83 @param BufferSize Indicates the buffer size passed in, and on output the size\r
84 required to complete the read\r
85 @param FoundType Indicates the type of the file who's data is returned\r
86 @param FileAttributes Indicates the attributes of the file who's data is resturned\r
87 @param AuthenticationStatus Indicates the authentication status of the data\r
88\r
89 @retval EFI_SUCCESS\r
90 @retval EFI_WARN_BUFFER_TOO_SMALL\r
91 @retval EFI_NOT_FOUND\r
92 @retval EFI_DEVICE_ERROR\r
93 @retval EFI_ACCESS_DENIED\r
94\r
95**/\r
96EFI_STATUS\r
97EFIAPI\r
98FvReadFile (\r
99 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
100 IN EFI_GUID *NameGuid,\r
101 IN OUT VOID **Buffer,\r
102 IN OUT UINTN *BufferSize,\r
103 OUT EFI_FV_FILETYPE *FoundType,\r
104 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
105 OUT UINT32 *AuthenticationStatus\r
106 );\r
107\r
108/**\r
109 Read the requested section from the specified file and returns data in Buffer.\r
110\r
111 @param This Calling context\r
112 @param NameGuid Filename identifying the file from which to read\r
113 @param SectionType Indicates what section type to retrieve\r
114 @param SectionInstance Indicates which instance of SectionType to retrieve\r
115 @param Buffer Pointer to pointer to buffer in which contents of file are returned.\r
116 <br>\r
117 If Buffer is NULL, only type, attributes, and size are returned as\r
118 there is no output buffer.\r
119 <br>\r
120 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated\r
121 from BS pool by ReadFile\r
122 <br>\r
123 If Buffer != NULL and *Buffer != NULL, the output buffer has been\r
124 allocated by the caller and is being passed in.\r
125 @param BufferSize Indicates the buffer size passed in, and on output the size\r
126 required to complete the read\r
127 @param AuthenticationStatus Indicates the authentication status of the data\r
128\r
129 @retval EFI_SUCCESS\r
130 @retval EFI_WARN_BUFFER_TOO_SMALL\r
131 @retval EFI_OUT_OF_RESOURCES\r
132 @retval EFI_NOT_FOUND\r
133 @retval EFI_DEVICE_ERROR\r
134 @retval EFI_ACCESS_DENIED\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI \r
139FvReadSection (\r
140 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
141 IN EFI_GUID *NameGuid,\r
142 IN EFI_SECTION_TYPE SectionType,\r
143 IN UINTN SectionInstance,\r
144 IN OUT VOID **Buffer,\r
145 IN OUT UINTN *BufferSize,\r
146 OUT UINT32 *AuthenticationStatus\r
147 );\r
148\r
149/**\r
150 Write the supplied file (NameGuid) to the FV.\r
151\r
152 @param This Calling context\r
153 @param NumberOfFiles Indicates the number of file records pointed to by FileData\r
154 @param WritePolicy Indicates the level of reliability of the write with respect to\r
155 things like power failure events.\r
156 @param FileData A pointer to an array of EFI_FV_WRITE_FILE_DATA structures. Each\r
157 element in the array indicates a file to write, and there are\r
158 NumberOfFiles elements in the input array.\r
159\r
160 @retval EFI_SUCCESS\r
161 @retval EFI_OUT_OF_RESOURCES\r
162 @retval EFI_DEVICE_ERROR\r
163 @retval EFI_WRITE_PROTECTED\r
164 @retval EFI_NOT_FOUND\r
165 @retval EFI_INVALID_PARAMETER\r
166\r
167**/\r
168EFI_STATUS\r
169EFIAPI \r
170FvWriteFile (\r
171 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
172 IN UINT32 NumberOfFiles,\r
173 IN FRAMEWORK_EFI_FV_WRITE_POLICY WritePolicy,\r
174 IN FRAMEWORK_EFI_FV_WRITE_FILE_DATA *FileData\r
175 );\r
176\r
177/**\r
178 Given the input key, search for the next matching file in the volume.\r
179\r
180 @param This Calling context\r
181 @param Key Pointer to a caller allocated buffer that contains an implementation\r
182 specific key that is used to track where to begin searching on\r
183 successive calls.\r
184 @param FileType Indicates the file type to filter for\r
185 @param NameGuid Guid filename of the file found\r
186 @param Attributes Attributes of the file found\r
187 @param Size Size in bytes of the file found\r
188\r
189 @retval EFI_SUCCESS\r
190 @retval EFI_NOT_FOUND\r
191 @retval EFI_DEVICE_ERROR\r
192 @retval EFI_ACCESS_DENIED\r
193\r
194**/\r
195EFI_STATUS\r
196EFIAPI \r
197FvGetNextFile (\r
198 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
199 IN OUT VOID *Key,\r
200 IN OUT EFI_FV_FILETYPE *FileType,\r
201 OUT EFI_GUID *NameGuid,\r
202 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
203 OUT UINTN *Size\r
204 );\r
205\r
a3a83173 206#define FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('f', 'v', 't', 'h')\r
4259256b 207\r
208typedef struct {\r
209 UINTN Signature;\r
210 EFI_FIRMWARE_VOLUME_PROTOCOL FirmwareVolume;\r
211 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
212} FIRMWARE_VOLUME_PRIVATE_DATA;\r
213\r
214#define FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS(a) CR (a, FIRMWARE_VOLUME_PRIVATE_DATA, FirmwareVolume, FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE)\r
215\r
216//\r
217// Firmware Volume Protocol template\r
218//\r
219EFI_EVENT mFvRegistration;\r
220\r
221FIRMWARE_VOLUME_PRIVATE_DATA gFirmwareVolumePrivateDataTemplate = {\r
222 FIRMWARE_VOLUME_PRIVATE_DATA_SIGNATURE,\r
223 {\r
224 FvGetVolumeAttributes,\r
225 FvSetVolumeAttributes,\r
226 FvReadFile,\r
227 FvReadSection,\r
228 FvWriteFile,\r
229 FvGetNextFile,\r
230 0,\r
231 NULL\r
232 },\r
233 NULL\r
234};\r
235\r
236//\r
237// Module globals\r
238//\r
239\r
240VOID\r
241EFIAPI\r
242FvNotificationEvent (\r
243 IN EFI_EVENT Event,\r
244 IN VOID *Context\r
245 )\r
246{\r
247 EFI_STATUS Status;\r
248 UINTN BufferSize;\r
249 EFI_HANDLE Handle;\r
250 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
251 EFI_FIRMWARE_VOLUME_PROTOCOL *FirmwareVolume;\r
252\r
253 while (TRUE) {\r
254 BufferSize = sizeof (Handle);\r
255 Status = gBS->LocateHandle (\r
256 ByRegisterNotify,\r
257 &gEfiFirmwareVolume2ProtocolGuid,\r
258 mFvRegistration,\r
259 &BufferSize,\r
260 &Handle\r
261 );\r
262 if (EFI_ERROR (Status)) {\r
263 //\r
264 // Exit Path of While Loop....\r
265 //\r
266 break;\r
267 }\r
268\r
269 //\r
270 // Skip this handle if the Firmware Volume Protocol is already installed\r
271 //\r
272 Status = gBS->HandleProtocol (\r
273 Handle,\r
274 &gEfiFirmwareVolumeProtocolGuid,\r
275 (VOID **)&FirmwareVolume\r
276 );\r
277 if (!EFI_ERROR (Status)) {\r
278 continue;\r
279 }\r
280\r
281 //\r
282 // Allocate private data structure\r
283 //\r
284 Private = AllocateCopyPool (sizeof (FIRMWARE_VOLUME_PRIVATE_DATA), &gFirmwareVolumePrivateDataTemplate);\r
285 if (Private == NULL) {\r
286 continue;\r
287 }\r
288\r
289 //\r
290 // Retrieve the Firmware Volume2 Protocol\r
291 //\r
292 Status = gBS->HandleProtocol (\r
293 Handle,\r
294 &gEfiFirmwareVolume2ProtocolGuid,\r
295 (VOID **)&Private->FirmwareVolume2\r
296 );\r
297 ASSERT_EFI_ERROR (Status);\r
298\r
299 //\r
300 // Fill in rest of private data structure\r
301 //\r
302 Private->FirmwareVolume.KeySize = Private->FirmwareVolume2->KeySize;\r
303 Private->FirmwareVolume.ParentHandle = Private->FirmwareVolume2->ParentHandle;\r
304\r
305 //\r
306 // Install Firmware Volume Protocol onto same handle\r
307 //\r
308 Status = gBS->InstallMultipleProtocolInterfaces (\r
309 &Handle,\r
310 &gEfiFirmwareVolumeProtocolGuid,\r
311 &Private->FirmwareVolume,\r
312 NULL\r
313 );\r
314 ASSERT_EFI_ERROR (Status);\r
315 }\r
316}\r
317\r
318\r
319/**\r
320 The user Entry Point for DXE driver. The user code starts with this function\r
321 as the real entry point for the image goes into a library that calls this \r
322 function.\r
323\r
324 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
325 @param[in] SystemTable A pointer to the EFI System Table.\r
326 \r
327 @retval EFI_SUCCESS The entry point is executed successfully.\r
328 @retval other Some error occurs when executing this entry point.\r
329\r
330**/\r
331EFI_STATUS\r
332EFIAPI\r
333InitializeFirmwareVolume2 (\r
334 IN EFI_HANDLE ImageHandle,\r
335 IN EFI_SYSTEM_TABLE *SystemTable\r
336 )\r
337{\r
338 EfiCreateProtocolNotifyEvent (\r
339 &gEfiFirmwareVolume2ProtocolGuid,\r
340 TPL_CALLBACK,\r
341 FvNotificationEvent,\r
342 NULL,\r
343 &mFvRegistration\r
344 );\r
345 return EFI_SUCCESS;\r
346}\r
347\r
90eff005 348/**\r
349 Convert FV attrbiutes to FV2 attributes.\r
350\r
351 @param Fv2Attributes FV2 attributes.\r
352\r
353 @return FV attributes.\r
354\r
355**/\r
19caab51 356FRAMEWORK_EFI_FV_ATTRIBUTES\r
357Fv2AttributesToFvAttributes (\r
90eff005 358 IN EFI_FV_ATTRIBUTES Fv2Attributes\r
19caab51 359 )\r
360{\r
361 //\r
362 // Clear those filed that is not defined in Framework FV spec and Alignment conversion.\r
363 //\r
364 return (Fv2Attributes & 0x1ff) | ((UINTN) EFI_FV_ALIGNMENT_2 << RShiftU64((Fv2Attributes & EFI_FV2_ALIGNMENT), 16));\r
365}\r
366\r
4259256b 367/**\r
368 Retrieves attributes, insures positive polarity of attribute bits, returns\r
369 resulting attributes in output parameter\r
370\r
371 @param This Calling context\r
372 @param Attributes output buffer which contains attributes\r
373\r
374 @retval EFI_INVALID_PARAMETER\r
375 @retval EFI_SUCCESS\r
376\r
377**/\r
378EFI_STATUS\r
379EFIAPI\r
380FvGetVolumeAttributes (\r
381 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
382 OUT FRAMEWORK_EFI_FV_ATTRIBUTES *Attributes\r
383 )\r
384{\r
385 EFI_STATUS Status;\r
386 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
387 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
388\r
389 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
390 FirmwareVolume2 = Private->FirmwareVolume2;\r
391\r
392 Status = FirmwareVolume2->GetVolumeAttributes (\r
393 FirmwareVolume2,\r
394 Attributes\r
395 );\r
396 if (!EFI_ERROR (Status)) {\r
19caab51 397 *Attributes = Fv2AttributesToFvAttributes (*Attributes);\r
4259256b 398 }\r
399 return Status;\r
400}\r
401\r
402/**\r
403 Sets volume attributes\r
404\r
405 @param This Calling context\r
406 @param Attributes Buffer which contains attributes\r
407\r
408 @retval EFI_INVALID_PARAMETER\r
409 @retval EFI_DEVICE_ERROR\r
410 @retval EFI_SUCCESS\r
411\r
412**/\r
413EFI_STATUS\r
414EFIAPI\r
415FvSetVolumeAttributes (\r
416 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
417 IN OUT FRAMEWORK_EFI_FV_ATTRIBUTES *Attributes\r
418 )\r
419{\r
420 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
421 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
4259256b 422 EFI_FV_ATTRIBUTES Fv2Attributes; \r
19caab51 423 EFI_STATUS Status;\r
4259256b 424\r
425 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
426 FirmwareVolume2 = Private->FirmwareVolume2;\r
427\r
428 Fv2Attributes = (*Attributes & 0x1ff);\r
19caab51 429 Status = FirmwareVolume2->SetVolumeAttributes (\r
4259256b 430 FirmwareVolume2,\r
431 &Fv2Attributes\r
432 );\r
19caab51 433\r
434 *Attributes = Fv2AttributesToFvAttributes (Fv2Attributes);\r
435 \r
436 return Status;\r
4259256b 437}\r
438\r
439/**\r
440 Read the requested file (NameGuid) and returns data in Buffer.\r
441\r
442 @param This Calling context\r
443 @param NameGuid Filename identifying which file to read\r
444 @param Buffer Pointer to pointer to buffer in which contents of file are returned.\r
445 <br>\r
446 If Buffer is NULL, only type, attributes, and size are returned as\r
447 there is no output buffer.\r
448 <br>\r
449 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated\r
450 from BS pool by ReadFile\r
451 <br>\r
452 If Buffer != NULL and *Buffer != NULL, the output buffer has been\r
453 allocated by the caller and is being passed in.\r
454 @param BufferSize Indicates the buffer size passed in, and on output the size\r
455 required to complete the read\r
456 @param FoundType Indicates the type of the file who's data is returned\r
457 @param FileAttributes Indicates the attributes of the file who's data is resturned\r
458 @param AuthenticationStatus Indicates the authentication status of the data\r
459\r
460 @retval EFI_SUCCESS\r
461 @retval EFI_WARN_BUFFER_TOO_SMALL\r
462 @retval EFI_NOT_FOUND\r
463 @retval EFI_DEVICE_ERROR\r
464 @retval EFI_ACCESS_DENIED\r
465\r
466**/\r
467EFI_STATUS\r
468EFIAPI\r
469FvReadFile (\r
470 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
471 IN EFI_GUID *NameGuid,\r
472 IN OUT VOID **Buffer,\r
473 IN OUT UINTN *BufferSize,\r
474 OUT EFI_FV_FILETYPE *FoundType,\r
475 OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r
476 OUT UINT32 *AuthenticationStatus\r
477 )\r
478{\r
479 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
480 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
19caab51 481 EFI_STATUS Status;\r
4259256b 482\r
483 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
484 FirmwareVolume2 = Private->FirmwareVolume2;\r
485\r
19caab51 486 Status = FirmwareVolume2->ReadFile (\r
4259256b 487 FirmwareVolume2,\r
488 NameGuid,\r
489 Buffer,\r
490 BufferSize,\r
491 FoundType,\r
492 FileAttributes,\r
493 AuthenticationStatus\r
494 );\r
19caab51 495\r
496 //\r
497 // For Framework FV attrbutes, only alignment fields are valid.\r
498 //\r
499 *FileAttributes = *FileAttributes & EFI_FV_FILE_ATTRIB_ALIGNMENT;\r
500 \r
501 return Status;\r
4259256b 502}\r
503\r
504/**\r
505 Read the requested section from the specified file and returns data in Buffer.\r
506\r
507 @param This Calling context\r
508 @param NameGuid Filename identifying the file from which to read\r
509 @param SectionType Indicates what section type to retrieve\r
510 @param SectionInstance Indicates which instance of SectionType to retrieve\r
511 @param Buffer Pointer to pointer to buffer in which contents of file are returned.\r
512 <br>\r
513 If Buffer is NULL, only type, attributes, and size are returned as\r
514 there is no output buffer.\r
515 <br>\r
516 If Buffer != NULL and *Buffer == NULL, the output buffer is allocated\r
517 from BS pool by ReadFile\r
518 <br>\r
519 If Buffer != NULL and *Buffer != NULL, the output buffer has been\r
520 allocated by the caller and is being passed in.\r
521 @param BufferSize Indicates the buffer size passed in, and on output the size\r
522 required to complete the read\r
523 @param AuthenticationStatus Indicates the authentication status of the data\r
524\r
525 @retval EFI_SUCCESS\r
526 @retval EFI_WARN_BUFFER_TOO_SMALL\r
527 @retval EFI_OUT_OF_RESOURCES\r
528 @retval EFI_NOT_FOUND\r
529 @retval EFI_DEVICE_ERROR\r
530 @retval EFI_ACCESS_DENIED\r
531\r
532**/\r
533EFI_STATUS\r
534EFIAPI \r
535FvReadSection (\r
536 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
537 IN EFI_GUID *NameGuid,\r
538 IN EFI_SECTION_TYPE SectionType,\r
539 IN UINTN SectionInstance,\r
540 IN OUT VOID **Buffer,\r
541 IN OUT UINTN *BufferSize,\r
542 OUT UINT32 *AuthenticationStatus\r
543 )\r
544{\r
545 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
546 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
547\r
548 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
549 FirmwareVolume2 = Private->FirmwareVolume2;\r
550\r
551 return FirmwareVolume2->ReadSection (\r
552 FirmwareVolume2,\r
553 NameGuid,\r
554 SectionType,\r
555 SectionInstance,\r
556 Buffer,\r
557 BufferSize,\r
558 AuthenticationStatus\r
559 );\r
560}\r
561\r
562/**\r
563 Write the supplied file (NameGuid) to the FV.\r
564\r
565 @param This Calling context\r
566 @param NumberOfFiles Indicates the number of file records pointed to by FileData\r
567 @param WritePolicy Indicates the level of reliability of the write with respect to\r
568 things like power failure events.\r
569 @param FileData A pointer to an array of EFI_FV_WRITE_FILE_DATA structures. Each\r
570 element in the array indicates a file to write, and there are\r
571 NumberOfFiles elements in the input array.\r
572\r
573 @retval EFI_SUCCESS\r
574 @retval EFI_OUT_OF_RESOURCES\r
575 @retval EFI_DEVICE_ERROR\r
576 @retval EFI_WRITE_PROTECTED\r
577 @retval EFI_NOT_FOUND\r
578 @retval EFI_INVALID_PARAMETER\r
579\r
580**/\r
581EFI_STATUS\r
582EFIAPI \r
583FvWriteFile (\r
584 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
585 IN UINT32 NumberOfFiles,\r
586 IN FRAMEWORK_EFI_FV_WRITE_POLICY WritePolicy,\r
587 IN FRAMEWORK_EFI_FV_WRITE_FILE_DATA *FileData\r
588 )\r
589{\r
590 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
591 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
19caab51 592 EFI_FV_WRITE_FILE_DATA *PiFileData;\r
593 EFI_STATUS Status;\r
594 UINTN Index;\r
4259256b 595\r
596 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
597 FirmwareVolume2 = Private->FirmwareVolume2;\r
598\r
19caab51 599 PiFileData = AllocateCopyPool (sizeof (EFI_FV_WRITE_FILE_DATA), FileData);\r
771ececd 600 ASSERT (PiFileData != NULL);\r
19caab51 601\r
602 //\r
603 // Framework Spec assume firmware files are Memory-Mapped.\r
604 //\r
605 for (Index = 0; Index < NumberOfFiles; Index++) {\r
606 PiFileData[Index].FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED;\r
607 }\r
608\r
609 Status = FirmwareVolume2->WriteFile (\r
4259256b 610 FirmwareVolume2,\r
611 NumberOfFiles,\r
612 WritePolicy,\r
613 (EFI_FV_WRITE_FILE_DATA *)FileData\r
614 );\r
19caab51 615\r
616 FreePool (PiFileData);\r
617 return Status;\r
4259256b 618}\r
619\r
620/**\r
621 Given the input key, search for the next matching file in the volume.\r
622\r
623 @param This Calling context\r
624 @param Key Pointer to a caller allocated buffer that contains an implementation\r
625 specific key that is used to track where to begin searching on\r
626 successive calls.\r
627 @param FileType Indicates the file type to filter for\r
628 @param NameGuid Guid filename of the file found\r
629 @param Attributes Attributes of the file found\r
630 @param Size Size in bytes of the file found\r
631\r
632 @retval EFI_SUCCESS\r
633 @retval EFI_NOT_FOUND\r
634 @retval EFI_DEVICE_ERROR\r
635 @retval EFI_ACCESS_DENIED\r
636\r
637**/\r
638EFI_STATUS\r
639EFIAPI \r
640FvGetNextFile (\r
641 IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,\r
642 IN OUT VOID *Key,\r
643 IN OUT EFI_FV_FILETYPE *FileType,\r
644 OUT EFI_GUID *NameGuid,\r
645 OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r
646 OUT UINTN *Size\r
647 )\r
648{\r
649 FIRMWARE_VOLUME_PRIVATE_DATA *Private;\r
650 EFI_FIRMWARE_VOLUME2_PROTOCOL *FirmwareVolume2;\r
19caab51 651 EFI_STATUS Status;\r
4259256b 652\r
653 Private = FIRMWARE_VOLUME_PRIVATE_DATA_FROM_THIS (This);\r
654 FirmwareVolume2 = Private->FirmwareVolume2;\r
655\r
19caab51 656 Status = FirmwareVolume2->GetNextFile (\r
4259256b 657 FirmwareVolume2,\r
658 Key,\r
659 FileType,\r
660 NameGuid,\r
661 Attributes,\r
662 Size\r
663 );\r
19caab51 664\r
665 //\r
666 // For Framework FV attrbutes, only alignment fields are valid.\r
667 //\r
668 *Attributes = *Attributes & EFI_FV_FILE_ATTRIB_ALIGNMENT;\r
669 \r
670 return Status;\r
4259256b 671}\r