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 9D0C47803D1 for ; Wed, 24 Apr 2024 09:50:13 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=g3SpstKsxBHyNQr0MRGKbPV38ke7ceY/47do+wI8Mqs=; 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=1713952212; v=1; b=wbXoG31LzJhmEZMq9Z4FvLf25vht2cE1MuC3dzdPQNJYH+X1zzitIe57zhWvgYtyy2vzbnQ6 x+MYW831EjB0rVjPgICu1Zq15U+wXgu67q2r7YaYLyIOfFSQt3o7N5ABsZ3WrWPyI065TeR6zoy tpzJvOJxzMLJ2GkChqg1QisQT3EXokR5lw7SNzK3TxEh9jsEqr4T6cSPNVy3RUtOAfYn4hE+L5K brhzluMzr5BGECEfracHRl5ktZ/L4AcM8wN/DX6BHfIrSTneiz5UBZ+EZQKdun90FUwI5jB1E+4 I/a01GWBTFtypL+4j8yoFR2HWOjM4N/5x192vkvnwDmLg== X-Received: by 127.0.0.2 with SMTP id dmZtYY7687511xgk56t0NNTT; Wed, 24 Apr 2024 02:50:12 -0700 X-Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.45]) by mx.groups.io with SMTP id smtpd.web10.12567.1713952210580954852 for ; Wed, 24 Apr 2024 02:50:11 -0700 X-Received: from AM0PR02CA0192.eurprd02.prod.outlook.com (2603:10a6:20b:28e::29) by PAWPR08MB9736.eurprd08.prod.outlook.com (2603:10a6:102:2ea::12) 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:50:01 +0000 X-Received: from AM3PEPF0000A78F.eurprd04.prod.outlook.com (2603:10a6:20b:28e:cafe::cf) by AM0PR02CA0192.outlook.office365.com (2603:10a6:20b:28e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.34 via Frontend Transport; Wed, 24 Apr 2024 09:50:01 +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 AM3PEPF0000A78F.mail.protection.outlook.com (10.167.16.118) 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:50:01 +0000 X-Received: ("Tessian outbound f1e9a43166b5:v313"); Wed, 24 Apr 2024 09:50:01 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ff0b06778dc9b13c X-CR-MTA-TID: 64aa7808 X-Received: from 88a7d74f8554.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id FB5E30EE-4A56-44FA-820A-DF13579094F8.1; Wed, 24 Apr 2024 09:49:54 +0000 X-Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 88a7d74f8554.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 24 Apr 2024 09:49:54 +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:52 +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:52 +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 04/14] Platform/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c Thread-Topic: [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 04/14] Platform/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c Thread-Index: AQHalY9TA8pYbzh2IE+PucDhcGH+zbF3LmEy Date: Wed, 24 Apr 2024 09:49:52 +0000 Message-ID: References: <20240423055638.1271531-1-Sahil.Kaushal@arm.com> <20240423055638.1271531-5-Sahil.Kaushal@arm.com> In-Reply-To: <20240423055638.1271531-5-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_|AM3PEPF0000A78F:EE_|PAWPR08MB9736:EE_ X-MS-Office365-Filtering-Correlation-Id: cf528e85-ba90-41e4-60eb-08dc6443e915 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: B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VtGoncl?= =?koi8-r?Q?GHVJ0lGASmThCL0UU1+k+0MbzgPfM84U7yGQSp1yv4FqsVawUr/YDmLo7Pbqd7?= =?koi8-r?Q?jwd51WcMUMmL9wTySbFeL8AcsoGw5TYpE0QNsperchBm5hT/reJalSGEASy/ML?= =?koi8-r?Q?r0SooFUlyk6Fe0B2hQk67llnphwC2ID2K+xcAjTmECetxON5m4DXMjbOHQiiSi?= =?koi8-r?Q?AeMRhYRh6aHX9O3OGpKTVNpKHroR3nk+H4HlQvlGYroDJMUrb4nczK6XoKMrxr?= =?koi8-r?Q?L1M6lUQSG/iGzUElDgB5Z/Jav3YAngkq7aR2Ac0rOfI0XZrM4vIOCOD7DuNE37?= =?koi8-r?Q?V2LUF/fQVSNH/5aLh37ccfwTuZy6Zl0jkb/VAqSvVQnLu75p3e05jecZmrFgQI?= =?koi8-r?Q?6Nw+ZFoCmQxRd0mbnRQFIK2JUBwyn6wgvjCgV4omJlXbpDfwRELRon4FFnXsfJ?= =?koi8-r?Q?KYvPMZvkBEC4wBpS5VOLjOEci09+4EJMVaWp7S/nqWtrAZF8LTGnii04/unEc8?= =?koi8-r?Q?1Q=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: AM3PEPF0000A78F.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a57b2177-d7ee-4f96-0606-08dc6443e397 X-Microsoft-Antispam-Message-Info: =?koi8-r?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DsHJq/5BTYp25p+gkDD/lyO9D/XsRGnHvPhCKQVhw7ajd2?= =?koi8-r?Q?Pf0AO2AsEjmySlW1BaMxexSiSKR89PbY+Lo/dj5mGr2ajjjpeUvEScsxLCOEdV?= =?koi8-r?Q?gKHPfkTHWc/u03AQNOoIo6EwhbpPdumyu8rBNPpYvL2hmjUTGuzXuZlYUGrJWN?= =?koi8-r?Q?dXBLx0MRuX5ILX90UbQy9Pvz6IWYOskD+kmyMrc76ntwW4M8JWBzM4t+JJ1RbE?= =?koi8-r?Q?3RiLHWAGozt/z18UTG4Ep7Go/FTHTpcqDbgkpFkHh1gp2Vywb5MmCCEmC0dJkf?= =?koi8-r?Q?wqe4BmnH3JyQMK/beP2ZG2rte0HeTKb7DBehkBEdx/wbmihqnNecei19frTupf?= =?koi8-r?Q?NCPLUC5vZOKnPWcnNiqW/VRy7MZ5LpLvd2QpaQsZX6KnSwuwFwGTWdcoa842FF?= =?koi8-r?Q?3Y+7XiQeo/vxemiFkozztKamrlkgM62StkeQDauicz0cpTh9r+8hLBnvvP6vBJ?= =?koi8-r?Q?s6TTvW0mpZ8X59KdY0os3AsZiWKGlYqBPtQcvGccyJ/7?= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2024 09:50:01.5221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf528e85-ba90-41e4-60eb-08dc6443e915 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: AM3PEPF0000A78F.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9736 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:50:11 -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: hczbyLVXOq3LEpGMYuIqRK9Xx7686176AA= 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=wbXoG31L; 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 04/14] Platfor= m/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c From: sahil Refactoring done in this patch has two major parts: 1. Moving out NorFlashUnlockAndEraseSingleBlock and NorFlashWriteFullBlock functions from NorFlashDxe.c and NorFlashStandaloneMm.c to NorFlash.c files. 2. At the same time, we are adding NorFlashLock and NorFlashUnlock functions which will take care of TPL related operations needed by functions mentioned in point 1. These functions are implemented in NorFlashDxe.c but are just dummy placeholder functions in NorFlashStandaloneMm.c file. Signed-off-by: sahil --- Platform/ARM/Drivers/NorFlashDxe/NorFlash.h | 26 +++ Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h | 14 -- Platform/ARM/Drivers/NorFlashDxe/NorFlash.c | 136 ++++++++++++= +- Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c | 193 ++++--------= -------- Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 151 +++---------= --- 5 files changed, 225 insertions(+), 295 deletions(-) diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h b/Platform/ARM/Dri= vers/NorFlashDxe/NorFlash.h index e0ebb1e2fd35..bd5c6a949cf0 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h @@ -220,4 +220,30 @@ NorFlashWriteSingleWord ( IN UINT32 WriteData ); +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ); + +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ); + +VOID +EFIAPI +NorFlashLock ( + IN EFI_TPL *OriginalTPL + ); + +VOID +EFIAPI +NorFlashUnlock ( + IN EFI_TPL OriginalTPL + ); + #endif /* __NOR_FLASH_H__ */ diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h b/Platform/A= RM/Drivers/NorFlashDxe/NorFlashCommon.h index e329e0727617..c0a3b5861532 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h @@ -31,20 +31,6 @@ // // NorFlashDxe.c // -EFI_STATUS -NorFlashWriteFullBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINT32 *DataBuffer, - IN UINT32 BlockSizeInWords - ); - -EFI_STATUS -NorFlashUnlockAndEraseSingleBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN UINTN BlockAddress - ); - EFI_STATUS NorFlashCreateInstance ( IN UINTN NorFlashDeviceBase, diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c b/Platform/ARM/Dri= vers/NorFlashDxe/NorFlash.c index 4e5a97c83c7b..15000a692b02 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c @@ -10,7 +10,6 @@ #include #include "NorFlash.h" -#include "NorFlashCommon.h" // // Global variable declarations @@ -817,3 +816,138 @@ NorFlashReset ( SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); return EFI_SUCCESS; } + +/** + * This function unlock and erase an entire NOR Flash block. +**/ +EFI_STATUS +NorFlashUnlockAndEraseSingleBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN UINTN BlockAddress + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_TPL OriginalTPL; + + NorFlashLock (&OriginalTPL); + + Index =3D 0; + // The block erase might fail a first time (SW bug ?). Retry it ... + do { + // Unlock the block if we have to + Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D NorFlashEraseSingleBlock (Instance, BlockAddress); + Index++; + } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status =3D=3D EFI_WRITE_PRO= TECTED)); + + if (Index =3D=3D NOR_FLASH_ERASE_RETRY) { + DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Lo= cked Error (try to erase %d times)\n", BlockAddress, Index)); + } + + NorFlashUnlock (OriginalTPL); + + return Status; +} + +EFI_STATUS +NorFlashWriteFullBlock ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINT32 *DataBuffer, + IN UINT32 BlockSizeInWords + ) +{ + EFI_STATUS Status; + UINTN WordAddress; + UINT32 WordIndex; + UINTN BufferIndex; + UINTN BlockAddress; + UINTN BuffersInBlock; + UINTN RemainingWords; + EFI_TPL OriginalTPL; + UINTN Cnt; + + Status =3D EFI_SUCCESS; + + // Get the physical address of the block + BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba= , BlockSizeInWords * 4); + + // Start writing from the first address at the start of the block + WordAddress =3D BlockAddress; + + NorFlashLock (&OriginalTPL); + + Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and E= rase the single block at 0x%X\n", BlockAddress)); + goto EXIT; + } + + // To speed up the programming operation, NOR Flash is programmed using = the Buffered Programming method. + + // Check that the address starts at a 32-word boundary, i.e. last 7 bits= must be zero + if ((WordAddress & BOUNDARY_OF_32_WORDS) =3D=3D 0x00) { + // First, break the entire block into buffer-sized chunks. + BuffersInBlock =3D (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE= _IN_BYTES; + + // Then feed each buffer chunk to the NOR Flash + // If a buffer does not contain any data, don't write it. + for (BufferIndex =3D 0; + BufferIndex < BuffersInBlock; + BufferIndex++, WordAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES, Dat= aBuffer +=3D P30_MAX_BUFFER_SIZE_IN_WORDS + ) + { + // Check the buffer to see if it contains any data (not set all 1s). + for (Cnt =3D 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { + if (~DataBuffer[Cnt] !=3D 0 ) { + // Some data found, write the buffer. + Status =3D NorFlashWriteBuffer ( + Instance, + WordAddress, + P30_MAX_BUFFER_SIZE_IN_BYTES, + DataBuffer + ); + if (EFI_ERROR (Status)) { + goto EXIT; + } + + break; + } + } + } + + // Finally, finish off any remaining words that are less than the maxi= mum size of the buffer + RemainingWords =3D BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; + + if (RemainingWords !=3D 0) { + Status =3D NorFlashWriteBuffer (Instance, WordAddress, (RemainingWor= ds * 4), DataBuffer); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } else { + // For now, use the single word programming algorithm + // It is unlikely that the NOR Flash will exist in an address which fa= lls within a 32 word boundary range, + // i.e. which ends in the range 0x......01 - 0x......7F. + for (WordIndex =3D 0; WordIndex < BlockSizeInWords; WordIndex++, DataB= uffer++, WordAddress =3D WordAddress + 4) { + Status =3D NorFlashWriteSingleWord (Instance, WordAddress, *DataBuff= er); + if (EFI_ERROR (Status)) { + goto EXIT; + } + } + } + +EXIT: + NorFlashUnlock (OriginalTPL); + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); + } + + return Status; +} diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c b/Platform/ARM/= Drivers/NorFlashDxe/NorFlashDxe.c index b1e01169c24e..4bad6e9b2a6b 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c @@ -174,161 +174,6 @@ NorFlashCreateInstance ( return Status; } -/** - * This function unlock and erase an entire NOR Flash block. - **/ -EFI_STATUS -NorFlashUnlockAndEraseSingleBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN UINTN BlockAddress - ) -{ - EFI_STATUS Status; - UINTN Index; - EFI_TPL OriginalTPL; - - if (!EfiAtRuntime ()) { - // Raise TPL to TPL_HIGH to stop anyone from interrupting us. - OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); - } else { - // This initialization is only to prevent the compiler to complain abo= ut the - // use of uninitialized variables - OriginalTPL =3D TPL_HIGH_LEVEL; - } - - Index =3D 0; - // The block erase might fail a first time (SW bug ?). Retry it ... - do { - // Unlock the block if we have to - Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); - if (EFI_ERROR (Status)) { - break; - } - - Status =3D NorFlashEraseSingleBlock (Instance, BlockAddress); - Index++; - } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status =3D=3D EFI_WRITE_PRO= TECTED)); - - if (Index =3D=3D NOR_FLASH_ERASE_RETRY) { - DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Lo= cked Error (try to erase %d times)\n", BlockAddress, Index)); - } - - if (!EfiAtRuntime ()) { - // Interruptions can resume. - gBS->RestoreTPL (OriginalTPL); - } - - return Status; -} - -EFI_STATUS -NorFlashWriteFullBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINT32 *DataBuffer, - IN UINT32 BlockSizeInWords - ) -{ - EFI_STATUS Status; - UINTN WordAddress; - UINT32 WordIndex; - UINTN BufferIndex; - UINTN BlockAddress; - UINTN BuffersInBlock; - UINTN RemainingWords; - EFI_TPL OriginalTPL; - UINTN Cnt; - - Status =3D EFI_SUCCESS; - - // Get the physical address of the block - BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba= , BlockSizeInWords * 4); - - // Start writing from the first address at the start of the block - WordAddress =3D BlockAddress; - - if (!EfiAtRuntime ()) { - // Raise TPL to TPL_HIGH to stop anyone from interrupting us. - OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); - } else { - // This initialization is only to prevent the compiler to complain abo= ut the - // use of uninitialized variables - OriginalTPL =3D TPL_HIGH_LEVEL; - } - - Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and E= rase the single block at 0x%X\n", BlockAddress)); - goto EXIT; - } - - // To speed up the programming operation, NOR Flash is programmed using = the Buffered Programming method. - - // Check that the address starts at a 32-word boundary, i.e. last 7 bits= must be zero - if ((WordAddress & BOUNDARY_OF_32_WORDS) =3D=3D 0x00) { - // First, break the entire block into buffer-sized chunks. - BuffersInBlock =3D (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE= _IN_BYTES; - - // Then feed each buffer chunk to the NOR Flash - // If a buffer does not contain any data, don't write it. - for (BufferIndex =3D 0; - BufferIndex < BuffersInBlock; - BufferIndex++, WordAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES, Dat= aBuffer +=3D P30_MAX_BUFFER_SIZE_IN_WORDS - ) - { - // Check the buffer to see if it contains any data (not set all 1s). - for (Cnt =3D 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { - if (~DataBuffer[Cnt] !=3D 0 ) { - // Some data found, write the buffer. - Status =3D NorFlashWriteBuffer ( - Instance, - WordAddress, - P30_MAX_BUFFER_SIZE_IN_BYTES, - DataBuffer - ); - if (EFI_ERROR (Status)) { - goto EXIT; - } - - break; - } - } - } - - // Finally, finish off any remaining words that are less than the maxi= mum size of the buffer - RemainingWords =3D BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; - - if (RemainingWords !=3D 0) { - Status =3D NorFlashWriteBuffer (Instance, WordAddress, (RemainingWor= ds * 4), DataBuffer); - if (EFI_ERROR (Status)) { - goto EXIT; - } - } - } else { - // For now, use the single word programming algorithm - // It is unlikely that the NOR Flash will exist in an address which fa= lls within a 32 word boundary range, - // i.e. which ends in the range 0x......01 - 0x......7F. - for (WordIndex =3D 0; WordIndex < BlockSizeInWords; WordIndex++, DataB= uffer++, WordAddress =3D WordAddress + 4) { - Status =3D NorFlashWriteSingleWord (Instance, WordAddress, *DataBuff= er); - if (EFI_ERROR (Status)) { - goto EXIT; - } - } - } - -EXIT: - if (!EfiAtRuntime ()) { - // Interruptions can resume. - gBS->RestoreTPL (OriginalTPL); - } - - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); - } - - return Status; -} - EFI_STATUS EFIAPI NorFlashInitialise ( @@ -549,3 +394,41 @@ NorFlashVirtualNotifyEvent ( return; } + +/** + Lock all pending read/write to Nor flash device + + @param[in] *OriginalTPL Pointer to Nor flash device Original TPL= . +**/ +VOID +EFIAPI +NorFlashLock ( + IN EFI_TPL *OriginalTPL + ) +{ + if (!EfiAtRuntime ()) { + // Raise TPL to TPL_HIGH to stop anyone from interrupting us. + *OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); + } else { + // This initialization is only to prevent the compiler to complain abo= ut the + // use of uninitialized variables + *OriginalTPL =3D TPL_HIGH_LEVEL; + } +} + +/** + Unlock all pending read/write to Nor flash device + + @param[in] OriginalTPL Nor flash device Original TPL. +**/ +VOID +EFIAPI +NorFlashUnlock ( + IN EFI_TPL OriginalTPL + ) +{ + if (!EfiAtRuntime ()) { + // Interruptions can resume. + gBS->RestoreTPL (OriginalTPL); + } +} diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/Plat= form/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c index f2919265139b..5bff524e5e18 100644 --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c @@ -153,131 +153,6 @@ NorFlashCreateInstance ( return Status; } -/** - * This function unlock and erase an entire NOR Flash block. - **/ -EFI_STATUS -NorFlashUnlockAndEraseSingleBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN UINTN BlockAddress - ) -{ - EFI_STATUS Status; - UINTN Index; - - Index =3D 0; - // The block erase might fail a first time (SW bug ?). Retry it ... - do { - // Unlock the block if we have to - Status =3D NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddres= s); - if (EFI_ERROR (Status)) { - break; - } - - Status =3D NorFlashEraseSingleBlock (Instance, BlockAddress); - Index++; - } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status =3D=3D EFI_WRITE_PRO= TECTED)); - - if (Index =3D=3D NOR_FLASH_ERASE_RETRY) { - DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=3D0x%08x: Block Lo= cked Error (try to erase %d times)\n", BlockAddress, Index)); - } - - return Status; -} - -EFI_STATUS -NorFlashWriteFullBlock ( - IN NOR_FLASH_INSTANCE *Instance, - IN EFI_LBA Lba, - IN UINT32 *DataBuffer, - IN UINT32 BlockSizeInWords - ) -{ - EFI_STATUS Status; - UINTN WordAddress; - UINT32 WordIndex; - UINTN BufferIndex; - UINTN BlockAddress; - UINTN BuffersInBlock; - UINTN RemainingWords; - UINTN Cnt; - - Status =3D EFI_SUCCESS; - - // Get the physical address of the block - BlockAddress =3D GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba= , BlockSizeInWords * 4); - - // Start writing from the first address at the start of the block - WordAddress =3D BlockAddress; - - Status =3D NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and E= rase the single block at 0x%X\n", BlockAddress)); - goto EXIT; - } - - // To speed up the programming operation, NOR Flash is programmed using = the Buffered Programming method. - - // Check that the address starts at a 32-word boundary, i.e. last 7 bits= must be zero - if ((WordAddress & BOUNDARY_OF_32_WORDS) =3D=3D 0x00) { - // First, break the entire block into buffer-sized chunks. - BuffersInBlock =3D (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE= _IN_BYTES; - - // Then feed each buffer chunk to the NOR Flash - // If a buffer does not contain any data, don't write it. - for (BufferIndex =3D 0; - BufferIndex < BuffersInBlock; - BufferIndex++, WordAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES, Dat= aBuffer +=3D P30_MAX_BUFFER_SIZE_IN_WORDS - ) - { - // Check the buffer to see if it contains any data (not set all 1s). - for (Cnt =3D 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { - if (~DataBuffer[Cnt] !=3D 0 ) { - // Some data found, write the buffer. - Status =3D NorFlashWriteBuffer ( - Instance, - WordAddress, - P30_MAX_BUFFER_SIZE_IN_BYTES, - DataBuffer - ); - if (EFI_ERROR (Status)) { - goto EXIT; - } - - break; - } - } - } - - // Finally, finish off any remaining words that are less than the maxi= mum size of the buffer - RemainingWords =3D BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; - - if (RemainingWords !=3D 0) { - Status =3D NorFlashWriteBuffer (Instance, WordAddress, (RemainingWor= ds * 4), DataBuffer); - if (EFI_ERROR (Status)) { - goto EXIT; - } - } - } else { - // For now, use the single word programming algorithm - // It is unlikely that the NOR Flash will exist in an address which fa= lls within a 32 word boundary range, - // i.e. which ends in the range 0x......01 - 0x......7F. - for (WordIndex =3D 0; WordIndex < BlockSizeInWords; WordIndex++, DataB= uffer++, WordAddress =3D WordAddress + 4) { - Status =3D NorFlashWriteSingleWord (Instance, WordAddress, *DataBuff= er); - if (EFI_ERROR (Status)) { - goto EXIT; - } - } - } - -EXIT: - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed = at address 0x%08x. Exit Status =3D \"%r\".\n", WordAddress, Status)); - } - - return Status; -} - EFI_STATUS EFIAPI NorFlashInitialise ( @@ -382,3 +257,29 @@ NorFlashFvbInitialize ( return Status; } + +/** + Lock all pending read/write to Nor flash device + + @param[in] OriginalTPL Nor flash device Original TPL. +**/ +VOID +EFIAPI +NorFlashLock ( + IN EFI_TPL *OriginalTPL + ) +{ +} + +/** + Unlock all pending read/write to Nor flash device + + @param[in] OriginalTPL Nor flash device Original TPL. +**/ +VOID +EFIAPI +NorFlashUnlock ( + IN EFI_TPL OriginalTPL + ) +{ +} -- 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118154): https://edk2.groups.io/g/devel/message/118154 Mute This Topic: https://groups.io/mt/105690939/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 (#118188): https://edk2.groups.io/g/devel/message/118188 Mute This Topic: https://groups.io/mt/105690939/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-