From nobody Mon Feb 9 11:06:30 2026 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+82535+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+82535+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1634917621; cv=none; d=zohomail.com; s=zohoarc; b=BeO3OVo76LddTCzmhBEQ8SEHRq07nGIterS1eE6ph1lpu0H6Nm8ycUtLYtiG3/oMCHrRL+uwoYQNfMKc/Q124yf3kzPhKRlbBFdNbcZm1ciyNOOX9Trfh9IFSBGrirOrRX2iX4u/yl605McPYXqbLZJB4cepLoOYrvGjxL4r1DU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634917621; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hs4B++wJk+oRSfOJ8sIFcaUQ7y6GYHaC4W+74eFbItI=; b=NMFnSzC4cMFGrCCwq9TqtuKBSbU4uHlIDQHTguvwpPLNzG7vt41ppUKrCCaJ+poEoFJNxzS35FKnGv69ClEceGHeBMRd7AwF/eXBlHKimgU/yVhqePkjGEbUJuy7JRgBVodNnRkU2lliTg/kcxorv0fuwjWd05xLVb+LYStaOA4= 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+82535+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 1634917621041353.15613441635173; Fri, 22 Oct 2021 08:47:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OcURYY1788612xNXJ12LUQYC; Fri, 22 Oct 2021 08:47:00 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.10216.1634917618991189270 for ; Fri, 22 Oct 2021 08:46:59 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10145"; a="209428373" X-IronPort-AV: E=Sophos;i="5.87,173,1631602800"; d="scan'208";a="209428373" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2021 08:46:43 -0700 X-IronPort-AV: E=Sophos;i="5.87,173,1631602800"; d="scan'208";a="445333081" X-Received: from gdong1-mobl1.amr.corp.intel.com ([10.212.41.65]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Oct 2021 08:46:42 -0700 From: "Guo Dong" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Maurice Ma , Benjamin You Subject: [edk2-devel] [`edk2-devel][PATCH V3 5/8] UefiPayloadPkg: Add FlashDeviceLib Date: Fri, 22 Oct 2021 08:46:24 -0700 Message-Id: <20211022154627.1607-6-guo.dong@intel.com> In-Reply-To: <20211022154627.1607-1-guo.dong@intel.com> References: <20211022154627.1607-1-guo.dong@intel.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,guo.dong@intel.com X-Gm-Message-State: xyCR1UTtXNpcwNZO01Mqu3mOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634917620; bh=U0kUq1f/Nxcgizi2q0tJmzgWQpPA2gAwGFGCYzgO48Q=; h=Cc:Date:From:Reply-To:Subject:To; b=H2nw91svg5d2YkVZK5qLEl2yz50sVcGikYKuCVJmELoUYuTQzaYYvLqxj1F/H2RJq7p X8zJQlmtG5jgPIZL3aLo5qeJ+N28HIxHZnwMNqfBXSGEqrGDQVtI0s4bHzIhTK5wYudeh 0fpKJTr8rYHeFwJQwz3I1rwSZosr4poEeDM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634917622260100011 Content-Type: text/plain; charset="utf-8" From: Guo Dong This library provides FlashDeviceLib APIs based on SpiFlashLib and consumed by FVB driver. Signed-off-by: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Reviewed-by: Ray Ni Reviewed-by: Benjamin You --- .../Include/Library/FlashDeviceLib.h | 108 ++++++++++++ .../Library/FlashDeviceLib/FlashDeviceLib.c | 165 ++++++++++++++++++ .../Library/FlashDeviceLib/FlashDeviceLib.inf | 38 ++++ 3 files changed, 311 insertions(+) create mode 100644 UefiPayloadPkg/Include/Library/FlashDeviceLib.h create mode 100644 UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.c create mode 100644 UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.inf diff --git a/UefiPayloadPkg/Include/Library/FlashDeviceLib.h b/UefiPayloadP= kg/Include/Library/FlashDeviceLib.h new file mode 100644 index 0000000000..d71481c1b6 --- /dev/null +++ b/UefiPayloadPkg/Include/Library/FlashDeviceLib.h @@ -0,0 +1,108 @@ +/** @file + Flash device library class header file. + + Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +#ifndef FLASHDEVICE_LIB_H_ +#define FLASHDEVICE_LIB_H_ + +/** + Read NumBytes bytes of data from the address specified by + PAddress into Buffer. + + @param[in] PAddress The starting physical address of the read. + @param[in,out] NumBytes On input, the number of bytes to read. On ou= tput, the number + of bytes actually read. + @param[out] Buffer The destination data buffer for the read. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceRead ( + IN UINTN PAddress, + IN OUT UINTN *NumBytes, + OUT UINT8 *Buffer + ); + + +/** + Write NumBytes bytes of data from Buffer to the address specified by + PAddresss. + + @param[in] PAddress The starting physical address of the write. + @param[in,out] NumBytes On input, the number of bytes to write. On outp= ut, + the actual number of bytes written. + @param[in] Buffer The source data buffer for the write. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceWrite ( + IN UINTN PAddress, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + + +/** + Erase the block starting at PAddress. + + @param[in] PAddress The starting physical address of the region to be e= rased. + @param[in] LbaLength The length of the region to be erased. This para= meter is necessary + as the physical block size on a flash device could = be different than + the logical block size of Firmware Volume Block pro= tocol. Erase on + flash chip is always performed block by block. Ther= efore, the ERASE + operation to a logical block is converted a number = of ERASE operation + (or a partial erase) on the hardware. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceBlockErase ( + IN UINTN PAddress, + IN UINTN LbaLength +); + + +/** + Lock or unlock the block starting at PAddress. + + @param[in] PAddress The starting physical address of region to be (un)l= ocked. + @param[in] LbaLength The length of the region to be (un)locked. This = parameter is necessary + as the physical block size on a flash device could = be different than + the logical block size of Firmware Volume Block pro= tocol. (Un)Lock on + flash chip is always performed block by block. Ther= efore, the (Un)Lock + operation to a logical block is converted a number = of (Un)Lock operation + (or a partial erase) on the hardware. + @param[in] Lock TRUE to lock. FALSE to unlock. + + @retval EFI_SUCCESS. Opertion is successful. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceBlockLock ( + IN UINTN PAddress, + IN UINTN LbaLength, + IN BOOLEAN Lock +); + +PHYSICAL_ADDRESS +EFIAPI +LibFvbFlashDeviceMemoryMap ( +); + +#endif diff --git a/UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.c b/UefiP= ayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.c new file mode 100644 index 0000000000..065841bc93 --- /dev/null +++ b/UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.c @@ -0,0 +1,165 @@ +/** @file + Flash Device Library based on SPI Flash library. + +Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** + Initialize spi flash device. + + @retval EFI_SUCCESS The tested spi flash device is supporte= d. + @retval EFI_UNSUPPORTED The tested spi flash device is not supp= orted. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceInit ( + VOID + ) +{ + return SpiConstructor (); +} + + +/** + Read NumBytes bytes of data from the address specified by + PAddress into Buffer. + + @param[in] PAddress The starting physical address of the read. + @param[in,out] NumBytes On input, the number of bytes to read. On = output, the number + of bytes actually read. + @param[out] Buffer The destination data buffer for the read. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceRead ( + IN UINTN PAddress, + IN OUT UINTN *NumBytes, + OUT UINT8 *Buffer + ) +{ + EFI_STATUS Status; + UINT32 ByteCount; + UINT32 RgnSize; + UINT32 AddrOffset; + + Status =3D SpiGetRegionAddress (FlashRegionBios, NULL, &RgnSize); + if (EFI_ERROR (Status)) { + return Status; + } + + // BIOS region offset can be calculated by (PAddress - (0x100000000 - Rg= nSize)) + // which equal (PAddress + RgnSize) here. + AddrOffset =3D (UINT32)((UINT32)PAddress + RgnSize); + ByteCount =3D (UINT32)*NumBytes; + return SpiFlashRead (FlashRegionBios, AddrOffset, ByteCount, Buffer); +} + + +/** + Write NumBytes bytes of data from Buffer to the address specified by + PAddresss. + + @param[in] PAddress The starting physical address of the wri= te. + @param[in,out] NumBytes On input, the number of bytes to write. = On output, + the actual number of bytes written. + @param[in] Buffer The source data buffer for the write. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceWrite ( + IN UINTN PAddress, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_STATUS Status; + UINT32 ByteCount; + UINT32 RgnSize; + UINT32 AddrOffset; + + Status =3D SpiGetRegionAddress (FlashRegionBios, NULL, &RgnSize); + if (EFI_ERROR (Status)) { + return Status; + } + + // BIOS region offset can be calculated by (PAddress - (0x100000000 - Rg= nSize)) + // which equal (PAddress + RgnSize) here. + AddrOffset =3D (UINT32)((UINT32)PAddress + RgnSize); + ByteCount =3D (UINT32)*NumBytes; + return SpiFlashWrite (FlashRegionBios, AddrOffset, ByteCount, Buffer); +} + + +/** + Erase the block starting at PAddress. + + @param[in] PAddress The starting physical address of the block t= o be erased. + This library assume that caller garantee tha= t the PAddress + is at the starting address of this block. + @param[in] LbaLength The length of the logical block to be erased. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceBlockErase ( + IN UINTN PAddress, + IN UINTN LbaLength + ) +{ + EFI_STATUS Status; + UINT32 RgnSize; + UINT32 AddrOffset; + + Status =3D SpiGetRegionAddress (FlashRegionBios, NULL, &RgnSize); + if (EFI_ERROR (Status)) { + return Status; + } + + // BIOS region offset can be calculated by (PAddress - (0x100000000 - Rg= nSize)) + // which equal (PAddress + RgnSize) here. + AddrOffset =3D (UINT32)((UINT32)PAddress + RgnSize); + return SpiFlashErase (FlashRegionBios, AddrOffset, (UINT32)LbaLength); +} + + +/** + Lock or unlock the block starting at PAddress. + + @param[in] PAddress The starting physical address of region to b= e (un)locked. + @param[in] LbaLength The length of the logical block to be erased. + @param[in] Lock TRUE to lock. FALSE to unlock. + + @retval EFI_SUCCESS. Opertion is successful. + @retval EFI_DEVICE_ERROR If there is any device errors. + +**/ +EFI_STATUS +EFIAPI +LibFvbFlashDeviceBlockLock ( + IN UINTN PAddress, + IN UINTN LbaLength, + IN BOOLEAN Lock + ) +{ + return EFI_SUCCESS; +} + diff --git a/UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.inf b/Uef= iPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.inf new file mode 100644 index 0000000000..0ad22cffba --- /dev/null +++ b/UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.inf @@ -0,0 +1,38 @@ +## @file +# Library instace of Flash Device Library Class +# +# This library implement the flash device library class for the lakeport p= latform. +#@copyright +# Copyright (c) 2014 - 2021 Intel Corporation. All rights reserved +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D FlashDeviceLib + FILE_GUID =3D BA7CA537-1C65-4a90-9379-622A24A08141 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D FlashDeviceLib | DXE_SMM_DRIVER DXE_R= UNTIME_DRIVER + + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + FlashDeviceLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + DebugLib + BaseMemoryLib + SpiFlashLib + --=20 2.32.0.windows.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 (#82535): https://edk2.groups.io/g/devel/message/82535 Mute This Topic: https://groups.io/mt/86517143/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-