Advertisement
Guest User

sd read debugging

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