Discussion in "8051 Discussion Forum" started by    Help    Dec 8, 2008.
Thu Feb 12 2009, 08:10 am
Thank you dave,

That is very nice explanation. According to boot sector information I have calculated the FAT sector address i.e LBA is 0xF9 =249 comming to FAT sector I can see no of sectors per cluster is 0x08 so the cluster size would be 8*512=4096(0x1000) am I correct? but I cannot find the chain of cluster information. How to find this address ("Fataddress[ 0x000D * 2 ] will have a value in it ( probably 0x000E )").0x000D*2 = 0x001A at this address I can see only 0xFF.I am unable to get this information please help me.
shiva



Thu Feb 12 2009, 08:28 am
I think this will also be useful.

Thu Feb 12 2009, 09:51 am
Hi Shiva,

Using the memory dump above
The first important part of this boot sector is at address 0x01FE and 0x01FF - These are the sector verification bytes.

The next important address is located at 0x01C6 - This is the first partition sector(PartSector), which will have all the data you need about the card. (THIS IS NOT THE FAT SECTOR...THE LOCATION OF THE FAT SECTOR IS WITHIN THE PARTITION SECTOR.)

Remembering the card is little endian, the sector address here is: 0x000000F9, which is the absolute address (multiply by 512) of 0x0001F200

Using the previous memory dump
Now you have the first partition table, which has all the information you need.

The first important part of this partition sector is at address 0x01F3FE and 0x01F3FF - These are the sector verification bytes.

Next, if you read the sector into a variable called Buffer[512], the the following code can be used to gather information:
/* Number of sectors per FAT */
sects_fat = (WORD)(Buffer[0x16]) + ((WORD)(Buffer[0x17])<<8); 

/* Number of FAT copies */
n_fats = (WORD)(Buffer[0x10]); 

/* Number of sectors per cluster */
csize = (WORD)(Buffer[0x0d]); 

/* Number of reserved sectors in the file system */
ReservedSectors = (WORD)(Buffer[0x0e]) + ((WORD)(Buffer[0x0f])<<8); 

/* FAT start sector (LBA) */
fatbase = (BootSector + ReservedSectors);

/* Nmuber of root directory entries */
n_rootdir = (WORD)(Buffer[0x11]) + ((WORD)(Buffer[0x12])<<8); 

/* Number of sectors in the file system */
TotalSectors = (ULONG)(Buffer[0x13]) + ((ULONG)(Buffer[0x14])<<8); 
if( TotalSectors == 0 )
   TotalSectors =(ULONG)(Buffer[0x20]) + ((ULONG)(Buffer[0x21])<<8) +
                 ((ULONG)(Buffer[0x22])<<16) + ((ULONG)(Buffer[0x23])<<32); 

/* Root directory start sector (LBA) */
dirbase = fatbase + (n_fats * sects_fat);

DirEntriesPerSector = ( SD_DATA_SIZE / DIR_ENTRY_SIZE );

TotalRootSectors = n_rootdir / DirEntriesPerSector;

/* Data start sector (LBA) */
database = dirbase + TotalRootSectors;

/* Calculate file system ID */
max_clust = (TotalSectors - database) / csize;

if( max_clust < 0x00000FF5 )
   fat_ID = FS_FAT12;
else 
   if( max_clust <  0x0000FFF5 )
      fat_ID = FS_FAT16;
   else 
      fat_ID = FS_FAT32;


The key here is the sector address for the FAT - That's where the string of clusters are located...
If you read that sector, and dump it, you will find what you are looking for...

For further reference, review the structure of a FAT16 system here:
http://en.wikipedia.org/wiki/File_Allocation_Table

Hope this helps,

-Dave


[ Edited Thu Feb 12 2009, 09:57 am ]
Thu Feb 12 2009, 09:53 am
is the sector 249 in my sd card is file allocation table. If I am wrong guide me where can I find FAT.
Thu Feb 12 2009, 10:00 am
No, address 0x000000F9 (249) is the address of the first partition table.

After you read in the first partition sector, look at relative offset addresses as outlined above, and calculate the FAT address...

The FAT sector is the address of the partition table (called BootSector in the example software) plus the number of reserved sectors (read from the partition table).

-Dave


[ Edited Thu Feb 12 2009, 10:09 am ]
Thu Feb 12 2009, 10:34 am
ya, I got it. thank you dave.
Thu Feb 12 2009, 11:27 am
Dave,

According to data sheets I read that we cannot write single byte to sd card but can read single byte from the card(from page 5-10 of sandisk manual). is it true .I want to know is there any commands to write or read a single block. It would be very useful for my source code.


thank you
shiva.
Thu Feb 12 2009, 10:27 pm
Which datasheet are you referring to? Is it titled,
"SanDisk Secure Digital Card, Product Manual, Version 1.9, Document No. 80-13-00169, December 2003"
Thu Feb 12 2009, 10:53 pm
@Ajay
I was thinking it might be a good idea to summarize all this stuff we have learned and put it into a tutorial...

What do you think about this?

-Dave
 eljun like this.
Fri Feb 13 2009, 02:56 am


@Ajay
I was thinking it might be a good idea to summarize all this stuff we have learned and put it into a tutorial...

What do you think about this?

-Dave

DavesGarage


great you are the best person i guess.. u can put everything into a word document with images. I will make it a tutorial
 eljun like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am