Patchwork [U-Boot] mmc write bug fix

login
register
mail settings
Submitter Ruud Commandeur
Date May 22, 2013, 11:19 a.m.
Message ID <15AE5A936F5E3A42A9144E66875A0A89308FCA@server1-derijp.CLB-Benelux.lokaal>
Download mbox | patch
Permalink /patch/245588/
State Accepted, archived
Delegated to: Andy Fleming
Headers show

Comments

Ruud Commandeur - May 22, 2013, 11:19 a.m.
This patch fixes a bug related to mmc writes.

When doing fatwrites on an SD-Card, MMC bus problems can occur. Depending
on the size of the file, "MMC0: Bus busy timeout!" is reported, resulting
in an SD-Card that is no longer responding.
It appears to be, that set_cluster can be called with a size being zero.
That can be with a file that has a size being an exact multiple
(including 0) of the clustersize, but also for files that are smaller than
the size of one cluster.
The same problem occurs if the "mmc write" command is given with a block
count being 0.

By adding a check for the block count being zero in mmc_write_blocks
(drivers/mmc.c), this problem is solved.

Signed-off-by: Ruud Commandeur <rcommandeur@clb.nl>
Cc: Tom Rini <trini@ti.com>
Cc: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Mats Karrman <Mats.Karrman@tritech.se>
Cc: Andy Fleming <afleming@gmail.com>
Andy Fleming - June 13, 2013, 10:38 p.m.
On Wed, May 22, 2013 at 01:19:43PM +0200, Ruud Commandeur wrote:
> This patch fixes a bug related to mmc writes.
> 
> When doing fatwrites on an SD-Card, MMC bus problems can occur. Depending
> on the size of the file, "MMC0: Bus busy timeout!" is reported, resulting
> in an SD-Card that is no longer responding.
> It appears to be, that set_cluster can be called with a size being zero.
> That can be with a file that has a size being an exact multiple
> (including 0) of the clustersize, but also for files that are smaller than
> the size of one cluster.
> The same problem occurs if the "mmc write" command is given with a block
> count being 0.
> 
> By adding a check for the block count being zero in mmc_write_blocks
> (drivers/mmc.c), this problem is solved.
> 
> Signed-off-by: Ruud Commandeur <rcommandeur@clb.nl>
> Cc: Tom Rini <trini@ti.com>
> Cc: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
> Cc: Mats Karrman <Mats.Karrman@tritech.se>
> Cc: Andy Fleming <afleming@gmail.com>


Please use git to generate patches, if possible. This didn't apply
cleanly, and required that I apply it by hand.

However, applied it is.

Andy

Patch

Index: drivers/mmc/mmc.c
===================================================================
--- drivers/mmc/mmc.c	(revision 9)
+++ drivers/mmc/mmc.c	(revision 35)
@@ -280,10 +280,12 @@ 
 		return 0;
 	}
 
-	if (blkcnt > 1)
-		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
-	else
+	if (blkcnt == 0)
+		return 0;
+	else if (blkcnt == 1)
 		cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK;
+	else
+		cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
 
 	if (mmc->high_capacity)
 		cmd.cmdarg = start;