From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web09.612.1666630906140592219 for ; Mon, 24 Oct 2022 10:01:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IWD8mSge; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 259D9B815C6; Mon, 24 Oct 2022 17:01:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82837C4347C; Mon, 24 Oct 2022 17:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666630902; bh=4JEGbTRbMDHLsQGqBObtSFXj+vuCx1QRsdm0R8w1NVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IWD8mSge63Q8T/CM9NvDSZFf1CqFR5c9W5zqVka8Sb0iUl/HEcvNE13y0+7qZuuLt 8wLw+qGkPaXZD6KT9i8i3N2D/0tS01BhPA3CxoLT7SFiooLEJo5N9Zey8vDO0O3/lp BOivoLqZKUUQMHV/vuCJAITkHQfo5h8RILr+wif+N9D7GiT18QrrMk+3veye6DOJCV TPMj2/0slRJaq9bCE2qtN6Kl4LXV+i436wkDmmjtPakK3/63Ua69rWbOiYRK4avo72 HRnrPo0HN2BkI/ehBxlxdRXed/MvrthYCdjGuvLyb/c3HjxW4Td75bQX/TZzIva9Gt 60Eboo4Th+3cw== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Gerd Hoffmann , Sunil V L , Sami Mujawar , Leif Lindholm Subject: [PATCH 05/11] OvmfPkg/VirtNorFlashDxe: drop block I/O protocol implementation Date: Mon, 24 Oct 2022 19:01:16 +0200 Message-Id: <20221024170122.594577-6-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221024170122.594577-1-ardb@kernel.org> References: <20221024170122.594577-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable We never boot from NOR flash, and generally rely on the firmware volume PI protocols to expose the contents. So drop the block I/O protocol implementation from VirtNorFlashDxe. Signed-off-by: Ard Biesheuvel --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 49 ++++++------------ OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h | 52 +------------------- OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c | 40 +++------------ OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf | 1 - OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c | 52 ++++++++------------ 5 files changed, 44 insertions(+), 150 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 1094d48f7de4..f41d9d372f49 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -366,10 +366,6 @@ NorFlashWriteBlocks ( return EFI_INVALID_PARAMETER;=0D }=0D =0D - if (Instance->Media.ReadOnly =3D=3D TRUE) {=0D - return EFI_WRITE_PROTECTED;=0D - }=0D -=0D // We must have some bytes to read=0D DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=3D0x%x\n", = BufferSizeInBytes));=0D if (BufferSizeInBytes =3D=3D 0) {=0D @@ -377,22 +373,22 @@ NorFlashWriteBlocks ( }=0D =0D // The size of the buffer must be a multiple of the block size=0D - DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =3D0x%x\n"= , Instance->Media.BlockSize));=0D - if ((BufferSizeInBytes % Instance->Media.BlockSize) !=3D 0) {=0D + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =3D0x%x\n"= , Instance->BlockSize));=0D + if ((BufferSizeInBytes % Instance->BlockSize) !=3D 0) {=0D return EFI_BAD_BUFFER_SIZE;=0D }=0D =0D // All blocks must be within the device=0D - NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;=0D + NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->BlockSize;=0D =0D - DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=3D%d, LastBlock=3D%= ld, Lba=3D%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));=0D + DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=3D%d, LastBlock=3D%= ld, Lba=3D%ld.\n", NumBlocks, Instance->LastBlock, Lba));=0D =0D - if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {=0D + if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) {=0D DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed l= ast block.\n"));=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D - BlockSizeInWords =3D Instance->Media.BlockSize / 4;=0D + BlockSizeInWords =3D Instance->BlockSize / 4;=0D =0D // Because the target *Buffer is a pointer to VOID, we must put all the = data into a pointer=0D // to a proper data type, so use *ReadBuffer=0D @@ -489,8 +485,8 @@ NorFlashReadBlocks ( DEBUG_BLKIO,=0D "NorFlashReadBlocks: BufferSize=3D0x%xB BlockSize=3D0x%xB LastBlock=3D= %ld, Lba=3D%ld.\n",=0D BufferSizeInBytes,=0D - Instance->Media.BlockSize,=0D - Instance->Media.LastBlock,=0D + Instance->BlockSize,=0D + Instance->LastBlock,=0D Lba=0D ));=0D =0D @@ -505,14 +501,14 @@ NorFlashReadBlocks ( }=0D =0D // The size of the buffer must be a multiple of the block size=0D - if ((BufferSizeInBytes % Instance->Media.BlockSize) !=3D 0) {=0D + if ((BufferSizeInBytes % Instance->BlockSize) !=3D 0) {=0D return EFI_BAD_BUFFER_SIZE;=0D }=0D =0D // All blocks must be within the device=0D - NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;=0D + NumBlocks =3D ((UINT32)BufferSizeInBytes) / Instance->BlockSize;=0D =0D - if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {=0D + if ((Lba + NumBlocks) > (Instance->LastBlock + 1)) {=0D DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed las= t block\n"));=0D return EFI_INVALID_PARAMETER;=0D }=0D @@ -521,7 +517,7 @@ NorFlashReadBlocks ( StartAddress =3D GET_NOR_BLOCK_ADDRESS (=0D Instance->RegionBaseAddress,=0D Lba,=0D - Instance->Media.BlockSize=0D + Instance->BlockSize=0D );=0D =0D // Put the device into Read Array mode=0D @@ -554,7 +550,7 @@ NorFlashRead ( return EFI_SUCCESS;=0D }=0D =0D - if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > I= nstance->Size) {=0D + if (((Lba * Instance->BlockSize) + Offset + BufferSizeInBytes) > Instanc= e->Size) {=0D DEBUG ((DEBUG_ERROR, "NorFlashRead: ERROR - Read will exceed device si= ze.\n"));=0D return EFI_INVALID_PARAMETER;=0D }=0D @@ -563,7 +559,7 @@ NorFlashRead ( StartAddress =3D GET_NOR_BLOCK_ADDRESS (=0D Instance->RegionBaseAddress,=0D Lba,=0D - Instance->Media.BlockSize=0D + Instance->BlockSize=0D );=0D =0D // Put the device into Read Array mode=0D @@ -577,7 +573,7 @@ NorFlashRead ( =0D /*=0D Write a full or portion of a block. It must not span block boundaries; t= hat is,=0D - Offset + *NumBytes <=3D Instance->Media.BlockSize.=0D + Offset + *NumBytes <=3D Instance->BlockSize.=0D */=0D EFI_STATUS=0D NorFlashWriteSingleBlock (=0D @@ -605,15 +601,8 @@ NorFlashWriteSingleBlock ( =0D DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer));=0D =0D - // Detect WriteDisabled state=0D - if (Instance->Media.ReadOnly =3D=3D TRUE) {=0D - DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - Can not write:= Device is in WriteDisabled state.\n"));=0D - // It is in WriteDisabled state, return an error right away=0D - return EFI_ACCESS_DENIED;=0D - }=0D -=0D // Cache the block size to avoid de-referencing pointers all the time=0D - BlockSize =3D Instance->Media.BlockSize;=0D + BlockSize =3D Instance->BlockSize;=0D =0D // The write must not span block boundaries.=0D // We need to check each variable individually because adding two large = values together overflows.=0D @@ -819,12 +808,6 @@ NorFlashVirtualNotifyEvent ( EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->DeviceBas= eAddress);=0D EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->RegionBas= eAddress);=0D =0D - // Convert BlockIo protocol=0D - EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.FlushBlocks);=0D - EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.ReadBlocks);=0D - EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.Reset);=0D - EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoPr= otocol.WriteBlocks);=0D -=0D // Convert Fvb=0D EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.EraseBlocks);=0D EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtoc= ol.GetAttributes);=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.h index 71af755e8366..df3cdb05d065 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h @@ -14,7 +14,6 @@ =0D #include =0D =0D -#include =0D #include =0D =0D #include =0D @@ -109,7 +108,6 @@ =0D #define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0')=0D #define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtoco= l, NOR_FLASH_SIGNATURE)=0D -#define INSTANCE_FROM_BLKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, BlockIoPro= tocol, NOR_FLASH_SIGNATURE)=0D =0D typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;=0D =0D @@ -129,9 +127,8 @@ struct _NOR_FLASH_INSTANCE { UINTN RegionBaseAddress;=0D UINTN Size;=0D EFI_LBA StartLba;=0D -=0D - EFI_BLOCK_IO_PROTOCOL BlockIoProtocol;=0D - EFI_BLOCK_IO_MEDIA Media;=0D + EFI_LBA LastBlock;=0D + UINT32 BlockSize;=0D =0D EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;=0D VOID *ShadowBuffer;=0D @@ -155,51 +152,6 @@ NorFlashWriteBuffer ( IN UINT32 *Buffer=0D );=0D =0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.Reset=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoReset (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN BOOLEAN ExtendedVerification=0D - );=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoReadBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - OUT VOID *Buffer=0D - );=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoWriteBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This,=0D - IN UINT32 MediaId,=0D - IN EFI_LBA Lba,=0D - IN UINTN BufferSizeInBytes,=0D - IN VOID *Buffer=0D - );=0D -=0D -//=0D -// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks=0D -//=0D -EFI_STATUS=0D -EFIAPI=0D -NorFlashBlockIoFlushBlocks (=0D - IN EFI_BLOCK_IO_PROTOCOL *This=0D - );=0D -=0D //=0D // NorFlashFvbDxe.c=0D //=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashDxe.c index 4875b057d5e2..2ceda226359c 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.c @@ -34,29 +34,8 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate =3D { 0, // RegionBaseAddress ... NEED TO BE FILLED=0D 0, // Size ... NEED TO BE FILLED=0D 0, // StartLba=0D -=0D - {=0D - EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision=0D - NULL, // Media ... NEED TO BE FILLED=0D - NorFlashBlockIoReset, // Reset;=0D - NorFlashBlockIoReadBlocks, // ReadBlocks=0D - NorFlashBlockIoWriteBlocks, // WriteBlocks=0D - NorFlashBlockIoFlushBlocks // FlushBlocks=0D - }, // BlockIoProtocol=0D -=0D - {=0D - 0, // MediaId ... NEED TO BE FILLED=0D - FALSE, // RemovableMedia=0D - TRUE, // MediaPresent=0D - FALSE, // LogicalPartition=0D - FALSE, // ReadOnly=0D - FALSE, // WriteCaching;=0D - 0, // BlockSize ... NEED TO BE FILLED=0D - 4, // IoAlign=0D - 0, // LastBlock ... NEED TO BE FILLED=0D - 0, // LowestAlignedLba=0D - 1, // LogicalBlocksPerPhysicalBlock=0D - }, // Media;=0D + 0, // LastBlock=0D + 0, // BlockSize=0D =0D {=0D FvbGetAttributes, // GetAttributes=0D @@ -115,11 +94,8 @@ NorFlashCreateInstance ( Instance->DeviceBaseAddress =3D NorFlashDeviceBase;=0D Instance->RegionBaseAddress =3D NorFlashRegionBase;=0D Instance->Size =3D NorFlashSize;=0D -=0D - Instance->BlockIoProtocol.Media =3D &Instance->Media;=0D - Instance->Media.MediaId =3D Index;=0D - Instance->Media.BlockSize =3D BlockSize;=0D - Instance->Media.LastBlock =3D (NorFlashSize / BlockSize)-1;=0D + Instance->BlockSize =3D BlockSize;=0D + Instance->LastBlock =3D (NorFlashSize / BlockSize) - 1;=0D =0D CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);=0D Instance->DevicePath.Index =3D (UINT8)Index;=0D @@ -136,8 +112,6 @@ NorFlashCreateInstance ( &Instance->Handle,=0D &gEfiDevicePathProtocolGuid,=0D &Instance->DevicePath,=0D - &gEfiBlockIoProtocolGuid,=0D - &Instance->BlockIoProtocol,=0D &gEfiFirmwareVolumeBlockProtocolGuid,=0D &Instance->FvbProtocol,=0D NULL=0D @@ -151,8 +125,6 @@ NorFlashCreateInstance ( &Instance->Handle,=0D &gEfiDevicePathProtocolGuid,=0D &Instance->DevicePath,=0D - &gEfiBlockIoProtocolGuid,=0D - &Instance->BlockIoProtocol,=0D NULL=0D );=0D if (EFI_ERROR (Status)) {=0D @@ -434,7 +406,7 @@ NorFlashFvbInitialize ( PcdGet64 (PcdFlashNvStorageVariableBase64)= : PcdGet32 (PcdFlashNvStorageVariableBase);=0D =0D // Set the index of the first LBA for the FVB=0D - Instance->StartLba =3D (mFlashNvStorageVariableBase - Instance->RegionBa= seAddress) / Instance->Media.BlockSize;=0D + Instance->StartLba =3D (mFlashNvStorageVariableBase - Instance->RegionBa= seAddress) / Instance->BlockSize;=0D =0D BootMode =3D GetBootModeHob ();=0D if (BootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS) {=0D @@ -455,7 +427,7 @@ NorFlashFvbInitialize ( ));=0D =0D // Erase all the NorFlash that is reserved for variable storage=0D - FvbNumLba =3D (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (Pc= dFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) = / Instance->Media.BlockSize;=0D + FvbNumLba =3D (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (Pc= dFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) = / Instance->BlockSize;=0D =0D Status =3D FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumL= ba, EFI_LBA_LIST_TERMINATOR);=0D if (EFI_ERROR (Status)) {=0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf b/OvmfPkg/VirtNorF= lashDxe/VirtNorFlashDxe.inf index 53e9d5820488..2a3d4a218e61 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf @@ -19,7 +19,6 @@ [Defines] [Sources.common]=0D VirtNorFlash.c=0D VirtNorFlash.h=0D - VirtNorFlashBlockIoDxe.c=0D VirtNorFlashDxe.c=0D VirtNorFlashFvb.c=0D =0D diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashFvb.c index c824e0a0fbad..eefa71fa1e20 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c @@ -89,7 +89,7 @@ InitializeFvAndVariableStoreHeaders ( }=0D =0D // Check if the size of the area is at least one block size=0D - if ((NvStorageVariableSize <=3D 0) || (NvStorageVariableSize / Instance-= >Media.BlockSize <=3D 0)) {=0D + if ((NvStorageVariableSize <=3D 0) || (NvStorageVariableSize / Instance-= >BlockSize <=3D 0)) {=0D DEBUG ((=0D DEBUG_ERROR,=0D "%a: NvStorageVariableSize is 0x%x, should be atleast one block size= \n",=0D @@ -99,7 +99,7 @@ InitializeFvAndVariableStoreHeaders ( return EFI_INVALID_PARAMETER;=0D }=0D =0D - if ((NvStorageFtwWorkingSize <=3D 0) || (NvStorageFtwWorkingSize / Insta= nce->Media.BlockSize <=3D 0)) {=0D + if ((NvStorageFtwWorkingSize <=3D 0) || (NvStorageFtwWorkingSize / Insta= nce->BlockSize <=3D 0)) {=0D DEBUG ((=0D DEBUG_ERROR,=0D "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block si= ze\n",=0D @@ -109,7 +109,7 @@ InitializeFvAndVariableStoreHeaders ( return EFI_INVALID_PARAMETER;=0D }=0D =0D - if ((NvStorageFtwSpareSize <=3D 0) || (NvStorageFtwSpareSize / Instance-= >Media.BlockSize <=3D 0)) {=0D + if ((NvStorageFtwSpareSize <=3D 0) || (NvStorageFtwSpareSize / Instance-= >BlockSize <=3D 0)) {=0D DEBUG ((=0D DEBUG_ERROR,=0D "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size= \n",=0D @@ -120,9 +120,9 @@ InitializeFvAndVariableStoreHeaders ( }=0D =0D // Ensure the Variable area Base Addresses are aligned on a block size b= oundaries=0D - if ((NvStorageVariableBase % Instance->Media.BlockSize !=3D 0) ||=0D - (NvStorageFtwWorkingBase % Instance->Media.BlockSize !=3D 0) ||=0D - (NvStorageFtwSpareBase % Instance->Media.BlockSize !=3D 0))=0D + if ((NvStorageVariableBase % Instance->BlockSize !=3D 0) ||=0D + (NvStorageFtwWorkingBase % Instance->BlockSize !=3D 0) ||=0D + (NvStorageFtwSpareBase % Instance->BlockSize !=3D 0))=0D {=0D DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to = block size boundaries", __FUNCTION__));=0D return EFI_INVALID_PARAMETER;=0D @@ -149,8 +149,8 @@ InitializeFvAndVariableStoreHeaders ( );=0D FirmwareVolumeHeader->HeaderLength =3D sizeof (EFI_FIRMWARE_VOL= UME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY);=0D FirmwareVolumeHeader->Revision =3D EFI_FVH_REVISION;=0D - FirmwareVolumeHeader->BlockMap[0].NumBlocks =3D Instance->Media.LastBloc= k + 1;=0D - FirmwareVolumeHeader->BlockMap[0].Length =3D Instance->Media.BlockSiz= e;=0D + FirmwareVolumeHeader->BlockMap[0].NumBlocks =3D Instance->LastBlock + 1;= =0D + FirmwareVolumeHeader->BlockMap[0].Length =3D Instance->BlockSize;=0D FirmwareVolumeHeader->BlockMap[1].NumBlocks =3D 0;=0D FirmwareVolumeHeader->BlockMap[1].Length =3D 0;=0D FirmwareVolumeHeader->Checksum =3D CalculateCheckSum16 ((UI= NT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);=0D @@ -294,17 +294,12 @@ FvbGetAttributes ( EFI_FVB2_READ_STATUS | = // Reads are currently enabled=0D EFI_FVB2_STICKY_WRITE | = // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY=0D EFI_FVB2_MEMORY_MAPPED | = // It is memory mapped=0D - EFI_FVB2_ERASE_POLARITY = // After erasure all bits take this value (i.e. '1')=0D + EFI_FVB2_ERASE_POLARITY | = // After erasure all bits take this value (i.e. '1')=0D + EFI_FVB2_WRITE_STATUS | = // Writes are currently enabled=0D + EFI_FVB2_WRITE_ENABLED_CAP = // Writes may be enabled=0D =0D );=0D =0D - // Check if it is write protected=0D - if (Instance->Media.ReadOnly !=3D TRUE) {=0D - FlashFvbAttributes =3D FlashFvbAttributes |=0D - EFI_FVB2_WRITE_STATUS | // Writes are curren= tly enabled=0D - EFI_FVB2_WRITE_ENABLED_CAP; // Writes may be ena= bled=0D - }=0D -=0D *Attributes =3D FlashFvbAttributes;=0D =0D DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes));=0D @@ -418,15 +413,15 @@ FvbGetBlockSize ( =0D Instance =3D INSTANCE_FROM_FVB_THIS (This);=0D =0D - DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=3D%ld, BlockSize=3D0x%x, LastB= lock=3D%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock))= ;=0D + DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=3D%ld, BlockSize=3D0x%x, LastB= lock=3D%ld)\n", Lba, Instance->BlockSize, Instance->LastBlock));=0D =0D - if (Lba > Instance->Media.LastBlock) {=0D - DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is be= yond the last Lba (%ld).\n", Lba, Instance->Media.LastBlock));=0D + if (Lba > Instance->LastBlock) {=0D + DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is be= yond the last Lba (%ld).\n", Lba, Instance->LastBlock));=0D Status =3D EFI_INVALID_PARAMETER;=0D } else {=0D // This is easy because in this platform each NorFlash device has equa= l sized blocks.=0D - *BlockSize =3D (UINTN)Instance->Media.BlockSize;=0D - *NumberOfBlocks =3D (UINTN)(Instance->Media.LastBlock - Lba + 1);=0D + *BlockSize =3D (UINTN)Instance->BlockSize;=0D + *NumberOfBlocks =3D (UINTN)(Instance->LastBlock - Lba + 1);=0D =0D DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=3D0x%x, *NumberOfBlo= cks=3D0x%x.\n", *BlockSize, *NumberOfBlocks));=0D =0D @@ -498,7 +493,7 @@ FvbRead ( TempStatus =3D EFI_SUCCESS;=0D =0D // Cache the block size to avoid de-referencing pointers all the time=0D - BlockSize =3D Instance->Media.BlockSize;=0D + BlockSize =3D Instance->BlockSize;=0D =0D DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=3D0x%x + NumBytes=3D0x%x= ) <=3D BlockSize=3D0x%x\n", Offset, *NumBytes, BlockSize));=0D =0D @@ -669,13 +664,6 @@ FvbEraseBlocks ( =0D Status =3D EFI_SUCCESS;=0D =0D - // Detect WriteDisabled state=0D - if (Instance->Media.ReadOnly =3D=3D TRUE) {=0D - // Firmware volume is in WriteDisabled state=0D - DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Device is in WriteDisabl= ed state.\n"));=0D - return EFI_ACCESS_DENIED;=0D - }=0D -=0D // Before erasing, check the entire list of parameters to ensure all spe= cified blocks are valid=0D =0D VA_START (Args, This);=0D @@ -698,9 +686,9 @@ FvbEraseBlocks ( "FvbEraseBlocks: Check if: ( StartingLba=3D%ld + NumOfLba=3D%Lu - 1 = ) > LastBlock=3D%ld.\n",=0D Instance->StartLba + StartingLba,=0D (UINT64)NumOfLba,=0D - Instance->Media.LastBlock=0D + Instance->LastBlock=0D ));=0D - if ((NumOfLba =3D=3D 0) || ((Instance->StartLba + StartingLba + NumOfL= ba - 1) > Instance->Media.LastBlock)) {=0D + if ((NumOfLba =3D=3D 0) || ((Instance->StartLba + StartingLba + NumOfL= ba - 1) > Instance->LastBlock)) {=0D VA_END (Args);=0D DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past th= e last Lba.\n"));=0D Status =3D EFI_INVALID_PARAMETER;=0D @@ -733,7 +721,7 @@ FvbEraseBlocks ( BlockAddress =3D GET_NOR_BLOCK_ADDRESS (=0D Instance->RegionBaseAddress,=0D Instance->StartLba + StartingLba,=0D - Instance->Media.BlockSize=0D + Instance->BlockSize=0D );=0D =0D // Erase it=0D --=20 2.35.1