X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=UnixPkg%2FFvbServicesRuntimeDxe%2FFWBlockService.c;h=b49a660eabf8dfdc6933ec9367c52d0380427bc8;hp=840b0da2f1915e87191fc68f499236e7ba8fb254;hb=3bbe68a3627e7c75474955352f27b923c5831ad7;hpb=7492c63d423201cbabc00c343cc25269bb1254c1 diff --git a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c index 840b0da2f1..b49a660eab 100644 --- a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c +++ b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c @@ -1,7 +1,7 @@ /*++ -Copyright (c) 2006 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2012, 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 @@ -21,9 +21,7 @@ Revision History #include "PiDxe.h" #include -#include #include -#include #include #include @@ -36,6 +34,8 @@ Revision History #include #include #include +#include + #include "FwBlockService.h" ESAL_FWB_GLOBAL *mFvbModuleGlobal; @@ -77,9 +77,6 @@ EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = { FvbProtocolWrite, FvbProtocolEraseBlocks, NULL - }, - { - FvbExtendProtocolEraseCustomBlockRange } }; @@ -133,7 +130,6 @@ Returns: Index++; } - EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]); EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal); } @@ -214,7 +210,7 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_STATUS Status; // @@ -230,7 +226,7 @@ Returns: EFI_STATUS FvbGetVolumeAttributes ( IN UINTN Instance, - OUT EFI_FVB_ATTRIBUTES_2 *Attributes, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes, IN ESAL_FWB_GLOBAL *Global, IN BOOLEAN Virtual ) @@ -254,7 +250,7 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_STATUS Status; // @@ -307,7 +303,7 @@ Returns: UINTN Offset; EFI_LBA StartLba; EFI_LBA NextLba; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FV_BLOCK_MAP_ENTRY *BlockMap; EFI_STATUS Status; @@ -564,10 +560,10 @@ Returns: { EFI_FVB_ATTRIBUTES_2 Attributes; - UINTN LbaAddress; - UINTN LbaLength; - EFI_STATUS Status; - UINT8 Data; + UINTN LbaAddress; + UINTN LbaLength; + EFI_STATUS Status; + UINT8 Data; // // Check if the FV is write enabled @@ -597,117 +593,10 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -FvbEraseCustomBlockRange ( - IN UINTN Instance, - IN EFI_LBA StartLba, - IN UINTN OffsetStartLba, - IN EFI_LBA LastLba, - IN UINTN OffsetLastLba, - IN ESAL_FWB_GLOBAL *Global, - IN BOOLEAN Virtual - ) -/*++ - -Routine Description: - Erases and initializes a specified range of a firmware volume - -Arguments: - Instance - The FV instance to be erased - StartLba - The starting logical block index to be erased - OffsetStartLba - Offset into the starting block at which to - begin erasing - LastLba - The last logical block index to be erased - OffsetStartLba - Offset into the last block at which to end erasing - Global - Pointer to ESAL_FWB_GLOBAL that contains all - instance data - Virtual - Whether CPU is in virtual or physical mode - -Returns: - EFI_SUCCESS - The firmware volume was erased successfully - EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state - EFI_DEVICE_ERROR - The block device is not functioning correctly and - could not be written. Firmware device may have been - partially erased - EFI_INVALID_PARAMETER - Instance not found - ---*/ -{ - EFI_LBA Index; - UINTN LbaSize; - UINTN ScratchLbaSizeData; - EFI_STATUS Status; - - // - // First LBA - // - Status = FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Use the scratch space as the intermediate buffer to transfer data - // Back up the first LBA in scratch space. - // - FvbReadBlock (Instance, StartLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual); - - // - // erase now - // - FvbEraseBlock (Instance, StartLba, Global, Virtual); - ScratchLbaSizeData = OffsetStartLba; - - // - // write the data back to the first block - // - if (ScratchLbaSizeData > 0) { - Status = FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual); - if (EFI_ERROR (Status)) { - return Status; - } - } - // - // Middle LBAs - // - if (LastLba > (StartLba + 1)) { - for (Index = (StartLba + 1); Index <= (LastLba - 1); Index++) { - FvbEraseBlock (Instance, Index, Global, Virtual); - } - } - // - // Last LBAs, the same as first LBAs - // - if (LastLba > StartLba) { - Status = FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual); - if (EFI_ERROR (Status)) { - return Status; - } - FvbReadBlock (Instance, LastLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual); - FvbEraseBlock (Instance, LastLba, Global, Virtual); - } - - ScratchLbaSizeData = LbaSize - (OffsetLastLba + 1); - - if (ScratchLbaSizeData > 0) { - Status = FvbWriteBlock ( - Instance, - LastLba, - (OffsetLastLba + 1), - &ScratchLbaSizeData, - Global->FvbScratchSpace[Virtual] + OffsetLastLba + 1, - Global, - Virtual - ); - } - - return Status; -} - EFI_STATUS FvbSetVolumeAttributes ( IN UINTN Instance, - IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes, IN ESAL_FWB_GLOBAL *Global, IN BOOLEAN Virtual ) @@ -737,13 +626,13 @@ Returns: --*/ { - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FVB_ATTRIBUTES_2 OldAttributes; EFI_FVB_ATTRIBUTES_2 *AttribPtr; - UINT32 Capabilities; - UINT32 OldStatus; - UINT32 NewStatus; - EFI_STATUS Status; + UINT32 Capabilities; + UINT32 OldStatus; + UINT32 NewStatus; + EFI_STATUS Status; EFI_FVB_ATTRIBUTES_2 UnchangedAttributes; @@ -844,7 +733,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetPhysicalAddress ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, OUT EFI_PHYSICAL_ADDRESS *Address ) /*++ @@ -875,7 +764,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetBlockSize ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, OUT UINTN *BlockSize, OUT UINTN *NumOfBlocks @@ -919,8 +808,8 @@ Returns: EFI_STATUS EFIAPI FvbProtocolGetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, - OUT EFI_FVB_ATTRIBUTES_2 *Attributes + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) /*++ @@ -946,8 +835,8 @@ Returns: EFI_STATUS EFIAPI FvbProtocolSetAttributes ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, - IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes ) /*++ @@ -973,7 +862,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolEraseBlocks ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, ... ) /*++ @@ -1002,7 +891,7 @@ Returns: --*/ { EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; UINTN NumOfBlocks; VA_LIST args; EFI_LBA StartingLba; @@ -1029,14 +918,10 @@ Returns: // // Check input parameters // - if (NumOfLba == 0) { + if (NumOfLba == 0 || (StartingLba + NumOfLba) > NumOfBlocks) { VA_END (args); return EFI_INVALID_PARAMETER; } - - if ((StartingLba + NumOfLba) > NumOfBlocks) { - return EFI_INVALID_PARAMETER; - } } while (1); VA_END (args); @@ -1071,7 +956,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolWrite ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -1119,7 +1004,7 @@ Returns: EFI_STATUS EFIAPI FvbProtocolRead ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, + IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This, IN EFI_LBA Lba, IN UINTN Offset, IN OUT UINTN *NumBytes, @@ -1164,55 +1049,6 @@ Returns: return FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ()); } -// -// FVB Extension Protocols -// -EFI_STATUS -EFIAPI -FvbExtendProtocolEraseCustomBlockRange ( - IN EFI_FVB_EXTENSION_PROTOCOL *This, - IN EFI_LBA StartLba, - IN UINTN OffsetStartLba, - IN EFI_LBA LastLba, - IN UINTN OffsetLastLba - ) -/*++ - -Routine Description: - Erases and initializes a specified range of a firmware volume - -Arguments: - This - Calling context - StartLba - The starting logical block index to be erased - OffsetStartLba - Offset into the starting block at which to - begin erasing - LastLba - The last logical block index to be erased - OffsetStartLba - Offset into the last block at which to end erasing - -Returns: - EFI_SUCCESS - The firmware volume was erased successfully - EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state - EFI_DEVICE_ERROR - The block device is not functioning correctly and - could not be written. Firmware device may have been - partially erased - ---*/ -{ - EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; - - FvbDevice = FVB_EXTEND_DEVICE_FROM_THIS (This); - - return FvbEraseCustomBlockRange ( - FvbDevice->Instance, - StartLba, - OffsetStartLba, - LastLba, - OffsetLastLba, - mFvbModuleGlobal, - EfiGoneVirtual () - ); -} - EFI_STATUS ValidateFvHeader ( EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader @@ -1284,7 +1120,7 @@ Returns: --*/ { EFI_STATUS Status; - EFI_FW_VOL_INSTANCE *FwhInstance; + EFI_FW_VOL_INSTANCE *FwhInstance = NULL; EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; EFI_DXE_SERVICES *DxeServices; EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; @@ -1488,7 +1324,7 @@ Returns: NULL ); ASSERT_EFI_ERROR (Status); - } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) { + } else if (IsDevicePathEnd (TempFwbDevicePath)) { // // Device allready exists, so reinstall the FVB protocol // @@ -1513,19 +1349,6 @@ Returns: // ASSERT (FALSE); } - // - // Install FVB Extension Protocol on the same handle - // - Status = gBS->InstallMultipleProtocolInterfaces ( - &FwbHandle, - &gEfiFvbExtensionProtocolGuid, - &FvbDevice->FvbExtension, - &gEfiAlternateFvBlockGuid, - NULL, - NULL - ); - - ASSERT_EFI_ERROR (Status); FwhInstance = (EFI_FW_VOL_INSTANCE *) ( @@ -1536,17 +1359,5 @@ Returns: FvHob.Raw = GET_NEXT_HOB (FvHob); } - // - // Allocate for scratch space, an intermediate buffer for FVB extention - // - Status = gBS->AllocatePool ( - EfiRuntimeServicesData, - MaxLbaSize, - (VOID**)&mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL] - ); - ASSERT_EFI_ERROR (Status); - - mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL] = mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL]; - return EFI_SUCCESS; }