Code scrub EdkFvbServiceLib.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6412 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2008-11-06 08:29:42 +00:00
parent 63a66a35c8
commit bac86c0d52
3 changed files with 53 additions and 49 deletions

View File

@ -20,7 +20,7 @@
FILE_GUID = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67 FILE_GUID = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67
MODULE_TYPE = DXE_RUNTIME_DRIVER MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
LIBRARY_CLASS = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION LIBRARY_CLASS = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER
EDK_RELEASE_VERSION = 0x00020000 EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000 EFI_SPECIFICATION_VERSION = 0x00020000
@ -49,9 +49,10 @@
DebugLib DebugLib
BaseLib BaseLib
UefiLib UefiLib
MemoryAllocationLib
[Protocols] [Protocols]
gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED
gEfiFvbExtensionProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiFvbExtensionProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_CONSUMED

View File

@ -8,7 +8,6 @@
were described in the HOB. We have to remember the handle so we can tell if were described in the HOB. We have to remember the handle so we can tell if
the protocol has been reinstalled and it needs updateing. the protocol has been reinstalled and it needs updateing.
If you are using any of these lib functions.you must first call FvbInitialize ().
Copyright (c) 2006 - 2008, Intel Corporation Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
@ -24,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Fvb.h" #include "Fvb.h"
// //
// Event for Set Virtual Map Changed Event // Event for Set Virtual Map Changed Event
// //
@ -32,9 +32,9 @@ EFI_EVENT mSetVirtualMapChangedEvent = NULL;
// //
// Lib will ASSERT if more FVB devices than this are added to the system. // Lib will ASSERT if more FVB devices than this are added to the system.
// //
FVB_ENTRY *mFvbEntry; FVB_ENTRY *mFvbEntry = NULL;
EFI_EVENT mFvbRegistration; EFI_EVENT mFvbRegistration = NULL;
UINTN mFvbCount; UINTN mFvbCount = 0;
/** /**
Check whether an address is runtime memory or not. Check whether an address is runtime memory or not.
@ -78,12 +78,8 @@ IsRuntimeMemory (
// Enlarge space here, because we will allocate pool now. // Enlarge space here, because we will allocate pool now.
// //
MemoryMapSize += EFI_PAGE_SIZE; MemoryMapSize += EFI_PAGE_SIZE;
Status = gBS->AllocatePool ( MemoryMap = AllocatePool (MemoryMapSize);
EfiBootServicesData, ASSERT (MemoryMap != NULL);
MemoryMapSize,
(VOID**)&MemoryMap
);
ASSERT_EFI_ERROR (Status);
// //
// Get System MemoryMap // Get System MemoryMap
@ -108,7 +104,7 @@ IsRuntimeMemory (
// //
// Found it // Found it
// //
if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) { if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {
IsRuntime = TRUE; IsRuntime = TRUE;
} }
break; break;
@ -116,17 +112,18 @@ IsRuntimeMemory (
// //
// Get next item // Get next item
// //
MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize); MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);
} }
// //
// Done // Done
// //
gBS->FreePool (MemoryMapPtr); FreePool (MemoryMapPtr);
return IsRuntime; return IsRuntime;
} }
/** /**
Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is
reinstalled. reinstalled.
@ -211,14 +208,11 @@ FvbNotificationEvent (
} }
// //
// Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:
// from two way: // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced
// 1) Dxe Core. (FVB information is transferred from FV HOB). // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in
// 2) FVB driver. // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in
// The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can
// FVBs can only be accessed in boot time.
// FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime.
// The FVB itself produced by FVB driver is allocated in runtime memory. So we can
// determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated
// in RUNTIME memory. // in RUNTIME memory.
// //
@ -241,13 +235,14 @@ FvbVirtualAddressChangeNotifyEvent (
) )
{ {
UINTN Index; UINTN Index;
if (mFvbEntry != NULL) { if (mFvbEntry != NULL) {
for (Index = 0; Index < MAX_FVB_COUNT; Index++) { for (Index = 0; Index < MAX_FVB_COUNT; Index++) {
if (!mFvbEntry[Index].IsRuntimeAccess) { if (!mFvbEntry[Index].IsRuntimeAccess) {
continue; continue;
} }
if (NULL != mFvbEntry[Index].Fvb) { if (mFvbEntry[Index].Fvb != NULL) {
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);
@ -258,7 +253,7 @@ FvbVirtualAddressChangeNotifyEvent (
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);
} }
if (NULL != mFvbEntry[Index].FvbExtension) { if (mFvbEntry[Index].FvbExtension != NULL) {
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension); EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);
} }
@ -268,6 +263,7 @@ FvbVirtualAddressChangeNotifyEvent (
} }
} }
/** /**
Library constructor function entry. Library constructor function entry.
@ -284,21 +280,14 @@ FvbLibInitialize (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
UINTN Status; EFI_STATUS Status;
mFvbCount = 0;
Status = gBS->AllocatePool ( mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
EfiRuntimeServicesData, ASSERT (mFvbEntry != NULL);
(UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,
(VOID *) &mFvbEntry
);
if (EFI_ERROR (Status)) {
return Status;
}
ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
//
// Register FvbNotificationEvent () notify function.
//
EfiCreateProtocolNotifyEvent ( EfiCreateProtocolNotifyEvent (
&gEfiFirmwareVolumeBlockProtocolGuid, &gEfiFirmwareVolumeBlockProtocolGuid,
TPL_CALLBACK, TPL_CALLBACK,
@ -319,7 +308,7 @@ FvbLibInitialize (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS; return Status;
} }
// //
@ -328,10 +317,6 @@ FvbLibInitialize (
// The Instance translates into Fvb instance. The Fvb order defined by HOBs and // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
// thus the sequence of FVB protocol addition define Instance. // thus the sequence of FVB protocol addition define Instance.
// //
// EfiFvbInitialize () must be called before any of the following functions
// must be called.
// =============================================================================
//
/** /**
Reads specified number of bytes into a buffer from the specified block. Reads specified number of bytes into a buffer from the specified block.
@ -362,14 +347,18 @@ FvbLibInitialize (
@param[out] Buffer Pointer to a caller allocated buffer that will be @param[out] Buffer Pointer to a caller allocated buffer that will be
used to hold the data read. used to hold the data read.
@retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer. @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
@retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer. @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains
the total number of bytes returned in Buffer.
@retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state. @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.
@retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read. @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.
@retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index is larger than the last block of the firmware volume. Offset is larger than the block size. @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index
is larger than the last block of the firmware volume. Offset is larger
than the block size.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbReadBlock ( EfiFvbReadBlock (
IN UINTN Instance, IN UINTN Instance,
IN EFI_LBA Lba, IN EFI_LBA Lba,
@ -436,13 +425,14 @@ EfiFvbReadBlock (
@retval EFI_SUCCESS The firmware volume was written successfully. @retval EFI_SUCCESS The firmware volume was written successfully.
@retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary. @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
On output, NumBytes contains the total number of bytes actually written. On output, NumBytes contains the total number of bytes actually written.
@retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state. @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
@retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written. @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.
@retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number.
Lba index is larger than the last block of the firmware volume. Lba index is larger than the last block of the firmware volume.
Offset is larger than the block size. Offset is larger than the block size.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbWriteBlock ( EfiFvbWriteBlock (
IN UINTN Instance, IN UINTN Instance,
IN EFI_LBA Lba, IN EFI_LBA Lba,
@ -464,6 +454,7 @@ EfiFvbWriteBlock (
return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer); return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
} }
/** /**
Erases and initializes a firmware volume block. Erases and initializes a firmware volume block.
@ -493,6 +484,7 @@ EfiFvbWriteBlock (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbEraseBlock ( EfiFvbEraseBlock (
IN UINTN Instance, IN UINTN Instance,
IN EFI_LBA Lba IN EFI_LBA Lba
@ -509,6 +501,7 @@ EfiFvbEraseBlock (
return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR); return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);
} }
/** /**
Retrieves the attributes and current settings of the specified block, Retrieves the attributes and current settings of the specified block,
returns resulting attributes in output parameter. returns resulting attributes in output parameter.
@ -527,6 +520,7 @@ EfiFvbEraseBlock (
@retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbGetVolumeAttributes ( EfiFvbGetVolumeAttributes (
IN UINTN Instance, IN UINTN Instance,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes OUT EFI_FVB_ATTRIBUTES_2 *Attributes
@ -545,6 +539,7 @@ EfiFvbGetVolumeAttributes (
return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes); return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);
} }
/** /**
Modify the attributes and current settings of the specified block Modify the attributes and current settings of the specified block
according to the input parameter. according to the input parameter.
@ -566,6 +561,7 @@ EfiFvbGetVolumeAttributes (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbSetVolumeAttributes ( EfiFvbSetVolumeAttributes (
IN UINTN Instance, IN UINTN Instance,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
@ -584,6 +580,7 @@ EfiFvbSetVolumeAttributes (
return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes); return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);
} }
/** /**
Retrieves the physical address of the specified memory mapped FV. Retrieves the physical address of the specified memory mapped FV.
@ -603,6 +600,7 @@ EfiFvbSetVolumeAttributes (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbGetPhysicalAddress ( EfiFvbGetPhysicalAddress (
IN UINTN Instance, IN UINTN Instance,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress OUT EFI_PHYSICAL_ADDRESS *BaseAddress
@ -621,6 +619,7 @@ EfiFvbGetPhysicalAddress (
return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress); return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);
} }
/** /**
Retrieve the block size of the specified fv. Retrieve the block size of the specified fv.
@ -630,7 +629,7 @@ EfiFvbGetPhysicalAddress (
the last block of the firmware volume, this function return the status code the last block of the firmware volume, this function return the status code
EFI_INVALID_PARAMETER. EFI_INVALID_PARAMETER.
If BlockSize is NULL, then ASSERT(). If BlockSize is NULL, then ASSERT().
If NumOfBlocks is NULL, then ASSERT(). If NumOfBlocks is NULL, then ASSERT().
@ -648,6 +647,7 @@ EfiFvbGetPhysicalAddress (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbGetBlockSize ( EfiFvbGetBlockSize (
IN UINTN Instance, IN UINTN Instance,
IN EFI_LBA Lba, IN EFI_LBA Lba,
@ -669,6 +669,7 @@ EfiFvbGetBlockSize (
return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks); return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);
} }
/** /**
Erases and initializes a specified range of a firmware volume. Erases and initializes a specified range of a firmware volume.
@ -691,6 +692,7 @@ EfiFvbGetBlockSize (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI
EfiFvbEraseCustomBlockRange ( EfiFvbEraseCustomBlockRange (
IN UINTN Instance, IN UINTN Instance,
IN EFI_LBA StartLba, IN EFI_LBA StartLba,

View File

@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/UefiRuntimeLib.h> #include <Library/UefiRuntimeLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#define MAX_FVB_COUNT 16 #define MAX_FVB_COUNT 16