]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c
Code scrub DxeIpl, Runtime, DevicePath, FvbServicesLib, DiskIo, Partition, English...
[mirror_edk2.git] / MdeModulePkg / Library / EdkFvbServiceLib / Fvb.c
1 /**@file
2 Firmware Volume Block Protocol Runtime Interface Abstraction
3 And FVB Extension protocol Runtime Interface Abstraction
4
5 mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the
6 index in the mFvbEntry array. This should be the same sequence as the FVB's
7 were described in the HOB. We have to remember the handle so we can tell if
8 the protocol has been reinstalled and it needs updating.
9
10
11 Copyright (c) 2006 - 2008, Intel Corporation
12 All rights reserved. This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
16
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19
20 **/
21
22
23 #include "Fvb.h"
24
25
26 //
27 // Event for Set Virtual Map Changed Event
28 //
29 EFI_EVENT mSetVirtualMapChangedEvent = NULL;
30
31 //
32 // Lib will ASSERT if more FVB devices than this are added to the system.
33 //
34 FVB_ENTRY *mFvbEntry = NULL;
35 EFI_EVENT mFvbRegistration = NULL;
36 UINTN mFvbCount = 0;
37
38 /**
39 Check whether an address is runtime memory or not.
40
41 @param Address The Address being checked.
42
43 @retval TRUE The address is runtime memory.
44 @retval FALSE The address is not runtime memory.
45 **/
46 BOOLEAN
47 IsRuntimeMemory (
48 IN VOID *Address
49 )
50 {
51 EFI_STATUS Status;
52 UINT8 TmpMemoryMap[1];
53 UINTN MapKey;
54 UINTN DescriptorSize;
55 UINT32 DescriptorVersion;
56 UINTN MemoryMapSize;
57 EFI_MEMORY_DESCRIPTOR *MemoryMap;
58 EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
59 BOOLEAN IsRuntime;
60 UINTN Index;
61
62 IsRuntime = FALSE;
63
64 //
65 // Get System MemoryMapSize
66 //
67 MemoryMapSize = 1;
68 Status = gBS->GetMemoryMap (
69 &MemoryMapSize,
70 (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,
71 &MapKey,
72 &DescriptorSize,
73 &DescriptorVersion
74 );
75 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
76 //
77 // Enlarge space here, because we will allocate pool now.
78 //
79 MemoryMapSize += EFI_PAGE_SIZE;
80 MemoryMap = AllocatePool (MemoryMapSize);
81 ASSERT (MemoryMap != NULL);
82
83 //
84 // Get System MemoryMap
85 //
86 Status = gBS->GetMemoryMap (
87 &MemoryMapSize,
88 MemoryMap,
89 &MapKey,
90 &DescriptorSize,
91 &DescriptorVersion
92 );
93 ASSERT_EFI_ERROR (Status);
94
95 MemoryMapPtr = MemoryMap;
96 //
97 // Search the request Address
98 //
99 for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
100 if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) &&
101 ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart
102 + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) {
103 //
104 // Found it
105 //
106 if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {
107 IsRuntime = TRUE;
108 }
109 break;
110 }
111 //
112 // Get next item
113 //
114 MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);
115 }
116
117 //
118 // Done
119 //
120 FreePool (MemoryMapPtr);
121
122 return IsRuntime;
123 }
124
125
126 /**
127 Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is
128 reinstalled.
129
130 @param Event The Event that is being processed
131 @param Context Event Context
132
133 **/
134 VOID
135 EFIAPI
136 FvbNotificationEvent (
137 IN EFI_EVENT Event,
138 IN VOID *Context
139 )
140 {
141 EFI_STATUS Status;
142 UINTN BufferSize;
143 EFI_HANDLE Handle;
144 UINTN Index;
145 UINTN UpdateIndex;
146
147 while (TRUE) {
148 BufferSize = sizeof (Handle);
149 Status = gBS->LocateHandle (
150 ByRegisterNotify,
151 &gEfiFirmwareVolumeBlockProtocolGuid,
152 mFvbRegistration,
153 &BufferSize,
154 &Handle
155 );
156 if (EFI_ERROR (Status)) {
157 //
158 // Exit Path of While Loop....
159 //
160 break;
161 }
162
163 UpdateIndex = MAX_FVB_COUNT;
164 for (Index = 0; Index < mFvbCount; Index++) {
165 if (mFvbEntry[Index].Handle == Handle) {
166 //
167 // If the handle is already in the table just update the protocol
168 //
169 UpdateIndex = Index;
170 break;
171 }
172 }
173
174 if (UpdateIndex == MAX_FVB_COUNT) {
175 //
176 // Use the next free slot for a new entry
177 //
178 UpdateIndex = mFvbCount++;
179 //
180 // Check the UpdateIndex whether exceed the maximum value.
181 //
182 ASSERT (UpdateIndex < MAX_FVB_COUNT);
183 mFvbEntry[UpdateIndex].Handle = Handle;
184 }
185 //
186 // The array does not have enough entries
187 //
188 ASSERT (UpdateIndex < MAX_FVB_COUNT);
189
190 //
191 // Get the interface pointer and if it's ours, skip it
192 //
193 Status = gBS->HandleProtocol (
194 Handle,
195 &gEfiFirmwareVolumeBlockProtocolGuid,
196 (VOID **) &mFvbEntry[UpdateIndex].Fvb
197 );
198 ASSERT_EFI_ERROR (Status);
199
200 Status = gBS->HandleProtocol (
201 Handle,
202 &gEfiFvbExtensionProtocolGuid,
203 (VOID **) &mFvbEntry[UpdateIndex].FvbExtension
204 );
205 if (Status != EFI_SUCCESS) {
206 mFvbEntry[UpdateIndex].FvbExtension = NULL;
207 }
208
209 //
210 // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:
211 // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced
212 // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in
213 // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in
214 // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can
215 // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated
216 // in RUNTIME memory.
217 //
218 mFvbEntry[UpdateIndex].IsRuntimeAccess = IsRuntimeMemory (mFvbEntry[UpdateIndex].Fvb);
219 }
220 }
221
222 /**
223 Convert all pointers in mFvbEntry after ExitBootServices.
224
225 @param Event The Event that is being processed
226 @param Context Event Context
227
228 **/
229 VOID
230 EFIAPI
231 FvbVirtualAddressChangeNotifyEvent (
232 IN EFI_EVENT Event,
233 IN VOID *Context
234 )
235 {
236 UINTN Index;
237
238 if (mFvbEntry != NULL) {
239 for (Index = 0; Index < MAX_FVB_COUNT; Index++) {
240 if (!mFvbEntry[Index].IsRuntimeAccess) {
241 continue;
242 }
243
244 if (mFvbEntry[Index].Fvb != NULL) {
245 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);
246 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);
247 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);
248 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->SetAttributes);
249 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Read);
250 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Write);
251 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);
252 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);
253 }
254
255 if (mFvbEntry[Index].FvbExtension != NULL) {
256 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);
257 EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);
258 }
259 }
260
261 EfiConvertPointer (0x0, (VOID **) &mFvbEntry);
262 }
263 }
264
265
266 /**
267 Library constructor function entry.
268
269 @param ImageHandle The handle of image who call this library.
270 @param SystemTable The point of System Table.
271
272 @retval EFI_SUCESS Success construct this library.
273 @retval Others Fail to construct this library.
274 **/
275 EFI_STATUS
276 EFIAPI
277 FvbLibInitialize (
278 IN EFI_HANDLE ImageHandle,
279 IN EFI_SYSTEM_TABLE *SystemTable
280 )
281 {
282 EFI_STATUS Status;
283
284 mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
285 ASSERT (mFvbEntry != NULL);
286
287 //
288 // Register FvbNotificationEvent () notify function.
289 //
290 EfiCreateProtocolNotifyEvent (
291 &gEfiFirmwareVolumeBlockProtocolGuid,
292 TPL_CALLBACK,
293 FvbNotificationEvent,
294 NULL,
295 &mFvbRegistration
296 );
297
298 //
299 // Register SetVirtualAddressMap () notify function
300 //
301 Status = gBS->CreateEvent (
302 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
303 TPL_NOTIFY,
304 FvbVirtualAddressChangeNotifyEvent,
305 NULL,
306 &mSetVirtualMapChangedEvent
307 );
308 ASSERT_EFI_ERROR (Status);
309
310 return Status;
311 }
312
313 //
314 // =============================================================================
315 // The following functions wrap Fvb protocol in the Runtime Lib functions.
316 // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
317 // thus the sequence of FVB protocol addition define Instance.
318 //
319
320 /**
321 Reads specified number of bytes into a buffer from the specified block.
322
323 The EfiFvbReadBlock() function reads the requested number of bytes from
324 the requested block in the specified firmware volume and stores them in
325 the provided buffer. Implementations should be mindful that the firmware
326 volume might be in the ReadDisabled state. If it is in this state, the
327 EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED
328 without modifying the contents of the buffer.
329
330 The EfiFvbReadBlock() function must also prevent spanning block boundaries.
331 If a read is requested that would span a block boundary, the read must read
332 up to the boundary but not beyond. The output parameter NumBytes must be
333 set to correctly indicate the number of bytes actually read.
334 The caller must be aware that a read may be partially completed.
335
336 If NumBytes is NULL, then ASSERT().
337
338 If Buffer is NULL, then ASSERT().
339
340 @param[in] Instance The FV instance to be read from.
341 @param[in] Lba The logical block address to be read from
342 @param[in] Offset The offset relative to the block, at which to begin reading.
343 @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total
344 size of the buffer. On output, it contains the actual number
345 of bytes read.
346 @param[out] Buffer Pointer to a caller allocated buffer that will be
347 used to hold the data read.
348
349 @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
350 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains
351 the total number of bytes returned in Buffer.
352 @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.
353 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.
354 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index
355 is larger than the last block of the firmware volume. Offset is larger
356 than the block size.
357
358 **/
359 EFI_STATUS
360 EFIAPI
361 EfiFvbReadBlock (
362 IN UINTN Instance,
363 IN EFI_LBA Lba,
364 IN UINTN Offset,
365 IN OUT UINTN *NumBytes,
366 OUT UINT8 *Buffer
367 )
368 {
369 ASSERT (NumBytes != NULL);
370 ASSERT (Buffer != NULL);
371
372 if (Instance >= mFvbCount) {
373 return EFI_INVALID_PARAMETER;
374 }
375
376 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
377 return EFI_INVALID_PARAMETER;
378 }
379
380 return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
381 }
382
383 /**
384 Writes specified number of bytes from the input buffer to the block
385
386 The EfiFvbWriteBlock() function writes the specified number of bytes
387 from the provided buffer to the specified block and offset in the
388 requested firmware volume.
389
390 If the firmware volume is sticky write, the caller must ensure that
391 all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY
392 state before calling the EfiFvbWriteBlock() function, or else the
393 result will be unpredictable. This unpredictability arises because,
394 for a sticky-write firmware volume, a write may negate a bit in the
395 EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In
396 general, before calling the EfiFvbWriteBlock() function, the caller
397 should call the EfiFvbEraseBlock() function first to erase the specified
398 block to write. A block erase cycle will transition bits from the
399 (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state.
400 Implementations should be mindful that the firmware volume might be
401 in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock()
402 function must return the status code EFI_ACCESS_DENIED without modifying
403 the contents of the firmware volume.
404
405 The EfiFvbWriteBlock() function must also prevent spanning block boundaries.
406 If a write is requested that spans a block boundary, the write must store
407 up to the boundary but not beyond. The output parameter NumBytes must be
408 set to correctly indicate the number of bytes actually written. The caller
409 must be aware that a write may be partially completed.
410 All writes, partial or otherwise, must be fully flushed to the hardware
411 before the EfiFvbWriteBlock() function returns.
412
413 If NumBytes is NULL, then ASSERT().
414
415 @param Instance The FV instance to be written to.
416 @param Lba The starting logical block index to write.
417 @param Offset The offset relative to the block to write.
418 @param NumBytes Pointer to a UINTN. On input, *NumBytes contains
419 the total size of the buffer. On output, it contains
420 the actual number of bytes written.
421 @param Buffer Pointer to a caller allocated buffer that contains
422 the source for the write
423
424 @retval EFI_SUCCESS The firmware volume was written successfully.
425 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
426 On output, NumBytes contains the total number of bytes actually written.
427 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
428 @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.
429 @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number.
430 Lba index is larger than the last block of the firmware volume.
431 Offset is larger than the block size.
432 **/
433 EFI_STATUS
434 EFIAPI
435 EfiFvbWriteBlock (
436 IN UINTN Instance,
437 IN EFI_LBA Lba,
438 IN UINTN Offset,
439 IN OUT UINTN *NumBytes,
440 IN UINT8 *Buffer
441 )
442 {
443 ASSERT (NumBytes != NULL);
444
445 if (Instance >= mFvbCount) {
446 return EFI_INVALID_PARAMETER;
447 }
448
449 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
450 return EFI_INVALID_PARAMETER;
451 }
452
453 return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
454 }
455
456
457 /**
458 Erases and initializes a firmware volume block.
459
460 The EfiFvbEraseBlock() function erases one block specified by Lba.
461 Implementations should be mindful that the firmware volume might
462 be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock()
463 function must return the status code EFI_ACCESS_DENIED without
464 modifying the contents of the firmware volume. If Instance is
465 larger than the max FVB number, or Lba index is larger than the
466 last block of the firmware volume, this function return the status
467 code EFI_INVALID_PARAMETER.
468
469 All calls to EfiFvbEraseBlock() must be fully flushed to the
470 hardware before this function returns.
471
472 @param[in] Instance The FV instance to be erased.
473 @param[in] Lba The logical block index to be erased from.
474
475 @retval EFI_SUCCESS The erase request was successfully completed.
476 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
477 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and
478 could not be written. The firmware device may
479 have been partially erased.
480 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max
481 FVB number. Lba index is larger than the last block
482 of the firmware volume.
483
484 **/
485 EFI_STATUS
486 EFIAPI
487 EfiFvbEraseBlock (
488 IN UINTN Instance,
489 IN EFI_LBA Lba
490 )
491 {
492 if (Instance >= mFvbCount) {
493 return EFI_INVALID_PARAMETER;
494 }
495
496 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
497 return EFI_INVALID_PARAMETER;
498 }
499
500 return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);
501 }
502
503
504 /**
505 Retrieves the attributes and current settings of the specified block,
506 returns resulting attributes in output parameter.
507
508 The EfiFvbGetAttributes() function retrieves the attributes and current
509 settings of the block specified by Instance. If Instance is larger than
510 the max FVB number, this function returns the status code EFI_INVALID_PARAMETER.
511
512 If Attributes is NULL, then ASSERT().
513
514 @param[in] Instance The FV instance to be operated.
515 @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
516 attributes and current settings are returned.
517
518 @retval EFI_EFI_SUCCESS The firmware volume attributes were returned.
519 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
520 **/
521 EFI_STATUS
522 EFIAPI
523 EfiFvbGetVolumeAttributes (
524 IN UINTN Instance,
525 OUT EFI_FVB_ATTRIBUTES_2 *Attributes
526 )
527 {
528 ASSERT (Attributes != NULL);
529
530 if (Instance >= mFvbCount) {
531 return EFI_INVALID_PARAMETER;
532 }
533
534 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
535 return EFI_INVALID_PARAMETER;
536 }
537
538 return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);
539 }
540
541
542 /**
543 Modify the attributes and current settings of the specified block
544 according to the input parameter.
545
546 The EfiFvbSetAttributes() function sets configurable firmware volume
547 attributes and returns the new settings of the firmware volume specified
548 by Instance. If Instance is larger than the max FVB number, this function
549 returns the status code EFI_INVALID_PARAMETER.
550
551 If Attributes is NULL, then ASSERT().
552
553 @param[in] Instance The FV instance to be operated.
554 @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2
555 that contains the desired firmware volume settings.
556 On successful return, it contains the new settings of the firmware volume.
557
558 @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully.
559 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
560
561 **/
562 EFI_STATUS
563 EFIAPI
564 EfiFvbSetVolumeAttributes (
565 IN UINTN Instance,
566 IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
567 )
568 {
569 ASSERT (Attributes != NULL);
570
571 if (Instance >= mFvbCount) {
572 return EFI_INVALID_PARAMETER;
573 }
574
575 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
576 return EFI_INVALID_PARAMETER;
577 }
578
579 return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);
580 }
581
582
583 /**
584 Retrieves the physical address of the specified memory mapped FV.
585
586 Retrieve the base address of a memory-mapped firmware volume specified by Instance.
587 If Instance is larger than the max FVB number, this function returns the status
588 code EFI_INVALID_PARAMETER.
589
590 If BaseAddress is NULL, then ASSERT().
591
592 @param[in] Instance The FV instance to be operated.
593 @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
594 that on successful return, contains the base address
595 of the firmware volume.
596
597 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
598 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
599
600 **/
601 EFI_STATUS
602 EFIAPI
603 EfiFvbGetPhysicalAddress (
604 IN UINTN Instance,
605 OUT EFI_PHYSICAL_ADDRESS *BaseAddress
606 )
607 {
608 ASSERT (BaseAddress != NULL);
609
610 if (Instance >= mFvbCount) {
611 return EFI_INVALID_PARAMETER;
612 }
613
614 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
615 return EFI_INVALID_PARAMETER;
616 }
617
618 return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);
619 }
620
621
622 /**
623 Retrieve the block size of the specified fv.
624
625 The EfiFvbGetBlockSize() function retrieves the size of the requested block.
626 It also returns the number of additional blocks with the identical size.
627 If Instance is larger than the max FVB number, or Lba index is larger than
628 the last block of the firmware volume, this function return the status code
629 EFI_INVALID_PARAMETER.
630
631 If BlockSize is NULL, then ASSERT().
632
633 If NumOfBlocks is NULL, then ASSERT().
634
635 @param[in] Instance The FV instance to be operated.
636 @param[in] Lba Indicates which block to return the size for.
637 @param[out] BlockSize Pointer to a caller-allocated UINTN in which the
638 size of the block is returned.
639 @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the
640 number of consecutive blocks, starting with Lba,
641 is returned. All blocks in this range have a size of BlockSize.
642
643 @retval EFI_EFI_SUCCESS The firmware volume base address is returned.
644 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
645 Lba index is larger than the last block of the firmware volume.
646
647 **/
648 EFI_STATUS
649 EFIAPI
650 EfiFvbGetBlockSize (
651 IN UINTN Instance,
652 IN EFI_LBA Lba,
653 OUT UINTN *BlockSize,
654 OUT UINTN *NumOfBlocks
655 )
656 {
657 ASSERT (BlockSize != NULL);
658 ASSERT (NumOfBlocks != NULL);
659
660 if (Instance >= mFvbCount) {
661 return EFI_INVALID_PARAMETER;
662 }
663
664 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
665 return EFI_INVALID_PARAMETER;
666 }
667
668 return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);
669 }
670
671
672 /**
673 Erases and initializes a specified range of a firmware volume.
674
675 The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware
676 volume index by Instance. If Instance is larger than the max FVB number, StartLba or
677 LastLba index is larger than the last block of the firmware volume, StartLba > LastLba
678 or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return
679 the status code EFI_INVALID_PARAMETER.
680
681 @param[in] Instance The FV instance to be operated.
682 @param[in] StartLba The starting logical block index to be erased.
683 @param[in] OffsetStartLba Offset into the starting block at which to
684 begin erasing.
685 @param[in] LastLba The last logical block index to be erased.
686 @param[in] OffsetLastLba Offset into the last block at which to end erasing.
687
688 @retval EFI_EFI_SUCCESS Successfully erase custom block range
689 @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
690 @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.
691
692 **/
693 EFI_STATUS
694 EFIAPI
695 EfiFvbEraseCustomBlockRange (
696 IN UINTN Instance,
697 IN EFI_LBA StartLba,
698 IN UINTN OffsetStartLba,
699 IN EFI_LBA LastLba,
700 IN UINTN OffsetLastLba
701 )
702 {
703 if (Instance >= mFvbCount) {
704 return EFI_INVALID_PARAMETER;
705 }
706
707 if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {
708 return EFI_INVALID_PARAMETER;
709 }
710
711 if (!(mFvbEntry[Instance].FvbExtension)) {
712 return EFI_UNSUPPORTED;
713 }
714
715 if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {
716 return EFI_UNSUPPORTED;
717 }
718
719 return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (
720 mFvbEntry[Instance].FvbExtension,
721 StartLba,
722 OffsetStartLba,
723 LastLba,
724 OffsetLastLba
725 );
726 }