Monday, July 23, 2007

MMC progress...

Well, I'm slowly progressing with my MMC card reading, I've gotten sector reading working okay, and from there read the boot sector with the partition information and then onto the FAT Mast Boot Record. However, I'm struggling to get from there to the root directory. The only info I have says that I use the root FAT+ReservedSectors+FatSectorSize = DirRoot, and while this works for one card, it appears to be coincedance.

Once I can get the root directory, it should be plain sailing to load a file. Each Directory entry points to a base sector (or cluster) and from there you use the FAT to cluster hop, reading in the file. I have to confess, I thought sectors were allocated rather than clusters and that sectors were resizable. But it appears that its the number of sectors in a cluster that changes. oh well, its much the same I guess.

Once I have a file loading, I'm going to build a Plus4 interface - or add it to my MemoryCard expansion, Im not sure...I guess it would be easier to build a seprate interface, although Im having a little trouble figuring out the best way of reading the card. The only way I can figure is using 2 flipflop buffers, one for in and one for out. However, the ChipSelect on the card may help with this, I havent sat down and worked it out yet.

8 comments:

TNT said...

Remember that not all cards have Master Boot Record. Windows tends to format memory cards as Super Floppies, meaning that sector 0 is Partition Boot Record already.

Mike said...

No, I think its more than that. I can find the FAT root okay (the bit with the text "FAT16" in it), but I cant get from there to the root directory properly.

TNT said...

Sector offsets in PBR are relative to it, so the correct offset to root dir is

partitionBase + RsvdSecCnt + NumFATs * FATsize

Do you do the multiply?

Mike said...

I dont think so... Just, just a *2.... I guess my other cards could have different values, I'll try that tonight...

Mike said...

Well, I followed that system but I'm 1 block out on 2 cards (256mb, and 2GB, and 2 on another (32Mb).

I was adding a single block before to account for the FAT BootRecord, but without that...it's 1 out; and I've no idea why the 32Mb one is 2 out.

TNT said...

You do add partitionBase (=sector with PBR) and RsvdSecCnt, right? There shouldn't be reason to add anything else than those fields I listed.

If you can make an image of your 32 MB card then zip it and mail it to me and _I will have a look.

Mike said...

lol....Yep, thats it... NO idea what I was doing wrong there. I rewrote it, and it worked :)

Whoops... Cheers (again) dude.

BTW. Whats your ebay handle, so I dont end up bidding against you for stuff :)

TNT said...

My ebay ID is jorigami_fin.

Note about CS signal: this may reset SPI bus, so you shouldn't toggle it when any command is active. I use it specifically for that purpose: before every command I deselect card, send $ff and then select the card again. That makes sure the bit counter is reset.


I hope I'm not spoiling the fun of experimenting!