public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/EmmcDxe: Use Trim instead of Erase for EraseBlocks
@ 2017-08-08  2:04 Hao Wu
  2017-08-10  3:38 ` Jun Nie
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Wu @ 2017-08-08  2:04 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Star Zeng, Ruiyu Ni

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 <star.zeng@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 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/Sd/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 = &EraseBlock->SdMmcStatusBlk;
   EraseBlock->Packet.Timeout        = EMMC_GENERIC_TIMEOUT;
 
-  EraseBlock->SdMmcCmdBlk.CommandIndex = EMMC_ERASE;
-  EraseBlock->SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
-  EraseBlock->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  EraseBlock->SdMmcCmdBlk.CommandIndex    = EMMC_ERASE;
+  //
+  // Perform a Trim operation which applies the erase operation to write blocks
+  // instead of erase groups. (Spec JESD84-B51, eMMC Electrical Standard 5.1,
+  // Section 6.6.10 and 6.10.4)
+  //
+  EraseBlock->SdMmcCmdBlk.CommandArgument = 1;
+  EraseBlock->SdMmcCmdBlk.CommandType     = SdMmcCommandTypeAc;
+  EraseBlock->SdMmcCmdBlk.ResponseType    = SdMmcResponseTypeR1b;
 
   EraseBlock->IsEnd = IsEnd;
   EraseBlock->Token = Token;
-- 
2.12.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] MdeModulePkg/EmmcDxe: Use Trim instead of Erase for EraseBlocks
  2017-08-08  2:04 [PATCH] MdeModulePkg/EmmcDxe: Use Trim instead of Erase for EraseBlocks Hao Wu
@ 2017-08-10  3:38 ` Jun Nie
  0 siblings, 0 replies; 2+ messages in thread
From: Jun Nie @ 2017-08-10  3:38 UTC (permalink / raw)
  To: Hao Wu, edk2-devel; +Cc: Ruiyu Ni, Star Zeng

On 2017年08月08日 10:04, Hao Wu wrote:
> 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<star.zeng@intel.com>
> Cc: Ruiyu Ni<ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu<hao.a.wu@intel.com>

Reviewed-by: Jun Nie <jun.nie@linaro.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-10  3:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-08  2:04 [PATCH] MdeModulePkg/EmmcDxe: Use Trim instead of Erase for EraseBlocks Hao Wu
2017-08-10  3:38 ` Jun Nie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox