From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.76]) by mx.groups.io with SMTP id smtpd.web12.6766.1608782953264471885 for ; Wed, 23 Dec 2020 20:09:13 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@vmware.com header.s=selector2 header.b=gp022HuW; spf=pass (domain: vmware.com, ip: 40.107.94.76, mailfrom: awarkentin@vmware.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hka8yRNftDPDtYtTSt48EibLNpoJLEz3VkSaTL8/cQ4HJwuDlbYJz3u4lvS+MIZ6vzGYBKpUZ48HeMyjVWg/ENSqvT+Ll+UxsIhxXXpBP5bLXliEJeMvp/zgWmB6hBRVjQavxjMgm5uWTbYu5WsR0p2lroh6gm6YScWwCQ2KePjH5gxtFjtPZzzXHoGwZPTTRxy/ALA8fRGCZ9OGRWtnmMyBY1NjzGy97OYcGq8BGJnbbUMbMZGgdLXE/EnUORgnavn9TQFbd2ddMatdhBR66z0BjLSV9wR+1sCINf8QCDWtfeYDjGHsyJimPH+rWM0PLgjrAunGRjwqmZ9NA4cZVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JaM02LiZ2C4f77zdQ6I5lpYKr/ccj10oeDw9JwYVGig=; b=jgR5tGQcJCIp3+3w7X3dqlZ3eYu+uUQcd/TzWVnnxKzN4K7aMhA6n+oWNu8cf41cMtU/MRfM0ChUmpDfzGHRPkvmqoiyScuLidiCJ1qN28mbPwvaiJfbEA9GMSoC+mOXIe3YrE4IcX2/nFUK1AbOnOFx5C5o3qNVJPCzYRv3F+A91jcnsVgrr/xeY3pKcWpSpN8TocNPxlT1oYduZ9rIW2egXC49SyYQ7u4KDnxCjdjnI1IvA7iI1ykvw/xZ+u5Jya0MSXoL4EjuTX/m8XRRUmsVM7HelndLsDTb238D/BV4Gvnc0Ch1LgdokIOKLKB4SQSj4WdflO3QGOCp6+yJJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JaM02LiZ2C4f77zdQ6I5lpYKr/ccj10oeDw9JwYVGig=; b=gp022HuWdOyGjaSQOzHUZfHYxMPDjB8VJyG6g00LRRhpvsr37VzaEKfv77T3oZgoXWTm4hD9DqoYmVCCOq6SOWX3g6KFmf/w8MamY/4zLdFIo8cCsWz7DS2neJMEtVWMd8uxrL9GcWby7tr+WxgflH+CxrrpnApwg6cDzT7V/Dw= Received: from SN7PR05MB7582.namprd05.prod.outlook.com (2603:10b6:806:f7::16) by SN6PR05MB5695.namprd05.prod.outlook.com (2603:10b6:805:101::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.19; Thu, 24 Dec 2020 04:09:11 +0000 Received: from SN7PR05MB7582.namprd05.prod.outlook.com ([fe80::5840:b0dd:d2c8:866f]) by SN7PR05MB7582.namprd05.prod.outlook.com ([fe80::5840:b0dd:d2c8:866f%7]) with mapi id 15.20.3676.033; Thu, 24 Dec 2020 04:09:11 +0000 From: "Andrei Warkentin" To: Pete Batard , "devel@edk2.groups.io" CC: "ard.biesheuvel@arm.com" , "leif@nuviainc.com" , "samer.el-haj-mahmoud@arm.com" Subject: Re: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Add system/user defined reset delay Thread-Topic: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Add system/user defined reset delay Thread-Index: AQHW2Gi+uDAvmvYCOk6WlGaFraDUh6oFos61 Date: Thu, 24 Dec 2020 04:09:11 +0000 Message-ID: References: <20201222134528.793-1-pete@akeo.ie> In-Reply-To: <20201222134528.793-1-pete@akeo.ie> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: akeo.ie; dkim=none (message not signed) header.d=none;akeo.ie; dmarc=none action=none header.from=vmware.com; x-originating-ip: [176.57.76.33] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ba24138b-c648-4fe2-79b1-08d8a7c1ab2c x-ms-traffictypediagnostic: SN6PR05MB5695: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: esnuFx3pE2y/Nv+2alLHMovQV3M1Q1wYDtV+4guW8VJkwMlvCCtxe88vTZxY1H/lYgMuuQIPUvRUl0UHjg0EOjR9GIeqB+L1r8u/MVFPTDDoJY5gzxepF+7N9eUWWg1+G+PihWHTcwYUQX4HtELumoly89PsNlEPVV3VxqPmV5DoUYNnF+2IUler3VrmHY4AmPtRI7cFI0i/r603OBXfJmDBcPs9LiMgLJFC+lZwZ/aalFtU2Q6ICJAc7TclWjS6yTM4rbyqYFUv6ddsVn/3ZLz85aweuc7p3EPT2dn2Z01bmf3HVz0aESD7DDi9/5Avr/NhNAkgXPriWguMI+T0PxLhM6o0SedWxRwsvGHsofKgkT0F55qc1s4lhopgFb4UJkNrQApjAHH7y3okRF2ZlQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN7PR05MB7582.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(39860400002)(346002)(366004)(376002)(6506007)(66446008)(19627235002)(66556008)(19627405001)(478600001)(64756008)(66476007)(66946007)(53546011)(8676002)(2906002)(76116006)(91956017)(4326008)(83380400001)(7696005)(26005)(5660300002)(52536014)(86362001)(110136005)(9686003)(8936002)(71200400001)(316002)(54906003)(66574015)(33656002)(186003)(55016002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?iso-8859-7?Q?aN1muHoKKNKi79fXzvgHCBEY4oWbMYND7bT4152kMIVWQ8Cnd5FVdv1VTM?= =?iso-8859-7?Q?+yenYBCUbRw90bblVOraZnWjIAhfNiTV2Z/S53S8zeu/GfoAN5osNIlwAJ?= =?iso-8859-7?Q?FehYRkZJbSxqW3oFDlnXAuGmIWUv5Es74YQ2/JwXbmOUJS/Y+H0o10a+dD?= =?iso-8859-7?Q?mcxyJ7sTD/JG8587prmGr7ubJQXY+eG2/Wl9Z6wIH62O9GLsEYX5iA38AK?= =?iso-8859-7?Q?xBncgk6sUGWtmYq+II/nIvJhyDjRcdXlXzhOP+i3gzoYI5/dmlmtXTnEmb?= =?iso-8859-7?Q?9HO9Rz5rThRkWUuGgVQyzpbygR6fr/VzHC3TN+uoG8izP8I6Tj2Ou9bl9q?= =?iso-8859-7?Q?nXiKcPdaDB0diF0iOvqZFugLa37unLYWN1k4ojpmeG1jBWebWIP8bYPhUW?= =?iso-8859-7?Q?m48Sa4twpN7yzHyp5UVFNwarSeNRdRCyuIA9mTm/nC+nJQ6a84flUcUlVi?= =?iso-8859-7?Q?c2xzfA6hn4+M1OSbYUzULG7Jwq/dFj6T83t0xyU0382lsJi8PP8KbJ+5MW?= =?iso-8859-7?Q?v8ngTcVUwQJOheqCYCLJN+PVLCCJE10/unPjF2kzrGpNJxEDiu1Xz7mTrz?= =?iso-8859-7?Q?NR44/I8upRoGVz3TVvWwMDEEMexv8phB2t+TetMSee52gmmlrkpP8d0L9J?= =?iso-8859-7?Q?qJd4Uhrwbl27RrddDeSw2WWXpxjT4coQuvy4ouMnZ7ITgbjzmdnzGoTqz0?= =?iso-8859-7?Q?MHaHBFSS3063b/ar877oKJMJXaXviGnyfFlujBf5RD08WDfuh+aBbP3XQ4?= =?iso-8859-7?Q?7tfOki2pqFf/8jLWH5fRYs2ctPr9147IzOO2s8wUBXvGBF1Fsx6kGZnaCb?= =?iso-8859-7?Q?ku9vBFqM12yXxSx3Q9rBe4OpM6YizYP5/VIbk2KSEFFTQKZmr6a2e8G2wN?= =?iso-8859-7?Q?ayRBKZbWy6RwBsjDZdzDP7iiefHpf5u4Lmn/qJVF0Lp/uzOqeCXlgcpTHz?= =?iso-8859-7?Q?twcd1D89qcD7LE+5Fe/tlE6cJrHLj44goV2opwyZi+8HqudPoN+t7D2BfQ?= =?iso-8859-7?Q?ifI4b4r2Nwd9vcN9w=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN7PR05MB7582.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba24138b-c648-4fe2-79b1-08d8a7c1ab2c X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Dec 2020 04:09:11.4464 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: e0vt4ZuX5YIQysrL6oGIxBPNJyANX1hiKarIOs0cDGm7VWzZ+o3iELSVQjjOd6EIZEuFX6nLz+Nlxhaaix+ebg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR05MB5695 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_SN7PR05MB75821FB4B4C780350D5AC01AB9DD0SN7PR05MB7582namp_" --_000_SN7PR05MB75821FB4B4C780350D5AC01AB9DD0SN7PR05MB7582namp_ Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Sure. I wish there was something more precise, I'm guessing that would at l= east be very different between USB and SD/MMC... Reviewed-by: Andrei Warkentin ________________________________ From: Pete Batard Sent: Tuesday, December 22, 2020 7:45 AM To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com ; leif@nuviainc.com ; samer.el-haj-mahmoud@arm.com ; Andrei Warkentin Subject: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Add system/user = defined reset delay Due to the method in which NV variables are stored on removable media for the Raspberry Pi platform, and the manner in which we dump updated variables right before reset, it is possible, and has been repeatedly demonstrated with SSD-based USB 3.0 devices, that the updated file does not actually end up being written to permanent storage, due to the device write-cache not having enough time to be flushed before reset. To compensate for this, since we don't know of a generic method that would allow turning off USB mass storage devices write cache (and also because we are seeing an issue that seems related for SD-based media), we add a new reset delay PCD, which can be set by the user, and which we also set as required when NV variables are being dumped. Our testing show that, with more than 3 seconds of extra delay, the storage media has enough time to finalize its internal write, thus solving the issue of configuration changes not being persisted. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c | 2= 4 ++++++++++++++++++++ Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.inf | = 1 + Platform/RaspberryPi/Library/ResetLib/ResetLib.c | 1= 1 +++++++++ Platform/RaspberryPi/Library/ResetLib/ResetLib.inf | = 5 ++++ Platform/RaspberryPi/RPi3/RPi3.dsc | = 6 +++++ Platform/RaspberryPi/RPi4/RPi4.dsc | = 6 +++++ Platform/RaspberryPi/RaspberryPi.dec | = 1 + 7 files changed, 54 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServic= eDxe.c b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe= .c index 07f3f1c24295..4071a3fca468 100644 --- a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c +++ b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c @@ -10,6 +10,18 @@ #include "VarBlockService.h" +// +// Minimum delay to enact before reset, when variables are dirty (in =ECs)= . +// Needed to ensure that SSD-based USB 3.0 devices have time to flush thei= r +// write cache after updating the NV vars. A much smaller delay is applied +// on Pi 3 compared to Pi 4, as we haven't had reports of issues there yet= . +// +#if (RPI_MODEL =3D=3D 3) +#define PLATFORM_RESET_DELAY 500000 +#else +#define PLATFORM_RESET_DELAY 3500000 +#endif + VOID *mSFSRegistration; @@ -154,6 +166,7 @@ DumpVars ( ) { EFI_STATUS Status; + RETURN_STATUS PcdStatus; if (mFvInstance->Device =3D=3D NULL) { DEBUG ((DEBUG_INFO, "Variable store not found?\n")); @@ -173,6 +186,17 @@ DumpVars ( } DEBUG ((DEBUG_INFO, "Variables dumped!\n")); + + // + // Add a reset delay to give time for slow/cached devices + // to flush the NV variables write to permanent storage. + // But only do so if this won't reduce an existing user-set delay. + // + if (PcdGet32 (PcdPlatformResetDelay) < PLATFORM_RESET_DELAY) { + PcdStatus =3D PcdSet32S (PcdPlatformResetDelay, PLATFORM_RESET_DELAY); + ASSERT_RETURN_ERROR (PcdStatus); + } + mFvInstance->Dirty =3D FALSE; } diff --git a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServic= eDxe.inf b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceD= xe.inf index ecfb8f85c9c1..c2edb25bd41d 100644 --- a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.in= f +++ b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.in= f @@ -79,6 +79,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 [FeaturePcd] diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c b/Platform/Ra= spberryPi/Library/ResetLib/ResetLib.c index c62a92321ecb..4a50166dd63b 100644 --- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c +++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ LibResetSystem ( ) { ARM_SMC_ARGS ArmSmcArgs; + UINT32 Delay; if (!EfiAtRuntime ()) { /* @@ -52,6 +54,15 @@ LibResetSystem ( EfiEventGroupSignal (&gRaspberryPiEventResetGuid); } + Delay =3D PcdGet32 (PcdPlatformResetDelay); + if (Delay !=3D 0) { + DEBUG ((DEBUG_INFO, "Platform will be reset in %d.%d seconds...\n", + Delay / 1000000, (Delay % 1000000) / 100000)); + MicroSecondDelay (Delay); + } + DEBUG ((DEBUG_INFO, "Platform %a.\n", + (ResetType =3D=3D EfiResetShutdown) ? "shutdown" : "reset")); + switch (ResetType) { case EfiResetPlatformSpecific: // Map the platform specific reset as reboot diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf b/Platform/= RaspberryPi/Library/ResetLib/ResetLib.inf index b02a06d9d0bf..9bdb94a52ebf 100644 --- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf +++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf @@ -33,8 +33,13 @@ [LibraryClasses] DebugLib BaseLib ArmSmcLib + PcdLib + TimerLib UefiLib UefiRuntimeLib [Guids] gRaspberryPiEventResetGuid + +[Pcd] + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay ## CONSUMES diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 9408138d0a09..530b42796a0d 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -508,6 +508,12 @@ [PcdsDynamicHii.common.DEFAULT] gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0 gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gConfigDxeFormSetGuid|0= x0|0 + # + # Reset-related. + # + + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index ddf4dd6a416e..5f8452aa0b76 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -522,6 +522,12 @@ [PcdsDynamicHii.common.DEFAULT] gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"|gConfigDxeFormSetGu= id|0x0|0 gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gConfigDxeFormSetGuid|0= x0|60 + # + # Reset-related. + # + + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index c64c61930ea8..10723036aa31 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -68,3 +68,4 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, Pc= dsDynamicEx] gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001A gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C gRaspberryPiTokenSpaceGuid.PcdFanTemp|0|UINT32|0x0000001D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|0|UINT32|0x0000001E -- 2.29.2.windows.2 --_000_SN7PR05MB75821FB4B4C780350D5AC01AB9DD0SN7PR05MB7582namp_ Content-Type: text/html; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable
Sure. I wish there was something more precise, I'm guessing that would at l= east be very different between USB and SD/MMC...

Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>

From: Pete Batard <pete@= akeo.ie>
Sent: Tuesday, December 22, 2020 7:45 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: ard.biesheuvel@arm.com <ard.biesheuvel@arm.com>; leif@nuvi= ainc.com <leif@nuviainc.com>; samer.el-haj-mahmoud@arm.com <samer.= el-haj-mahmoud@arm.com>; Andrei Warkentin <awarkentin@vmware.com><= br> Subject: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Add syste= m/user defined reset delay
 
Due to the method in which NV variables are stored= on removable media
for the Raspberry Pi platform, and the manner in which we dump updated
variables right before reset, it is possible, and has been repeatedly
demonstrated with SSD-based USB 3.0 devices, that the updated file does
not actually end up being written to permanent storage, due to the
device write-cache not having enough time to be flushed before reset.

To compensate for this, since we don't know of a generic method that
would allow turning off USB mass storage devices write cache (and also
because we are seeing an issue that seems related for SD-based media),
we add a new reset delay PCD, which can be set by the user, and which
we also set as required when NV variables are being dumped.

Our testing show that, with more than 3 seconds of extra delay, the
storage media has enough time to finalize its internal write, thus
solving the issue of configuration changes not being persisted.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c&= nbsp;  | 24 ++++++++++++++++++++
 Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.in= f |  1 +
 Platform/RaspberryPi/Library/ResetLib/ResetLib.c   &nb= sp;            =        | 11 +++++++++
 Platform/RaspberryPi/Library/ResetLib/ResetLib.inf   &= nbsp;           &nbs= p;     |  5 ++++
 Platform/RaspberryPi/RPi3/RPi3.dsc      = ;            &n= bsp;            = ;      |  6 +++++
 Platform/RaspberryPi/RPi4/RPi4.dsc      = ;            &n= bsp;            = ;      |  6 +++++
 Platform/RaspberryPi/RaspberryPi.dec     &nb= sp;            =             &nb= sp;    |  1 +
 7 files changed, 54 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServic= eDxe.c b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe= .c
index 07f3f1c24295..4071a3fca468 100644
--- a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c<= br> +++ b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.c<= br> @@ -10,6 +10,18 @@
 

 #include "VarBlockService.h"

 

+//

+// Minimum delay to enact before reset, when variables are dirty (in =ECs)= .

+// Needed to ensure that SSD-based USB 3.0 devices have time to flush thei= r

+// write cache after updating the NV vars. A much smaller delay is applied=

+// on Pi 3 compared to Pi 4, as we haven't had reports of issues there yet= .

+//

+#if (RPI_MODEL =3D=3D 3)

+#define PLATFORM_RESET_DELAY     500000

+#else

+#define PLATFORM_RESET_DELAY    3500000

+#endif

+

 VOID *mSFSRegistration;

 

 

@@ -154,6 +166,7 @@ DumpVars (
   )

 {

   EFI_STATUS Status;

+  RETURN_STATUS PcdStatus;

 

   if (mFvInstance->Device =3D=3D NULL) {

     DEBUG ((DEBUG_INFO, "Variable store not found= ?\n"));

@@ -173,6 +186,17 @@ DumpVars (
   }

 

   DEBUG ((DEBUG_INFO, "Variables dumped!\n"));

+

+  //

+  // Add a reset delay to give time for slow/cached devices

+  // to flush the NV variables write to permanent storage.

+  // But only do so if this won't reduce an existing user-set delay.<= br>
+  //

+  if (PcdGet32 (PcdPlatformResetDelay) < PLATFORM_RESET_DELAY) {
+    PcdStatus =3D PcdSet32S (PcdPlatformResetDelay, PLATFOR= M_RESET_DELAY);

+    ASSERT_RETURN_ERROR (PcdStatus);

+  }

+

   mFvInstance->Dirty =3D FALSE;

 }

 

diff --git a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServic= eDxe.inf b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceD= xe.inf
index ecfb8f85c9c1..c2edb25bd41d 100644
--- a/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.in= f
+++ b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.in= f
@@ -79,6 +79,7 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
   gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase

+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay

   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64=

 

 [FeaturePcd]

diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c b/Platform/Ra= spberryPi/Library/ResetLib/ResetLib.c
index c62a92321ecb..4a50166dd63b 100644
--- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.c
+++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.c
@@ -16,6 +16,7 @@
 

 #include <Library/BaseLib.h>

 #include <Library/DebugLib.h>

+#include <Library/TimerLib.h>

 #include <Library/EfiResetSystemLib.h>

 #include <Library/ArmSmcLib.h>

 #include <Library/UefiLib.h>

@@ -44,6 +45,7 @@ LibResetSystem (
   )

 {

   ARM_SMC_ARGS ArmSmcArgs;

+  UINT32 Delay;

 

   if (!EfiAtRuntime ()) {

     /*

@@ -52,6 +54,15 @@ LibResetSystem (
     EfiEventGroupSignal (&gRaspberryPiEventResetGu= id);

   }

 

+  Delay =3D PcdGet32 (PcdPlatformResetDelay);

+  if (Delay !=3D 0) {

+    DEBUG ((DEBUG_INFO, "Platform will be reset in %d.= %d seconds...\n",

+            Delay /= 1000000, (Delay % 1000000) / 100000));

+    MicroSecondDelay (Delay);

+  }

+  DEBUG ((DEBUG_INFO, "Platform %a.\n",

+          (ResetType =3D=3D E= fiResetShutdown) ? "shutdown" : "reset"));

+

   switch (ResetType) {

   case EfiResetPlatformSpecific:

     // Map the platform specific reset as reboot

diff --git a/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf b/Platform/= RaspberryPi/Library/ResetLib/ResetLib.inf
index b02a06d9d0bf..9bdb94a52ebf 100644
--- a/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf
+++ b/Platform/RaspberryPi/Library/ResetLib/ResetLib.inf
@@ -33,8 +33,13 @@ [LibraryClasses]
   DebugLib

   BaseLib

   ArmSmcLib

+  PcdLib

+  TimerLib

   UefiLib

   UefiRuntimeLib

 

 [Guids]

   gRaspberryPiEventResetGuid

+

+[Pcd]

+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay   &= nbsp;  ## CONSUMES

diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc
index 9408138d0a09..530b42796a0d 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -508,6 +508,12 @@ [PcdsDynamicHii.common.DEFAULT]
   gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"= |gConfigDxeFormSetGuid|0x0|0

   gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gCo= nfigDxeFormSetGuid|0x0|0

 

+  #

+  # Reset-related.

+  #

+

+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay&= quot;|gRaspberryPiTokenSpaceGuid|0x0|0

+

   #

   # Common UEFI ones.

   #

diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc
index ddf4dd6a416e..5f8452aa0b76 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -522,6 +522,12 @@ [PcdsDynamicHii.common.DEFAULT]
   gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|L"FanOnGpio"= |gConfigDxeFormSetGuid|0x0|0

   gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gCo= nfigDxeFormSetGuid|0x0|60

 

+  #

+  # Reset-related.

+  #

+

+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay&= quot;|gRaspberryPiTokenSpaceGuid|0x0|0

+

   #

   # Common UEFI ones.

   #

diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec
index c64c61930ea8..10723036aa31 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -68,3 +68,4 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, Pc= dsDynamicEx]
   gRaspberryPiTokenSpaceGuid.PcdRamLimitTo3GB|0|UINT32|0x0000001= A

   gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C
   gRaspberryPiTokenSpaceGuid.PcdFanTemp|0|UINT32|0x0000001D

+  gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|0|UINT32|0x0000001= E

--
2.29.2.windows.2

--_000_SN7PR05MB75821FB4B4C780350D5AC01AB9DD0SN7PR05MB7582namp_--