]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
Clean up DEC files:
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / FwVolBlock / FwVolBlock.c
... / ...
CommitLineData
1/** @file\r
2 Implementations for Firmware Volume Block protocol.\r
3\r
4 It consumes FV HOBs and creates read-only Firmare Volume Block protocol\r
5 instances for each of them.\r
6\r
7Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
8This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include "DxeMain.h"\r
19#include "FwVolBlock.h"\r
20\r
21FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {\r
22 {\r
23 {\r
24 HARDWARE_DEVICE_PATH,\r
25 HW_MEMMAP_DP,\r
26 {\r
27 (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r
28 (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8)\r
29 }\r
30 },\r
31 EfiMemoryMappedIO,\r
32 (EFI_PHYSICAL_ADDRESS) 0,\r
33 (EFI_PHYSICAL_ADDRESS) 0,\r
34 },\r
35 {\r
36 END_DEVICE_PATH_TYPE,\r
37 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
38 {\r
39 END_DEVICE_PATH_LENGTH,\r
40 0\r
41 }\r
42 }\r
43};\r
44\r
45FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {\r
46 {\r
47 {\r
48 MEDIA_DEVICE_PATH,\r
49 MEDIA_PIWG_FW_VOL_DP,\r
50 {\r
51 (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)),\r
52 (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8)\r
53 }\r
54 },\r
55 { 0 }\r
56 },\r
57 {\r
58 END_DEVICE_PATH_TYPE,\r
59 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
60 {\r
61 END_DEVICE_PATH_LENGTH,\r
62 0\r
63 }\r
64 }\r
65};\r
66\r
67EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {\r
68 FVB_DEVICE_SIGNATURE,\r
69 NULL,\r
70 NULL,\r
71 {\r
72 FwVolBlockGetAttributes,\r
73 (EFI_FVB_SET_ATTRIBUTES)FwVolBlockSetAttributes,\r
74 FwVolBlockGetPhysicalAddress,\r
75 FwVolBlockGetBlockSize,\r
76 FwVolBlockReadBlock,\r
77 (EFI_FVB_WRITE)FwVolBlockWriteBlock,\r
78 (EFI_FVB_ERASE_BLOCKS)FwVolBlockEraseBlock,\r
79 NULL\r
80 },\r
81 0,\r
82 NULL,\r
83 0,\r
84 0\r
85};\r
86\r
87\r
88\r
89/**\r
90 Retrieves Volume attributes. No polarity translations are done.\r
91\r
92 @param This Calling context\r
93 @param Attributes output buffer which contains attributes\r
94\r
95 @retval EFI_SUCCESS The firmware volume attributes were returned.\r
96\r
97**/\r
98EFI_STATUS\r
99EFIAPI\r
100FwVolBlockGetAttributes (\r
101 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
102 OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
103 )\r
104{\r
105 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
106\r
107 FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
108\r
109 //\r
110 // Since we are read only, it's safe to get attributes data from our in-memory copy.\r
111 //\r
112 *Attributes = FvbDevice->FvbAttributes & ~EFI_FVB2_WRITE_STATUS;\r
113\r
114 return EFI_SUCCESS;\r
115}\r
116\r
117\r
118\r
119/**\r
120 Modifies the current settings of the firmware volume according to the input parameter.\r
121\r
122 @param This Calling context\r
123 @param Attributes input buffer which contains attributes\r
124\r
125 @retval EFI_SUCCESS The firmware volume attributes were returned.\r
126 @retval EFI_INVALID_PARAMETER The attributes requested are in conflict with\r
127 the capabilities as declared in the firmware\r
128 volume header.\r
129 @retval EFI_UNSUPPORTED Not supported.\r
130\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134FwVolBlockSetAttributes (\r
135 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
136 IN CONST EFI_FVB_ATTRIBUTES_2 *Attributes\r
137 )\r
138{\r
139 return EFI_UNSUPPORTED;\r
140}\r
141\r
142\r
143\r
144/**\r
145 The EraseBlock() function erases one or more blocks as denoted by the\r
146 variable argument list. The entire parameter list of blocks must be verified\r
147 prior to erasing any blocks. If a block is requested that does not exist\r
148 within the associated firmware volume (it has a larger index than the last\r
149 block of the firmware volume), the EraseBlock() function must return\r
150 EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.\r
151\r
152 @param This Calling context\r
153 @param ... Starting LBA followed by Number of Lba to erase.\r
154 a -1 to terminate the list.\r
155\r
156 @retval EFI_SUCCESS The erase request was successfully completed.\r
157 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled\r
158 state.\r
159 @retval EFI_DEVICE_ERROR The block device is not functioning correctly\r
160 and could not be written. The firmware device\r
161 may have been partially erased.\r
162 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the variable\r
163 argument list do\r
164 @retval EFI_UNSUPPORTED Not supported.\r
165\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169FwVolBlockEraseBlock (\r
170 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
171 ...\r
172 )\r
173{\r
174 return EFI_UNSUPPORTED;\r
175}\r
176\r
177\r
178\r
179/**\r
180 Read the specified number of bytes from the block to the input buffer.\r
181\r
182 @param This Indicates the calling context.\r
183 @param Lba The starting logical block index to read.\r
184 @param Offset Offset into the block at which to begin reading.\r
185 @param NumBytes Pointer to a UINT32. At entry, *NumBytes\r
186 contains the total size of the buffer. At exit,\r
187 *NumBytes contains the total number of bytes\r
188 actually read.\r
189 @param Buffer Pinter to a caller-allocated buffer that\r
190 contains the destine for the read.\r
191\r
192 @retval EFI_SUCCESS The firmware volume was read successfully.\r
193 @retval EFI_BAD_BUFFER_SIZE The read was attempted across an LBA boundary.\r
194 @retval EFI_ACCESS_DENIED Access denied.\r
195 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not\r
196 be read.\r
197\r
198**/\r
199EFI_STATUS\r
200EFIAPI\r
201FwVolBlockReadBlock (\r
202 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
203 IN CONST EFI_LBA Lba,\r
204 IN CONST UINTN Offset,\r
205 IN OUT UINTN *NumBytes,\r
206 IN OUT UINT8 *Buffer\r
207 )\r
208{\r
209 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
210 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
211 UINT8 *LbaOffset;\r
212 UINTN LbaStart;\r
213 UINTN NumOfBytesRead;\r
214 UINTN LbaIndex;\r
215\r
216 FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
217\r
218 //\r
219 // Check if This FW can be read\r
220 //\r
221 if ((FvbDevice->FvbAttributes & EFI_FVB2_READ_STATUS) == 0) {\r
222 return EFI_ACCESS_DENIED;\r
223 }\r
224\r
225 LbaIndex = (UINTN) Lba;\r
226 if (LbaIndex >= FvbDevice->NumBlocks) {\r
227 //\r
228 // Invalid Lba, read nothing.\r
229 //\r
230 *NumBytes = 0;\r
231 return EFI_BAD_BUFFER_SIZE;\r
232 }\r
233\r
234 if (Offset > FvbDevice->LbaCache[LbaIndex].Length) {\r
235 //\r
236 // all exceed boundry, read nothing.\r
237 //\r
238 *NumBytes = 0;\r
239 return EFI_BAD_BUFFER_SIZE;\r
240 }\r
241\r
242 NumOfBytesRead = *NumBytes;\r
243 if (Offset + NumOfBytesRead > FvbDevice->LbaCache[LbaIndex].Length) {\r
244 //\r
245 // partial exceed boundry, read data from current postion to end.\r
246 //\r
247 NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;\r
248 }\r
249\r
250 LbaStart = FvbDevice->LbaCache[LbaIndex].Base;\r
251 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN) FvbDevice->BaseAddress);\r
252 LbaOffset = (UINT8 *) FwVolHeader + LbaStart + Offset;\r
253\r
254 //\r
255 // Perform read operation\r
256 //\r
257 CopyMem (Buffer, LbaOffset, NumOfBytesRead);\r
258\r
259 if (NumOfBytesRead == *NumBytes) {\r
260 return EFI_SUCCESS;\r
261 }\r
262\r
263 *NumBytes = NumOfBytesRead;\r
264 return EFI_BAD_BUFFER_SIZE;\r
265}\r
266\r
267\r
268\r
269/**\r
270 Writes the specified number of bytes from the input buffer to the block.\r
271\r
272 @param This Indicates the calling context.\r
273 @param Lba The starting logical block index to write to.\r
274 @param Offset Offset into the block at which to begin writing.\r
275 @param NumBytes Pointer to a UINT32. At entry, *NumBytes\r
276 contains the total size of the buffer. At exit,\r
277 *NumBytes contains the total number of bytes\r
278 actually written.\r
279 @param Buffer Pinter to a caller-allocated buffer that\r
280 contains the source for the write.\r
281\r
282 @retval EFI_SUCCESS The firmware volume was written successfully.\r
283 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.\r
284 On output, NumBytes contains the total number of\r
285 bytes actually written.\r
286 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled\r
287 state.\r
288 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not\r
289 be written.\r
290 @retval EFI_UNSUPPORTED Not supported.\r
291\r
292**/\r
293EFI_STATUS\r
294EFIAPI\r
295FwVolBlockWriteBlock (\r
296 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
297 IN EFI_LBA Lba,\r
298 IN UINTN Offset,\r
299 IN OUT UINTN *NumBytes,\r
300 IN UINT8 *Buffer\r
301 )\r
302{\r
303 return EFI_UNSUPPORTED;\r
304}\r
305\r
306\r
307\r
308/**\r
309 Get Fvb's base address.\r
310\r
311 @param This Indicates the calling context.\r
312 @param Address Fvb device base address.\r
313\r
314 @retval EFI_SUCCESS Successfully got Fvb's base address.\r
315 @retval EFI_UNSUPPORTED Not supported.\r
316\r
317**/\r
318EFI_STATUS\r
319EFIAPI\r
320FwVolBlockGetPhysicalAddress (\r
321 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
322 OUT EFI_PHYSICAL_ADDRESS *Address\r
323 )\r
324{\r
325 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
326\r
327 FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
328\r
329 if ((FvbDevice->FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {\r
330 *Address = FvbDevice->BaseAddress;\r
331 return EFI_SUCCESS;\r
332 }\r
333\r
334 return EFI_UNSUPPORTED;\r
335}\r
336\r
337\r
338\r
339/**\r
340 Retrieves the size in bytes of a specific block within a firmware volume.\r
341\r
342 @param This Indicates the calling context.\r
343 @param Lba Indicates the block for which to return the\r
344 size.\r
345 @param BlockSize Pointer to a caller-allocated UINTN in which the\r
346 size of the block is returned.\r
347 @param NumberOfBlocks Pointer to a caller-allocated UINTN in which the\r
348 number of consecutive blocks starting with Lba\r
349 is returned. All blocks in this range have a\r
350 size of BlockSize.\r
351\r
352 @retval EFI_SUCCESS The firmware volume base address is returned.\r
353 @retval EFI_INVALID_PARAMETER The requested LBA is out of range.\r
354\r
355**/\r
356EFI_STATUS\r
357EFIAPI\r
358FwVolBlockGetBlockSize (\r
359 IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r
360 IN CONST EFI_LBA Lba,\r
361 IN OUT UINTN *BlockSize,\r
362 IN OUT UINTN *NumberOfBlocks\r
363 )\r
364{\r
365 UINTN TotalBlocks;\r
366 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
367 EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
368 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
369\r
370 FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
371\r
372 //\r
373 // Do parameter checking\r
374 //\r
375 if (Lba >= FvbDevice->NumBlocks) {\r
376 return EFI_INVALID_PARAMETER;\r
377 }\r
378\r
379 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);\r
380\r
381 PtrBlockMapEntry = FwVolHeader->BlockMap;\r
382\r
383 //\r
384 // Search the block map for the given block\r
385 //\r
386 TotalBlocks = 0;\r
387 while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length !=0 )) {\r
388 TotalBlocks += PtrBlockMapEntry->NumBlocks;\r
389 if (Lba < TotalBlocks) {\r
390 //\r
391 // We find the range\r
392 //\r
393 break;\r
394 }\r
395\r
396 PtrBlockMapEntry++;\r
397 }\r
398\r
399 *BlockSize = PtrBlockMapEntry->Length;\r
400 *NumberOfBlocks = TotalBlocks - (UINTN)Lba;\r
401\r
402 return EFI_SUCCESS;\r
403}\r
404\r
405\r
406\r
407/**\r
408 This routine produces a firmware volume block protocol on a given\r
409 buffer.\r
410\r
411 @param BaseAddress base address of the firmware volume image\r
412 @param Length length of the firmware volume image\r
413 @param ParentHandle handle of parent firmware volume, if this image\r
414 came from an FV image file in another firmware\r
415 volume (ala capsules)\r
416 @param FvProtocol Firmware volume block protocol produced.\r
417\r
418 @retval EFI_VOLUME_CORRUPTED Volume corrupted.\r
419 @retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.\r
420 @retval EFI_SUCCESS Successfully produced a FVB protocol on given\r
421 buffer.\r
422\r
423**/\r
424EFI_STATUS\r
425ProduceFVBProtocolOnBuffer (\r
426 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
427 IN UINT64 Length,\r
428 IN EFI_HANDLE ParentHandle,\r
429 OUT EFI_HANDLE *FvProtocol OPTIONAL\r
430 )\r
431{\r
432 EFI_STATUS Status;\r
433 EFI_FW_VOL_BLOCK_DEVICE *FvbDev;\r
434 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
435 UINTN BlockIndex;\r
436 UINTN BlockIndex2;\r
437 UINTN LinearOffset;\r
438 UINT32 FvAlignment;\r
439 EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
440\r
441 FvAlignment = 0;\r
442 FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN) BaseAddress;\r
443 //\r
444 // Validate FV Header, if not as expected, return\r
445 //\r
446 if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {\r
447 return EFI_VOLUME_CORRUPTED;\r
448 }\r
449 //\r
450 // Get FvHeader alignment\r
451 //\r
452 FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
453 //\r
454 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. \r
455 //\r
456 if (FvAlignment < 8) {\r
457 FvAlignment = 8;\r
458 }\r
459 if ((UINTN)BaseAddress % FvAlignment != 0) {\r
460 //\r
461 // FvImage buffer is not at its required alignment.\r
462 //\r
463 return EFI_VOLUME_CORRUPTED;\r
464 }\r
465 //\r
466 // Allocate EFI_FW_VOL_BLOCK_DEVICE\r
467 //\r
468 FvbDev = AllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);\r
469 if (FvbDev == NULL) {\r
470 return EFI_OUT_OF_RESOURCES;\r
471 }\r
472\r
473 FvbDev->BaseAddress = BaseAddress;\r
474 FvbDev->FvbAttributes = FwVolHeader->Attributes;\r
475 FvbDev->FwVolBlockInstance.ParentHandle = ParentHandle;\r
476\r
477 //\r
478 // Init the block caching fields of the device\r
479 // First, count the number of blocks\r
480 //\r
481 FvbDev->NumBlocks = 0;\r
482 for (PtrBlockMapEntry = FwVolHeader->BlockMap;\r
483 PtrBlockMapEntry->NumBlocks != 0;\r
484 PtrBlockMapEntry++) {\r
485 FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;\r
486 }\r
487 //\r
488 // Second, allocate the cache\r
489 //\r
490 FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));\r
491 if (FvbDev->LbaCache == NULL) {\r
492 CoreFreePool (FvbDev);\r
493 return EFI_OUT_OF_RESOURCES;\r
494 }\r
495 \r
496 //\r
497 // Last, fill in the cache with the linear address of the blocks\r
498 //\r
499 BlockIndex = 0;\r
500 LinearOffset = 0;\r
501 for (PtrBlockMapEntry = FwVolHeader->BlockMap;\r
502 PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
503 for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {\r
504 FvbDev->LbaCache[BlockIndex].Base = LinearOffset;\r
505 FvbDev->LbaCache[BlockIndex].Length = PtrBlockMapEntry->Length;\r
506 LinearOffset += PtrBlockMapEntry->Length;\r
507 BlockIndex++;\r
508 }\r
509 }\r
510\r
511 //\r
512 // Judget whether FV name guid is produced in Fv extension header\r
513 //\r
514 if (FwVolHeader->ExtHeaderOffset == 0) {\r
515 //\r
516 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH\r
517 //\r
518 FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);\r
519 if (FvbDev->DevicePath == NULL) {\r
520 FreePool (FvbDev);\r
521 return EFI_OUT_OF_RESOURCES;\r
522 }\r
523 ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;\r
524 ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;\r
525 } else {\r
526 //\r
527 // FV contains extension header, then produce MEDIA_FW_VOL_DEVICE_PATH\r
528 //\r
529 FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);\r
530 if (FvbDev->DevicePath == NULL) {\r
531 FreePool (FvbDev);\r
532 return EFI_OUT_OF_RESOURCES;\r
533 }\r
534 CopyGuid (\r
535 &((FV_PIWG_DEVICE_PATH *)FvbDev->DevicePath)->FvDevPath.FvName, \r
536 (GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)\r
537 );\r
538 }\r
539 \r
540 //\r
541 //\r
542 // Attach FvVolBlock Protocol to new handle\r
543 //\r
544 Status = CoreInstallMultipleProtocolInterfaces (\r
545 &FvbDev->Handle,\r
546 &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,\r
547 &gEfiDevicePathProtocolGuid, FvbDev->DevicePath,\r
548 NULL\r
549 );\r
550\r
551 //\r
552 // If they want the handle back, set it.\r
553 //\r
554 if (FvProtocol != NULL) {\r
555 *FvProtocol = FvbDev->Handle;\r
556 }\r
557\r
558 return Status;\r
559}\r
560\r
561\r
562\r
563/**\r
564 This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.\r
565\r
566 @param ImageHandle The image handle.\r
567 @param SystemTable The system table.\r
568\r
569 @retval EFI_SUCCESS Successfully initialized firmware volume block\r
570 driver.\r
571\r
572**/\r
573EFI_STATUS\r
574EFIAPI\r
575FwVolBlockDriverInit (\r
576 IN EFI_HANDLE ImageHandle,\r
577 IN EFI_SYSTEM_TABLE *SystemTable\r
578 )\r
579{\r
580 EFI_PEI_HOB_POINTERS FvHob;\r
581\r
582 //\r
583 // Core Needs Firmware Volumes to function\r
584 //\r
585 FvHob.Raw = GetHobList ();\r
586 while ((FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw)) != NULL) {\r
587 //\r
588 // Produce an FVB protocol for it\r
589 //\r
590 ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, NULL);\r
591 FvHob.Raw = GET_NEXT_HOB (FvHob);\r
592 }\r
593\r
594 return EFI_SUCCESS;\r
595}\r
596\r
597\r
598\r
599/**\r
600 This DXE service routine is used to process a firmware volume. In\r
601 particular, it can be called by BDS to process a single firmware\r
602 volume found in a capsule.\r
603\r
604 @param FvHeader pointer to a firmware volume header\r
605 @param Size the size of the buffer pointed to by FvHeader\r
606 @param FVProtocolHandle the handle on which a firmware volume protocol\r
607 was produced for the firmware volume passed in.\r
608\r
609 @retval EFI_OUT_OF_RESOURCES if an FVB could not be produced due to lack of\r
610 system resources\r
611 @retval EFI_VOLUME_CORRUPTED if the volume was corrupted\r
612 @retval EFI_SUCCESS a firmware volume protocol was produced for the\r
613 firmware volume\r
614\r
615**/\r
616EFI_STATUS\r
617EFIAPI\r
618CoreProcessFirmwareVolume (\r
619 IN VOID *FvHeader,\r
620 IN UINTN Size,\r
621 OUT EFI_HANDLE *FVProtocolHandle\r
622 )\r
623{\r
624 VOID *Ptr;\r
625 EFI_STATUS Status;\r
626\r
627 *FVProtocolHandle = NULL;\r
628 Status = ProduceFVBProtocolOnBuffer (\r
629 (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
630 (UINT64)Size,\r
631 NULL,\r
632 FVProtocolHandle\r
633 );\r
634 //\r
635 // Since in our implementation we use register-protocol-notify to put a\r
636 // FV protocol on the FVB protocol handle, we can't directly verify that\r
637 // the FV protocol was produced. Therefore here we will check the handle\r
638 // and make sure an FV protocol is on it. This indicates that all went\r
639 // well. Otherwise we have to assume that the volume was corrupted\r
640 // somehow.\r
641 //\r
642 if (!EFI_ERROR(Status)) {\r
643 Ptr = NULL;\r
644 Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);\r
645 if (EFI_ERROR(Status) || (Ptr == NULL)) {\r
646 return EFI_VOLUME_CORRUPTED;\r
647 }\r
648 return EFI_SUCCESS;\r
649 }\r
650 return Status;\r
651}\r
652\r
653\r
654\r