增加SD卡fat32文件系统的读
来源:互联网 发布:php网站开发视频教程 编辑:程序博客网 时间:2024/05/17 09:00
Fat文件系统升级和SD卡升级文档
在fat.h中添加的代码
#define END_OF_FILE32 0X0FFFFFF8 //用来判断保存文件的扇区是否结束
typedef struct
{
BYTE BS_jmpBoot[3];
BYTE BS_OEMName[8];
BYTE BPB_BytsPerSec[2];
BYTE BPB_SecPerClus;
BYTE BPB_RsvdSecCnt[2];
BYTE BPB_NumFATs;
BYTE BPB_RootEntCnt[2];
BYTE BPB_SmallSec[2];
BYTE BPB_Media;
BYTE BPB_SecPerFat[2];
BYTE BPB_SecPerTrk[2];
BYTE BPB_NumHead[2];
BYTE BPB_HiddenSec[4];
BYTE BPB_LarSec[4];
BYTE BPB_SecPerFat32[4];
BYTE BPB_ExtendFlag[2];
BYTE BPB_FileSystemVer[2];
BYTE BPB_RootCluNum[4];
BYTE BPB_FileSySInfoSecNum[2];
BYTE BPB_PerForGuidSec[2];
BYTE BPB_SaveFor32[12];
BYTE BPB_PhyDriveNum;
BYTE BPB_Res;
BYTE BPB_ExtenBootSig;
BYTE BPB_VolSerNum[4];
BYTE BPB_VolLab[11];
BYTE BPB_SysID[8];
}FAT32_BPB_STRUCTURE,*P_FAT32_BPB_STRUCTURE;//fat32BPB结构体
BOOL fillBootBlockStructure32(P_FAT32_BPB_STRUCTURE pBPB, BYTE *buffer);
void getFATDataStructure32(P_FAT32_BPB_STRUCTURE pBPB, P_FAT_STRUCTURE pFAT);
void getSectorOffset32(P_FAT32_BPB_STRUCTURE pBPB, P_FAT_STRUCTURE pFAT,
P_READ_FAT pReadFAT, XLLP_UINT32_T cluster);
Fat.c中添加的代码
//填充FAT32BPB结构体
BOOL fillBootBlockStructure32(P_FAT32_BPB_STRUCTURE pBPB, BYTE *buffer)
{
int i, offset;
if(buffer[0] != 0xEB && buffer[0] != 0xE9)
return FALSE;
for (i=0; i<3; i++)
pBPB->BS_jmpBoot[i] = (BYTE)buffer[i];
offset = 3;
for (i = 0; i < 8; i++)
pBPB->BS_OEMName[i] = (BYTE)buffer[i+offset];
offset+=8;
for (i = 0; i < 2; i++)
pBPB->BPB_BytsPerSec[i] = (BYTE)buffer[i+offset];
offset+=2;
pBPB->BPB_SecPerClus = (BYTE)buffer[offset];
offset++;
for (i = 0; i < 2; i++)
pBPB->BPB_RsvdSecCnt[i] = (BYTE)buffer[i+offset];
offset+=2;
pBPB->BPB_NumFATs = (BYTE)buffer[offset];
offset++;
for (i = 0; i < 2; i++)
pBPB->BPB_RootEntCnt[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 2; i++)
pBPB->BPB_SmallSec[i] = (BYTE)buffer[i+offset];
offset+=2;
pBPB->BPB_Media = (BYTE)buffer[offset];
offset++;
for (i = 0; i < 2; i++)
pBPB->BPB_SecPerFat[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 2; i++)
pBPB->BPB_SecPerTrk[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 2; i++)
pBPB->BPB_NumHead[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 4; i++)
pBPB->BPB_HiddenSec[i] = (BYTE)buffer[i+offset];
offset+=4;
for (i = 0; i < 4; i++)
pBPB->BPB_LarSec[i] = (BYTE)buffer[i+offset];
offset+=4;
for (i = 0; i < 4; i++)
pBPB->BPB_SecPerFat32[i] = (BYTE)buffer[i+offset];
offset+=4;
for (i = 0; i < 2; i++)
pBPB->BPB_ExtendFlag[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 2; i++)
pBPB->BPB_FileSystemVer[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 4; i++)
pBPB->BPB_RootCluNum[i] = (BYTE)buffer[i+offset];
offset+=4;
for (i = 0; i < 2; i++)
pBPB->BPB_FileSySInfoSecNum[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 2; i++)
pBPB->BPB_PerForGuidSec[i] = (BYTE)buffer[i+offset];
offset+=2;
for (i = 0; i < 12; i++)
pBPB->BPB_SaveFor32[i] = (BYTE)buffer[i+offset];
offset+=12;
pBPB->BPB_PhyDriveNum = (BYTE)buffer[offset];
offset++;
pBPB->BPB_Res = (BYTE)buffer[offset];
offset++;
pBPB->BPB_ExtenBootSig = (BYTE)buffer[offset];
offset++;
for (i = 0; i < 4; i++)
pBPB->BPB_VolSerNum[i] = (BYTE)buffer[i+offset];
offset+=4;
for (i = 0; i < 11; i++)
pBPB->BPB_VolLab[i] = (BYTE)buffer[i+offset];
offset+=11;
for (i = 0; i < 8; i++)
pBPB->BPB_SysID[i] = (BYTE)buffer[i+offset];
return TRUE;
}
//填充FAt结构体
void getFATDataStructure32(P_FAT32_BPB_STRUCTURE pBPB, P_FAT_STRUCTURE pFAT)
{
XLLP_UINT32_T RootEntCnt, BytsPerSec, FATSz16,FATSz32;
XLLP_UINT32_T TotSec16, TotSec32, RsvdSecCnt;
RootEntCnt = pBPB->BPB_RootEntCnt[1];
RootEntCnt = RootEntCnt << 8;
RootEntCnt |= pBPB->BPB_RootEntCnt[0];
BytsPerSec = pBPB->BPB_BytsPerSec[1];
BytsPerSec = BytsPerSec << 8;
BytsPerSec |= pBPB->BPB_BytsPerSec[0];
FATSz16 = pBPB->BPB_SecPerFat[1];
FATSz16 = FATSz16 << 8;
FATSz16 |= pBPB->BPB_SecPerFat[0];
FATSz32 = pBPB->BPB_SecPerFat32[3];
FATSz32 = FATSz32<<8;
FATSz32 |= pBPB->BPB_SecPerFat32[2];
FATSz32 = FATSz32<<8;
FATSz32 |= pBPB->BPB_SecPerFat32[1];
FATSz32 = FATSz32<<8;
FATSz32 |= pBPB->BPB_SecPerFat32[0];
TotSec16 = pBPB->BPB_SmallSec[1];
TotSec16 = TotSec16 << 8;
TotSec16 |= pBPB->BPB_SmallSec[0];
TotSec32 = pBPB->BPB_LarSec[3];
TotSec32 = TotSec32 << 8;
TotSec32 |= pBPB->BPB_LarSec[2];
TotSec32 = TotSec32 << 8;
TotSec32 |= pBPB->BPB_LarSec[1];
TotSec32 = TotSec32 << 8;
TotSec32 |= pBPB->BPB_LarSec[0];
RsvdSecCnt = pBPB->BPB_RsvdSecCnt[1];
RsvdSecCnt = RsvdSecCnt << 8;
RsvdSecCnt |= pBPB->BPB_RsvdSecCnt[0];
pFAT->RootDirsSectors = ((RootEntCnt * 32) + (BytsPerSec - 1)) / BytsPerSec;//跟目录所占的扇区数0
//pFAT->FATSz = FATSz16;
//数据区的起始地址,簇2的第一个扇区计算
if(FATSz16 != 0)
pFAT->FATSz = FATSz16;
else
pFAT->FATSz = FATSz32;
pFAT->FirstDataSector = RsvdSecCnt + (pBPB->BPB_NumFATs*pFAT->FATSz) + pFAT->RootDirsSectors;
pFAT->FirstRootDirSecNum =
RsvdSecCnt + ((XLLP_UINT32_T)pBPB->BPB_NumFATs * pFAT->FATSz);
//pFAT->FirstDataSector = pFAT->FirstRootDirSecNum + pFAT->RootDirsSectors;
if(TotSec16 != 0)
pFAT->TotSec = TotSec16;
else
pFAT->TotSec = TotSec32;
pFAT->DataSec = pFAT->TotSec - pFAT->FirstDataSector;
pFAT->CountOfClusters = pFAT->DataSec / (XLLP_UINT32_T)pBPB->BPB_SecPerClus;
if(pFAT->CountOfClusters < 4085)
pFAT->FATType = FAT12;
else if(pFAT->CountOfClusters < 65525)
pFAT->FATType = FAT16;
else
pFAT->FATType = FAT32;
}
//扇区偏移位置
void getSectorOffset32(P_FAT32_BPB_STRUCTURE pBPB, P_FAT_STRUCTURE pFAT,
P_READ_FAT pReadFAT, XLLP_UINT32_T cluster)
{
XLLP_UINT32_T BytsPerSec, RsvdSecCnt, FATOffset;
BytsPerSec = pBPB->BPB_BytsPerSec[1];
BytsPerSec = BytsPerSec << 8;
BytsPerSec |= pBPB->BPB_BytsPerSec[0];
RsvdSecCnt = pBPB->BPB_RsvdSecCnt[1];
RsvdSecCnt = RsvdSecCnt << 8;
RsvdSecCnt |= pBPB->BPB_RsvdSecCnt[0];
if(pFAT->FATType == FAT16)
FATOffset = cluster * 2;
else if(pFAT->FATType == FAT32)
FATOffset = cluster * 4;
pReadFAT->ThisFATSecNum = RsvdSecCnt + (FATOffset / BytsPerSec);
pReadFAT->ThisFATEntOffset = FATOffset % BytsPerSec;
}
Blcommon.c中添加的代码
int Fat32Flags=0;
int Fat16Flags=0;
XLLP_UINT32_T R_firstCluster,R_currentFAT;
//读DBR判断是fat32还是fat16
if(buffer[0] != 0xEB && buffer[0] != 0xE9)
{
EdbgOutputDebugString("No valid boot block found!!!\r\n");
if (get_output_channel()==OUTPUT_SCREEN)
{
ShowWarning("No valid boot block found!!!");
}
EdbgOutputDebugString("try finding DBR one sector by sector!!\r\n");
sectorsBeforePartition = 0;
while(1)
{
SDMMCReadBlock(&context, sectorsBeforePartition*BLK_LEN, buffer);
if((((buffer[0] == 0xEB) &&(buffer[2] == 0x90)) || (buffer[0] == 0xE9)) &&
(buffer[510] == 0x55) && (buffer[511] == 0xaa) &&
(buffer[54] == 0x46) && (buffer[55] == 0x41) && (buffer[56] == 0x54) &&
(buffer[57] == 0x31) && (buffer[58] == 0x36))
{
EdbgOutputDebugString("found DBR! sector = %d\r\n", sectorsBeforePartition);
if (!fillBootBlockStructure(&bpb, buffer))
{
EdbgOutputDebugString("No valid boot block found!!!\r\n");
FailedLED();
while(1);
}
if (get_output_channel()==OUTPUT_SCREEN)
{
ShowWarning("found boot DBR!");
}
Fat16Flags=1;
break;
}
else if((((buffer[0] == 0xEB) &&(buffer[2] == 0x90))|| (buffer[0] == 0xE9)) &&
(buffer[17==0x00])&&(buffer[18]==0x00)&&(buffer[510] == 0x55) && (buffer[511] == 0xaa) &&
(buffer[82] == 0x46) && (buffer[83] == 0x41) && (buffer[84] == 0x54) &&
(buffer[85] == 0x33) && (buffer[86] == 0x32))
{
EdbgOutputDebugString("found DBR! sector = %d\r\n", sectorsBeforePartition);
if (!fillBootBlockStructure32(&bpb32, buffer))
{
EdbgOutputDebugString("No valid boot block found!!!\r\n");
FailedLED();
while(1);
}
if (get_output_channel()==OUTPUT_SCREEN)
{
ShowWarning("found boot DBR!");
}
Fat32Flags=1;
break;
}
if(++sectorsBeforePartition > sectorsBeforePartition1)
{
//EdbgOutputDebugString("mbr setctorsBeforePartition = 0x%x\r\n",sectorsBeforePartition);
EdbgOutputDebugString("can't found DBR, sd update abord!\r\n");
FailedLED();
while(1);
return FALSE;
}
EdbgOutputDebugString("mbr setctorsBeforePartition = 0x%x\r\n",sectorsBeforePartition);
}
}
else
{
EdbgOutputDebugString("coming else ,not coing if\r\n");
if((buffer[57] == 0x31) && (buffer[58] == 0x36))
{
if (!fillBootBlockStructure(&bpb, buffer))
{
EdbgOutputDebugString("No valid boot block found!!!\r\n");
FailedLED();
while(1);
}
Fat16Flags=1;
}
else if((buffer[17]==0x00)&&(buffer[18]==0x00)&&(buffer[85] == 0x33) && (buffer[86] == 0x32))
{
if (!fillBootBlockStructure32(&bpb32, buffer))
{
EdbgOutputDebugString("No valid boot block found!!!\r\n");
FailedLED();
while(1);
}
Fat32Flags=1;
}
}
//fat32代码
if(Fat32Flags)
{
EdbgOutputDebugString("\r\n coming fat32!!!! \r\n");
if (memcmp(bpb32.BPB_SysID,"FAT32",5)!=0)
{
EdbgOutputDebugString("Not FAT32 Format!!!\r\n");
if (get_output_channel()==OUTPUT_SCREEN)
{
ShowWarning("Not FAT32 Format!!!");
}
FailedLED();
while(1);
return FALSE;
}
//EdbgOutputDebugString("\r\n this is fat32 file system \r\n");
//getdat32(&bpb32);
//EdbgOutputDebugString("======================= \r\n");
getFATDataStructure32(&bpb32,&fat);
readOffset = 2*bpb32.BPB_SecPerClus;//这里可能错了
filename = convertToUpperCase(filename);
EdbgOutputDebugString("\r\nSearching for file: %s\r\n", filename);
//从跟目录中读文件信息
//SDMMCReadBlock(&context,(fat.FirstRootDirSecNum+sectorsBeforePartition)*BLK_LEN, rootDir);//读出了fat16 跟目录下的所有文件
//fat32的跟目录跟文件一样,所以要像读文件一样读
R_firstCluster = bpb32.BPB_RootCluNum[3];
R_firstCluster = R_firstCluster<<8;
R_firstCluster |= bpb32.BPB_RootCluNum[2];
R_firstCluster = R_firstCluster<<8;
R_firstCluster |= bpb32.BPB_RootCluNum[1];
R_firstCluster = R_firstCluster<<8;
R_firstCluster |= bpb32.BPB_RootCluNum[0];
root_sector = R_firstCluster;
EdbgOutputDebugString("\r\n R_ClusterNum = 0x%x \r\n",R_firstCluster);//0x2
fileFound = FALSE;
do
{
for(j=0; j<bpb32.BPB_SecPerClus; j++)// 簇的扇区数
{
//EdbgOutputDebugString("\r\n j = %d \r\n",j);
//EdbgOutputDebugString("\r\n bpb32.BPB_SecPerClus = 0x%x \r\n",bpb32.BPB_SecPerClus);
SDMMCReadBlock(&context, (((fat.FirstRootDirSecNum
+root_sector*bpb32.BPB_SecPerClus)-readOffset+j)
+sectorsBeforePartition)*BLK_LEN, rootDir);
for(i=0; i<BLK_LEN; i+=ROOT_SIZE)
{
/*if(rootDir[i]==0x00)
{
EdbgOutputDebugString("%s not found=====.\r\n", filename);
endRootDir = TRUE;
//return FALSE;
}
*/
if((rootDir[i]!=0x5e) && (rootDir[i]!=0x00))
{
getShortDirStructure(&dir, &rootDir[i]);
//getshortdir(&dir);
//kk ++;
//EdbgOutputDebugString(" kk = %d\r\n", kk);
//EdbgOutputDebugString(" dir is %s\r\n", &dir);
if (compareFileName(&dir, filename))
{
XLLP_UINT32_T firstCluster, currentFAT;
fileFound = TRUE;
//XLLP_UINT32_T firstCluster, currentFAT;
EdbgOutputDebugString("%s found.\r\n", filename);
EdbgOutputDebugString("Starting download...\r\n");
if (get_output_channel()==OUTPUT_SCREEN)
{
if (!memcmp("LOADER.BIN",filename,strlen(filename)))
ShowStatus1("LOADER.BIN: Reading file...");
if (!memcmp("FLASH.BIN",filename,strlen(filename)))
ShowStatus2("FLASH.BIN: Reading file...");
if (!memcmp("MODEM.BIN",filename,strlen(filename)))
ShowStatus3("MODEM.BIN: Reading file...");
}
ShowProcessBar(0);
//get the file size
fileSize = dir.DIR_FileSize[3];
fileSize = fileSize << 8;
fileSize |= dir.DIR_FileSize[2];
fileSize = fileSize << 8;
fileSize |= dir.DIR_FileSize[1];
fileSize = fileSize << 8;
fileSize |= dir.DIR_FileSize[0];
//calculater where the first cluster of data is located
//EdbgOutputDebugString("\r\n dir.DIR_FstClusHI = 0x%x!!!\r\n",dir.DIR_FstClusHI);
//EdbgOutputDebugString("\r\n FAT = %s!!!\r\n",FAT);
firstCluster = dir.DIR_FstClusHI[1];
firstCluster = firstCluster << 8;
firstCluster |= dir.DIR_FstClusHI[0];
firstCluster = firstCluster << 8;
firstCluster |= dir.DIR_FstClusLO[1];
firstCluster = firstCluster << 8;
firstCluster |= dir.DIR_FstClusLO[0];
EdbgOutputDebugString("**first cluster = 0x%x file size=0x%x\r\n", firstCluster,fileSize);
getSectorOffset32(&bpb32 , &fat, &readFAT, firstCluster);
//get the first block of the FAT
SDMMCReadBlock(&context,
(readFAT.ThisFATSecNum+sectorsBeforePartition)*BLK_LEN, FAT);
//EdbgOutputDebugString("\r\n FAT = %s!!!\r\n",FAT);
//EdbgOutputDebugString("\r\n *(FAT + readFAT.ThisFATEntOffset) = 0x%d!!!\r\n",*(FAT + readFAT.ThisFATEntOffset));
currentFAT = readFAT.ThisFATSecNum;
//determine where the next data block is by reading the FAT
sector = *(FAT + readFAT.ThisFATEntOffset+3);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset+2);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset+1);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset);
//EdbgOutputDebugString("\r\n sector = 0x%x!!!\r\n",sector);
//EdbgOutputDebugString("\r\n readFAT.ThisFATSecNum = %d!!!\r\n",readFAT.ThisFATSecNum);
//EdbgOutputDebugString("\r\n readFAT.ThisFATEntOffset = %d!!!\r\n",readFAT.ThisFATEntOffset);
clus_len = bpb32.BPB_SecPerClus*BLK_LEN;
read_start_point = (unsigned char*)FileBufferStart;
read_end_point = read_start_point + clus_len;
//download the first data cluster
for(secPerClus = 0; secPerClus < bpb32.BPB_SecPerClus; secPerClus++)
{
//EdbgOutputDebugString("start read SD flash!!!!!!\r\n");
SDMMCReadBlock(&context, (((fat.FirstDataSector+
firstCluster*bpb32.BPB_SecPerClus)-readOffset+secPerClus)
+sectorsBeforePartition)*BLK_LEN,
(BYTE *)read_start_point+sectorsRead*BLK_LEN);
sectorsRead++;
}
while(!isEOF(fat.FATType, sector))
{
if (FALSE==IsCardInsert(&context))
{
if (get_output_channel()==OUTPUT_SCREEN)
{
ShowWarning("T-Flash card removed!!!");
}
EdbgOutputDebugString("\r\nT-Flash card removed!!!\r\n");
FailedLED();
while(1);
}
if ((DWORD)read_end_point+clus_len>FileBufferEnd)
{
//尾指针快到底,需要进行写flash
EdbgOutputDebugString("start write flash!!!!!!\r\n");
FlashImageSDMMC(&read_start_point,read_end_point);
memcpy((BYTE *)FileBufferStart,read_start_point,(DWORD)read_end_point-(DWORD)read_start_point);
read_end_point = (unsigned char*)FileBufferStart + (DWORD)read_end_point-(DWORD)read_start_point;
read_start_point = (unsigned char*)FileBufferStart;
if (get_output_channel()==OUTPUT_SCREEN)
{
if (!memcmp("FLASH.BIN",filename,strlen(filename)))
ShowStatus2("FLASH.BIN: Reading file...");
}
}
for(secPerClus=0; secPerClus < bpb32.BPB_SecPerClus; secPerClus++)
{
//EdbgOutputDebugString("start read SD flash!!!!!!\r\n");
SDMMCReadBlock(&context, (((fat.FirstDataSector
+sector*bpb32.BPB_SecPerClus)-readOffset+secPerClus)
+sectorsBeforePartition)*BLK_LEN,
(BYTE *)read_end_point+secPerClus*BLK_LEN);
sectorsRead++;
}
read_end_point += clus_len;
getSectorOffset32(&bpb32 , &fat, &readFAT,sector);
//EdbgOutputDebugString("\r\n readFAT.ThisFATSecNum = %d!!!\r\n",readFAT.ThisFATSecNum);
//EdbgOutputDebugString("\r\n readFAT.ThisFATEntOffset = %d!!!\r\n",readFAT.ThisFATEntOffset);
//if entry is not in current block of FAT,
//page in the next block of FAT
if(readFAT.ThisFATSecNum != currentFAT)
{
SDMMCReadBlock(&context, (readFAT.ThisFATSecNum
+sectorsBeforePartition)*BLK_LEN, FAT);
currentFAT = readFAT.ThisFATSecNum;
//EdbgOutputDebugString("currentFAT change to %d\r\n",currentFAT);
}
sector = *(FAT + readFAT.ThisFATEntOffset+3);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset+2);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset+1);
sector = sector << 8;
sector |= *(FAT + readFAT.ThisFATEntOffset);
ShowProcessBar((unsigned char)(sectorsRead*BLK_LEN/(fileSize/100)));
}
break;
}
}
}
if(fileFound)
{
EdbgOutputDebugString("*********************************\r\n");
EdbgOutputDebugString("write the last date to the flash!\r\n");
if ((DWORD)read_end_point>(DWORD)read_start_point) //最后一部分数据写入flash
FlashImageSDMMC(&read_start_point,read_end_point);
EdbgOutputDebugString("%d of %d Complete!\r\n", sectorsRead*BLK_LEN, fileSize);
EdbgOutputDebugString("\r\nFlash Complete!\r\n");
if (get_output_channel()==OUTPUT_SCREEN)
{
if (!memcmp("FLASH.BIN",filename,strlen(filename)))
ShowStatus2("FLASH.BIN: Flash Complete!");
}
}
if(fileFound)
break;
//SDMMCReadBlock(&context, (fat.FirstRootDirSecNum
// +sectorsBeforePartition+j)*BLK_LEN, rootDir);
}
if(fileFound)
break;
getSectorOffset32(&bpb32 , &fat, &readFAT,root_sector);
//if(readFAT.ThisFATSecNum != R_currentFAT)
{
SDMMCReadBlock(&context, (readFAT.ThisFATSecNum
+sectorsBeforePartition)*BLK_LEN, FAT);
R_currentFAT = readFAT.ThisFATSecNum;
EdbgOutputDebugString("R_currentFAT change to %d\r\n",R_currentFAT);
}
root_sector = *(FAT + readFAT.ThisFATEntOffset+3);
root_sector = root_sector << 8;
root_sector |= *(FAT + readFAT.ThisFATEntOffset+2);
root_sector = root_sector << 8;
root_sector |= *(FAT + readFAT.ThisFATEntOffset+1);
root_sector = root_sector << 8;
root_sector |= *(FAT + readFAT.ThisFATEntOffset);
//EdbgOutputDebugString("\r\n root_sector = 0x%x \r\n",root_sector);
}
while(!isEOF(fat.FATType, root_sector));
if (!fileFound)
{
EdbgOutputDebugString(("Image: '%s' not found!!!"), filename);
if (get_output_channel()==OUTPUT_SCREEN)
{
if (!memcmp("LOADER.BIN",filename,strlen(filename)))
ShowStatus1("LOADER.BIN: not found!!!");
if (!memcmp("FLASH.BIN",filename,strlen(filename)))
ShowStatus2("FLASH.BIN: not found!!!");
if (!memcmp("MODEM.BIN",filename,strlen(filename)))
ShowStatus3("MODEM.BIN: not found!!!");
}
return FALSE;
}
}
Sdmmc.c中添加的代码
#define CARDTYPE_SD20HC 0X04
int Card_type = 0;
在XLLP_UINT32_T SDMMCCardInit(P_XLLP_MMC_CONTEXT_T pContext)函数中添加的代码
// SD ver.2的代码
//Send CMD0 a few times to make sure card is in idle state
//XllpMMCStartBusClock(pContext, XLLP_MMC_CONTROLLER_1);
//msWait(100);
for (i = 0; i < 3; i++)
{
argument = NO_ARGUMENT;
flags |= XLLP_MMC_INIT_COMMAND;
flags |= XLLP_MMC_RESPONSE_NONE;
SDMMCSendCommand(pContext, XLLP_MMC_CMD0, argument, flags);
resp = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_MASK, TRUE);
//EdbgOutputDebugString(" cmd0 resp = %d\r\n",resp);
}
//EdbgOutputDebugString("retrytime = %d\r\n",retrytime);
argument = CMD8_ARGUMENT;
flags = NO_FLAGS;
flags |= XLLP_MMC_INIT_COMMAND;
flags |= XLLP_MMC_RESPONSE_R7;
SDMMCSendCommand(pContext, XLLP_MMC_CMD8, argument, flags);
//resp = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R7, TRUE);
do
{
flags = NO_FLAGS;
flags |= XLLP_MMC_INIT_COMMAND;
flags |= XLLP_MMC_RESPONSE_R1;
argument = LOW_ARG;
SDMMCSendCommand(pContext, XLLP_MMC_CMD55, argument, flags);
//cmd55_resp = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R1, TRUE);
flags = NO_FLAGS;
flags |= XLLP_MMC_INIT_COMMAND;
flags |= XLLP_MMC_RESPONSE_R3;
//argument = SD_OCR;
argument = SD_OCR_SDHC;
SDMMCSendCommand(pContext, XLLP_SD_ACMD41, argument, flags);
resp = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R3, TRUE);
//resp = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R3, TRUE);
//EdbgOutputDebugString(" in cmd8 cmd41 resp = 0x%x\r\n",resp);
}while(resp!=0x3fc0);
//send CMD2 to get the CID numbers
flags = NO_FLAGS;
flags |= XLLP_MMC_NORMAL_COMMAND;
flags |= XLLP_MMC_RESPONSE_R2;
argument = NO_ARGUMENT;
SDMMCSendCommand(pContext, XLLP_MMC_CMD2, argument, flags);
msWait(5);
serialNum = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R2, FALSE);
if (SD)
{
//send CMD3 to assign a RCA to the card
flags = NO_FLAGS;
flags |= XLLP_MMC_NORMAL_COMMAND;
flags |= XLLP_MMC_RESPONSE_R6;
argument = NO_ARGUMENT;
SDMMCSendCommand(pContext, XLLP_MMC_CMD3, argument, flags);
rca = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R6, FALSE);
EdbgOutputDebugString("rca = %d\r\n",rca);
}
//send CMD7 to get card into transfer state
flags = NO_FLAGS;
flags |= XLLP_MMC_NORMAL_COMMAND;
flags |= XLLP_MMC_RESPONSE_R1;
argument = (rca << 16) | LOW_ARG;
SDMMCSendCommand(pContext, XLLP_MMC_CMD7, argument, flags);
cardStatus = SDMMCGetResponse(pContext, XLLP_MMC_RESPONSE_R1, FALSE);
EdbgOutputDebugString("++++++++++++++++++++++++++++++++++++++++++\r\n");
EdbgOutputDebugString("cardStatus = 0x%x\r\n",cardStatus);
XllpMMCSetBusRate(pContext, XLLP_MMC_19_5MHz, XLLP_MMC_CONTROLLER_1);
Card_type = CARDTYPE_SD20HC;
return (rca << 16) | LOW_ARG;
}
在void SDMMCReadFifo(P_XLLP_MMC_CONTEXT_T pContext, BYTE *buffer)中添加代码
if(Card_type == CARDTYPE_SD20HC)
{
while(!(pContext->pMMC1Reg->mmc_i_reg & SD_REG_RXFIFO_RD_REQ));
do
{
*buffer = *pMMC_RX_Fifo;
buffer++;
i++;
}while(i<512);
}
在void SDMMCReadBlock(P_XLLP_MMC_CONTEXT_T pContext,
XLLP_UINT32_T block, BYTE *buffer)中添加代码
if(Card_type == CARDTYPE_SD20HC)
{
SDMMCSendCommand(pContext, XLLP_MMC_CMD17,block/512 , flags);
}
在XLLP_MMC.H中添加代码
// response types
XLLP_MMC_RESPONSE_R7 = 10L<<8,
在sdmmc.h中添加代码
XLLP_MMC_CMD8 = 0x8, // 4GB -32GB Sd card
#define CMD8_ARGUMENT 0x1AA
#define CMD41_ARGUMENT 0xf0ff8000
#define SD_OCR_SDHC 0x40ff8000
- 增加SD卡fat32文件系统的读
- sd卡与FAT32文件系统
- 基于ATmega32的SD卡上FAT32文件系统数据读取
- SD卡FAT32文件系统调试笔记
- SD卡中的FAT32文件系统(一)
- SD卡中的FAT32文件系统(二)
- FAT32文件系统格式(for sd)
- ZYNQ系统中实现FAT32文件系统的SD卡读写 之一 硬件介绍
- ZYNQ系统中实现FAT32文件系统的SD卡读写 之二 VIVADO配置
- ZYNQ系统中实现FAT32文件系统的SD卡读写之三 SDK编程调试
- ZYNQ系统中实现FAT32文件系统的SD卡读写之四 经验总结
- SD卡FAT32文件系统,如何访问具体文件
- 用WinHex查看SD卡FAT32文件系统结构
- 用WinHex查看SD卡FAT32文件系统结构
- SD卡中FAT32文件格式
- SD卡fat32文件格式说明
- DOS文件系统-FAT32的理解
- SD卡的FAT文件系统
- 设计技巧32:信使简化代码 Messenger 简单地将信息打包到一个用于传送的对象中
- SQL Server 2008中的代码安全(五):非对称密钥加密
- SQL SERVER 带包含列的索引
- Lua学习笔记(七)
- android 自定义水平的ProgressBar
- 增加SD卡fat32文件系统的读
- Extjs4 设置panel内部的gridpanel的滚动条
- mysql和sqlserver的order by 和group by和distinct引起的兼容性问题 max函数解决
- jsp中文乱码
- iphone ios app互相调用
- 异常与锁的释放(synchronized )
- 设计技巧33:从方法中获取信息 Collecting Parameter:集合参数,从方法中获取信息 容器比较常用
- android ClassicBT 概要介绍
- jrtplib下载地址