[0041] Example 2
[0042] When the NANDFLASH is formatted, the computer will calculate the relevant information according to the FLASH capacity and put it into the DBR. FAT divides the FLASH space according to a certain number of sectors, each sector is 512Bytes, and multiple sectors form a " cluster". The following structure is the detailed information in DBR:
[0043] #define UINT8 unsigned char
[0044] #define UINT16 unsigned int
[0045] #define UINT32 unsigned long
[0046] typedef struct
[0047] {
[0048] UINT8 jmpBoot[3]; /*Jump instruction */
[0049] UINT8 OEMName[8]; /*vendor name */
[0050] UINT16 BytsPerSec; /*Bytes per sector */
[0051] UINT8 SecPerClus; /*Number of sectors per cluster */
[0052] UINT16 RsvdSecCnt; /*Number of reserved sectors */
[0053] UINT8 NumFATs; /*Number of FAT tables */
[0054] UINT16 RootEntCnt; /*Maximum number of root directory files, 0 in FAT32 */
[0055] UINT16 TotSec16; /*Total number of sectors, 0 in FAT32 */
[0056] UINT8 Media; /*Media descriptor */
[0057] UINT16 FATSz16; /*Number of sectors per FAT */
[0058] UINT16 SecPerTrk; /*Number of sectors per track */
[0059] UINT16 NumHeads; /*Number of heads (number of sides) */
[0060] UINT32 HiddSec; /*The number of hidden sectors */
[0061] UINT32 TotSec32; /*If BPB_TotSec16=0, record the total number of sectors */
[0062] UINT8 DrvNum; /*drive of interrupt 13 */
[0063] UINT8 Reserved1; /*Reserved */
[0064] UINT8 BootSig; /*Extended boot flag */
[0065] UINT32 VolID; /*Volume serial number */
[0066] UINT8 VolLab[11]; /*Volume label */
[0067] UINT8 FilSysType[8]; /*File system type */
[0068] UINT8 Code[448]; /*boot code */
[0069] UINT16 Over; /*End flag */
[0070] }DBRINFO;
[0071] Take Samsung K9K8G08U1M as an example. It has 4096 blocks, each block contains 64 pages, and each page is composed of 4 sectors and a 64-byte spare area. The total size is 512M+16M (16M is spare area). The following is the DBR area information of the FAT file system established on this block of NANDFLASH.
[0072] 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[0073] 01: EB 3C 90 4D 53 57 49 4E 34 2E 31 00 02 10 01 00
[0074] 02: 02 00 02 00 00 F8 F9 00 20 00 3E 00 20 00 00 00
[0075] 03: 00 86 0F 00 80 00 29 22 96 1B 00 61 61 61 00 00
[0076] 04: 00 00 00 00 00 00 46 41 54 31 36 20 20 20 FA 33
[0077] 05: C0 8E D0 BC 00 7C 16 07 BB 78 00 36 C5 37 1E 56
[0078] 06: 16 53 BF 3E 7C B9 0B 00 FC F3 A4 06 1F C6 45 FE
[0079] 07: 0F 8B 0E 18 7C 88 4D F9 89 47 02 C7 07 3E 7C FB
[0080] 08: CD 13 72 79 33 C0 39 06 13 7C 74 08 8B 0E 13 7C
[0081] 09: 89 0E 20 7C A0 10 7C F7 26 16 7C 03 06 1C 7C 13
[0082] 10: 16 1E 7C 03 06 0E 7C 83 D2 00 A3 50 7C 89 16 52
[0083] 11: 7C A3 49 7C 89 16 4B 7C B8 20 00 F7 26 11 7C 8B
[0084] 12: 1E 0B 7C 03 C3 48 F7 F3 01 06 49 7C 83 16 4B 7C
[0085] 13:00 BB 00 05 8B 16 52 7C A1 50 7C E8 92 00 72 1D
[0086] 14: B0 01 E8 AC 00 72 16 8B FB B9 0B 00 BE E6 7D F3
[0087] 15: A6 75 0A 8D 7F 20 B9 0B 00 F3 A6 74 18 BE 9E 7D
[0088] 16: E8 5F 00 33 C0 CD 16 5E 1F 8F 04 8F 44 02 CD 19
[0089] 17: 58 58 58 EB E8 8B 47 1A 48 48 8A 1E 0D 7C 32 FF
[0090] 18: F7 E3 03 06 49 7C 13 16 4B 7C BB 00 07 B9 03 00
[0091] 19: 50 52 51 E8 3A 00 72 D8 B0 01 E8 54 00 59 5A 58
[0092] 20: 72 BB 05 01 00 83 D2 00 03 1E 0B 7C E2 E2 8A 2E
[0093] 21:15 7C 8A 16 24 7C 8B 1E 49 7C A1 4B 7C EA 00 00
[0094] 22: 70 00 AC 0A C0 74 29 B4 0E BB 07 00 CD 10 EB F2
[0095] 23: 3B 16 18 7C 73 19 F7 36 18 7C FE C2 88 16 4F 7C
[0096] 24: 33 D2 F7 36 1A 7C 88 16 25 7C A3 4D 7C F8 C3 F9
[0097] 25: C3 B4 02 8B 16 4D 7C B1 06 D2 E6 0A 36 4F 7C 8B
[0098] 26: CA 86 E9 8A 16 24 7C 8A 36 25 7C CD 13 C3 0D 0A
[0099] 27: 4E 6F 6E 2D 53 79 73 74 65 6D 20 64 69 73 6B 20
[0100] 28: 6F 72 20 64 69 73 6B 20 65 72 72 6F 72 0D 0A 52
[0101] 29: 65 70 6C 61 63 65 20 61 6E 64 20 70 72 65 73 73
[0102] 30: 20 61 6E 79 20 6B 65 79 20 77 68 65 6E 20 72 65
[0103] 31: 61 64 79 0D 0A 00 49 4F 20 20 20 20 20 20 53 59
[0104] 32: 53 4D 53 44 4F 53 20 20 2053 59 53 00 00 55 AA
[0105] The underlined part in the above table is the BPB information of 53 bytes. From the table, you can know:
[0106] Number of bytes per sector: BytesPerSector = 0x0200;
[0107] The number of sectors per cluster: SecPerClus=0x10;
[0108] The total number of sectors: TotSec32=0xF8600;
[0109] Since SecPerBlock=256.
[0110] So the number of clusters per block can be calculated:
[0111] ClusPerBlock=SecPerBlock/SecPerClus=16.
[0112] The following table is a sector of the FAT table after bad block processing (bad block mark has been made in the table):
[0113] 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
[0114] 01: F8 FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00
[0115] 02: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0116] 03: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0117] 04: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0118] 05: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0119] 06:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0120] 07: 00 00 00 00 FE FF FE FF FE FF FE FF FE FF FE FF
[0121] 08: FE FF FE FF FE FF FE FF FE FF FE FF FE FF FE FF
[0122] 09: FE FF FE FF 00 00 00 00 00 00 00 00 00 00 00 00 00
[0123] 10:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0124] 11:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0125] 12: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0126] 13:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0127] 14:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0128] 15:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0129] 16:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0130] 17:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0131] 18:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0132] 19:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0133] 20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0134] 21: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0135] 22:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0136] 23:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0137] 24: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0138] 25: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0139] 26: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0140] 27: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0141] 28: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0142] 29: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0143] 30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0144] 31: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[0145] 32: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00