Advertisement
Guest User

sd read debugging

a guest
Jun 28th, 2010
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.20 KB | None | 0 0
  1. Index: sd-as3525.c
  2. ===================================================================
  3. --- sd-as3525.c (revision 27165)
  4. +++ sd-as3525.c (working copy)
  5. @@ -257,6 +257,32 @@
  6.      return false;
  7.  }
  8.  
  9. +static void sd_set_widebus_mode(IF_MD2(int drive,) int on) {
  10. +#ifndef HAVE_MULTIDRIVE
  11. +    const int drive = 0;
  12. +#endif
  13. +    long response;
  14. +    int ret;
  15. +    if((ret = sd_wait_for_tran_state(drive)) < 0) {
  16. +        send_cmd(drive, SD_SEND_STATUS, card_info[drive].rca, MCI_RESP,
  17. +                    &response);
  18. +        panicf("sd_set_widebus: tran: %d (%ld)", ret, response);
  19. +    }
  20. +    /* CMD55 */              /*  Response is requested due to timing issue  */
  21. +    if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, &response))
  22. +        panicf("sd_set_widebus: app_cmd");
  23. +    /* ACMD6  */
  24. +    if(!send_cmd(drive, SD_SET_BUS_WIDTH, on ? 2 : 0, MCI_RESP, &response))
  25. +        panicf("sd_set_widebus: set_bus_width");
  26. +    /* Now that card is widebus make controller aware */
  27. +    if (on) {
  28. +        MCI_CLOCK(drive) |= MCI_CLOCK_WIDEBUS;
  29. +    } else {
  30. +        MCI_CLOCK(drive) &= ~MCI_CLOCK_WIDEBUS;
  31. +    }
  32. +}
  33. +
  34. +
  35.  #define MCI_FULLSPEED     (MCI_CLOCK_ENABLE | MCI_CLOCK_BYPASS)     /* MCLK   */
  36.  #define MCI_HALFSPEED     (MCI_CLOCK_ENABLE)                        /* MCLK/2 */
  37.  #define MCI_QUARTERSPEED  (MCI_CLOCK_ENABLE | 1)                    /* MCLK/4 */
  38. @@ -362,24 +388,17 @@
  39.      if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_RESP, &response))
  40.          return -10;
  41.  
  42. -    /*  Switch to to 4 bit widebus mode  */
  43. -    if(sd_wait_for_tran_state(drive) < 0)
  44. -        return -11;
  45. +    /* Disable card detect pullup, we don't need it */
  46.      /* CMD55 */             /*  Response is requested due to timing issue  */
  47.      if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, &response))
  48.          return -14;
  49.      /* ACMD42  */
  50.      if(!send_cmd(drive, SD_SET_CLR_CARD_DETECT, 0, MCI_RESP, &response))
  51.          return -15;
  52. -    /* CMD55 */              /*  Response is requested due to timing issue  */
  53. -    if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, &response))
  54. -        return -12;
  55. -    /* ACMD6  */
  56. -    if(!send_cmd(drive, SD_SET_BUS_WIDTH, 2, MCI_RESP, &response))
  57. -        return -13;
  58. -    /* Now that card is widebus make controller aware */
  59. -    MCI_CLOCK(drive) |= MCI_CLOCK_WIDEBUS;
  60.  
  61. +    /*  Switch to to 4 bit widebus mode  */
  62. +    sd_set_widebus_mode(IF_MD2(drive,) 1);
  63. +
  64.      /*
  65.       * enable bank switching
  66.       * without issuing this command, we only have access to 1/4 of the blocks
  67. @@ -874,10 +893,38 @@
  68.      return ret;
  69.  }
  70.  
  71. +#define VERIFY_READ 1
  72. +
  73.  int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
  74.                       void* buf)
  75.  {
  76. -    return sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false);
  77. +    int ret;
  78. +
  79. +    ret = sd_transfer_sectors(IF_MD2(drive,) start, count, buf, false);
  80. +
  81. +#ifdef VERIFY_READ
  82. +    if (ret) /* read failed, no point in verifying? */
  83. +        return ret;
  84. +
  85. +    sd_set_widebus_mode(IF_MD2(drive,) 0); /* verify in 1bit mode */
  86. +
  87. +    while (count) {
  88. +        int transfer = count;
  89. +        if(transfer > UNALIGNED_NUM_SECTORS)
  90. +            transfer = UNALIGNED_NUM_SECTORS;
  91. +
  92. +        sd_transfer_sectors(IF_MD2(drive,) start, transfer, aligned_buffer, false);
  93. +        if (memcmp(buf, aligned_buffer, transfer * 512) != 0)
  94. +            panicf("sd: read verify failed: sec=%ld n=%d!", start, transfer);
  95. +
  96. +        buf   += transfer * 512;
  97. +        count -= transfer;
  98. +        start += transfer;
  99. +    }
  100. +
  101. +    sd_set_widebus_mode(IF_MD2(drive,) 1); /* switch back to 4bit mode */
  102. +#endif
  103. +    return ret;
  104.  }
  105.  
  106.  int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
  107. @@ -908,7 +955,7 @@
  108.          if (memcmp(buf, aligned_buffer, transfer * 512) != 0) {
  109.              /* try the write again in the hope to repair the damage */
  110.              sd_transfer_sectors(IF_MD2(drive,) saved_start, saved_count, saved_buf, true);
  111. -            panicf("sd: verify failed: sec=%ld n=%d!", start, transfer);
  112. +            panicf("sd: write verify failed: sec=%ld n=%d!", start, transfer);
  113.          }
  114.  
  115.          buf   += transfer * 512;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement