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 BF96EAC0F9C for ; Fri, 12 Jan 2024 12:15:02 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=MHAklEfcXUYtbzcXqTFoAVOhVj6YOhVIPaZTW/v32iU=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1705061701; v=1; b=YgxB1F51xG38SAMVmxcfLP1Ua5yU0tGDvlD70GmMfxLi0JdbA8xd2OhA8D6w6DP/R5WQi+Jo 5su6FJ37/PRdXEt7ReR1MQhUhTKFNmnU767s/u4BGRhmzvQ7lYXg4dBhMhIPQ7enjAN2XdqdDuk ZAnrwTycH8oDfXkHY4Bb/eUo= X-Received: by 127.0.0.2 with SMTP id JO7PYY7687511xxCxTDGfAPO; Fri, 12 Jan 2024 04:15:01 -0800 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.5661.1705061700414717228 for ; Fri, 12 Jan 2024 04:15:00 -0800 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id E4CC2B822AA for ; Fri, 12 Jan 2024 12:14:58 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4918DC433C7 for ; Fri, 12 Jan 2024 12:14:57 +0000 (UTC) X-Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50e7b273352so6818696e87.1 for ; Fri, 12 Jan 2024 04:14:57 -0800 (PST) X-Gm-Message-State: dZrAVFh0HnYndLyCmM4kcBAWx7686176AA= X-Google-Smtp-Source: AGHT+IEpwMSq1iWeq5Vc/ubG8QbDf0EemsxT9st1+entzH3+np3UhUSvk0oFLjqvf297t0zCGevJi4CEN3jIYTvcGp4= X-Received: by 2002:a05:6512:1055:b0:50e:9ba0:5e20 with SMTP id c21-20020a056512105500b0050e9ba05e20mr722452lfb.99.1705061695481; Fri, 12 Jan 2024 04:14:55 -0800 (PST) MIME-Version: 1.0 References: <20240112113754.14710-1-kraxel@redhat.com> <20240112113754.14710-3-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-3-kraxel@redhat.com> From: "Ard Biesheuvel" Date: Fri, 12 Jan 2024 13:14:44 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 2/4] OvmfPkg/VirtNorFlashDxe: clarify block write logic To: Gerd Hoffmann Cc: devel@edk2.groups.io, Laszlo Ersek , Jiewen Yao , oliver@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,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=YgxB1F51; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (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 On Fri, 12 Jan 2024 at 12:38, Gerd Hoffmann wrote: > > 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 Reviewed-by: Ard Biesheuvel Nit below > --- > 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; > + These var declarations should be at the start of the function. > + 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 (#113727): https://edk2.groups.io/g/devel/message/113727 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] -=-=-=-=-=-=-=-=-=-=-=-