From nobody Tue May 26 08:57:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113921+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113921+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705425076; cv=none; d=zohomail.com; s=zohoarc; b=WIIrJMRt9GJPrCA7HvDBuNgCanaQyyZLaTV8LJ+MOtf/4pxOXsKy7ks49O0GOxBKGXMY4/j96To7cIBEhblxj9V9O3EBhxkTZtA5D7zBTuNahrGU/lpbLZpHVZPZuL7nY7ATqAT9UBlHiABWhiV9yapcVrtne7+0GgXQWus/T7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705425076; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=GTdLKSuvc/Xfh+04g6VMXjEziXYPPQXdXzz7ADD2z7I=; b=kKp9x0OLWKqmPbgxR604MIixiM+aIPJZhCqe2rF9gNEx8Uypj36/XNRcEaYIOHZYP9stJGXSAK5Elm8fB1CtQJNvtkeLpvgjM0UJxl1Fn+LYUkhCNMb9O/Kk2wMu7jYv2WMG0eIB0vO47Vah04sjFoggCn9W8HtdJGfkimNGkA0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113921+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705425076899443.0165722195152; Tue, 16 Jan 2024 09:11:16 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=qsT/pZOw6nFZoZr34RRflUmJefg6G2xwf5EgysBGtaw=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705425076; v=1; b=TNVQjDzHKzFL+8PIsMwvtZqNnd6cEANuL+G4qEV8nkIu/LQdgwNeHxDT2nIULFGkNqx4MCIB XA3OeWQj+7hXYv87dAIf58LFokkNzYWai+M6852d84Y2zNdDB5Ak9pjZy10mR5eylubo+26EJml PxL8lZmMEIJqTj440MG7G7tQ= X-Received: by 127.0.0.2 with SMTP id MMgKYY1788612xSb2MeqL4oB; Tue, 16 Jan 2024 09:11:16 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.22115.1705425073989530738 for ; Tue, 16 Jan 2024 09:11:14 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-_wx4iOtwND2k0rE0jKVeCw-1; Tue, 16 Jan 2024 12:11:11 -0500 X-MC-Unique: _wx4iOtwND2k0rE0jKVeCw-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83A4B102B62A for ; Tue, 16 Jan 2024 17:11:11 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 546843C25; Tue, 16 Jan 2024 17:11:11 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 691D6AEDC4; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 6/6] OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function Date: Tue, 16 Jan 2024 18:11:05 +0100 Message-ID: <20240116171105.37831-7-kraxel@redhat.com> In-Reply-To: <20240116171105.37831-1-kraxel@redhat.com> References: <20240116171105.37831-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: SUFPaO9H0J2vv9R51DJHzaS0x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425077374100019 Content-Type: text/plain; charset="utf-8"; x-default="true" Move the DoErase code block into a separate function, call the function instead of jumping around with goto. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 76 ++++++++++++++++++-------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 3d1d20daa1e5..e6aaed27ceba 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -502,6 +502,38 @@ NorFlashRead ( return EFI_SUCCESS; } =20 +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 =3D NorFlashReadBlocks (Instance, Lba, Instance->BlockSize, Insta= nce->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, *NumB= ytes); + + // Write the modified buffer back to the NorFlash + Status =3D NorFlashWriteBlocks (Instance, Lba, Instance->BlockSize, Inst= ance->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; t= hat is, Offset + *NumBytes <=3D 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 =3D 0; CurOffset < *NumBytes; CurOffset++) { if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) { - goto DoErase; + Status =3D NorFlashWriteSingleBlockWithErase ( + Instance, + Lba, + Offset, + NumBytes, + Buffer + ); + return Status; } =20 OrigData[CurOffset] =3D 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 =3D NorFlashWriteSingleBlockWithErase ( + Instance, + Lba, + Offset, + NumBytes, + Buffer + ); return Status; } =20 -DoErase: - // Read NOR Flash data into shadow buffer - Status =3D NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->Shado= wBuffer); - 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); =20 - // Put the data at the appropriate location inside the buffer area - CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumB= ytes); - - // Write the modified buffer back to the NorFlash - Status =3D NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->Shad= owBuffer); - if (EFI_ERROR (Status)) { - // Return one of the pre-approved error statuses - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; + return Status; } =20 EFI_STATUS --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113921): https://edk2.groups.io/g/devel/message/113921 Mute This Topic: https://groups.io/mt/103766779/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-