From nobody Fri Dec 27 02:06:21 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1502157887812766.9835757652768; Mon, 7 Aug 2017 19:04:47 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E2DE121DFE91C; Mon, 7 Aug 2017 19:02:28 -0700 (PDT) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 52D6621DFE909 for ; Mon, 7 Aug 2017 19:02:27 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2017 19:04:43 -0700 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by fmsmga001.fm.intel.com with ESMTP; 07 Aug 2017 19:04:41 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,340,1498546800"; d="scan'208";a="1180077126" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 8 Aug 2017 10:04:38 +0800 Message-Id: <20170808020438.14540-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg/EmmcDxe: Use Trim instead of Erase for EraseBlocks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , Ruiyu Ni , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The current implementation of the Erase Block Protocol service EraseBlocks() uses the erase command. According to spec eMMC Electrical Standard 5.1, Section 6.6.9: The erasable unit of the eMMC is the "Erase Group"; Erase group is measured in write blocks that are the basic writable units of the Device. However, code logic in function EmmcEraseBlocks() does not check whether the starting logical block address to be erased and/or the size in bytes to be erased is aligned with the erase group. Missing such checks will erase the data on additional blocks on an eMMC device. This commit will use the Trim command instead to perform the block erase for eMMC devices. Unlike the Erase command, according to spec eMMC Electrical Standard 5.1, Section 6.6.10: The Trim operation is similar to the default erase operation described in 6.6.9. The Trim function applies the erase operation to write blocks instead of erase groups. Also, the Trim operation is mandatory for eMMC devices according to spec eMMC Electrical Standard 5.1, Chapter 11, Table 220. Cc: Star Zeng Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Jun Nie --- MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c b/MdeModulePkg/Bus/S= d/EmmcDxe/EmmcBlockIo.c index c432d26801..5fd6a1eeaa 100644 --- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c +++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c @@ -1848,9 +1848,15 @@ EmmcEraseBlock ( EraseBlock->Packet.SdMmcStatusBlk =3D &EraseBlock->SdMmcStatusBlk; EraseBlock->Packet.Timeout =3D EMMC_GENERIC_TIMEOUT; =20 - EraseBlock->SdMmcCmdBlk.CommandIndex =3D EMMC_ERASE; - EraseBlock->SdMmcCmdBlk.CommandType =3D SdMmcCommandTypeAc; - EraseBlock->SdMmcCmdBlk.ResponseType =3D SdMmcResponseTypeR1b; + EraseBlock->SdMmcCmdBlk.CommandIndex =3D EMMC_ERASE; + // + // Perform a Trim operation which applies the erase operation to write b= locks + // instead of erase groups. (Spec JESD84-B51, eMMC Electrical Standard 5= .1, + // Section 6.6.10 and 6.10.4) + // + EraseBlock->SdMmcCmdBlk.CommandArgument =3D 1; + EraseBlock->SdMmcCmdBlk.CommandType =3D SdMmcCommandTypeAc; + EraseBlock->SdMmcCmdBlk.ResponseType =3D SdMmcResponseTypeR1b; =20 EraseBlock->IsEnd =3D IsEnd; EraseBlock->Token =3D Token; --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel