b1l1s / qemu

QEMU-CTR - see README.md for more info
Other
12 stars 0 forks source link

SD emulation fails if SD card being emulated is SDHC or SDXC #1

Open gemarcano opened 8 years ago

gemarcano commented 8 years ago

Specifically, the CSD or the CID specify the type of the card, which is ignored by the emulator. This leads to issues with sdmmc.c, where it returns the type of the card as being regular SD when it really should be detected as SDHC or SDXC.

One problem caused by this is that sector calculations for reading and writing are multiplied by 512 if not SDHC or SDXC, which if the card really is one of those can cause for the location information (sector * 512) to overflow. I observed the overflow by stepping through GDB. The same exact binary works on hardware.

I am unable to provide a quick example at the moment. My recommendation to reproduce is to get the CID and CSD of an SDXC card, set the faux card with qemu, then try to do a read or write using sdmmc.c (I was using my own lib's sdmmc.c, based on Normmatt's work). Stepping through the operation should at one point hit a line with if(handelSD.isSDHC == 0) sector_no <<= 9; -- that conditional is only hit if the card isn't SDHC. With an SDXC card that line executes in the emulator, works as intended on hardware.