From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6F61B740035 for ; Wed, 24 Apr 2024 09:49:29 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eyBAd5nw4o+wejP/ck9RbQwUZ2fYVf3vdCDul0BiQLM=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:Authentication-Results-Original:nodisclaimer:MIME-Version:Original-Authentication-Results:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20240206; t=1713952167; v=1; b=Lt+UKWLMU+wVRYEs+58Jp2D/dotojMBAHjdVQjGpgYRSoK0WIJSiDk6rwzuA/qC2BAUgdjbk PHWMfjLxg6XYnoZfORKgVvi7Er98/YYj21seQwFDsq1nrKzLyMDv+gk4fvhvwvA64CQaKQLMCac Fekg4peYQavAuq1PBipdPLKYyzPP+YOcQMbEUCVdLAF75HRpdqI0s/21nuKpLqLLFXe3q8dp+tF h/okS8XA90b0KGGd7EmKcGF/G2VYFx9xwKlgIjTmsa75Yc1qdC60OUA80Ru9jbw3iFwksYVKNfk LAjBvYFxzlwAVit3e5tasWlWY9sV86Nbai1UrHzRwZQSg== X-Received: by 127.0.0.2 with SMTP id yTFtYY7687511xcHdZxpXViz; Wed, 24 Apr 2024 02:49:27 -0700 X-Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.45]) by mx.groups.io with SMTP id smtpd.web11.12464.1713952166295414499 for ; Wed, 24 Apr 2024 02:49:26 -0700 X-Received: from DB7PR05CA0038.eurprd05.prod.outlook.com (2603:10a6:10:2e::15) by DU2PR08MB10277.eurprd08.prod.outlook.com (2603:10a6:10:49b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22; Wed, 24 Apr 2024 09:49:21 +0000 X-Received: from DU6PEPF0000A7DD.eurprd02.prod.outlook.com (2603:10a6:10:2e:cafe::4c) by DB7PR05CA0038.outlook.office365.com (2603:10a6:10:2e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.22 via Frontend Transport; Wed, 24 Apr 2024 09:49:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=arm.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DU6PEPF0000A7DD.mail.protection.outlook.com (10.167.8.37) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.7519.19 via Frontend Transport; Wed, 24 Apr 2024 09:49:20 +0000 X-Received: ("Tessian outbound e14047529286:v313"); Wed, 24 Apr 2024 09:49:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e661a0ad05876a38 X-CR-MTA-TID: 64aa7808 X-Received: from 747b74f3393c.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C1A04786-915D-4006-BCAA-E9AB46C8DFC8.1; Wed, 24 Apr 2024 09:49:13 +0000 X-Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 747b74f3393c.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 24 Apr 2024 09:49:13 +0000 X-Received: from AM0PR08MB4289.eurprd08.prod.outlook.com (2603:10a6:208:148::12) by DB9PR08MB6427.eurprd08.prod.outlook.com (2603:10a6:10:25a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Wed, 24 Apr 2024 09:49:10 +0000 X-Received: from AM0PR08MB4289.eurprd08.prod.outlook.com ([fe80::4a5d:48:bf49:a524]) by AM0PR08MB4289.eurprd08.prod.outlook.com ([fe80::4a5d:48:bf49:a524%7]) with mapi id 15.20.7472.044; Wed, 24 Apr 2024 09:49:10 +0000 From: "levi.yun" To: "devel@edk2.groups.io" , Sahil Kaushal CC: Ard Biesheuvel , =?koi8-r?Q?Leif_Lindholm_=9A?= , Sami Mujawar Subject: Re: [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 01/14] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Thread-Topic: [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 01/14] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Thread-Index: AQHalY7uU/JrRUZXM0SjNeXFuzRnsbF3Li57 Date: Wed, 24 Apr 2024 09:49:10 +0000 Message-ID: References: <20240423055638.1271531-1-Sahil.Kaushal@arm.com> <20240423055638.1271531-2-Sahil.Kaushal@arm.com> In-Reply-To: <20240423055638.1271531-2-Sahil.Kaushal@arm.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: AM0PR08MB4289:EE_|DB9PR08MB6427:EE_|DU6PEPF0000A7DD:EE_|DU2PR08MB10277:EE_ X-MS-Office365-Filtering-Correlation-Id: dd35a78b-c2c2-40b0-92e6-08dc6443d0e4 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untr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LKEGMXfQk9Wx6CWOrj?= =?koi8-r?Q?wGqUIdknDATKYtE75gygzuUAfdml9oHqVvY9HPnk18FSk8V7A+iO5Ay0vKjZP0?= =?koi8-r?Q?RkRva1s78eDEhWpGpqm7URC2Gu8+Fk09pdGHzU8KJH0mACNkEDfbEU0NIvDmoO?= =?koi8-r?Q?qOzk1CE3rK6eCtyJYUPmb/yfEu0OG8ZWpiPhegGnypyoj11uzd8t6O6I+XXsB+?= =?koi8-r?Q?zLY/MWfiw2buSGNFNN1bd1M0CsavmFu8+oHVFzS+UDzLI+wodiEUErqAha3LtJ?= =?koi8-r?Q?kUdYeGsWY1vTQFIaI+STU3IHERGuVmXYGS41G3fY2LZQYlpaFRvOOoQS7NU0Sz?= =?koi8-r?Q?2g/o2Fg3ia+iobqgi8QdsTRLfKMfluS+KMU3XlaLp0T0mBtVMFI19yNSIxSICb?= =?koi8-r?Q?Cwgc5Y6V8PMPaEG1b1XVm02ZTX1+HsXw47R7JE7eNEhojuG2WmTEcenkRMtlH7?= =?koi8-r?Q?joeQvzYUxtKdwk2lMde8XUhlOD7swkpMzAlW5/H1EPWRdj0NcKuM55rF2NysT6?= =?koi8-r?Q?NQ=3D=3D?= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR08MB4289.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(38070700009);DIR:OUT;SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6427 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DU6PEPF0000A7DD.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 41655c61-cce2-4bdf-fd95-08dc6443ca95 X-Microsoft-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isPD3LFr9mCN9PnvVyMHkX3vKrHa0qp2NsOd5tNdGrCiVMPh32GhOF1Z4l/?= =?koi8-r?Q?mrMJVJPkw2j8fPkCQzVUSPLRENFyKHOnGcpE+AudwxOGBGyTAh6jmA2vQw4oPp?= =?koi8-r?Q?GQJSelFVllKCixlc3c0V9d85+OwQF0t78g7rAwrKcqyjqB8+vUrEB+6KFlsapS?= =?koi8-r?Q?doImTdUiI/HBQfUaR27FBKgIBD1meOuEiaA/PJs+VV+Y7raR11Y6kmkc7NBcOp?= =?koi8-r?Q?56LK+wt8hxradXkooOo1k9jzeNGloRrf57JqK+dld7PlggtYFThDwkP69Kd3+z?= =?koi8-r?Q?exJ0aXdQPh7ByB9Kaqeiv3nPnDmxppsqgKvgytR8trSzpQjwZxWtqbtG9Rt/0n?= =?koi8-r?Q?Qt8ppvm/RvurTkZUBo7TpVOFcGykduUDJCeNK4DqPMI0G3tl/9oqIUhK/ffpgS?= =?koi8-r?Q?vUmBTUQMPz6rqwlSFYvq9lu1NZE2CcCsGKgGzfLoxrIAdHSO3NERd3ejMV0mGM?= =?koi8-r?Q?oyNH2HG/vbPZLNOy/6FbTy7jXBhCuagFEGOGqbRIjZ/l?= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 09:49:20.9994 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd35a78b-c2c2-40b0-92e6-08dc6443d0e4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DU6PEPF0000A7DD.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB10277 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 Resent-Date: Wed, 24 Apr 2024 02:49:26 -0700 Resent-From: yeoreum.yun@arm.com Reply-To: devel@edk2.groups.io,yeoreum.yun@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: VMzZJfb4yWlsJxA2U4dTRynPx7686176AA= Content-Language: en-GB Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=Lt+UKWLM; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io Reviewed-by: levi.yun ________________________________________ From: devel@edk2.groups.io on behalf of Sahil Kausha= l via groups.io Sent: 23 April 2024 06:56 To: devel@edk2.groups.io Cc: Ard Biesheuvel; Leif Lindholm ; Sami Mujawar; Sahil Kaushal Subject: [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 01/14] Platfor= m/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c From: sahil Moving these functions from NorFlash.c to NorFlashBlockIoDxe.c as they are not dependent on any particular flash implementation. Signed-off-by: sahil --- Platform/ARM/Drivers/NorFlashDxe/NorFlash.c | 129 --------------= ------ Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 129 ++++++++++++++= ++++++ 2 files changed, 129 insertions(+), 129 deletions(-) diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c b/Platform/ARM/Dri= vers/NorFlashDxe/NorFlash.c index 1b431073ee93..60854ef2a7d0 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c @@ -807,135 +807,6 @@ NorFlashWriteSingleBlock ( return EFI_SUCCESS; } -/* - Although DiskIoDxe will automatically install the DiskIO protocol whenev= er - we install the BlockIO protocol, its implementation is sub-optimal as it= reads - and writes entire blocks using the BlockIO protocol. In fact we can acce= ss - NOR flash with a finer granularity than that, so we can improve performa= nce - by directly producing the DiskIO protocol. -*/ - -/** - Read BufferSize bytes from Offset into Buffer. - - @param This Protocol instance pointer. - @param MediaId Id of the media, changes every time the me= dia is replaced. - @param Offset The starting byte offset to read from - @param BufferSize Size of Buffer - @param Buffer Buffer containing read data - - @retval EFI_SUCCESS The data was read correctly from the devic= e. - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. - @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not - valid for the device. - -**/ -EFI_STATUS -EFIAPI -NorFlashDiskIoReadDisk ( - IN EFI_DISK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN UINT64 DiskOffset, - IN UINTN BufferSize, - OUT VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - UINT32 BlockSize; - UINT32 BlockOffset; - EFI_LBA Lba; - - Instance =3D INSTANCE_FROM_DISKIO_THIS (This); - - if (MediaId !=3D Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize =3D Instance->Media.BlockSize; - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); - - return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); -} - -/** - Writes a specified number of bytes to a device. - - @param This Indicates a pointer to the calling context. - @param MediaId ID of the medium to be written. - @param Offset The starting byte offset on the logical block I/O dev= ice to write. - @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device. - @param Buffer A pointer to the buffer containing the data to be wri= tten. - - @retval EFI_SUCCESS The data was written correctly to the devi= ce. - @retval EFI_WRITE_PROTECTED The device can not be written to. - @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write. - @retval EFI_NO_MEDIA There is no media in the device. - @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. - @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not - valid for the device. - -**/ -EFI_STATUS -EFIAPI -NorFlashDiskIoWriteDisk ( - IN EFI_DISK_IO_PROTOCOL *This, - IN UINT32 MediaId, - IN UINT64 DiskOffset, - IN UINTN BufferSize, - IN VOID *Buffer - ) -{ - NOR_FLASH_INSTANCE *Instance; - UINT32 BlockSize; - UINT32 BlockOffset; - EFI_LBA Lba; - UINTN RemainingBytes; - UINTN WriteSize; - EFI_STATUS Status; - - Instance =3D INSTANCE_FROM_DISKIO_THIS (This); - - if (MediaId !=3D Instance->Media.MediaId) { - return EFI_MEDIA_CHANGED; - } - - BlockSize =3D Instance->Media.BlockSize; - Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); - - RemainingBytes =3D BufferSize; - - // Write either all the remaining bytes, or the number of bytes that bri= ng - // us up to a block boundary, whichever is less. - // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next - // block boundary (even if it is already on one). - WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset); - - do { - if (WriteSize =3D=3D BlockSize) { - // Write a full block - Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32)); - } else { - // Write a partial block - Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer); - } - - if (EFI_ERROR (Status)) { - return Status; - } - - // Now continue writing either all the remaining bytes or single block= s. - RemainingBytes -=3D WriteSize; - Buffer =3D (UINT8 *)Buffer + WriteSize; - Lba++; - BlockOffset =3D 0; - WriteSize =3D MIN (RemainingBytes, BlockSize); - } while (RemainingBytes); - - return Status; -} - EFI_STATUS NorFlashReset ( IN NOR_FLASH_INSTANCE *Instance diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/Platfo= rm/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c index 9d4732c6905a..9b8c76a171d4 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c @@ -121,3 +121,132 @@ NorFlashBlockIoFlushBlocks ( // Nothing to do so just return without error return EFI_SUCCESS; } + +/* + Although DiskIoDxe will automatically install the DiskIO protocol whenev= er + we install the BlockIO protocol, its implementation is sub-optimal as it= reads + and writes entire blocks using the BlockIO protocol. In fact we can acce= ss + NOR flash with a finer granularity than that, so we can improve performa= nce + by directly producing the DiskIO protocol. +*/ + +/** + Read BufferSize bytes from Offset into Buffer. + + @param This Protocol instance pointer. + @param MediaId Id of the media, changes every time the me= dia is replaced. + @param Offset The starting byte offset to read from + @param BufferSize Size of Buffer + @param Buffer Buffer containing read data + + @retval EFI_SUCCESS The data was read correctly from the devic= e. + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the read. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. + @retval EFI_INVALID_PARAMETER The read request contains device addresses= that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoReadDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + OUT VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); + + return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); +} + +/** + Writes a specified number of bytes to a device. + + @param This Indicates a pointer to the calling context. + @param MediaId ID of the medium to be written. + @param Offset The starting byte offset on the logical block I/O dev= ice to write. + @param BufferSize The size in bytes of Buffer. The number of bytes to w= rite to the device. + @param Buffer A pointer to the buffer containing the data to be wri= tten. + + @retval EFI_SUCCESS The data was written correctly to the devi= ce. + @retval EFI_WRITE_PROTECTED The device can not be written to. + @retval EFI_DEVICE_ERROR The device reported an error while perform= ing the write. + @retval EFI_NO_MEDIA There is no media in the device. + @retval EFI_MEDIA_CHANGED The MediaId does not match the current dev= ice. + @retval EFI_INVALID_PARAMETER The write request contains device addresse= s that are not + valid for the device. + +**/ +EFI_STATUS +EFIAPI +NorFlashDiskIoWriteDisk ( + IN EFI_DISK_IO_PROTOCOL *This, + IN UINT32 MediaId, + IN UINT64 DiskOffset, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + NOR_FLASH_INSTANCE *Instance; + UINT32 BlockSize; + UINT32 BlockOffset; + EFI_LBA Lba; + UINTN RemainingBytes; + UINTN WriteSize; + EFI_STATUS Status; + + Instance =3D INSTANCE_FROM_DISKIO_THIS (This); + + if (MediaId !=3D Instance->Media.MediaId) { + return EFI_MEDIA_CHANGED; + } + + BlockSize =3D Instance->Media.BlockSize; + Lba =3D (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &Block= Offset); + + RemainingBytes =3D BufferSize; + + // Write either all the remaining bytes, or the number of bytes that bri= ng + // us up to a block boundary, whichever is less. + // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next + // block boundary (even if it is already on one). + WriteSize =3D MIN (RemainingBytes, ((DiskOffset | (BlockSize - 1)) + 1) = - DiskOffset); + + do { + if (WriteSize =3D=3D BlockSize) { + // Write a full block + Status =3D NorFlashWriteFullBlock (Instance, Lba, Buffer, BlockSize = / sizeof (UINT32)); + } else { + // Write a partial block + Status =3D NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &Wr= iteSize, Buffer); + } + + if (EFI_ERROR (Status)) { + return Status; + } + + // Now continue writing either all the remaining bytes or single block= s. + RemainingBytes -=3D WriteSize; + Buffer =3D (UINT8 *)Buffer + WriteSize; + Lba++; + BlockOffset =3D 0; + WriteSize =3D MIN (RemainingBytes, BlockSize); + } while (RemainingBytes); + + return Status; +} -- 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118151): https://edk2.groups.io/g/devel/message/118151 Mute This Topic: https://groups.io/mt/105690936/7717249 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [yeoreum.yun@arm.com] -=3D-=3D-=3D-=3D-=3D-=3D IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you. -=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 (#118185): https://edk2.groups.io/g/devel/message/118185 Mute This Topic: https://groups.io/mt/105690936/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-