From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: oliver@redhat.com
Subject: Re: [edk2-devel] [PATCH v3 6/6] OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function
Date: Wed, 17 Jan 2024 11:20:16 +0100 [thread overview]
Message-ID: <6a7e9ad1-622f-ac78-1df7-94372f160f56@redhat.com> (raw)
In-Reply-To: <20240116171105.37831-7-kraxel@redhat.com>
On 1/16/24 18:11, Gerd Hoffmann wrote:
> Move the DoErase code block into a separate function, call the function
> instead of jumping around with goto.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 76 ++++++++++++++++++--------
> 1 file changed, 52 insertions(+), 24 deletions(-)
>
> diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
> index 3d1d20daa1e5..e6aaed27ceba 100644
> --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
> +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c
> @@ -502,6 +502,38 @@ NorFlashRead (
> return EFI_SUCCESS;
> }
>
> +STATIC
> +EFI_STATUS
> +NorFlashWriteSingleBlockWithErase (
> + IN NOR_FLASH_INSTANCE *Instance,
> + IN EFI_LBA Lba,
> + IN UINTN Offset,
> + IN OUT UINTN *NumBytes,
> + IN UINT8 *Buffer
> + )
> +{
> + EFI_STATUS Status;
> +
> + // Read NOR Flash data into shadow buffer
> + Status = NorFlashReadBlocks (Instance, Lba, Instance->BlockSize, Instance->ShadowBuffer);
> + if (EFI_ERROR (Status)) {
> + // Return one of the pre-approved error statuses
> + return EFI_DEVICE_ERROR;
> + }
> +
> + // Put the data at the appropriate location inside the buffer area
> + CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
> +
> + // Write the modified buffer back to the NorFlash
> + Status = NorFlashWriteBlocks (Instance, Lba, Instance->BlockSize, Instance->ShadowBuffer);
> + if (EFI_ERROR (Status)) {
> + // Return one of the pre-approved error statuses
> + return EFI_DEVICE_ERROR;
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> /*
> Write a full or portion of a block. It must not span block boundaries; that is,
> Offset + *NumBytes <= Instance->BlockSize.
> @@ -607,7 +639,14 @@ NorFlashWriteSingleBlock (
> // that we want to set. In that case, we will need to erase the block first.
> for (CurOffset = 0; CurOffset < *NumBytes; CurOffset++) {
> if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) {
> - goto DoErase;
> + Status = NorFlashWriteSingleBlockWithErase (
> + Instance,
> + Lba,
> + Offset,
> + NumBytes,
> + Buffer
> + );
> + return Status;
> }
>
> OrigData[CurOffset] = Buffer[CurOffset];
> @@ -636,33 +675,22 @@ NorFlashWriteSingleBlock (
> goto Exit;
> }
> }
> -
> -Exit:
> - // Put device back into Read Array mode
> - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
> -
> + } else {
> + Status = NorFlashWriteSingleBlockWithErase (
> + Instance,
> + Lba,
> + Offset,
> + NumBytes,
> + Buffer
> + );
> return Status;
> }
>
> -DoErase:
> - // Read NOR Flash data into shadow buffer
> - Status = NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
> - if (EFI_ERROR (Status)) {
> - // Return one of the pre-approved error statuses
> - return EFI_DEVICE_ERROR;
> - }
> +Exit:
> + // Put device back into Read Array mode
> + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
>
> - // Put the data at the appropriate location inside the buffer area
> - CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
> -
> - // Write the modified buffer back to the NorFlash
> - Status = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
> - if (EFI_ERROR (Status)) {
> - // Return one of the pre-approved error statuses
> - return EFI_DEVICE_ERROR;
> - }
> -
> - return EFI_SUCCESS;
> + return Status;
> }
>
> EFI_STATUS
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This series is now ready to be merged, but I'm unsure what the CI status
is, after the recent security fixes seem to have caused breakage with
multiple external definitions of the same symbol. For now I'll keep this
tagged, as a reminder for myself.
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113944): https://edk2.groups.io/g/devel/message/113944
Mute This Topic: https://groups.io/mt/103766779/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-01-17 10:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 17:10 [edk2-devel] [PATCH v3 0/6] OvmfPkg/VirtNorFlashDxe: fix corruption + misc small improvements Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 1/6] OvmfPkg/VirtNorFlashDxe: add casts to UINTN and UINT32 Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 2/6] OvmfPkg/VirtNorFlashDxe: clarify block write logic & fix shadowbuffer reads Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 3/6] OvmfPkg/VirtNorFlashDxe: add a loop for NorFlashWriteBuffer calls Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 4/6] OvmfPkg/VirtNorFlashDxe: allow larger writes without block erase Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 5/6] OvmfPkg/VirtNorFlashDxe: ValidateFvHeader: unwritten state is EOL too Gerd Hoffmann
2024-01-16 17:11 ` [edk2-devel] [PATCH v3 6/6] OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function Gerd Hoffmann
2024-01-17 10:20 ` Laszlo Ersek [this message]
2024-01-18 20:28 ` [edk2-devel] [PATCH v3 0/6] OvmfPkg/VirtNorFlashDxe: fix corruption + misc small improvements Laszlo Ersek
2024-01-19 7:52 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a7e9ad1-622f-ac78-1df7-94372f160f56@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox