📄 tffs_api.c
字号:
/* Function name : TFFSCheckVolume*/
/* Description : */
/* Return type : static FLStatus */
/* Argument : IOreq* ioreq*/
/*----------------------------------------------------------------------*/
static FLStatus TFFSCheckVolume(IOreq* ioreq)
{
FLStatus flStatus;
if(dochVol.mountCount[FL_GET_FLASH_PARTITION_FROM_HANDLE(ioreq)] > 0)
flStatus = flOK;
else
flStatus = flNotMounted;
return flStatus;
}/*TFFSCheckVolume*/
#ifndef FL_READ_ONLY
/*----------------------------------------------------------------------*/
/* T F F S D e f r a g m e n t V o l u m e */
/* */
/* Performs a general defragmentation and recycling of non-writable */
/* Flash areas, to achieve optimal write speed. */
/* */
/* NOTE: The required number of sectors (in irLength) may be changed */
/* (from another execution thread) while defragmentation is active. In */
/* particular, the defragmentation may be cut short after it began by */
/* modifying the irLength field to 0. */
/* */
/* Parameters: */
/* irHandle : Drive number (0, 1, ...) */
/* bits 7-4 - Partition # (zero based) */
/* bits 3-0 - Socket # (zero based) */
/* irLength : Minimum number of sectors to make available for */
/* writes. */
/* */
/* Returns: */
/* irLength : Actual number of sectors available for writes */
/* FLStatus : 0 on success, otherwise failed */
/*----------------------------------------------------------------------*/
static FLStatus TFFSDefragmentVolume(IOreq* ioreq)
{
DOCH_Error rc;
IOreq myIoreq;
FLSDword request = ioreq->irLength;
TFFS_API_GET_UNIT_SIZE(myIoreq, ioreq, rc, flStatus);
/*Return values*/
/*=============*/
switch(request)
{
case FL_MINIMAL_DEFRAGMENTATION:
case FL_MAXIMUM_DEFRAGMENTATION:
ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
return flNotEnoughMemory;
case FL_STATIC_WEAR_LEVELING_DELAYED:
case FL_STATIC_WEAR_LEVELING_NOW:
case FL_STATIC_WEAR_LEVELING_ON:
case FL_STATIC_WEAR_LEVELING_OFF:
ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
break;
default:
if(request > 0)
ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
else
{
if(request == 0)
ioreq->irLength = 0;
else
return flBadParameter;
}
return flNotEnoughMemory;
}
return flOK;
}/*TFFSDefragmentVolume()*/
/*********************************************************/
/* Function name : tffsFormatSetProtectionAttribs*/
/* Description : */
/* Return type : FLStatus */
/* Argument : FLByte bProtType*/
/* Argument : DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI*/
/* Argument : FLByte * bKey*/
/* Argument : FLWord wKeyLen*/
/*********************************************************/
static FLStatus tffsFormatSetProtectionAttribs( FLByte bProtType, DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI,
FLByte * pKey, FLWord wKeyLen)
{
FLBoolean read_protect, write_protect, change_protect, locked;
read_protect = write_protect = change_protect = locked =FALSE;
/*Enabled Protections*/
if( (bProtType & READ_PROTECTED) == READ_PROTECTED)
read_protect = TRUE;
if( (bProtType & WRITE_PROTECTED) == WRITE_PROTECTED)
write_protect = TRUE;
if( (bProtType & CHANGEABLE_PROTECTION) == CHANGEABLE_PROTECTION)
change_protect = TRUE;
if( (bProtType & LOCK_ENABLED) == LOCK_ENABLED)
locked = TRUE;
/*Protection requested*/
if(read_protect || write_protect)
{
pPartitionFormatInfoAPI->dwProtectionType = DOCH_PARTITION_PWD_PROTECTED;
/*Specific protection*/
if(read_protect)
{
pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_NONE;
}
else /*write_protect*/
{
pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_RO;
}
}
else
{/*No protection requested or changeable protection only requested */
pPartitionFormatInfoAPI->dwProtectionType = (change_protect!=FALSE)?DOCH_PARTITION_PWD_PROTECTED:DOCH_PARTITION_NOT_PROTECTED;
pPartitionFormatInfoAPI->dwUserAccessMode = DOCH_PART_ACCESS_MODE_FULL;
pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_FULL;
}
/* lock notification */
pPartitionFormatInfoAPI->dwLockControl = (locked==TRUE) ? DOCH_LOCK_ACTIVE : DOCH_LOCK_NOT_ACTIVE;
/*Passkey*/
if(read_protect || write_protect || change_protect)
{
tffscpy(pPartitionFormatInfoAPI->bPasskey, pKey, wKeyLen);
}
return flOK;
}/*tffsFormatSetProtectionAttribs*/
#ifdef FL_FORMAT_VOLUME
/*----------------------------------------------------------------------*/
/* T F F S F l a s h F o r m a t */
/* */
/* Performs formatting of the DiskOnChip. */
/* All existing data is destroyed. */
/* */
/* Note : This routine is the format routine for OSAK 5.0 and up. */
/* */
/* Parameters: */
/* irHandle : Socket number (0, 1, ...) */
/* Partition number must be 0 */
/* irFlags : */
/* TL_NORMAL_FORMAT : Normal format */
/* TL_LEAVE_BINARY_AREA : Leave the previous binary area */
/* TL_LEAVE_SOME_BINARY_AREA : Leave some of the previous */
/* TL_DO_NOT_PERFORM_DOWNLOAD */
/* binary partitions. */
/* irData : Address of FormatParams3 structure to use */
/* (defined in format.h) */
/* irLength : If the TL_LEAVE_SOME_BINARY_AREA flag is set, */
/* this field will indicate the number of binary */
/* partitions to leave. */
/* */
/* Returns: */
/* FLStatus : 0 on success, otherwise failed */
/*----------------------------------------------------------------------*/
static FLStatus TFFSflashFormat(IOreq* ioreq)
{
DOCH_Error rc = DOCH_OK;
IOreq myIoreq;
FLSNative i=0;
FLByte partNum=0, numOfBinaryPartitions, totalNumOfPartitions;
FormatParams3 FAR1 * FP3 = (FormatParams3 FAR1 *)ioreq->irData;
BDTLPartitionFormatParams3 FAR2 * bdtlUserParams;
BinaryPartitionFormatParams3 FAR2 * binUserParams;
FLSNative total_num_of_partitions = (FP3->noOfBinaryPartitions + FP3->noOfBDTLPartitions);
FLSNative numOfParToLeave = 0;
FLSNative numOfBinaryParToLeave = 0;
FLByte bOtpPresent, bIplPresent;
FLWord lastRemainingPartition, wNumOfOriginalPartitions;
FLByte* intBuf = dochVol.intermediateBuf;
DOCH_DiskUserAttrWithBinary* pDiskUserAttrWithBinary = (DOCH_DiskUserAttrWithBinary*)intBuf;
DOCH_PartitionUserAttrWithBinary* pPartitionUserAttrWithBinary = (DOCH_PartitionUserAttrWithBinary*)intBuf;
DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI = (DOCH_PartitionFormatInfoAPI*)intBuf;
DOCH_Socket* pDev;
#ifdef BDK_ACCESS
FLDword dwPartitionTotalSize;
#endif /*BDK_ACCESS*/
DOCH_get_socket(pDev, FL_GET_SOCKET_FROM_HANDLE(ioreq));
if( pDev==NULL )
return flBadParameter;
/*If binary partitions requested and no BDK support - return error*/
#ifndef BDK_ACCESS
if(FP3->noOfBinaryPartitions > 0)
{
DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): Binary partitions not supported when BDK_ACCESS Not Defined!\r\n")));
return flBadParameter;
}
#endif /*BDK_ACCESS*/
/*Retrieve disk attributes*/
tffsset(&myIoreq, 0, sizeof(myIoreq));
myIoreq.irHandle = FL_GET_SOCKET_FROM_HANDLE(ioreq);
myIoreq.irData = intBuf;
rc = flDOCHGetDiskUserAttributes(&myIoreq);
if(rc != DOCH_OK)
{
DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHGetDiskUserAttributes failed with status: 0x%x "), rc));
return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
}
/* Get some data from disk attributes sector */
numOfBinaryPartitions = pDiskUserAttrWithBinary->bNumOfBinaryPartitions;
bIplPresent = pDiskUserAttrWithBinary->bIplPresent;
bOtpPresent = pDiskUserAttrWithBinary->bOtpPresent;
totalNumOfPartitions = (FLByte)pDev->wTotalNumOfPartitions;
/* check for corruption during format or wrong format */
/* wrong signature */
if( (tffscmp(pDiskUserAttrWithBinary->bMigrationSignature, TFFS_API_MIGRATION_SIGNATURE,
sizeof(pDiskUserAttrWithBinary->bMigrationSignature)) != 0)
/* disk attributes not match no. of partitions */
|| (pDev->wTotalNumOfPartitions<2 && bIplPresent && bOtpPresent)
/* there are enough partitions but IPL or/and OTP indication corrupted */
|| (pDev->wTotalNumOfPartitions>2 && (bIplPresent!=1 || bOtpPresent!=1)) )
{
bIplPresent = 0;
bOtpPresent = 0;
numOfBinaryPartitions = 0;
}
#ifdef BDK_ACCESS
/*Calculate how many binary partition to LEAVE*/
if(ioreq->irFlags == TL_LEAVE_BINARY_AREA)
{
numOfParToLeave = numOfBinaryPartitions;
numOfBinaryParToLeave = numOfBinaryPartitions;
}
else
{
if(ioreq->irFlags == TL_LEAVE_SOME_BINARY_AREA)
{
numOfParToLeave = ioreq->irLength;
numOfBinaryParToLeave = TFFSMIN(numOfBinaryPartitions, numOfParToLeave);
}
else
{
numOfParToLeave = 0;
numOfBinaryParToLeave = 0;
}
}
if(numOfParToLeave > totalNumOfPartitions)
{
DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): numOfParToLeave > totalNumOfPartitions \r\n ");
return flBadParameter;
}
if((numOfBinaryParToLeave + FP3->noOfBinaryPartitions) > MAX_BINARY_PARTITIONS_PER_DRIVE)
{
DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): Number of binary partitions exceed maximum allowed.\r\n ");
return flBadParameter;
}
if((numOfParToLeave > numOfBinaryPartitions) && (FP3->noOfBinaryPartitions > 0))
{
DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): Can`t create Binary after BDTL.\r\n ");
return flBadParameter;
}
#else /*BDK_ACCESS*/
if(ioreq->irFlags == TL_LEAVE_SOME_PARTITIONS)
{
numOfParToLeave = ioreq->irLength;
numOfBinaryParToLeave = numOfBinaryPartitions;
}
else
{
numOfParToLeave = 0;
numOfBinaryParToLeave = 0;
}
#endif /*BDK_ACCESS*/
if((numOfParToLeave + FP3->noOfBinaryPartitions + FP3->noOfBDTLPartitions) > FL_VOLUMES)
{
DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): Number of partitions exceed maximum allowed.\r\n ");
return flBadParameter;
}
/*Calculate number of remaining partitions*/
lastRemainingPartition = (numOfParToLeave + bOtpPresent + bIplPresent);
/*Retrieve DOCH extended info structure*/
/*-------------------------------------*/
TFFS_API_GET_UNIT_SIZE(myIoreq, ioreq, rc, flStatus);
wNumOfOriginalPartitions = ((DOCH_DeviceInfo*)intBuf)->wTotalNumOfPartitions;
/*Clear partition attributes for partitions to be deleted */
if(lastRemainingPartition > 0)
{
tffsset(intBuf, 0, DOCH_SECTOR_SIZE);
tffsset(&myIoreq, 0, sizeof(myIoreq));
myIoreq.irData = intBuf;
for(i=lastRemainingPartition; i < wNumOfOriginalPartitions; i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -