From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id CD3519417DA for ; Fri, 12 Jan 2024 11:38:01 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=cZiBcPTAKfIx4yHhHkZDX5j/RiPjG0DJSdn8W4YEa7M=; 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=1705059480; v=1; b=QyNO66oHDObr23A01Njn38MIGosiRCNNsQna+4uKJP5yJLgJLHU9kOtu7nDAUUA9Luzx96Fg AsfR/PYscHpT8/Ae8oIanCoYVwmWoU5Z/ukYJ5RooyLdy3jRaZ+OGOx1q1qpDehGGjD6jQNnmGp 7xfuoBLlI/tj95XZsNxI3Ss8= X-Received: by 127.0.0.2 with SMTP id cpXLYY7687511xrvweLLHhgg; Fri, 12 Jan 2024 03:38:00 -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.5198.1705059479863286290 for ; Fri, 12 Jan 2024 03:38:00 -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-657-0bg-FkzgPcyLJV2IxCrtxQ-1; Fri, 12 Jan 2024 06:37:57 -0500 X-MC-Unique: 0bg-FkzgPcyLJV2IxCrtxQ-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 5E57C280A9AC; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26CF32166B31; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 85824ABB80; Fri, 12 Jan 2024 12:37:54 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , oliver@redhat.com Subject: [edk2-devel] [PATCH 2/4] OvmfPkg/VirtNorFlashDxe: clarify block write logic Date: Fri, 12 Jan 2024 12:37:52 +0100 Message-ID: <20240112113754.14710-3-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-1-kraxel@redhat.com> References: <20240112113754.14710-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: pi8GjZjZQNjKeR5V5NpaktM5x7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=QyNO66oH; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Introduce Start and End variables to make it easier to follow the logic and code flow. Also replace the two NorFlashWriteBuffer calls with a loop containing one 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 --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 31 +++++++++++++------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c index cdc809d75e3d..90db12716a4c 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -560,13 +560,18 @@ NorFlashWriteSingleBlock ( // 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. // If any byte requires us to erase we just give up and rewrite all of it. + UINTN Start, End; + UINT32 Index, Count; + + Start = Offset & ~BOUNDARY_OF_32_WORDS; + End = (Offset + *NumBytes + BOUNDARY_OF_32_WORDS) & ~BOUNDARY_OF_32_WORDS; // Read the old version of the data into the shadow buffer Status = NorFlashRead ( Instance, Lba, - Offset & ~BOUNDARY_OF_32_WORDS, - (((Offset & BOUNDARY_OF_32_WORDS) + *NumBytes) | BOUNDARY_OF_32_WORDS) + 1, + Start, + End - Start, Instance->ShadowBuffer ); if (EFI_ERROR (Status)) { @@ -599,25 +604,19 @@ NorFlashWriteSingleBlock ( goto Exit; } - Status = NorFlashWriteBuffer ( - Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), - P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer - ); - if (EFI_ERROR (Status)) { - goto Exit; - } - - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) > P30_MAX_BUFFER_SIZE_IN_BYTES) { - BlockAddress += P30_MAX_BUFFER_SIZE_IN_BYTES; - + for (Index = 0, Count = (End - Start) / P30_MAX_BUFFER_SIZE_IN_BYTES; + Index < Count; + Index++, BlockAddress += P30_MAX_BUFFER_SIZE_IN_BYTES) + { Status = NorFlashWriteBuffer ( Instance, BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES + Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES * Index ); + if (EFI_ERROR (Status)) { + goto Exit; + } } Exit: -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113716): https://edk2.groups.io/g/devel/message/113716 Mute This Topic: https://groups.io/mt/103680931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-