From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fb.mail.gandi.net (spool8.mail.gandi.net [217.70.178.217]) by nmboxes7-ms7.sd4.0x35.net (Postfix) with ESMTPS id 7EFBC61930 for ; Tue, 16 Jan 2024 05:26:38 +0000 (UTC) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by fb.mail.gandi.net (Postfix) with ESMTPS id 0F10460377 for ; Tue, 16 Jan 2024 05:26:37 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eqv5LeK/neuYeNE2a0ZThkzFaprl5KNepj1IQyNMOKc=; 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=1705382796; v=1; b=wAvci0/MT5gm5H0KvKHZ974ZNaDhfLGAhtu2IgCJ4tjarR2rMt+kmvTANn1ZrxjVGebs05yZ yVcq/KBK9tyDDnphIsNgURS0CD0iIalF1eYzvkIKz5DdjNkBd/zssbr84ZYp+TvAENC24JLD0RZ Mad8m5zaOLtJXySm+MSzubb8= X-Received: by 127.0.0.2 with SMTP id k9kTYY7687511xnY0EUrUzaw; Mon, 15 Jan 2024 21:26:36 -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.84614.1705334396086788396 for ; Mon, 15 Jan 2024 07:59:56 -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-368-ZtkD2ZVyOz2sE7NNdwTP0w-1; Mon, 15 Jan 2024 10:59:53 -0500 X-MC-Unique: ZtkD2ZVyOz2sE7NNdwTP0w-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 B289C185A781 for ; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 872F2107BE; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D9E99AC98E; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 6/6] OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function Date: Mon, 15 Jan 2024 16:59:48 +0100 Message-ID: <20240115155948.136499-7-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: ELnr71aMtiY6LN8byCJL2L2ox7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: fb.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="wAvci0/M"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (fb.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Move the DoErase code block into a separate function, call the function instead of jumping around with goto. Signed-off-by: Gerd Hoffmann --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 76 +++++++++++++++++--------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c index d80e9f0a2f3a..203bd64f2bdf 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -502,6 +502,37 @@ 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. @@ -606,7 +637,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 + ); + goto Exit; } OrigData[CurOffset] = Buffer[CurOffset]; @@ -635,33 +673,21 @@ NorFlashWriteSingleBlock ( goto Exit; } } + } else { + Status = NorFlashWriteSingleBlockWithErase ( + Instance, + Lba, + Offset, + NumBytes, + Buffer + ); + } Exit: - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); - 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; - } - - // 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 -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113831): https://edk2.groups.io/g/devel/message/113831 Mute This Topic: https://groups.io/mt/103741665/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-