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