📄 flash4tffs.c
字号:
if (pDosVolDesc == NULL) { printf("dosFs still create failure! return to system control!\n"); return (ERROR); } else { printf("DosFs create success!\n"); } } else { printf("DosFs initalize success!\n"); } return (OK); }static FLStatus tffs_FlashRead(FLFlash vol,CardAddress address,void FAR1 * buffer, int length,int modes){ FAST UINT32 uiAddr; uiAddr = (UINT32)flMap(vol.socket, address); uiAddr -= g_tffs_DataBase; #ifdef GFLASH_DEBUG printf("tffs_FlashRead!\n"); #endif semTake(mm_SemFlash,WAIT_FOREVER); if(gFlash_Read(s_tffs_partid,uiAddr,(UINT8 *)buffer,length)) { semGive(mm_SemFlash); return ERROR; } semGive(mm_SemFlash); return (flOK);}static FLStatus tffs_FlashWrite(FLFlash vol,CardAddress address, const void * buffer,int dataLen,int modes){ FAST UINT32 uiAddr; #ifdef GFLASH_DEBUG printf("tffs_FlashWrite CardAddress=%d buffer=%d dataLen=%d\n",address, buffer, dataLen); #endif if (flWriteProtected(vol.socket)) { myAssert(0); return (ERROR); } #ifdef SOCKET_12_VOLTS checkStatus(flNeedVpp(vol.socket)); #endif uiAddr = (UINT32)flMap(vol.socket, address); uiAddr -= g_tffs_DataBase; #ifdef GFLASH_DEBUG printf("gFlash_Write address uiAddr=%d g_tffs_DataBase=%d\n",uiAddr,g_tffs_DataBase); #endif semTake(mm_SemFlash,WAIT_FOREVER);#if 1{ FAST CardAddress startBlock; int blockNum=0; FAST int count=0; startBlock = uiAddr & (~((UINT32)g_tffs_BlkSize-1)); if (((uiAddr + dataLen) % g_tffs_BlkSize) == 0 ) blockNum = (int)((uiAddr + dataLen - startBlock)/g_tffs_BlkSize); else blockNum = (int)((uiAddr + dataLen - startBlock)/g_tffs_BlkSize) + 1; #ifdef GFLASH_DEBUG printf("gFlash_Write flPartID=%d blockNum=%d g_tffs_DataBase=%d startBlock=%d\n",s_tffs_partid,blockNum,g_tffs_DataBase,startBlock); #endif for (count=0;count<blockNum;count++) { gFlash_Unlock(s_tffs_partid,(UINT32)(startBlock + count*g_tffs_BlkSize)); }}#endif if(gFlash_Write(s_tffs_partid,(UINT32)uiAddr,(UINT8 *)buffer,dataLen)) { myAssert(0); semGive(mm_SemFlash); return (ERROR); } semGive(mm_SemFlash); #ifdef GFLASH_DEBUG printf("tffs_FlashWrite OK!\n"); #endif return flOK; }static FLStatus tffs_FlashErase(FLFlash vol,int firstErasableBlock,int numOfErasableBlocks){ FAST int iBlock; UINT32 flashPtr; FLStatus status=flOK; #ifdef GFLASH_DEBUG printf("tffs_FlashErase! firstErasableBlock= %d numOfErasableBlocks=%d\n",firstErasableBlock, numOfErasableBlocks); #endif if (flWriteProtected(vol.socket)) { myAssert(0); return (flWriteProtect); } #ifdef SOCKET_12_VOLTS checkStatus(flNeedVpp(vol.socket)); #endif #ifdef GFLASH_DEBUG printf("flOK=%d \n", status); #endif semTake(mm_SemFlash,WAIT_FOREVER); for (iBlock = 0; (iBlock < numOfErasableBlocks)&&(status==flOK); iBlock++) { flashPtr =(firstErasableBlock + iBlock)*(vol.erasableBlockSize); status = tffs_EraseBlock(flashPtr); #ifdef GFLASH_DEBUG printf("tffs_FlashErase! flashPtr= %d status=%d \n",flashPtr, status); #endif } semGive(mm_SemFlash); #ifdef SOCKET_12_VOLTS flDontNeedVpp(vol.socket); #endif return status;}static FLStatus tffs_EraseBlock(UINT32 Addr){ UINT8 ucRet=0; #ifdef GFLASH_DEBUG printf("tffs_EraseBlock %x!\n",Addr); #endif ucRet=gFlash_Unlock(s_tffs_partid,Addr); if(ucRet) { return (ERROR); } ucRet=gFlash_Erase(s_tffs_partid,Addr); if(ucRet) { return (ERROR); } return (flOK);}void eraseTotalFlash(void){ UINT8 ucRet; printf("\nBegin erasing the flash ..."); semTake(mm_SemFlash,WAIT_FOREVER); printf("\nErasing TFFS zone ..."); ucRet=gFlash_UnlockAll(s_tffs_partid); if(ucRet) { printf(" Unlock failed!"); semGive(mm_SemFlash); return; } ucRet=gFlash_EraseAll(s_tffs_partid); if(ucRet) { printf(" Erase failed!"); semGive(mm_SemFlash); return; } printf("OK!\nErasing Boot Parameters zone ..."); ucRet=gFlash_UnlockAll(s_mac_partid); if(ucRet) { printf(" Unlock failed!"); semGive(mm_SemFlash); return; } ucRet=gFlash_EraseAll(s_mac_partid); if(ucRet) { printf(" Erase failed!"); semGive(mm_SemFlash); return; } printf("OK!"); printf("\nDone!"); semGive(mm_SemFlash);}extern int isValidCheckSum( void *pCfgPara);void InitBootCfgPara(char *pvCfgPara){ UINT32 *pMacAddr = (UINT32 *)s_MacDataBase; semTake(mm_SemFlash,WAIT_FOREVER); /* if(isValidCheckSum((void *)pMacAddr)) */ { memmove((char *)pvCfgPara,(char *)pMacAddr,256); } semGive(mm_SemFlash);}void ReadBootCfgPara(char *pvCfgPara){ semTake(mm_SemFlash,WAIT_FOREVER); gFlash_Read(s_mac_partid,0,pvCfgPara,256); semGive(mm_SemFlash);}int WriteBootCfgPara(char *pvCfgPara){ UINT8 ucRet; semTake(mm_SemFlash,WAIT_FOREVER); ucRet=gFlash_Unlock(s_mac_partid,0); if(ucRet) { semGive(mm_SemFlash); return (ERROR); } ucRet=gFlash_Erase(s_mac_partid,0); if(ucRet) { semGive(mm_SemFlash); return (ERROR); } ucRet=gFlash_Write(s_mac_partid,0,(char *)pvCfgPara,256); if(ucRet) { semGive(mm_SemFlash); return ERROR; } semGive(mm_SemFlash); return OK; }#ifdef LOGF_USED/* Routines for accessing log files */int logf_FlashRead (UINT32 uiStart, UINT8 *Buffer, UINT32 uiLen){ semTake(mm_SemFlash,WAIT_FOREVER); if(gFlash_Read(s_logf_partid,uiStart,(UINT8 *)Buffer,uiLen)) { semGive(mm_SemFlash); return ERROR; } semGive(mm_SemFlash); return OK;}int logf_FlashWrite(UINT32 uiStart, UINT8 *Buffer, UINT32 uiLen){ int iret; semTake(mm_SemFlash,WAIT_FOREVER); iret = gFlash_Write(s_logf_partid,uiStart,(char *)Buffer,uiLen); semGive(mm_SemFlash); return iret;}int logf_FlashErase(){ UINT8 ucRet; semTake(mm_SemFlash,WAIT_FOREVER); ucRet=gFlash_UnlockAll(s_logf_partid); if(ucRet) { semGive(mm_SemFlash); return (ERROR); } ucRet=gFlash_EraseAll(s_logf_partid); if(ucRet) { semGive(mm_SemFlash); return (ERROR); } semGive(mm_SemFlash); return OK; }UINT32 logf_GetFlashSize(){ return(s_mac_BlkSize);}#endifstatic const UINT8 Exp2N_Tbl[8]={1,2,4,8,16,32,64,128};static UINT8 IsValidChipSize(UINT32 uiBlkSize,UINT32 uiChipSize,UINT32 *uiVCS){ UINT8 i,q,m,p,f; f=0; p=0; *uiVCS = uiChipSize; q = uiChipSize/uiBlkSize; m = uiChipSize%uiBlkSize; for(i=0;i<8;i++) { if(q == Exp2N_Tbl[i]) { f=1; p=i+1; break; } else if(q > Exp2N_Tbl[i]) { p=i+1; } } if(!m && f) return 1; *uiVCS = Exp2N_Tbl[p] * uiBlkSize; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -