Fat

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fat

339 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by renan on Wed Jun 30 14:05:24 MST 2010
This code is part of the usb bootloader example for rdb1768:
// Generate File Allocation Table to save Flash space
    // First Two FAT entries are reserved
    Fat_RootDir[0]= 0xF8;
    Fat_RootDir[1]= 0xFF;
    Fat_RootDir[2]= 0xFF;
    /* Start cluster of a file is indicated by the Directory entry = 2 */
    m = 3;
    for ( n = 3;n < NO_OF_CLUSTERS+2;n+=2) {
        if( n == ((NO_OF_CLUSTERS+2)-1) )
        {
          next_cluster = 0xFFF;
        }
        else
        {
          next_cluster = n + 1;
        }
          [COLOR=Red]Fat_RootDir[m] = (BYTE)n & 0xFF;
          Fat_RootDir[m+1] = (((BYTE)next_cluster & 0xF) << 4) | ((BYTE)(n>>8)&0xF);
          Fat_RootDir[m+2] = (BYTE)(next_cluster >> 4) & 0xFF;
        m = m+3;[/COLOR]
    }


What's going on in the red part of the code?

Suppose that the FAT is the image attached. An example of how it is going to be the [COLOR=Black] [/COLOR][COLOR=Black]Fat_RootDir vector.

Renan
[/COLOR]
0 Kudos
Reply
1 Reply

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jun 30 14:56:56 MST 2010
The whole of this block of code is basically implementing the section in the Wikipedia entry that starts....


Quote:
The [B]File Allocation Table[/B] ([B]FAT[/B]) is a list of entries that  map to each cluster on the partition. Each entry records one of five  things:

about half way down http://en.wikipedia.org/wiki/File_Allocation_Table

The FAT variant used by the bootloader is FAT12, which means each entry consumes 12 bits, so 2 entries are spread across 3 bytes.

The 3 lines you have in red are basically writing two FAT entries per iteration, each FAT entry containing the cluster number of the next cluster in a chain - as the whole of the disk is being set up to contain a single file (the firmware.bin file).

Regards,
CodeRedSupport.
0 Kudos
Reply