Commit 0b453ffe28bb9227d86ddbe0893bd19c93f04ed7

Authored by Rabin Vincent
Committed by Andy Fleming
1 parent 9b1f942c09

mmc: fix response decoding on little endian

The mmc code defines the response as an array of chars.  However, it
access the response bytes both as (i) an array of four uints (with
casts) and (ii) as individual chars.  The former case is used more
often, including by the driver when it assigns the response.

The char-wise accesses are broken on little endian systems because they
assume that the bytes in the uints are in big endian byte order.

This patch fixes this by changing the response to be an array of four
uints and replacing the char-wise accesses with equivalent uint-wise
accesses.

Signed-off-by: Rabin Vincent <rabin@rab.in>

Showing 2 changed files with 13 additions and 13 deletions Side-by-side Diff

... ... @@ -651,7 +651,7 @@
651 651 mmc->csd[3] = ((uint *)(cmd.response))[3];
652 652  
653 653 if (mmc->version == MMC_VERSION_UNKNOWN) {
654   - int version = (cmd.response[0] >> 2) & 0xf;
  654 + int version = (cmd.response[0] >> 26) & 0xf;
655 655  
656 656 switch (version) {
657 657 case 0:
... ... @@ -676,8 +676,8 @@
676 676 }
677 677  
678 678 /* divide frequency by 10, since the mults are 10x bigger */
679   - freq = fbase[(cmd.response[3] & 0x7)];
680   - mult = multipliers[((cmd.response[3] >> 3) & 0xf)];
  679 + freq = fbase[(cmd.response[0] & 0x7)];
  680 + mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
681 681  
682 682 mmc->tran_speed = freq * mult;
683 683  
... ... @@ -791,13 +791,13 @@
791 791 mmc->block_dev.type = 0;
792 792 mmc->block_dev.blksz = mmc->read_bl_len;
793 793 mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
794   - sprintf(mmc->block_dev.vendor,"Man %02x%02x%02x Snr %02x%02x%02x%02x",
795   - mmc->cid[0], mmc->cid[1], mmc->cid[2],
796   - mmc->cid[9], mmc->cid[10], mmc->cid[11], mmc->cid[12]);
797   - sprintf(mmc->block_dev.product,"%c%c%c%c%c", mmc->cid[3],
798   - mmc->cid[4], mmc->cid[5], mmc->cid[6], mmc->cid[7]);
799   - sprintf(mmc->block_dev.revision,"%d.%d", mmc->cid[8] >> 4,
800   - mmc->cid[8] & 0xf);
  794 + sprintf(mmc->block_dev.vendor, "Man %06x Snr %08x", mmc->cid[0] >> 8,
  795 + (mmc->cid[2] << 8) | (mmc->cid[3] >> 24));
  796 + sprintf(mmc->block_dev.product, "%c%c%c%c%c", mmc->cid[0] & 0xff,
  797 + (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  798 + (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
  799 + sprintf(mmc->block_dev.revision, "%d.%d", mmc->cid[2] >> 28,
  800 + (mmc->cid[2] >> 24) & 0xf);
801 801 init_part(&mmc->block_dev);
802 802  
803 803 return 0;
... ... @@ -91,7 +91,7 @@
91 91 #define MMC_HS_TIMING 0x00000100
92 92 #define MMC_HS_52MHZ 0x2
93 93  
94   -#define OCR_BUSY 0x80
  94 +#define OCR_BUSY 0x80000000
95 95 #define OCR_HCS 0x40000000
96 96  
97 97 #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
... ... @@ -223,7 +223,7 @@
223 223 ushort cmdidx;
224 224 uint resp_type;
225 225 uint cmdarg;
226   - char response[18];
  226 + uint response[4];
227 227 uint flags;
228 228 };
229 229  
... ... @@ -253,7 +253,7 @@
253 253 uint ocr;
254 254 uint scr[2];
255 255 uint csd[4];
256   - char cid[16];
  256 + uint cid[4];
257 257 ushort rca;
258 258 uint tran_speed;
259 259 uint read_bl_len;