📄 fltl.c
字号:
#endif /* NO_NFTL_2_INFTL */
/*----------------------------------------------------------------------*/
/* f l P r e M o u n t */
/* */
/* Perform TL operation before the TL is mounted */
/* */
/* Notes for FL_COUNT_VOLUMES routine */
/* ---------------------------------- */
/* Note : The number of partitions returned is not neccarily the number */
/* That can be accesses. protected partitions will need a key. */
/* Note : TL that do not support several partitions will return 1 */
/* unless the socket can not be mounted in which case 0 will be */
/* returned. */
/* */
/* Parameters: */
/* callType : The type of the operation (see blockdev.h) */
/* ioreq : Input Output packet */
/* ioreq.irHandle : handle discribing the socket and the partition */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flPreMount(FLFunctionNo callType, IOreq FAR2* ioreq , FLFlash * flash)
{
FLStatus layerStatus = flUnknownMedia;
FLStatus callStatus;
FLSocket *socket = flSocketOf(FL_GET_SOCKET_FROM_HANDLE(ioreq));
int iTL;
/* Patch for OS drivers that call flInit before socket is initialized */
if (callType == FL_COUNT_VOLUMES)
{
if((socket == NULL) || (socket->window.base==NULL))
{
ioreq->irFlags = 1;
return flOK;
}
}
/* Identify flash medium and initlize flash record */
callStatus = flIdentifyFlash(socket,flash);
if (callStatus != flOK && callStatus != flUnknownMedia)
return callStatus;
/* Try sending call to the diffrent TLs */
for (iTL = 0; (iTL < doc_noOfTLs) && (layerStatus != flOK); iTL++)
{
if (tlTable[iTL].preMountRoutine != NULL)
{
/*layerStatus = tlTable[iTL].preMountRoutine(callType,ioreq, flash,&callStatus);*/
layerStatus=preMountINFTL(callType,ioreq, flash,&callStatus);
}
}
if (layerStatus != flOK)
{
switch (callType)
{
case FL_COUNT_VOLUMES:
ioreq->irFlags = 1;
return flOK;
#ifdef FORMAT_VOLUME
case FL_WRITE_BBT:
{
CardAddress endUnit = ((dword)(flash->chipSize * flash->noOfChips) >> flash->erasableBlockSizeBits); /* Media size */
CardAddress unitsPerFloor = endUnit/flash->noOfFloors;
CardAddress iUnit;
CardAddress bUnit = *((unsigned long FAR1 *) ioreq->irData)
>> flash->erasableBlockSizeBits;
word badBlockNo;
/* In case the user has given a specific length use it
instead of the entire media */
if ((ioreq->irLength != 0) && ( endUnit >
((dword)ioreq->irLength >> flash->erasableBlockSizeBits)))
{
endUnit = ioreq->irLength >> flash->erasableBlockSizeBits;
}
/* Millennium Plus DiskOnChip Family do not need a write bbt call */
if ((flash->mediaType == MDOCP_TYPE ) ||
(flash->mediaType == MDOCP_16_TYPE) )
{
DEBUG_PRINT(("DiskOnChip Millennium Plus has a H/W protected BBT.\r\n"));
DEBUG_PRINT(("No need to erase the DiskOnChip. Simply reformat.\r\n"));
return flFeatureNotSupported;
}
/* Erase entire media */
for (iUnit = flash->firstUsableBlock ,badBlockNo = 0;
iUnit < endUnit ;iUnit += ((iUnit+1) / unitsPerFloor) ?
1 : flash->firstUsableBlock + 1)
{
DFORMAT_PRINT(("Erasing unit number %ld\r",iUnit));
if (ioreq->irFlags > badBlockNo) /* There are additional bad blocks */
{
if (bUnit == iUnit)
{
badBlockNo++;
bUnit = (*((CardAddress FAR1 *)flAddLongToFarPointer
(ioreq->irData,badBlockNo*sizeof(CardAddress))))
>> flash->erasableBlockSizeBits;
flash->erase(flash,(word)iUnit,1);
markUnitBad(flash,iUnit);
continue;
}
}
callStatus = flash->erase(flash,(word)iUnit,1);
if (callStatus != flOK) /* Additional bad block was found */
{
/* DFORMAT_PRINT(("Failed erasing unit in write BBT (unit no %lu).\r\n",iUnit));*/
markUnitBad(flash,iUnit);
}
}
DEBUG_PRINT(("\nUnformat Complete \r\n"));
return flOK;
}
#endif /* FORMAT_VOLUME */
default : /* Protection routines */
return flFeatureNotSupported;
}
}
return callStatus;
}
/*----------------------------------------------------------------------*/
/* f l M o u n t */
/* */
/* Mount a translation layer */
/* */
/* Parameters: */
/* volNo : Volume no. */
/* socketNo : The socket no */
/* tl : Where to store translation layer methods */
/* useFilters : Whether to use filter translation-layers */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flMount(unsigned volNo, unsigned socketNo,TL *tl,
FLBoolean useFilters , FLFlash * flash)
{
FLFlash *volForCallback = NULL;
FLSocket *socket = flSocketOf(socketNo);
FLStatus status = flUnknownMedia;
int iTL;
FLStatus flashStatus = flIdentifyFlash(socket,flash);
if (flashStatus != flOK && flashStatus != flUnknownMedia)
return flashStatus;
tl->recommendedClusterInfo = NULL;
tl->writeMultiSector = NULL;
tl->readSectors = NULL;
#ifndef NO_READ_BBT_CODE
tl->readBBT = NULL;
#endif
#if (defined(VERIFY_VOLUME) || defined(VERIFY_WRITE))
tl->checkVolume = NULL;
#endif /* VERIFY_VOLUME || VERIFY_WRITE */
#ifdef DEFRAGMENT_VOLUME
tl->defragment = NULL;
#endif /* DEFRAGMENT */
for (iTL = 0; (iTL < doc_noOfTLs) && (status != flOK) && (status != flHWProtection); iTL++)
if (tlTable[iTL].formatRoutine != NULL) /* not a block-device filter */
status = tlTable[iTL].mountRoutine(volNo,tl,flashStatus == flOK ? flash : NULL,&volForCallback);
if (status == flOK) {
if (volForCallback)
volForCallback->setPowerOnCallback(volForCallback);
if (useFilters)
for (iTL = 0; iTL < doc_noOfTLs; iTL++)
if (tlTable[iTL].formatRoutine == NULL) /* block-device filter */
if (tlTable[iTL].mountRoutine(volNo,tl,NULL,NULL) == flOK)
break;
}
return status;
}
#ifdef FORMAT_VOLUME
/*----------------------------------------------------------------------*/
/* f l F o r m a t */
/* */
/* Formats the Flash volume */
/* */
/* Parameters: */
/* volNo : Physical drive no. */
/* formatParams : Address of FormatParams structure to use */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flFormat(unsigned volNo, TLFormatParams * formatParams,
FLFlash * flash)
{
BinaryPartitionFormatParams FAR1* partitionPtr;
FLSocket * socket = flSocketOf(volNo);
FLStatus status = flUnknownMedia;
int iTL,partitionNo;
FLStatus flashStatus = flIdentifyFlash(socket,flash);
if (flashStatus != flOK && flashStatus != flUnknownMedia)
return flashStatus;
/* Validity check for formatParams */
if (!(flash->flags & INFTL_ENABLED)) /* Flash does not support INFTL */
{
if ((formatParams->noOfBDTLPartitions > 1) ||
#ifdef HW_PROTECTION
((formatParams->BDTLPartitionInfo != NULL) &&
(formatParams->BDTLPartitionInfo->protectionType & PROTECTABLE)) ||
((formatParams->noOfBinaryPartitions > 0)&&
(formatParams->binaryPartitionInfo->protectionType & PROTECTABLE)) ||
#endif /* HW_PROTECTION */
(formatParams->noOfBinaryPartitions > 1))
{
DEBUG_PRINT(("Debug: feature not supported by the TL.\r\n"));
return flFeatureNotSupported;
}
}
for(partitionNo = 0 , partitionPtr = formatParams->binaryPartitionInfo;
partitionNo < formatParams->noOfBinaryPartitions;
partitionNo++,partitionPtr++)
{
if(*((dword FAR1*)(partitionPtr->sign)) == 0xffffffffL)
{
DEBUG_PRINT(("Debug: can not use 'FFFF' signature for Binary partition\r\n"));
return flBadParameter;
}
}
/* Try each of the registered TL */
#ifndef NO_NFTL_2_INFTL
checkStatus(check43Format(flash));
#endif /* NO_NFTL_2_INFTL */
for (iTL = 0; iTL < doc_noOfTLs && status == flUnknownMedia; iTL++)
if (tlTable[iTL].formatRoutine != NULL) /* not a block-device filter */
status = tlTable[iTL].formatRoutine(volNo,formatParams,flashStatus == flOK ? flash : NULL);
return status;
}
#endif
FLStatus noFormat (unsigned volNo, TLFormatParams * formatParams, FLFlash *flash)
{
return flOK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -