From nobody Sun May 12 12:03:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93294+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93294+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1662486880; cv=none; d=zohomail.com; s=zohoarc; b=d3ovOTDum0s6eX7GtcFM1MMujJ0j1cmwvXSl8Tc6mFz4w4MJ+QUR7XkL5PPW6GdaKIjoAXP+rOapIKpJ1Ad+2r5ZhLTnUuR01m2JwhRw9bn7INQra8nT6HAYruw2H6HDohO/mFrhSSjxcMini0eoUPuk7p7TceH7ZVFozditKPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662486880; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=9weAcowICgqrIW5Iq6NZC4t8sMi972YF/t8wigkI6tM=; b=TOq3+kT7dXXNGjmS1akh7SbUXacqHn9w/kzRs9tePvE6Gg/iaLAN+jm0+wG///Z+TSD8fR3LhFAaRda5sKCfzk54cYUdU6F+U4hj8mby2bFSmKxWGx9Vnz0rB+eUs6b4yiV7U4c+2gdPVrstKFdCuH4MfKEW9fWsyEQjtjxhR9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93294+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1662486880430364.2334551780111; Tue, 6 Sep 2022 10:54:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 19RoYY1788612xxaK7KdPmtc; Tue, 06 Sep 2022 10:54:39 -0700 X-Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by mx.groups.io with SMTP id smtpd.web12.2507.1662486878909637046 for ; Tue, 06 Sep 2022 10:54:39 -0700 X-Received: by mail-qt1-f175.google.com with SMTP id h22so8650251qtu.2 for ; Tue, 06 Sep 2022 10:54:38 -0700 (PDT) X-Gm-Message-State: 8Ck0LITWJut0rrqoACUdBltnx1787277AA= X-Google-Smtp-Source: AA6agR40puWQSo6sQ2QBb3EgOdQp7fYcdrmHEzd5h9+41nlrGD2ogH4upO3xkLd9ZhZsgSIpAqDLHw== X-Received: by 2002:a05:622a:4d1:b0:343:6be3:add with SMTP id q17-20020a05622a04d100b003436be30addmr45516383qtx.561.1662486877573; Tue, 06 Sep 2022 10:54:37 -0700 (PDT) X-Received: from aturtleortwo-benjamindomain.. ([2607:f2c0:e98c:e:b132:3785:fa38:a51]) by smtp.gmail.com with ESMTPSA id f1-20020a05620a408100b006bbd0ae9c05sm12700372qko.130.2022.09.06.10.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 10:54:37 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Sai Chaganty , Isaac Oram , Nate DeSimone , Ankit Sinha , Liming Gao , Eric Dong Subject: [edk2-devel][edk2-platforms][PATCH v1] EarlySpiFlashRescueFeaturePkg: Initial commit of new feature Date: Tue, 6 Sep 2022 13:54:24 -0400 Message-Id: <2c29b6d149370083935ef44fe5bfb62b6e8bdb62.1662486848.git.benjamin.doron00@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,benjamin.doron00@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1662486879; bh=SQHtL10In9KbXR4oOZIUhKjA317zS4BMNP/+mTEin4M=; h=Cc:Date:From:Reply-To:Subject:To; b=U1BCJWJgj/5e1NfbDke74KPsqWPlk20NYdWuiqu9tU60Ynj3lZhhswXp4RULhcZFeOD 6xCI4m6lzZ7sHiNtXUl9GbinRqmJLQXK2y9ci2Ti0UPaON8GAnb4e3J/C3BttUOdxIsWl CmYi31GgLm4zQYiYLN/7cytj6kNeXnHygIY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1662486881943100003 Content-Type: text/plain; charset="utf-8" Implement a new debug feature to assist in recovering the SPI flash from broken firmware. This feature is intended to be used with the userspace tool presently in my repo here: https://github.com/benjamindoron/early_flash_rescue. After my planned second project for GSoC 2022 finished early, I chose to implement this feature too with the remaining time. The UEFI shell app implemented for testing and located in that repo works quite well, though quite slow due to the serial port layer. The PEIM seems to be quite broken at present. CPU throws undefined opcode exception for a PciLibRead8() in the PchAcpiBaseSet()... constructor? Specifically, EIP points at `test ebx, 0xf0000f00`. Note that this means that re-entry actually succeeds. Maybe. Cc: Sai Chaganty Cc: Isaac Oram Cc: Nate DeSimone Cc: Ankit Sinha Cc: Liming Gao Cc: Eric Dong Signed-off-by: Benjamin Doron --- .../AdvancedFeaturePkg/AdvancedFeaturePkg.dsc | 1 + .../Include/AdvancedFeatures.dsc | 4 + .../Include/AdvancedFeaturesPcd.dsc | 2 + .../AdvancedFeaturePkg/Include/PostMemory.fdf | 4 + .../AdvancedFeaturePkg/Include/PreMemory.fdf | 4 + .../EarlySpiFlashRescueFeaturePkg.dec | 44 ++++ .../EarlySpiFlashRescueFeaturePkg.dsc | 47 ++++ .../FlashRescueBoardPei/FlashRescueBoard.h | 85 +++++++ .../FlashRescueBoardCommon.c | 236 ++++++++++++++++++ .../FlashRescueBoardPei/FlashRescueBoardPei.c | 211 ++++++++++++++++ .../FlashRescueBoardPei.inf | 53 ++++ .../Include/EarlySpiFlashRescueFeature.dsc | 34 +++ .../Include/PostMemory.fdf | 8 + .../Include/Ppi/FeatureInMemory.h | 23 ++ .../Include/PreMemory.fdf | 8 + .../EarlySpiFlashRescueFeaturePkg/Readme.md | 119 +++++++++ 16 files changed, 883 insertions(+) create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= EarlySpiFlashRescueFeaturePkg.dec create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= EarlySpiFlashRescueFeaturePkg.dsc create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= FlashRescueBoardPei/FlashRescueBoard.h create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= FlashRescueBoardPei/FlashRescueBoardCommon.c create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= FlashRescueBoardPei/FlashRescueBoardPei.c create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= FlashRescueBoardPei/FlashRescueBoardPei.inf create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= Include/EarlySpiFlashRescueFeature.dsc create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= Include/PostMemory.fdf create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= Include/Ppi/FeatureInMemory.h create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= Include/PreMemory.fdf create mode 100644 Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/= Readme.md diff --git a/Features/Intel/AdvancedFeaturePkg/AdvancedFeaturePkg.dsc b/Fea= tures/Intel/AdvancedFeaturePkg/AdvancedFeaturePkg.dsc index 63b36f4c0f7d..3847c39b68ed 100644 --- a/Features/Intel/AdvancedFeaturePkg/AdvancedFeaturePkg.dsc +++ b/Features/Intel/AdvancedFeaturePkg/AdvancedFeaturePkg.dsc @@ -50,6 +50,7 @@ gAcpiDebugFeaturePkgTokenSpaceGuid.PcdAcpiDebugFeatureEnable = |TRUE gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUseSmmVersion = |FALSE gBeepDebugFeaturePkgTokenSpaceGuid.PcdBeepDebugFeatureEnable = |TRUE + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnable= |TRUE gPostCodeDebugFeaturePkgTokenSpaceGuid.PcdPostCodeDebugFeatureEnable = |TRUE gUsb3DebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugFeatureEnable = |TRUE =20 diff --git a/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeatures.dsc= b/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeatures.dsc index 804aab89bc1b..f1fc643394a3 100644 --- a/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeatures.dsc +++ b/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeatures.dsc @@ -21,6 +21,10 @@ !include BeepDebugFeaturePkg/Include/BeepDebugFeature.dsc !endif =20 +!if gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnab= le =3D=3D TRUE + !include EarlySpiFlashRescueFeaturePkg/Include/EarlySpiFlashRescueFeatur= e.dsc +!endif + !if gPostCodeDebugFeaturePkgTokenSpaceGuid.PcdPostCodeDebugFeatureEnable = =3D=3D TRUE !include PostCodeDebugFeaturePkg/Include/PostCodeDebugFeature.dsc !endif diff --git a/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeaturesPcd.= dsc b/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeaturesPcd.dsc index 56743db239b0..798839a6a228 100644 --- a/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeaturesPcd.dsc +++ b/Features/Intel/AdvancedFeaturePkg/Include/AdvancedFeaturesPcd.dsc @@ -22,6 +22,7 @@ # AcpiDebugFeaturePkg/AcpiDebugFeaturePkg.dec BeepDebugFeaturePkg/BeepDebugFeaturePkg.dec + EarlySpiFlashRescueFeaturePkg/EarlySpiFlashRescueFeaturePkg.dec PostCodeDebugFeaturePkg/PostCodeDebugFeaturePkg.dec Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec =20 @@ -66,6 +67,7 @@ gAcpiDebugFeaturePkgTokenSpaceGuid.PcdAcpiDebugFeatureEnable = |FALSE gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUseSmmVersion = |FALSE gBeepDebugFeaturePkgTokenSpaceGuid.PcdBeepDebugFeatureEnable = |FALSE + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnable= |FALSE gPostCodeDebugFeaturePkgTokenSpaceGuid.PcdPostCodeDebugFeatureEnable = |FALSE gUsb3DebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugFeatureEnable = |FALSE =20 diff --git a/Features/Intel/AdvancedFeaturePkg/Include/PostMemory.fdf b/Fea= tures/Intel/AdvancedFeaturePkg/Include/PostMemory.fdf index 349bdcc49105..0188d1c97293 100644 --- a/Features/Intel/AdvancedFeaturePkg/Include/PostMemory.fdf +++ b/Features/Intel/AdvancedFeaturePkg/Include/PostMemory.fdf @@ -22,6 +22,10 @@ !include BeepDebugFeaturePkg/Include/PostMemory.fdf !endif =20 +!if gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnab= le =3D=3D TRUE + !include EarlySpiFlashRescueFeaturePkg/Include/PostMemory.fdf +!endif + !if gPostCodeDebugFeaturePkgTokenSpaceGuid.PcdPostCodeDebugFeatureEnable = =3D=3D TRUE !include PostCodeDebugFeaturePkg/Include/PostMemory.fdf !endif diff --git a/Features/Intel/AdvancedFeaturePkg/Include/PreMemory.fdf b/Feat= ures/Intel/AdvancedFeaturePkg/Include/PreMemory.fdf index b991a5aabf6c..46aa89f0e63f 100644 --- a/Features/Intel/AdvancedFeaturePkg/Include/PreMemory.fdf +++ b/Features/Intel/AdvancedFeaturePkg/Include/PreMemory.fdf @@ -22,6 +22,10 @@ !include BeepDebugFeaturePkg/Include/PreMemory.fdf !endif =20 +!if gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnab= le =3D=3D TRUE + !include EarlySpiFlashRescueFeaturePkg/Include/PostMemory.fdf +!endif + !if gPostCodeDebugFeaturePkgTokenSpaceGuid.PcdPostCodeDebugFeatureEnable = =3D=3D TRUE !include PostCodeDebugFeaturePkg/Include/PreMemory.fdf !endif diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/EarlySp= iFlashRescueFeaturePkg.dec b/Features/Intel/Debugging/EarlySpiFlashRescueFe= aturePkg/EarlySpiFlashRescueFeaturePkg.dec new file mode 100644 index 000000000000..d22a5983b8a3 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/EarlySpiFlashR= escueFeaturePkg.dec @@ -0,0 +1,44 @@ +## @file +# This package provides advanced feature functionality for rescuing SPI fl= ash. +# This package should only depend on EDK II Core packages, IntelSiliconPkg= , and MinPlatformPkg. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + DEC_SPECIFICATION =3D 0x00010017 + PACKAGE_NAME =3D EarlySpiFlashRescueFeaturePkg + PACKAGE_GUID =3D 605FCBD8-1D5A-4B72-9874-8FD7DD4FDABD + PACKAGE_VERSION =3D 0.1 + +[Includes] + Include + +[Guids] + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid =3D {0x3e9700b8, 0x98e2, = 0x4db4, {0x8a, 0x46, 0xfe, 0x10, 0x77, 0x64, 0xe8, 0xd0}} + +[PcdsFeatureFlag] + ## This PCD specifies whether early rescue PEIM is built. + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnable= |FALSE|BOOLEAN|0xB0000001 + +[PcdsFixedAtBuild] + ## This PCD specifies the wait timeout value in millisecond to await a u= serspace. + # Default timeout value is 15000 milliseconds. + # If user does not want system stall for long time, it can be set to sm= all value. + # Delays in 250ms increments between sending HELLO. Less than this deac= tivates the feature. + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdUserspaceHostWaitTimeout= |15000|UINT32|0xB0000002 + + ## This PCD specifies the size in bytes of data packets. + ## Dependent on implementation layer. Synchronise with userspace, user m= ust not change without support. + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdDataXferPacketSize|64|UI= NT16|0xB0000003 + +[Ppis] + ## Include/Ppi/FeatureInMemory.h + gPeiFlashRescueReadyInMemoryPpiGuid =3D {0xe5147285, 0x4d34, 0x415e, {0x= 8e, 0xa8, 0x85, 0xbd, 0xd8, 0xc6, 0x5b, 0xde }} diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/EarlySp= iFlashRescueFeaturePkg.dsc b/Features/Intel/Debugging/EarlySpiFlashRescueFe= aturePkg/EarlySpiFlashRescueFeaturePkg.dsc new file mode 100644 index 000000000000..5c4857a885d4 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/EarlySpiFlashR= escueFeaturePkg.dsc @@ -0,0 +1,47 @@ +## @file +# This package provides advanced feature functionality for rescuing SPI fl= ash. +# This package should only depend on EDK II Core packages, IntelSiliconPkg= , and MinPlatformPkg. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + PLATFORM_NAME =3D EarlySpiFlashRescueFeaturePkg + PLATFORM_GUID =3D E703420D-AEEF-41C5-B8CA-237BE36C64EC + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 0x00010005 + OUTPUT_DIRECTORY =3D Build/$(PLATFORM_NAME) + SUPPORTED_ARCHITECTURES =3D IA32|X64 + BUILD_TARGETS =3D DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER =3D DEFAULT + PEI_ARCH =3D IA32 + DXE_ARCH =3D X64 + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + +# +# MinPlatform common include for required feature PCD +# These PCD must be set before the core include files, CoreCommonLib, +# CorePeiLib, and CoreDxeLib. +# +!include MinPlatformPkg/Include/Dsc/MinPlatformFeaturesPcd.dsc.inc + +# +# Include common libraries +# +!include MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +!include MinPlatformPkg/Include/Dsc/CorePeiLib.dsc +!include MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc + +# +# This package always builds the feature. +# +!include Include/EarlySpiFlashRescueFeature.dsc diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRe= scueBoardPei/FlashRescueBoard.h b/Features/Intel/Debugging/EarlySpiFlashRes= cueFeaturePkg/FlashRescueBoardPei/FlashRescueBoard.h new file mode 100644 index 000000000000..ecc0e16de9e0 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRescueBoa= rdPei/FlashRescueBoard.h @@ -0,0 +1,85 @@ +/** @file + Early SPI flash rescue protocol - board implementation. + + Copyright (c) 2022, Baruch Binyamin Doron.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef FLASH_RESCUE_BOARD_H +#define FLASH_RESCUE_BOARD_H + +#include +#include + +#define SIZE_BLOCK 4096 +#define MS_IN_SECOND 1000 +#define NS_IN_SECOND (1000 * 1000 * 1000) + +#define EARLY_FLASH_RESCUE_PROTOCOL_VERSION 0.50 +#define EARLY_FLASH_RESCUE_COMMAND_HELLO 0x10 +#define EARLY_FLASH_RESCUE_COMMAND_CHECKSUM 0x11 +#define EARLY_FLASH_RESCUE_COMMAND_READ 0x12 +#define EARLY_FLASH_RESCUE_COMMAND_WRITE 0x13 +#define EARLY_FLASH_RESCUE_COMMAND_RESET 0x14 +#define EARLY_FLASH_RESCUE_COMMAND_EXIT 0x15 + +#pragma pack(push, 1) +typedef struct { + UINT8 Command; + UINT16 BlockNumber; // This 4K block in BIOS region +} EARLY_FLASH_RESCUE_COMMAND; + +typedef struct { + UINT8 Acknowledge; // Usually, ACK =3D=3D 0x01 + UINT16 Size; // OPTIONAL? +} EARLY_FLASH_RESCUE_RESPONSE; +#pragma pack(pop) + +/** + Returns a pointer to the PCH SPI PPI. + + @return Pointer to PCH_SPI2_PPI If an instance of the PCH SPI PPI is f= ound + @return NULL If an instance of the PCH SPI PPI is n= ot found + +**/ +PCH_SPI2_PROTOCOL * +GetSpiPpi ( + VOID + ); + +/** + * Perform system reset to start this firmware. +**/ +VOID +EFIAPI +PerformSystemReset ( + VOID + ); + +/** + * Send HELLO command to an awaiting userspace. + * Permit 15s for response. + * + * @return EFI_SUCCESS Command acknowledged. + * @return EFI_TIMEOUT Command timed-out. +**/ +EFI_STATUS +EFIAPI +SendHelloPacket ( + VOID + ); + +/** + * Perform flash. + * + * @return EFI_SUCCESS Successful flash. + * @return EFI_DEVICE_ERROR Successful flash. + * @return EFI_TIMEOUT Await command timed-out. +**/ +EFI_STATUS +EFIAPI +PerformFlash ( + VOID + ); + +#endif diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRe= scueBoardPei/FlashRescueBoardCommon.c b/Features/Intel/Debugging/EarlySpiFl= ashRescueFeaturePkg/FlashRescueBoardPei/FlashRescueBoardCommon.c new file mode 100644 index 000000000000..165636e34134 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRescueBoa= rdPei/FlashRescueBoardCommon.c @@ -0,0 +1,236 @@ +/** @file + Early SPI flash rescue protocol - board implementation. + + Copyright (c) 2022, Baruch Binyamin Doron.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FlashRescueBoard.h" + +// TODO: Appropriate size +static UINT16 XferBlockSize =3D FixedPcdGet16 (PcdDataXferPacketSize); + +/** + * Send HELLO command to an awaiting userspace. + * + * @return EFI_SUCCESS Command acknowledged. + * @return EFI_TIMEOUT Command timed-out. +**/ +EFI_STATUS +EFIAPI +SendHelloPacket ( + VOID + ) +{ + UINT32 WaitTimeout; + EARLY_FLASH_RESCUE_COMMAND CommandPacket; + UINTN TimeCounter; + EARLY_FLASH_RESCUE_RESPONSE ResponsePacket; + + WaitTimeout =3D FixedPcdGet32 (PcdUserspaceHostWaitTimeout); + + // TODO: Consider sending a total `BlockNumber`? + CommandPacket.Command =3D EARLY_FLASH_RESCUE_COMMAND_HELLO; + + for (TimeCounter =3D 0; TimeCounter < WaitTimeout; TimeCounter +=3D 250)= { + // Maybe packet was not in FIFO + SerialPortWrite ((UINT8 *)&CommandPacket, sizeof (CommandPacket)); + + SerialPortRead ((UINT8 *)&ResponsePacket, sizeof (ResponsePacket)); + if (ResponsePacket.Acknowledge =3D=3D 1) { + return EFI_SUCCESS; + } + + MicroSecondDelay (250 * MS_IN_SECOND); + } + + return EFI_TIMEOUT; +} + +/** + * Send the requested block CRC to an awaiting userspace. + * - TODO: NACK blocks as necessary +**/ +VOID +EFIAPI +SendBlockChecksum ( + UINTN BlockNumber + ) +{ + PCH_SPI2_PROTOCOL *Spi2Ppi; + UINTN Address; + UINT8 BlockData[SIZE_BLOCK]; + EFI_STATUS Status; + UINT32 Crc; + EARLY_FLASH_RESCUE_RESPONSE ResponsePacket; + + Spi2Ppi =3D GetSpiPpi (); + if (Spi2Ppi =3D=3D NULL) { + return; + } + + // `BlockNumber` starting in BIOS region + Address =3D BlockNumber * SIZE_BLOCK; + + Status =3D Spi2Ppi->FlashRead ( + Spi2Ppi, + &gFlashRegionBiosGuid, + Address, + SIZE_BLOCK, + BlockData + ); + if (EFI_ERROR (Status)) { + return; + } + + Crc =3D CalculateCrc32 (BlockData, SIZE_BLOCK); + + // Now, acknowledge userspace request and send block CRC + ResponsePacket.Acknowledge =3D 1; + SerialPortWrite ((UINT8 *)&ResponsePacket, sizeof (ResponsePacket)); + SerialPortWrite ((UINT8 *)&Crc, sizeof (Crc)); +} + +/** + * Write the requested SPI flash block. + * - TODO: NACK blocks as necessary +**/ +VOID +EFIAPI +WriteBlock ( + UINTN BlockNumber + ) +{ + PCH_SPI2_PROTOCOL *Spi2Ppi; + UINTN Address; + UINT8 BlockData[SIZE_BLOCK]; + EARLY_FLASH_RESCUE_RESPONSE ResponsePacket; + VOID *XferBlock; + UINTN Index; + EFI_STATUS Status; + + Spi2Ppi =3D GetSpiPpi (); + if (Spi2Ppi =3D=3D NULL) { + return; + } + + // `BlockNumber` starting in BIOS region + Address =3D BlockNumber * SIZE_BLOCK; + + // Acknowledge userspace command and retrieve block + ResponsePacket.Acknowledge =3D 1; + SerialPortWrite ((UINT8 *)&ResponsePacket, sizeof (ResponsePacket)); + + // Start streaming block + XferBlock =3D BlockData; + for (Index =3D 0; Index < SIZE_BLOCK; Index +=3D XferBlockSize) { + // FIXME: This will incur some penalty, but we must wait + // - Still debugging timing parameters, especially at higher baudrate + // - Possible optimisation: Shorter stall if SerialPortPoll() + MicroSecondDelay (33 * MS_IN_SECOND); + + SerialPortRead (XferBlock, XferBlockSize); + XferBlock +=3D XferBlockSize; + + // FIXME: This will incur some penalty, but userspace must wait + ResponsePacket.Acknowledge =3D 1; + SerialPortWrite ((UINT8 *)&ResponsePacket, sizeof (ResponsePacket)); + } + + // SPI flash is is fairly durable, but determine when erase is necessary. + Status =3D Spi2Ppi->FlashErase ( + Spi2Ppi, + &gFlashRegionBiosGuid, + Address, + SIZE_BLOCK + ); + if (EFI_ERROR (Status)) { + return; + } + + Status =3D Spi2Ppi->FlashWrite ( + Spi2Ppi, + &gFlashRegionBiosGuid, + Address, + SIZE_BLOCK, + BlockData + ); +} + +/** + * Perform flash. + * + * @return EFI_SUCCESS Successful flash. + * @return EFI_DEVICE_ERROR Initialise SPI service failed. + * @return EFI_TIMEOUT Await command timed-out. +**/ +EFI_STATUS +EFIAPI +PerformFlash ( + VOID + ) +{ + EFI_STATUS Status; + UINT8 NoUserspaceExit; + UINT64 LastServicedTimeNs; + EARLY_FLASH_RESCUE_COMMAND CommandPacket; + + // + // TODO: Library must reinstall its PPI, backed by NEM/DRAM + // + Status =3D SpiServiceInit (); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + // Userspace-side orchestrates procedure, so no looping over blocks + NoUserspaceExit =3D 1; + + LastServicedTimeNs =3D GetTimeInNanoSecond (GetPerformanceCounter ()); + while (NoUserspaceExit) { + // Check if there is command waiting for us + if (SerialPortPoll ()) { + // Stall a tiny bit, in-case the remainder of the packet is flushing + MicroSecondDelay (10 * MS_IN_SECOND); + + SerialPortRead ((UINT8 *)&CommandPacket, sizeof (CommandPacket)); + switch (CommandPacket.Command) { + case EARLY_FLASH_RESCUE_COMMAND_CHECKSUM: + SendBlockChecksum (CommandPacket.BlockNumber); + break; + case EARLY_FLASH_RESCUE_COMMAND_WRITE: + WriteBlock (CommandPacket.BlockNumber); + break; + case EARLY_FLASH_RESCUE_COMMAND_RESET: + PerformSystemReset (); + // Permit fallthrough + NoUserspaceExit =3D 0; + break; + case EARLY_FLASH_RESCUE_COMMAND_EXIT: + NoUserspaceExit =3D 0; + break; + default: + break; + } + + LastServicedTimeNs =3D GetTimeInNanoSecond (GetPerformanceCounter ()= ); + } + + if ((GetTimeInNanoSecond (GetPerformanceCounter ()) - LastServicedTime= Ns) >=3D + (10ULL * NS_IN_SECOND)) { + // This is very bad. SPI flash could be inconsistent + // - In CAR there's likely too little memory to stash a backup + return EFI_TIMEOUT; + } + } + + return EFI_SUCCESS; +} diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRe= scueBoardPei/FlashRescueBoardPei.c b/Features/Intel/Debugging/EarlySpiFlash= RescueFeaturePkg/FlashRescueBoardPei/FlashRescueBoardPei.c new file mode 100644 index 000000000000..60013e5538d7 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRescueBoa= rdPei/FlashRescueBoardPei.c @@ -0,0 +1,211 @@ +/** @file + Early SPI flash rescue protocol - board implementation. + + Copyright (c) 2022, Baruch Binyamin Doron.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FlashRescueBoard.h" + +STATIC CONST EFI_PEI_PPI_DESCRIPTOR mFlashRescueReadyInMemoryPpiList =3D { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gPeiFlashRescueReadyInMemoryPpiGuid, + NULL +}; + +/** + Returns a pointer to the PCH SPI PPI. + + @return Pointer to PCH_SPI2_PPI If an instance of the PCH SPI PPI is f= ound + @return NULL If an instance of the PCH SPI PPI is n= ot found + +**/ +PCH_SPI2_PPI * +GetSpiPpi ( + VOID + ) +{ + EFI_STATUS Status; + PCH_SPI2_PPI *PchSpi2Ppi; + + Status =3D PeiServicesLocatePpi ( + &gPchSpi2PpiGuid, + 0, + NULL, + (VOID **) &PchSpi2Ppi + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + return PchSpi2Ppi; +} + +/** + * Perform system reset to start this firmware. +**/ +VOID +EFIAPI +PerformSystemReset ( + VOID + ) +{ + // + // PPI may be unavailable, but do not risk UAF. Must use silicon variant + // + ResetCold (); +} + +VOID +InternalPrintVariableData ( + IN UINT8 *Data8, + IN UINTN DataSize + ) +{ + UINTN Index; + + for (Index =3D 0; Index < DataSize; Index++) { + if (Index % 0x10 =3D=3D 0) { + DEBUG ((DEBUG_INFO, "\n%08X:", Index)); + } + DEBUG ((DEBUG_INFO, " %02X", *Data8++)); + } + DEBUG ((DEBUG_INFO, "\n")); +} + +/** + Entry Point function + + @param[in] FileHandle Handle of the file being invoked. + @param[in] PeiServices Describes the list of possible PEI Services. + + @retval EFI_SUCCESS if it completed successfully. + @retval EFI_OUT_OF_RESOURCES if PEIM cannot be reloaded. +**/ +EFI_STATUS +EFIAPI +FlashRescueBoardPeiEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + VOID *FlashRescueReady; + VOID *ThisPeimData; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_PHYSICAL_ADDRESS PeimCopy; + EFI_PEIM_ENTRY_POINT2 PeimEntryPoint; + + // + // Second entry: Enter flash loop + // + Status =3D PeiServicesLocatePpi ( + &gPeiFlashRescueReadyInMemoryPpiGuid, + 0, + NULL, + (VOID **)&FlashRescueReady + ); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "perform flash now. Time to be quiet\n")); + + Status =3D PerformFlash (); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; + } + + // + // First entry: Establish communication with board or don't reload + // + DEBUG ((DEBUG_INFO, "HELLO begins. Re-connect with userspace-side now\n"= )); + MicroSecondDelay (5000 * MS_IN_SECOND); + + Status =3D SendHelloPacket (); + if (EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + // + // Find this PEIM, then obtain a PE context with its data handle + // + Status =3D PeiServicesFfsFindSectionData ( + EFI_SECTION_PE32, + FileHandle, + &ThisPeimData + ); + ASSERT_EFI_ERROR (Status); + + ZeroMem (&ImageContext, sizeof (ImageContext)); + + ImageContext.Handle =3D ThisPeimData; + ImageContext.ImageRead =3D PeCoffLoaderImageReadFromMemory; + + Status =3D PeCoffLoaderGetImageInfo (&ImageContext); + ASSERT_EFI_ERROR (Status); + + // + // Allocate memory from NEM or DRAM + // - RegisterForShadow() is simpler for DRAM, but simplify code paths + // + Status =3D PeiServicesAllocatePages ( + EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINT32)ImageContext.ImageSize), + &PeimCopy + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + DEBUG ((DEBUG_INFO, "there are %d pages for us at 0x%x\n", EFI_SIZE_TO_P= AGES ((UINT32)ImageContext.ImageSize), PeimCopy)); + + // + // Load and relocate into the new buffer + // + ImageContext.ImageAddress =3D PeimCopy; + Status =3D PeCoffLoaderLoadImage (&ImageContext); + ASSERT_EFI_ERROR (Status); + + Status =3D PeCoffLoaderRelocateImage (&ImageContext); + ASSERT_EFI_ERROR (Status); + + // + // Install flag PPI and call entrypoint + // + PeiServicesInstallPpi (&mFlashRescueReadyInMemoryPpiList); + ASSERT_EFI_ERROR (Status); +DEBUG ((DEBUG_INFO, "ATTN: Spewing the PEIM to be executed before invalida= te...\n")); + InternalPrintVariableData ((UINT8 *)(UINTN)ImageContext.ImageAddress, (U= INTN)ImageContext.ImageSize); + InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddres= s, (UINTN)ImageContext.ImageSize); + + DEBUG ((DEBUG_INFO, "ATTN: Spewing the PEIM to be executed after invalid= ate. I think this is same...\n")); + InternalPrintVariableData ((UINT8 *)(UINTN)ImageContext.ImageAddress, (U= INTN)ImageContext.ImageSize); + PeimEntryPoint =3D (EFI_PEIM_ENTRY_POINT2)(UINTN)ImageContext.EntryPoint; + DEBUG ((DEBUG_INFO, "ATTN: Shall jump into our 0x%p entrypoint! ready to= go!\n", PeimEntryPoint)); + Status =3D PeimEntryPoint (FileHandle, PeiServices); + ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_INFO, "ATTN: back from 0x%p entrypoint! good !\n", PeimEnt= ryPoint)); + + // + // Cleanup. It is important that PPIs do not point here + // + Status =3D SpiServiceInit (); + ASSERT_EFI_ERROR (Status); + + Status =3D PeiServicesFreePages ( + PeimCopy, + EFI_SIZE_TO_PAGES ((UINT32)ImageContext.ImageSize) + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRe= scueBoardPei/FlashRescueBoardPei.inf b/Features/Intel/Debugging/EarlySpiFla= shRescueFeaturePkg/FlashRescueBoardPei/FlashRescueBoardPei.inf new file mode 100644 index 000000000000..2bc4ce5e4c26 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/FlashRescueBoa= rdPei/FlashRescueBoardPei.inf @@ -0,0 +1,53 @@ +## @file +# Early SPI flash rescue protocol - board implementation. +# +# Copyright (c) 2022, Baruch Binyamin Doron.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D FlashRescueBoardPei + FILE_GUID =3D D1B51B35-E01A-4633-991F-E1B639B8D3AA + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 0.50 + ENTRY_POINT =3D FlashRescueBoardPeiEntryPoint + +[Sources] + FlashRescueBoardPei.c + FlashRescueBoardCommon.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EarlySpiFlashRescueFeaturePkg/EarlySpiFlashRescueFeaturePkg.dec + IntelSiliconPkg/IntelSiliconPkg.dec + KabylakeSiliconPkg/SiPkg.dec + +[LibraryClasses] + PeimEntryPoint + PeiServicesLib + BaseLib + BaseMemoryLib + CacheMaintenanceLib + DebugLib + MemoryAllocationLib + PeCoffLib + ResetSystemLib + SerialPortLib + SpiLib + TimerLib + +[Ppis] + gPeiFlashRescueReadyInMemoryPpiGuid + +[Guids] + gFlashRegionBiosGuid + +[Pcd] + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdUserspaceHostWaitTimeout + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdDataXferPacketSize + +[Depex] + TRUE diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include= /EarlySpiFlashRescueFeature.dsc b/Features/Intel/Debugging/EarlySpiFlashRes= cueFeaturePkg/Include/EarlySpiFlashRescueFeature.dsc new file mode 100644 index 000000000000..938c0740c7ce --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include/EarlyS= piFlashRescueFeature.dsc @@ -0,0 +1,34 @@ +## @file +# This is a build description file for the SPI flash rescue advanced featu= re. +# This file should be included into another package DSC file to build this= feature. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +##########################################################################= ###### +# +# Defines Section - statements that will be processed to create a Makefile. +# +##########################################################################= ###### +[Defines] +!ifndef $(PEI_ARCH) + !error "PEI_ARCH must be specified to build this feature!" +!endif +!ifndef $(DXE_ARCH) + !error "DXE_ARCH must be specified to build this feature!" +!endif + +##########################################################################= ###### +# +# Components section - list of all components needed by this feature. +# +##########################################################################= ###### +[Components.IA32] + EarlySpiFlashRescueFeaturePkg/FlashRescueBoardPei/FlashRescueBoardPei.inf diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include= /PostMemory.fdf b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/In= clude/PostMemory.fdf new file mode 100644 index 000000000000..6f6e94a51cd3 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include/PostMe= mory.fdf @@ -0,0 +1,8 @@ +## @file +# FDF file for post-memory modules that enable USB3 Debug +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include= /Ppi/FeatureInMemory.h b/Features/Intel/Debugging/EarlySpiFlashRescueFeatur= ePkg/Include/Ppi/FeatureInMemory.h new file mode 100644 index 000000000000..1f68c4abd423 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include/Ppi/Fe= atureInMemory.h @@ -0,0 +1,23 @@ +/** @file + This file declares that this feature is relocated into memory from XIP. + + This PPI is published by the feature PEIM after relocation. There is no + interface, it is used as a global variable. This is necessary to mitigate + possible bugs from flashing over XIP code. + + Copyright (c) 2022, Baruch Binyamin Doron.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __FEATURE_IN_MEMORY_H__ +#define __FEATURE_IN_MEMORY_H__ + +#define PEI_FLASH_RESCUE_READY_IN_MEMORY_PPI_GUID \ + { \ + 0xe5147285, 0x4d34, 0x415e, {0x8e, 0xa8, 0x85, 0xbd, 0xd8, 0xc6, 0x5b,= 0xde } \ + } + +extern EFI_GUID gPeiFlashRescueReadyInMemoryPpiGuid; + +#endif diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include= /PreMemory.fdf b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Inc= lude/PreMemory.fdf new file mode 100644 index 000000000000..28441c0b9ad0 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Include/PreMem= ory.fdf @@ -0,0 +1,8 @@ +## @file +# FDF file for pre-memory modules that enable USB3 Debug. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## diff --git a/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Readme.= md b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Readme.md new file mode 100644 index 000000000000..72d399f4ed40 --- /dev/null +++ b/Features/Intel/Debugging/EarlySpiFlashRescueFeaturePkg/Readme.md @@ -0,0 +1,119 @@ +# Overview +* **Feature Name:** Early SPI Flash Rescue +* **PI Phase(s) Supported:** PEI +* **SMM Required?** No + +More Information: +* [GitHub repo](https://github.com/benjamindoron/early_flash_rescue) + +## Purpose +The Early SPI Flash Rescue feature enables the use of a serial port to +rescue systems from broken firmware by delivering an update image to flash. +With an appropriate serial port library, this is an important capability in +firmware development, as debugging broken images on laptops is inefficient +and wastes the developer's time on tedium. Now, simply flash the image und= er +test, retrieve the broken debug log, then reflash another image. Even befo= re +permanent memory, it is assumed that the right serial port could complete +this task in a few minutes. Presently, optimisation is underway to reduce = the +time for even slow serial ports down from 30 minutes and make this less a +mere proof of concept. + +The feature is intended to be used with the userspace-side [here](https://= github.com/benjamindoron/early_flash_rescue/tree/main/flash_rescue_userspac= e) +presently implemented for POSIX Linux. + +# High-Level Theory of Operation +*_TODO_* +A description of how the device works at a high-level. + +The description should not be constrained to implementation details but pr= ovide a simple mental model of how the +feature is supposed to work. + +## Firmware Volumes +It is the user's responsibility to configure where the module is located. +PEI APRIORI (MinPlatform PreMem BootFV) is recommended, but post-mem FVs +are also expected. + +## Modules +* EarlyFlashRescueBoardPei + +## +*_TODO_* +Each module in the feature should have a section that describes the module= in a level of detail that is useful +to better understand the module source code. + +## +*_TODO_* +Each library in the feature should have a section that describes the libra= ry in a level of detail that is useful +to better understand the library source code. + +## Key Functions +*_TODO_* +A bulleted list of key functions for interacting with the feature. + +Not all features need to be listed. Only functions exposed through externa= l interfaces that are important for feature +users to be aware of. + +## Configuration +*_TODO_* +Information that is useful for configuring the feature. + +Not all configuration options need to be listed. This section is used to p= rovide more background on configuration +options than possible elsewhere. + +## Data Flows +*_TODO_* +Architecturally defined data structures and flows for the feature. + +## Control Flows +*_TODO_* +Key control flows for the feature. + +## Build Flows +*_TODO_* +Any special build flows should be described in this section. + +This is particularly useful for features that use custom build tools or re= quire non-standard tool configuration. If the +standard flow in the feature package template is used, this section may be= empty. + +## Test Point Results +No test points implemented + +## Functional Exit Criteria +*_TODO_* +The testable functionality for the feature. + +This section should provide an ordered list of criteria that a board integ= rator can reference to ensure the feature is +functional on their board. + +## TODO: Feature Enabling Checklist +* In the board DSC file, enable the feature +``` +[PcdsFeatureFlag] + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdFlashRescueFeatureEnable= |TRUE +``` +* In the board FDF file, insert the module into FV (and APRIORI) +``` +APRIORI PEI { + # Optionally, other modules prepended/appended... + INF EarlySpiFlashRescueFeaturePkg/EarlyFlashRescueBoardPei/EarlyFlashRe= scueBoardPei.inf +} + +INF EarlySpiFlashRescueFeaturePkg/EarlyFlashRescueBoardPei/EarlyFlashResc= ueBoardPei.inf +``` + + +## Performance Impact +A general expectation for the impact on overall boot performance due to us= ing this feature. + +This section is expected to provide guidance on: +* How to estimate performance impact due to the feature +* How to measure performance impact of the feature +* How to manage performance impact of the feature + +## Common Optimizations +* In the board DSC file, tune the timeout value and packet size +``` +[PcdsFixedAtBuild] + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdUserspaceHostWaitTimeout= |15000 + gEarlySpiFlashRescueFeaturePkgTokenSpaceGuid.PcdDataXferPacketSize|64 +``` --=20 2.37.2 -=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 (#93294): https://edk2.groups.io/g/devel/message/93294 Mute This Topic: https://groups.io/mt/93507328/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-