Skip to contentSkip to conversation

generic mmc bug in reading sd card capacity

U-Boot victor 2 participants 2 messages Nov 2, 2012 – Nov 6, 2012

lore
Share & tools
lore

victor

author
#0 lore raw

Hi All,

Accord to SD spec 2.0, the formula to find out sd card capacity is:

memory capacity = (C_SIZE+1) * 512K byte
and
C_SIZE is from CSD [69:48]

Thus, the code in generic mmc is wrong for the high capacity sd card. My patch is below.

Thanks,
victor

mmc.c.victor renamed from mmc.c +11 -5
@@ -1068,17 +1104,26 @@
 		mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
 
 	if (mmc->high_capacity) {
-		csize = (mmc->csd[1] & 0x3f) << 16
-			| (mmc->csd[2] & 0xffff0000) >> 16;
-		cmult = 8;
+		//csize = (mmc->csd[1] & 0x3f) << 16
+		//	| (mmc->csd[2] & 0xffff0000) >> 16;
+		//cmult = 8;
+                csize = (mmc->csd[2] & 0x3f) << 16
+                      | (mmc->csd[1] & 0xffff0000) >> 16;
 	} else {
 		csize = (mmc->csd[1] & 0x3ff) << 2
 			| (mmc->csd[2] & 0xc0000000) >> 30;
 		cmult = (mmc->csd[2] & 0x00038000) >> 15;
 	}
 
-	mmc->capacity = (csize + 1) << (cmult + 2);
-	mmc->capacity *= mmc->read_bl_len;
+	if (mmc->high_capacity) {
+		mmc->capacity = (csize + 1) * 512 * 1024;
+	} else {
+		mmc->capacity = (csize + 1) << (cmult + 2);
+		mmc->capacity *= mmc->read_bl_len;
+	}
 
 

================================================================================================
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and may be protected by legal privilege. If you are not the intended addressee (or authorized to receive for the addressee). be aware that any disclosure, copying, distribution or use of this e-mail or any attachment is prohibited. If you have received this e-mail in error, please notify us immediately by returning it to the sender and delete this copy from your system. Thank you for your cooperation. KeyASIC Inc.
================================================================================================

#1 lore raw
Quoted 11 lines · victor

Hi All,

Accord to SD spec 2.0, the formula to find out sd card capacity is:

memory capacity = (C_SIZE+1) * 512K byte
and
C_SIZE is from CSD [69:48]

Thus, the code in generic mmc is wrong for the high capacity sd card. My patch is below.

We should be careful about the fact that this only works for SD cards. The size parameter is handled differently on MMC devices larger than 2 GiB. What do you think of the following patch:

(Compile tested only, I do not have a board available for testing right now)

8<----------------------------------------------------------------------