X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FFwVolBlock%2FFwVolBlock.c;h=8d45105872ac3976df3a7fd2faf9c69d9e0b7111;hp=62795b2f355cb5697174b4bc096006da08e168ba;hb=9c4ac31cca01b4a503c36616770ea3157bf3bb9e;hpb=162ed594438ab8d39f89b43e6d645ca24e1e1e65
diff --git a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
index 62795b2f35..8d45105872 100644
--- a/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
+++ b/MdeModulePkg/Core/Dxe/FwVolBlock/FwVolBlock.c
@@ -1,22 +1,21 @@
/** @file
- Firmware Volume Block protocol. Consumes FV hobs and creates
- appropriate block protocols.
-
- Also consumes NT_NON_MM_FV envinronment variable and produces appropriate
- block protocols fro them also... (this is TBD)
-
-Copyright (c) 2006 - 2008, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+ Implementations for Firmware Volume Block protocol.
+
+ It consumes FV HOBs and creates read-lonly Firmare Volume Block protocol
+ instances for each of them.
+
+Copyright (c) 2006 - 2008, Intel Corporation.
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#include
+#include "DxeMain.h"
EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {
@@ -27,16 +26,22 @@ EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {
{
HARDWARE_DEVICE_PATH,
HW_MEMMAP_DP,
- { (UINT8)(sizeof (MEMMAP_DEVICE_PATH)), (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8) }
+ {
+ (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),
+ (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8)
+ }
},
EfiMemoryMappedIO,
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
+ (EFI_PHYSICAL_ADDRESS) 0,
+ (EFI_PHYSICAL_ADDRESS) 0,
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
- { END_DEVICE_PATH_LENGTH, 0 }
+ {
+ END_DEVICE_PATH_LENGTH,
+ 0
+ }
},
},
{
@@ -47,7 +52,7 @@ EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {
FwVolBlockReadBlock,
(EFI_FVB_WRITE)FwVolBlockWriteBlock,
(EFI_FVB_ERASE_BLOCKS)FwVolBlockEraseBlock,
- NULL
+ NULL
},
0,
NULL,
@@ -57,13 +62,11 @@ EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {
-
-
/**
Retrieves Volume attributes. No polarity translations are done.
- @param This Calling context
- @param Attributes output buffer which contains attributes
+ @param This Calling context
+ @param Attributes output buffer which contains attributes
@retval EFI_SUCCESS The firmware volume attributes were returned.
@@ -76,7 +79,7 @@ FwVolBlockGetAttributes (
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
-
+
FvbDevice = FVB_DEVICE_FROM_THIS (This);
//
@@ -92,13 +95,13 @@ FwVolBlockGetAttributes (
/**
Modifies the current settings of the firmware volume according to the input parameter.
- @param This Calling context
- @param Attributes input buffer which contains attributes
+ @param This Calling context
+ @param Attributes input buffer which contains attributes
- @retval EFI_SUCCESS The firmware volume attributes were returned.
- @retval EFI_INVALID_PARAMETER The attributes requested are in conflict with
- the capabilities as declared in the firmware
- volume header.
+ @retval EFI_SUCCESS The firmware volume attributes were returned.
+ @retval EFI_INVALID_PARAMETER The attributes requested are in conflict with
+ the capabilities as declared in the firmware
+ volume header.
@retval EFI_UNSUPPORTED Not supported.
**/
@@ -122,18 +125,18 @@ FwVolBlockSetAttributes (
block of the firmware volume), the EraseBlock() function must return
EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.
- @param This Calling context
- @param ... Starting LBA followed by Number of Lba to erase.
- a -1 to terminate the list.
-
- @retval EFI_SUCCESS The erase request was successfully completed.
- @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled
- state.
- @retval EFI_DEVICE_ERROR The block device is not functioning correctly
- and could not be written. The firmware device
- may have been partially erased.
- @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the variable
- argument list do
+ @param This Calling context
+ @param ... Starting LBA followed by Number of Lba to erase.
+ a -1 to terminate the list.
+
+ @retval EFI_SUCCESS The erase request was successfully completed.
+ @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled
+ state.
+ @retval EFI_DEVICE_ERROR The block device is not functioning correctly
+ and could not be written. The firmware device
+ may have been partially erased.
+ @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the variable
+ argument list do
@retval EFI_UNSUPPORTED Not supported.
**/
@@ -152,20 +155,20 @@ FwVolBlockEraseBlock (
/**
Read the specified number of bytes from the block to the input buffer.
- @param This Indicates the calling context.
- @param Lba The starting logical block index to read.
- @param Offset Offset into the block at which to begin reading.
- @param NumBytes Pointer to a UINT32. At entry, *NumBytes
- contains the total size of the buffer. At exit,
- *NumBytes contains the total number of bytes
- actually read.
- @param Buffer Pinter to a caller-allocated buffer that
- contains the destine for the read.
-
- @retval EFI_SUCCESS The firmware volume was read successfully.
- @retval EFI_BAD_BUFFER_SIZE The read was attempted across an LBA boundary.
- @retval EFI_ACCESS_DENIED Access denied.
- @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not
+ @param This Indicates the calling context.
+ @param Lba The starting logical block index to read.
+ @param Offset Offset into the block at which to begin reading.
+ @param NumBytes Pointer to a UINT32. At entry, *NumBytes
+ contains the total size of the buffer. At exit,
+ *NumBytes contains the total number of bytes
+ actually read.
+ @param Buffer Pinter to a caller-allocated buffer that
+ contains the destine for the read.
+
+ @retval EFI_SUCCESS The firmware volume was read successfully.
+ @retval EFI_BAD_BUFFER_SIZE The read was attempted across an LBA boundary.
+ @retval EFI_ACCESS_DENIED Access denied.
+ @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not
be read.
**/
@@ -185,7 +188,7 @@ FwVolBlockReadBlock (
UINTN LbaStart;
UINTN NumOfBytesRead;
UINTN LbaIndex;
-
+
FvbDevice = FVB_DEVICE_FROM_THIS (This);
//
@@ -194,8 +197,8 @@ FwVolBlockReadBlock (
if ((FvbDevice->FvbAttributes & EFI_FVB2_READ_STATUS) == 0) {
return EFI_ACCESS_DENIED;
}
-
- LbaIndex = (UINTN)Lba;
+
+ LbaIndex = (UINTN) Lba;
if (LbaIndex >= FvbDevice->NumBlocks) {
//
// Invalid Lba, read nothing.
@@ -203,7 +206,7 @@ FwVolBlockReadBlock (
*NumBytes = 0;
return EFI_BAD_BUFFER_SIZE;
}
-
+
if (Offset > FvbDevice->LbaCache[LbaIndex].Length) {
//
// all exceed boundry, read nothing.
@@ -211,7 +214,7 @@ FwVolBlockReadBlock (
*NumBytes = 0;
return EFI_BAD_BUFFER_SIZE;
}
-
+
NumOfBytesRead = *NumBytes;
if (Offset + NumOfBytesRead > FvbDevice->LbaCache[LbaIndex].Length) {
//
@@ -219,47 +222,47 @@ FwVolBlockReadBlock (
//
NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;
}
-
+
LbaStart = FvbDevice->LbaCache[LbaIndex].Base;
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);
- LbaOffset = (UINT8 *)FwVolHeader + LbaStart + Offset;
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN) FvbDevice->BaseAddress);
+ LbaOffset = (UINT8 *) FwVolHeader + LbaStart + Offset;
//
// Perform read operation
//
CopyMem (Buffer, LbaOffset, NumOfBytesRead);
-
+
if (NumOfBytesRead == *NumBytes) {
return EFI_SUCCESS;
}
-
+
*NumBytes = NumOfBytesRead;
return EFI_BAD_BUFFER_SIZE;
}
-
+
/**
Writes the specified number of bytes from the input buffer to the block.
- @param This Indicates the calling context.
- @param Lba The starting logical block index to write to.
- @param Offset Offset into the block at which to begin writing.
- @param NumBytes Pointer to a UINT32. At entry, *NumBytes
- contains the total size of the buffer. At exit,
- *NumBytes contains the total number of bytes
- actually written.
- @param Buffer Pinter to a caller-allocated buffer that
- contains the source for the write.
-
- @retval EFI_SUCCESS The firmware volume was written successfully.
- @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
- 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_DEVICE_ERROR The block device is malfunctioning and could not
- be written.
+ @param This Indicates the calling context.
+ @param Lba The starting logical block index to write to.
+ @param Offset Offset into the block at which to begin writing.
+ @param NumBytes Pointer to a UINT32. At entry, *NumBytes
+ contains the total size of the buffer. At exit,
+ *NumBytes contains the total number of bytes
+ actually written.
+ @param Buffer Pinter to a caller-allocated buffer that
+ contains the source for the write.
+
+ @retval EFI_SUCCESS The firmware volume was written successfully.
+ @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
+ 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_DEVICE_ERROR The block device is malfunctioning and could not
+ be written.
@retval EFI_UNSUPPORTED Not supported.
**/
@@ -275,16 +278,16 @@ FwVolBlockWriteBlock (
{
return EFI_UNSUPPORTED;
}
-
+
/**
Get Fvb's base address.
- @param This Indicates the calling context.
- @param Address Fvb device base address.
+ @param This Indicates the calling context.
+ @param Address Fvb device base address.
- @retval EFI_SUCCESS Successfully got Fvb's base address.
+ @retval EFI_SUCCESS Successfully got Fvb's base address.
@retval EFI_UNSUPPORTED Not supported.
**/
@@ -296,14 +299,14 @@ FwVolBlockGetPhysicalAddress (
)
{
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
-
+
FvbDevice = FVB_DEVICE_FROM_THIS (This);
-
+
if (FvbDevice->FvbAttributes & EFI_FVB2_MEMORY_MAPPED) {
*Address = FvbDevice->BaseAddress;
return EFI_SUCCESS;
}
-
+
return EFI_UNSUPPORTED;
}
@@ -312,17 +315,17 @@ FwVolBlockGetPhysicalAddress (
/**
Retrieves the size in bytes of a specific block within a firmware volume.
- @param This Indicates the calling context.
- @param Lba Indicates the block for which to return the
- size.
- @param BlockSize Pointer to a caller-allocated UINTN in which the
- size of the block is returned.
- @param NumberOfBlocks Pointer to a caller-allocated UINTN in which the
- number of consecutive blocks starting with Lba
- is returned. All blocks in this range have a
- size of BlockSize.
-
- @retval EFI_SUCCESS The firmware volume base address is returned.
+ @param This Indicates the calling context.
+ @param Lba Indicates the block for which to return the
+ size.
+ @param BlockSize Pointer to a caller-allocated UINTN in which the
+ size of the block is returned.
+ @param NumberOfBlocks Pointer to a caller-allocated UINTN in which the
+ number of consecutive blocks starting with Lba
+ is returned. All blocks in this range have a
+ size of BlockSize.
+
+ @retval EFI_SUCCESS The firmware volume base address is returned.
@retval EFI_INVALID_PARAMETER The requested LBA is out of range.
**/
@@ -339,20 +342,20 @@ FwVolBlockGetBlockSize (
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
-
+
FvbDevice = FVB_DEVICE_FROM_THIS (This);
-
+
//
// Do parameter checking
//
if (Lba >= FvbDevice->NumBlocks) {
return EFI_INVALID_PARAMETER;
}
-
+
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);
-
+
PtrBlockMapEntry = FwVolHeader->BlockMap;
-
+
//
// Search the block map for the given block
//
@@ -365,13 +368,13 @@ FwVolBlockGetBlockSize (
//
break;
}
-
+
PtrBlockMapEntry++;
}
-
+
*BlockSize = PtrBlockMapEntry->Length;
*NumberOfBlocks = TotalBlocks - (UINTN)Lba;
-
+
return EFI_SUCCESS;
}
@@ -381,16 +384,16 @@ FwVolBlockGetBlockSize (
This routine produces a firmware volume block protocol on a given
buffer.
- @param BaseAddress base address of the firmware volume image
- @param Length length of the firmware volume image
- @param ParentHandle handle of parent firmware volume, if this image
- came from an FV image file in another firmware
- volume (ala capsules)
- @param FvProtocol Firmware volume block protocol produced.
+ @param BaseAddress base address of the firmware volume image
+ @param Length length of the firmware volume image
+ @param ParentHandle handle of parent firmware volume, if this image
+ came from an FV image file in another firmware
+ volume (ala capsules)
+ @param FvProtocol Firmware volume block protocol produced.
- @retval EFI_VOLUME_CORRUPTED Volume corrupted.
- @retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.
- @retval EFI_SUCCESS Successfully produced a FVB protocol on given
+ @retval EFI_VOLUME_CORRUPTED Volume corrupted.
+ @retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.
+ @retval EFI_SUCCESS Successfully produced a FVB protocol on given
buffer.
**/
@@ -410,9 +413,9 @@ ProduceFVBProtocolOnBuffer (
UINTN LinearOffset;
UINT32 FvAlignment;
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
-
+
FvAlignment = 0;
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress;
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN) BaseAddress;
//
// Validate FV Header, if not as expected, return
//
@@ -433,9 +436,9 @@ ProduceFVBProtocolOnBuffer (
return EFI_VOLUME_CORRUPTED;
}
//
- // Allocate EFI_FW_VOL_BLOCK_DEVICE
+ // Allocate EFI_FW_VOL_BLOCK_DEVICE
//
- FvbDev = CoreAllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);
+ FvbDev = AllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);
if (FvbDev == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -450,14 +453,14 @@ ProduceFVBProtocolOnBuffer (
//
FvbDev->NumBlocks = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
- PtrBlockMapEntry->NumBlocks != 0;
- PtrBlockMapEntry++) {
+ PtrBlockMapEntry->NumBlocks != 0;
+ PtrBlockMapEntry++) {
FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;
}
//
// Second, allocate the cache
//
- FvbDev->LbaCache = CoreAllocateBootServicesPool (FvbDev->NumBlocks * sizeof (LBA_CACHE));
+ FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));
if (FvbDev->LbaCache == NULL) {
CoreFreePool (FvbDev);
return EFI_OUT_OF_RESOURCES;
@@ -468,7 +471,7 @@ ProduceFVBProtocolOnBuffer (
BlockIndex = 0;
LinearOffset = 0;
for (PtrBlockMapEntry = FwVolHeader->BlockMap;
- PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {
+ PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {
for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {
FvbDev->LbaCache[BlockIndex].Base = LinearOffset;
FvbDev->LbaCache[BlockIndex].Length = PtrBlockMapEntry->Length;
@@ -488,12 +491,12 @@ ProduceFVBProtocolOnBuffer (
// Attach FvVolBlock Protocol to new handle
//
Status = CoreInstallMultipleProtocolInterfaces (
- &FvbDev->Handle,
- &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,
- &gEfiDevicePathProtocolGuid, &FvbDev->DevicePath,
- &gEfiFirmwareVolumeDispatchProtocolGuid, NULL,
- NULL
- );
+ &FvbDev->Handle,
+ &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,
+ &gEfiDevicePathProtocolGuid, &FvbDev->DevicePath,
+ &gEfiFirmwareVolumeDispatchProtocolGuid, NULL,
+ NULL
+ );
//
// If they want the handle back, set it.
@@ -512,10 +515,10 @@ ProduceFVBProtocolOnBuffer (
libraries, consumes FV hobs and NT_NON_MM_FV environment variable and
produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.
- @param ImageHandle The image handle.
- @param SystemTable The system table.
+ @param ImageHandle The image handle.
+ @param SystemTable The system table.
- @retval EFI_SUCCESS Successfully initialized firmware volume block
+ @retval EFI_SUCCESS Successfully initialized firmware volume block
driver.
**/
@@ -527,6 +530,7 @@ FwVolBlockDriverInit (
)
{
EFI_PEI_HOB_POINTERS FvHob;
+
//
// Core Needs Firmware Volumes to function
//
@@ -535,9 +539,10 @@ FwVolBlockDriverInit (
//
// Produce an FVB protocol for it
//
- ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, NULL);
+ ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, NULL);
FvHob.Raw = GET_NEXT_HOB (FvHob);
}
+
return EFI_SUCCESS;
}
@@ -548,22 +553,22 @@ FwVolBlockDriverInit (
particular, it can be called by BDS to process a single firmware
volume found in a capsule.
- @param FvHeader pointer to a firmware volume header
- @param Size the size of the buffer pointed to by FvHeader
- @param FVProtocolHandle the handle on which a firmware volume protocol
- was produced for the firmware volume passed in.
+ @param FvHeader pointer to a firmware volume header
+ @param Size the size of the buffer pointed to by FvHeader
+ @param FVProtocolHandle the handle on which a firmware volume protocol
+ was produced for the firmware volume passed in.
- @retval EFI_OUT_OF_RESOURCES if an FVB could not be produced due to lack of
- system resources
- @retval EFI_VOLUME_CORRUPTED if the volume was corrupted
- @retval EFI_SUCCESS a firmware volume protocol was produced for the
+ @retval EFI_OUT_OF_RESOURCES if an FVB could not be produced due to lack of
+ system resources
+ @retval EFI_VOLUME_CORRUPTED if the volume was corrupted
+ @retval EFI_SUCCESS a firmware volume protocol was produced for the
firmware volume
**/
EFI_STATUS
CoreProcessFirmwareVolume (
IN VOID *FvHeader,
- IN UINTN Size,
+ IN UINTN Size,
OUT EFI_HANDLE *FVProtocolHandle
)
{
@@ -571,23 +576,23 @@ CoreProcessFirmwareVolume (
EFI_STATUS Status;
*FVProtocolHandle = NULL;
- Status = ProduceFVBProtocolOnBuffer (
- (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
- (UINT64)Size,
- NULL,
+ Status = ProduceFVBProtocolOnBuffer (
+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,
+ (UINT64)Size,
+ NULL,
FVProtocolHandle
);
//
// Since in our implementation we use register-protocol-notify to put a
// FV protocol on the FVB protocol handle, we can't directly verify that
// the FV protocol was produced. Therefore here we will check the handle
- // and make sure an FV protocol is on it. This indicates that all went
- // well. Otherwise we have to assume that the volume was corrupted
+ // and make sure an FV protocol is on it. This indicates that all went
+ // well. Otherwise we have to assume that the volume was corrupted
// somehow.
//
if (!EFI_ERROR(Status)) {
Ptr = NULL;
- Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Ptr);
+ Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);
if (EFI_ERROR(Status) || (Ptr == NULL)) {
return EFI_VOLUME_CORRUPTED;
}