From nobody Tue May 21 00:16:47 2024 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+113917+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+113917+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705425074; cv=none; d=zohomail.com; s=zohoarc; b=gnpGkbVSfdL0w6fYpYAIO93Gmbe2EpurHZ/0L84fmXeXiGBGl5GdaHDQi7ZVT003Hp0Wp3RzTYhXPRtWiiKm90Eh8iuYwik/JVA5tbmvddn1OybepHiJR1WELrPqyY5dnPgW75R0CMZQHdXZW9Guqti8y5Aaui1Tt1LxnRMAL9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705425074; 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=VibX2ABcvN2MfMh5V6G2XVQgIqKAB9aLQnKe2H4yduA=; b=NknAAYceFb5uCjO5FTAyadSso7MC4khFdpNdmRBPxAtjeEYHCpBSBItGRZirBTomly6Z++hKT9HLd1X8zbMKl9Z5MKxXjqq2DWH/UBOmXz4h9ae7KIcf600RR69/QrqXDwMU9+SEhp6COBEIGIj8IrFAm4Lu5M9pGxFwBby7H3w= 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+113917+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 1705425074737406.7253919943646; Tue, 16 Jan 2024 09:11:14 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=NuXCC29eVF24jgahBzlGIOgeCymFNupc/eX9Pz6wn9k=; 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-Type:Content-Transfer-Encoding; s=20140610; t=1705425074; v=1; b=xU6Oe2cpwSr6laplx8vvOR+REe/0sLjgBYwoQUGrTFESmpI8wYR96QDABM28ySzADTErlING 5YD3+hBkuVlrU2R+j2SdydQ4mE/czACZY5199bRUj9iSPx6Gn0IGAk97Ca0yhfBS+stlk/CTZA7 b+V2BkDl1FD6KCwpTW/huSnY= X-Received: by 127.0.0.2 with SMTP id KvvkYY1788612x2J8y3mg3f4; Tue, 16 Jan 2024 09:11:14 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.21911.1705425072995761477 for ; Tue, 16 Jan 2024 09:11:13 -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-654-aY27mw0pNkiXs7K_qWuBwA-1; Tue, 16 Jan 2024 12:11:08 -0500 X-MC-Unique: aY27mw0pNkiXs7K_qWuBwA-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 CDE1783106D for ; Tue, 16 Jan 2024 17:11:07 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E0822166B32; Tue, 16 Jan 2024 17:11:07 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 5BFFAAEDBA; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= Subject: [edk2-devel] [PATCH v3 1/6] OvmfPkg/VirtNorFlashDxe: add casts to UINTN and UINT32 Date: Tue, 16 Jan 2024 18:11:00 +0100 Message-ID: <20240116171105.37831-2-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.6 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: GZ3cnIyKMxZ4pqwb2KG17JALx1787277AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425075377100009 This is needed to avoid bit operations being applied to signed integers. Suggested-by: L=C3=A1szl=C3=B3 =C3=89rsek Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h | 2 +- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.h index b7f5d208b236..455eafacc2cf 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h @@ -61,7 +61,7 @@ #define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128) #define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINT= N)4)) #define MAX_BUFFERED_PROG_ITERATIONS 10000000 -#define BOUNDARY_OF_32_WORDS 0x7F +#define BOUNDARY_OF_32_WORDS ((UINTN)0x7F) =20 // CFI Addresses #define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10 diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 1afd60ce66eb..7f4743b00399 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -581,7 +581,7 @@ NorFlashWriteSingleBlock ( // contents, while checking whether the old version had any bits clear= ed // that we want to set. In that case, we will need to erase the block = first. for (CurOffset =3D 0; CurOffset < *NumBytes; CurOffset++) { - if (~OrigData[CurOffset] & Buffer[CurOffset]) { + if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) { goto DoErase; } =20 --=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 (#113917): https://edk2.groups.io/g/devel/message/113917 Mute This Topic: https://groups.io/mt/103766775/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- From nobody Tue May 21 00:16:47 2024 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+113916+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+113916+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705425073; cv=none; d=zohomail.com; s=zohoarc; b=QXb3UYlXfG6XgP3ymB1FiDJvNvZw3jRUQEnTu6+Z+ydEkM1+Nc7XuScyZR0AQGr4vmqwj7If+ilvdamdn+a7VdKbzH9N9Q2vzn2yu1nTmMBfcp689Vz6upFxNeMqYmpvaSmmlC1SJISIW+SuKtdMw+crLj7N7yfa9crgT9yEUDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705425073; 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=Oe7dNLwfwj+2aSh6T+XG7NQH1wmGR4M+eC7cnP16y1A=; b=i8Y1pqlh0TpzsXRDI1A+SRsXIyFvSG8Ndpbt83eOYJm6VzDkv7vs15OQH/OUwVNT2KCGJNv555jzLxaQ6iAlFgq8j47+8S4BWCbU1pDfBbFwtgUEAPIrNyLa9LAFet+ad0pbn9cEgFNA+P+RLsGiFbIKtEdC6oYWnBWrwnvMXP8= 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+113916+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 1705425073027646.7689612898291; Tue, 16 Jan 2024 09:11:13 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=tPscBqxnXh+9GaXJp++u5QU6i/kILyY+iYBnZjAj85Y=; 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=1705425072; v=1; b=kA2+E8OomoZsFebtFCeVITipoKFllkBidu0Wu2E9a+yvjt8TQtj2M32WBglyDvhwFQRIe04Q dc3wwF9RxRUVCsRnVHHSYxP1m0A+j9DEkppS1LNmO+weqThL2zG78+xJZMXQbTNUgWWBA/lKlWn NWqIZIMoT14z4hJ9gLiPq5rk= X-Received: by 127.0.0.2 with SMTP id b3gCYY1788612xQ7xmshGfRN; Tue, 16 Jan 2024 09:11:12 -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.22109.1705425071617794164 for ; Tue, 16 Jan 2024 09:11:11 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-kAQBXSiSNwK2ytT8SNAEag-1; Tue, 16 Jan 2024 12:11:09 -0500 X-MC-Unique: kAQBXSiSNwK2ytT8SNAEag-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 8C72B28240F2 for ; Tue, 16 Jan 2024 17:11:08 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD47340C6EB9; Tue, 16 Jan 2024 17:11:07 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 5E498AEDBC; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH v3 2/6] OvmfPkg/VirtNorFlashDxe: clarify block write logic & fix shadowbuffer reads Date: Tue, 16 Jan 2024 18:11:01 +0100 Message-ID: <20240116171105.37831-3-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.2 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: e70uSvWlaW4ZLyFfZR6iCmlTx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425073444100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Introduce 'Start' and 'End' variables to make it easier to follow the logic and code flow. Also add a ascii art diagram (based on a suggestion by Laszlo). This also fixes the 'Size' calculation for the NorFlashRead() call. Without this patch the code will read only one instead of two P30_MAX_BUFFER_SIZE_IN_BYTES blocks in case '*NumBytes' is smaller than P30_MAX_BUFFER_SIZE_IN_BYTES but 'Offset + *NumBytes' is not, i.e. the update range crosses a P30_MAX_BUFFER_SIZE_IN_BYTES boundary. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 36 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 7f4743b00399..88a4d2c23fc0 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -520,6 +520,7 @@ NorFlashWriteSingleBlock ( UINTN BlockSize; UINTN BlockAddress; UINT8 *OrigData; + UINTN Start, End; =20 DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); =20 @@ -555,7 +556,28 @@ NorFlashWriteSingleBlock ( // To avoid pathological cases were a 2 byte write is disregarded becaus= e it // occurs right at a 128 byte buffered write alignment boundary, permit = up to // twice the max buffer size, and perform two writes if needed. - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) <=3D (2 * P30_MAX_BUFF= ER_SIZE_IN_BYTES)) { + // + // 0 128 256 + // [----------------|----------------] + // ^ ^ ^ ^ + // | | | | + // | | | End, the next "word" boundary bey= ond + // | | | the (logical) update + // | | | + // | | (Offset & BOUNDARY_OF_32_WORDS) + NumBytes; + // | | i.e., the relative offset inside (or just past) + // | | the *double-word* such that it is the + // | | *exclusive* end of the (logical) update. + // | | + // | Offset & BOUNDARY_OF_32_WORDS; i.e., Offset within the "= word"; + // | this is where the (logical) update is supposed to start + // | + // Start =3D Offset & ~BOUNDARY_OF_32_WORDS; i.e., Offset truncated t= o "word" boundary + + Start =3D Offset & ~BOUNDARY_OF_32_WORDS; + End =3D ALIGN_VALUE (Offset + *NumBytes, P30_MAX_BUFFER_SIZE_IN_BYTES); + + if ((End - Start) <=3D (2 * P30_MAX_BUFFER_SIZE_IN_BYTES)) { // Check to see if we need to erase before programming the data into N= OR. // If the destination bits are only changing from 1s to 0s we can just= write. // After a block is erased all bits in the block is set to 1. @@ -565,8 +587,8 @@ NorFlashWriteSingleBlock ( Status =3D NorFlashRead ( Instance, Lba, - Offset & ~BOUNDARY_OF_32_WORDS, - (*NumBytes | BOUNDARY_OF_32_WORDS) + 1, + Start, + End - Start, Instance->ShadowBuffer ); if (EFI_ERROR (Status)) { @@ -601,7 +623,7 @@ NorFlashWriteSingleBlock ( =20 Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + BlockAddress + Start, P30_MAX_BUFFER_SIZE_IN_BYTES, Instance->ShadowBuffer ); @@ -609,12 +631,10 @@ NorFlashWriteSingleBlock ( goto Exit; } =20 - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) > P30_MAX_BUFFER_SIZ= E_IN_BYTES) { - BlockAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES; - + if ((End - Start) > P30_MAX_BUFFER_SIZE_IN_BYTES) { Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + BlockAddress + Start + P30_MAX_BUFFER_SIZE_IN_BYTES, P30_MAX_BUFFER_SIZE_IN_BYTES, Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES ); --=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 (#113916): https://edk2.groups.io/g/devel/message/113916 Mute This Topic: https://groups.io/mt/103766774/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- From nobody Tue May 21 00:16:47 2024 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+113919+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+113919+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705425075; cv=none; d=zohomail.com; s=zohoarc; b=ERAAcSEcMotFarMersqbn3niga4MrnzxChTluyAcw6End5JCLzXvoRZNaMvcjQEBB6HBT+EZkjTCSYC8xB2L/p4e5RijJO+wwaUPq5G5NjGvYprCPst0f5DCwJZ0glrPhxVXihlE8qU4e9YJelzTfVzb/kel4EtY+qwAv/P6ENs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705425075; 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=dpjBVM2/noyqQSVAITd9ma25/B7hdOiwTqxAjEx5Cfo=; b=G7DG1HmsnfTy7oLcplWmTLZfI1EgkaPDDWUmN/VDcRc9SGwgBjpoiXaTQJlPcxr1YWdh6Cvz/cEi/dca/HsYdIxtR7y1YHFk+gy1gpv38207+sJINkWbMDvAgWclqf+a9AmX0Q+R4evkWZ0GP1O8EP6KCN0GP1NULlvL8nqDJ+E= 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+113919+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 1705425075650864.2894165929827; Tue, 16 Jan 2024 09:11:15 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=AmW7ymeH0CY8mbhVHkXP+NsG9XAffegfq4aapEbJE94=; 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=1705425075; v=1; b=IxFobcjjtzjF5etRxXRA7B76+gKrlcrUWpJIiB57XXwD3yxGMv8VsqWzCKVbh/isu2Qag7Bz bOgdIfLVeBHtzmUXVb2K6gAGM0YQuiIaXN9Ig8fm3xwBYJisc8M0+hejv8VIF0dccPlTWqz7Bqi RccUCyZoZEexXzY0+uyPpftk= X-Received: by 127.0.0.2 with SMTP id IMyfYY1788612xIWwn3cM7p0; Tue, 16 Jan 2024 09:11:15 -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.22113.1705425073076131665 for ; Tue, 16 Jan 2024 09:11:13 -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-1-zc9Qp-5uPjKZDLcZMVJ_Pg-1; Tue, 16 Jan 2024 12:11:09 -0500 X-MC-Unique: zc9Qp-5uPjKZDLcZMVJ_Pg-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 401A4102B627 for ; Tue, 16 Jan 2024 17:11:09 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0362AC15E6C; Tue, 16 Jan 2024 17:11:09 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 61AA4AEDBE; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH v3 3/6] OvmfPkg/VirtNorFlashDxe: add a loop for NorFlashWriteBuffer calls. Date: Tue, 16 Jan 2024 18:11:02 +0100 Message-ID: <20240116171105.37831-4-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.8 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: ADVsip8tO6k5uISWlZvtygh2x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425077338100017 Content-Type: text/plain; charset="utf-8"; x-default="true" Replace the two NorFlashWriteBuffer() calls with a loop containing a single NorFlashWriteBuffer() call. With the changes in place the code is able to handle updates larger than two P30_MAX_BUFFER_SIZE_IN_BYTES blocks, even though the patch does not actually change the size limit. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 88a4d2c23fc0..3d1343b381bc 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -521,6 +521,7 @@ NorFlashWriteSingleBlock ( UINTN BlockAddress; UINT8 *OrigData; UINTN Start, End; + UINT32 Index, Count; =20 DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); =20 @@ -621,23 +622,17 @@ NorFlashWriteSingleBlock ( goto Exit; } =20 - Status =3D NorFlashWriteBuffer ( - Instance, - BlockAddress + Start, - P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer - ); - if (EFI_ERROR (Status)) { - goto Exit; - } - - if ((End - Start) > P30_MAX_BUFFER_SIZE_IN_BYTES) { + Count =3D (End - Start) / P30_MAX_BUFFER_SIZE_IN_BYTES; + for (Index =3D 0; Index < Count; Index++) { Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + Start + P30_MAX_BUFFER_SIZE_IN_BYTES, + BlockAddress + Start + Index * P30_MAX_BUFFER_SIZE_IN_BYT= ES, P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES + Instance->ShadowBuffer + Index * P30_MAX_BUFFER_SIZE_IN_B= YTES ); + if (EFI_ERROR (Status)) { + goto Exit; + } } =20 Exit: --=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 (#113919): https://edk2.groups.io/g/devel/message/113919 Mute This Topic: https://groups.io/mt/103766777/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- From nobody Tue May 21 00:16:47 2024 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+113918+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+113918+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705425073; cv=none; d=zohomail.com; s=zohoarc; b=XLPKXEwagE5bfn1duZxgwCfkXun8BzDRHnF5vWRRG4opidztKrapjFPIhq3g+HEyzYp20+FG2zK4SOaH94pU273k6mMqnPRDXPg3NggfqmXYVcpNtCg3xTMkGjoJm4GQp/M88MxbTnIU9dezYdIubGbf7fwVtwM/wHFq6Y2z22M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705425073; 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=EZe5f9u9xd57LSpGIPq2sxEqphRRRnqZuGKdc72no9Q=; b=lWLdW5Phz0RszGW7sCMWg+9y6awbSi6VDuJUmy4AEtE3H7bTAVgkkgMf7o7+tsCNOV/PCU6Oq9K9bZmJ5hqA8AhHE7EwELXyhNaeZ1ylxDnsJHto0Re8BaxCCW4NYr27BQlhsTo3hzSiNmVCFPXv27IwkDjZGP9aBJwafgxxIrY= 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+113918+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 1705425073937734.9166090482872; Tue, 16 Jan 2024 09:11:13 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=unNnmHuBuI59abdnuM/k3RP7un/sXokZubsGSUP3AYQ=; 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=1705425073; v=1; b=HE1DgVl4dACYyxwtpw0T3t4bYO5kewDi5QaxCc6EUB4xMLbsX2T9QDnk0m2MI9Sp7gLgoCic Mn66iEVrSJ20dZlRYI5XjFmzzrAL55jeYRWkMwn+HU/cov+XsDQjKu45fFNCT4/k80O8HVT4lOx uGJ6Iprf7Grz8RDjP4SYI07U= X-Received: by 127.0.0.2 with SMTP id rnDxYY1788612xHdcAaHwPsT; Tue, 16 Jan 2024 09:11:13 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.22112.1705425073009903793 for ; Tue, 16 Jan 2024 09:11:13 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-MEOXg53dPPmrAZWQruPIVw-1; Tue, 16 Jan 2024 12:11:10 -0500 X-MC-Unique: MEOXg53dPPmrAZWQruPIVw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 2A4121C05AD0 for ; Tue, 16 Jan 2024 17:11:10 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B64C2C15968; Tue, 16 Jan 2024 17:11:09 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 646DDAEDC0; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH v3 4/6] OvmfPkg/VirtNorFlashDxe: allow larger writes without block erase Date: Tue, 16 Jan 2024 18:11:03 +0100 Message-ID: <20240116171105.37831-5-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.8 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: 4DzxHzVWwSyaWrXEqIuaFlopx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425075396100010 Content-Type: text/plain; charset="utf-8"; x-default="true" Raise the limit for writes without block erase from two to four P30_MAX_BUFFER_SIZE_IN_BYTES blocks. With this in place almost all efi variable updates are handled without block erase. With the old limit some variable updates (with device paths) took the block erase code path. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 3d1343b381bc..3d1d20daa1e5 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -550,13 +550,15 @@ NorFlashWriteSingleBlock ( return EFI_BAD_BUFFER_SIZE; } =20 - // Pick P30_MAX_BUFFER_SIZE_IN_BYTES (=3D=3D 128 bytes) as a good start = for word - // operations as opposed to erasing the block and writing the data regar= dless - // if an erase is really needed. It looks like most individual NV varia= ble - // writes are smaller than 128 bytes. - // To avoid pathological cases were a 2 byte write is disregarded becaus= e it - // occurs right at a 128 byte buffered write alignment boundary, permit = up to - // twice the max buffer size, and perform two writes if needed. + // Pick 4 * P30_MAX_BUFFER_SIZE_IN_BYTES (=3D=3D 512 bytes) as a good + // start for word operations as opposed to erasing the block and + // writing the data regardless if an erase is really needed. + // + // Many NV variable updates are small enough for a a single + // P30_MAX_BUFFER_SIZE_IN_BYTES block write. In case the update is + // larger than a single block, or the update crosses a + // P30_MAX_BUFFER_SIZE_IN_BYTES boundary (as shown in the diagram + // below), or both, we might have to write two or more blocks. // // 0 128 256 // [----------------|----------------] @@ -578,7 +580,7 @@ NorFlashWriteSingleBlock ( Start =3D Offset & ~BOUNDARY_OF_32_WORDS; End =3D ALIGN_VALUE (Offset + *NumBytes, P30_MAX_BUFFER_SIZE_IN_BYTES); =20 - if ((End - Start) <=3D (2 * P30_MAX_BUFFER_SIZE_IN_BYTES)) { + if ((End - Start) <=3D (4 * P30_MAX_BUFFER_SIZE_IN_BYTES)) { // Check to see if we need to erase before programming the data into N= OR. // If the destination bits are only changing from 1s to 0s we can just= write. // After a block is erased all bits in the block is set to 1. --=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 (#113918): https://edk2.groups.io/g/devel/message/113918 Mute This Topic: https://groups.io/mt/103766776/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- From nobody Tue May 21 00:16:47 2024 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+113920+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+113920+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=kQuDcwlZhmmvpht2ftrWsyxwuwf+rZDw8i7mHBsEnE+uGzh4yCUlvyLf1/55pQF8TX42lawIbd6bcHEa40ogjVblthvHdJp/usW+Jqb211O816UGAJ30zq2P7FAxBLVkjZnYe9z289rFejauI8dYJ3hZOGYkF2mqfJrNlPgLzRM= 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=XYCtSgl9bcriLal3Wr2Mqr2aE8xd749yyxYopCQgUqQ=; b=KpgfjjH5lFDW2JL1nVaySiRqUhiGSvn66xEqQoGKWsbWfePkW7IgU+nwbMFr7XfZMh8ijsdKQv/rAM6VdPBYs6zgYGc6O3ucgmffuh6jV7LJeHm3ahjSDoMEGzqIkd8xfqC4VDX/wib1zavuqcjozkmYWOCi8if/D7k3vbN1+aI= 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+113920+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 1705425076488412.9870933137271; Tue, 16 Jan 2024 09:11:16 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wbJtf7WQJgzk1QOqnK0E1v7+QAodJzoZ/RMECYhiYcs=; 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=gjgl8uiolrGtMoexxeiBuWjWVoMBDN2t4qwQ0MmXvRiWmQXWGbcjqVSK24GcRaSxLHOY+7qc MASjJK9u0z3vOnvDFh4GH1Wia7oaIVTYJAQ14UOPLcPHkUe+RfFl/swsTtopyjRPYK7clnWCuM8 e/RkLNjvciZH5k1T8U7hi9MM= X-Received: by 127.0.0.2 with SMTP id fQflYY1788612xPjpYkUiDlt; 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.22114.1705425073746295000 for ; Tue, 16 Jan 2024 09:11:13 -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-221-Y5EptwN6N5y2dEagSAym3Q-1; Tue, 16 Jan 2024 12:11:11 -0500 X-MC-Unique: Y5EptwN6N5y2dEagSAym3Q-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 9B05385A58F for ; Tue, 16 Jan 2024 17:11:10 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A3CD2026D6F; Tue, 16 Jan 2024 17:11:10 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 66CB5AEDC2; Tue, 16 Jan 2024 18:11:05 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , Laszlo Ersek Subject: [edk2-devel] [PATCH v3 5/6] OvmfPkg/VirtNorFlashDxe: ValidateFvHeader: unwritten state is EOL too Date: Tue, 16 Jan 2024 18:11:04 +0100 Message-ID: <20240116171105.37831-6-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.4 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: Km1Qxvo1ovaR0cvW13TYoIJpx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705425077357100018 Content-Type: text/plain; charset="utf-8"; x-default="true" It is possible to find variable entries with State being 0xff, i.e. not updated since flash block erase. This indicates the variable driver could not complete the header write while appending a new entry, and therefore State was not set to VAR_HEADER_VALID_ONLY. This can only happen at the end of the variable list, so treat this as additional "end of variable list" condition. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashFvb.c index 8fcd999ac6df..c8b5e0be1379 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c @@ -302,6 +302,11 @@ ValidateFvHeader ( break; } =20 + if (VarHeader->State =3D=3D 0xff) { + DEBUG ((DEBUG_INFO, "%a: end of var list (unwritten state)\n", __fun= c__)); + break; + } + VarName =3D NULL; switch (VarHeader->State) { // usage: State =3D VAR_HEADER_VALID_ONLY --=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 (#113920): https://edk2.groups.io/g/devel/message/113920 Mute This Topic: https://groups.io/mt/103766778/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- From nobody Tue May 21 00:16:47 2024 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-