From nobody Fri Dec 19 20:53:42 2025 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+82294+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+82294+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1634624436; cv=none; d=zohomail.com; s=zohoarc; b=VdfEGAPJo65/8OimSArG96m6M5B5Oc8np2CdaXHl9o1AHgwCvi3J3FVqs3/UomlPO5cWyDQu5yM9/YcGfwR0UA4eKaS72ezq9pbEBBO+/V3LSUxcDNFb9Pa9YEhV8thUEO+2Ffw8IoYJL368PW3mqNEigk3sa4rS1TCn805R5r8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634624436; 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=GhtSWUS7zZyjJRyL+vqrelBrJDWTl2gAXaNXeFI/qVo=; b=b+aFrM7uZHTysztP8iTqKNGTHeAISHF3wIusdqtaWBO3A1kUm5GH9E/SbJEQC+3ZK6GvQURk3nFxv4m0L0rtH9D5DZDGn/Wv5y040VYGE8UUmA4D5umAmNIFCK2s8HWooF0XjIYCXHZmhOv7Ifz/T/zr5Ca3SRmJrqhq4nj6ybg= 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+82294+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 163462443661450.64455903599526; Mon, 18 Oct 2021 23:20:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 088LYY1788612xQYs4K90YxO; Mon, 18 Oct 2021 23:20:36 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web09.6092.1634624434578501013 for ; Mon, 18 Oct 2021 23:20:34 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10141"; a="228703403" X-IronPort-AV: E=Sophos;i="5.85,383,1624345200"; d="scan'208";a="228703403" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2021 23:20:33 -0700 X-IronPort-AV: E=Sophos;i="5.85,383,1624345200"; d="scan'208";a="566783122" X-Received: from gdong1-mobl1.amr.corp.intel.com ([10.213.170.103]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2021 23:20:33 -0700 From: "Guo Dong" To: devel@edk2.groups.io Cc: Guo Dong , Ray Ni , Maurice Ma , Benjamin You Subject: [edk2-devel] [`edk2-devel][PATCH V2 5/8] UefiPayloadPkg: Add FlashDeviceLib Date: Mon, 18 Oct 2021 23:20:12 -0700 Message-Id: <20211019062015.1092-6-guo.dong@intel.com> In-Reply-To: <20211019062015.1092-1-guo.dong@intel.com> References: <20211019062015.1092-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: MvjMSaK5Cm4ZS4MSrRxw68onx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634624436; bh=WKJVrbzhdaoUcqMJCMiDWoXA/muyEYOrGoaVn7u7iww=; h=Cc:Date:From:Reply-To:Subject:To; b=ZX6edh9P64SclZ/6TJjmsHRJwYWUI6FlUoeNBr1jVcK19jlHkk9hsLO2+B5vReAuP4J r6o235m78xALFG5YqJeI6vviY9lnP+9bpt73glHnnb9f5KZNRSagddNy8KCHZl09ATYlu gxQPA17G0FfepNCJUTVdC6gQ0guhuH5IdRQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634624437386100015 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 (#82294): https://edk2.groups.io/g/devel/message/82294 Mute This Topic: https://groups.io/mt/86433937/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-