diff mbox

[V5,1/3] hw/sd.c: Fix erase for high capacity cards

Message ID 1351436388-3636-2-git-send-email-i.mitsyanko@samsung.com
State New
Headers show

Commit Message

Igor Mitsyanko Oct. 28, 2012, 2:59 p.m. UTC
Standard capacity cards SDSC use byte unit address while SDHC and SDXC cards use
block unit address (512 bytes) when setting ERASE_START and ERASE_END with CMD32
and CMD33, we have to account for this.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
---
 hw/sd.c | 17 +++++++++++++----
 hw/sd.h |  1 +
 2 files changed, 14 insertions(+), 4 deletions(-)

Comments

Peter Maydell Oct. 29, 2012, 2:23 p.m. UTC | #1
On 28 October 2012 15:59, Igor Mitsyanko <i.mitsyanko@gmail.com> wrote:
> Standard capacity cards SDSC use byte unit address while SDHC and SDXC cards use
> block unit address (512 bytes) when setting ERASE_START and ERASE_END with CMD32
> and CMD33, we have to account for this.
>
> Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM
diff mbox

Patch

diff --git a/hw/sd.c b/hw/sd.c
index 297580a..b2f211c 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -476,19 +476,28 @@  void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
 
 static void sd_erase(SDState *sd)
 {
-    int i, start, end;
+    int i;
+    uint64_t erase_start = sd->erase_start;
+    uint64_t erase_end = sd->erase_end;
+
     if (!sd->erase_start || !sd->erase_end) {
         sd->card_status |= ERASE_SEQ_ERROR;
         return;
     }
 
-    start = sd_addr_to_wpnum(sd->erase_start);
-    end = sd_addr_to_wpnum(sd->erase_end);
+    if (extract32(sd->ocr, OCR_CCS_BITN, 1)) {
+        /* High capacity memory card: erase units are 512 byte blocks */
+        erase_start *= 512;
+        erase_end *= 512;
+    }
+
+    erase_start = sd_addr_to_wpnum(erase_start);
+    erase_end = sd_addr_to_wpnum(erase_end);
     sd->erase_start = 0;
     sd->erase_end = 0;
     sd->csd[14] |= 0x40;
 
-    for (i = start; i <= end; i++) {
+    for (i = erase_start; i <= erase_end; i++) {
         if (test_bit(i, sd->wp_groups)) {
             sd->card_status |= WP_ERASE_SKIP;
         }
diff --git a/hw/sd.h b/hw/sd.h
index 4eb9679..d9b97e4 100644
--- a/hw/sd.h
+++ b/hw/sd.h
@@ -50,6 +50,7 @@ 
 #define READY_FOR_DATA		(1 << 8)
 #define APP_CMD			(1 << 5)
 #define AKE_SEQ_ERROR		(1 << 3)
+#define OCR_CCS_BITN        30
 
 typedef enum {
     sd_none = -1,