From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by mx.groups.io with SMTP id smtpd.web12.11456.1608644743379980673 for ; Tue, 22 Dec 2020 05:45:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=u3KbGXLo; spf=pass (domain: akeo.ie, ip: 209.85.128.43, mailfrom: pete@akeo.ie) Received: by mail-wm1-f43.google.com with SMTP id e25so2249443wme.0 for ; Tue, 22 Dec 2020 05:45:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vp6xzCCqtZSEJLkhMC9RFqI+NcgufyzGxhRC2cdGd9w=; b=u3KbGXLoAm4OKk5cHpcN3uFJ6aBZBZxwvyh+5f7qioxMf6FGwopB+GYuBvQcYJYKJs V1+M67HQnnPliEZOSwQqE3ZWljXzUg7oCJqLjC4q15pqZyxA7g74hEIo3g1k1Z9j4H5v /lUX5i2td4Sh/5Z2TPgJFT+y124XnDBD/ej5z9ZsNpaE1R+OKk5haXf42aBuFvI+gZJr 2iSK4kLB1f+p67SzutSKW9de6Bo0Hf19yMyN//JD1TCFd0cx5xg2HWfCB3EU9fG9aHQS 9B2sqbZQkx5QiJ0l5Hao66BZQzr3gswpmk8la3Yc2olJj9sbBMIIjb7lz/2npQ+bGIrJ Sr5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vp6xzCCqtZSEJLkhMC9RFqI+NcgufyzGxhRC2cdGd9w=; b=YzzwzxUBdLJLLyhZXU3G9MRGNyaorpjnr22Y/gu5NqWLV7ze7HX1bzWbdOCOQaRvd4 5Rzo5ndqQK2ubSGsmEXuILb1z9YJ7xI9uAhB4UQC0/4caK+C7/mqlldFaREK1emUFfG4 9lQ6kYx/33byW/7g2/Z+vfOoGfeTK2599rWlPRJgvXZ3SCaxk8k+Id/XAg4KwmnLRWWV YXR3OnC2oIUfRtQBq5bT8fRipKtCpyP8OcPqL5iHxQeYo9QYvZ+w9awulOE1spzvzsxd 8BZyD2hyzF3k33GMfI0LgdWsJLca3eSlDrYHc7iIB8oi2X+mXmneOFKtX8vmnNPNeZ4Z N8bA== X-Gm-Message-State: AOAM531X+y2F+aibwsJnvJB+O7W5tGkJ7QiG8C1cAtGuH4whcW6Z1VQY OBPjT9Gu2pOTbCvyirziiPeKbdfY4zWGlQ== X-Google-Smtp-Source: ABdhPJwz2NIBhHGzWdgDT1YrciV9/pQrBIlNAaq+HbGAyDN8KsQg6OSk5j0mh3a9ZfcrFROtEjbk8A== X-Received: by 2002:a7b:c7d3:: with SMTP id z19mr22189382wmk.31.1608644741462; Tue, 22 Dec 2020 05:45:41 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.84.133]) by smtp.gmail.com with ESMTPSA id m21sm26655096wml.13.2020.12.22.05.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 05:45:40 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, samer.el-haj-mahmoud@arm.com, awarkentin@vmware.com Subject: [edk2-platforms][PATCH 1/1] Platform/RaspberryPi: Add system/user defined reset delay Date: Tue, 22 Dec 2020 13:45:28 +0000 Message-Id: <20201222134528.793-1-pete@akeo.ie> X-Mailer: git-send-email 2.29.2.windows.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 @@ =0D #include "VarBlockService.h"=0D =0D +//=0D +// Minimum delay to enact before reset, when variables are dirty (in =CE= =BCs).=0D +// Needed to ensure that SSD-based USB 3.0 devices have time to flush thei= r=0D +// write cache after updating the NV vars. A much smaller delay is applied= =0D +// on Pi 3 compared to Pi 4, as we haven't had reports of issues there yet= .=0D +//=0D +#if (RPI_MODEL =3D=3D 3)=0D +#define PLATFORM_RESET_DELAY 500000=0D +#else=0D +#define PLATFORM_RESET_DELAY 3500000=0D +#endif=0D +=0D VOID *mSFSRegistration;=0D =0D =0D @@ -154,6 +166,7 @@ DumpVars ( )=0D {=0D EFI_STATUS Status;=0D + RETURN_STATUS PcdStatus;=0D =0D if (mFvInstance->Device =3D=3D NULL) {=0D DEBUG ((DEBUG_INFO, "Variable store not found?\n"));=0D @@ -173,6 +186,17 @@ DumpVars ( }=0D =0D DEBUG ((DEBUG_INFO, "Variables dumped!\n"));=0D +=0D + //=0D + // Add a reset delay to give time for slow/cached devices=0D + // to flush the NV variables write to permanent storage.=0D + // But only do so if this won't reduce an existing user-set delay.=0D + //=0D + if (PcdGet32 (PcdPlatformResetDelay) < PLATFORM_RESET_DELAY) {=0D + PcdStatus =3D PcdSet32S (PcdPlatformResetDelay, PLATFORM_RESET_DELAY);= =0D + ASSERT_RETURN_ERROR (PcdStatus);=0D + }=0D +=0D mFvInstance->Dirty =3D FALSE;=0D }=0D =0D 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.inf +++ b/Platform/RaspberryPi/Drivers/VarBlockServiceDxe/VarBlockServiceDxe.inf @@ -79,6 +79,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase=0D gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogBase=0D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64=0D =0D [FeaturePcd]=0D 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 @@ =0D #include =0D #include =0D +#include =0D #include =0D #include =0D #include =0D @@ -44,6 +45,7 @@ LibResetSystem ( )=0D {=0D ARM_SMC_ARGS ArmSmcArgs;=0D + UINT32 Delay;=0D =0D if (!EfiAtRuntime ()) {=0D /*=0D @@ -52,6 +54,15 @@ LibResetSystem ( EfiEventGroupSignal (&gRaspberryPiEventResetGuid);=0D }=0D =0D + Delay =3D PcdGet32 (PcdPlatformResetDelay);=0D + if (Delay !=3D 0) {=0D + DEBUG ((DEBUG_INFO, "Platform will be reset in %d.%d seconds...\n",=0D + Delay / 1000000, (Delay % 1000000) / 100000));=0D + MicroSecondDelay (Delay);=0D + }=0D + DEBUG ((DEBUG_INFO, "Platform %a.\n",=0D + (ResetType =3D=3D EfiResetShutdown) ? "shutdown" : "reset"));=0D +=0D switch (ResetType) {=0D case EfiResetPlatformSpecific:=0D // Map the platform specific reset as reboot=0D 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=0D BaseLib=0D ArmSmcLib=0D + PcdLib=0D + TimerLib=0D UefiLib=0D UefiRuntimeLib=0D =0D [Guids]=0D gRaspberryPiEventResetGuid=0D +=0D +[Pcd]=0D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay ## CONSUMES=0D 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=0D gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gConfigDxeFormSetGuid|0= x0|0=0D =0D + #=0D + # Reset-related.=0D + #=0D +=0D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0=0D +=0D #=0D # Common UEFI ones.=0D #=0D 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=0D gRaspberryPiTokenSpaceGuid.PcdFanTemp|L"FanTemp"|gConfigDxeFormSetGuid|0= x0|60=0D =0D + #=0D + # Reset-related.=0D + #=0D +=0D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0=0D +=0D #=0D # Common UEFI ones.=0D #=0D 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=0D gRaspberryPiTokenSpaceGuid.PcdFanOnGpio|0|UINT32|0x0000001C=0D gRaspberryPiTokenSpaceGuid.PcdFanTemp|0|UINT32|0x0000001D=0D + gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|0|UINT32|0x0000001E=0D --=20 2.29.2.windows.2