📄 matchalg.c
字号:
(MTD_VARS->dwLogicalUnitsInPlatform<<MTD_VARS->bNoOfPlanesBits)/100*
(FLDword)sizeof (PhyUnitType)*(FLDword)((1<<MTD_VARS->bNoOfPlanesBits)-1)) ;
#else /*** Dynamic allocation ***/
/*** Static allocation ***/
MATCH_VARS->mathLookup.bTable = &(MathLookUpTable_Table[socketNo][0]) ;
MATCH_VARS->lookUpTable.logicalUnit = &(LookUp_logicalUnit[socketNo][0]) ;
MATCH_VARS->lookUpTable.physicalUnit = &(LookUp_physicalUnit[socketNo][0]) ;
#ifndef FL_SKIP_ARGS_CHECK
/*** Check that thge user has written the right parameters ***/
if (flashPtr->mediaSize>((FLDword)FL_ASSUMED_MAX_VOLUME_MBYTES<<20L))
{
DBG_PRINT_ERR(FLZONE_MTD,"ERROR - Media size is larger then customized in flcustom.h (FL_ASSUMED_MAX_VOLUME_MBYTES)\r\n") ;
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("ERROR Media size=%uMB while TrueFFS was customized for =%uMB \r\n"),(FLWord)(flashPtr->mediaSize>>20L),(FLWord)FL_ASSUMED_MAX_VOLUME_MBYTES)) ;
return flBadParameter;
}
if (flashPtr->erasableBlockSize<FL_ASSUMED_MIN_UNIT_SIZE)
{
DBG_PRINT_ERR(FLZONE_MTD,"ERROR Unit size is smaller then customized in flcustom.h (FL_ASSUMED_MIN_UNIT_SIZE)\r\n") ;
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("ERROR Unit size=%lu while TrueFFS is customized for %lu\r\n"),flashPtr->erasableBlockSize,FL_ASSUMED_MIN_UNIT_SIZE)) ;
return flBadParameter;
}
#endif /* !FL_SKIP_ARGS_CHECK */
#endif
tffsset (MATCH_VARS->mathLookup.bTable,MTD_MATH,MATCH_VARS->mathLookup.dwTableSize) ;
if((MATCH_VARS->mathLookup.bTable == NULL) ||
(MATCH_VARS->lookUpTable.logicalUnit == NULL) ||
(MATCH_VARS->lookUpTable.physicalUnit == NULL))
{
DBG_PRINT_ERR(FLZONE_MTD,"ERROR in createLogicalMapping: Not enough memory.\r\n") ;
return flNotEnoughMemory;
}
MATCH_VARS->lookUpTable.dwTableSize = 0 ;
MATCH_VARS->fTablesForLogicalMapWereCreated = TRUE ; /* A flag that we know the second time that mallocing is not necessary */
}
/*** Step 3,4 - Find the Logical unit to start from ***/
/*** Find from the table the first available logical unit in floor 0 ***/
wLastUnit = MATCH_VARS->FirstAvailUnitTable[0]; ;
/*** Now wUnit holds the first logical unit after the media header ***/
wFirstUnit = wLastUnit ;
for (i=0;i<argsPackPtr->noOfPartitions;i++)
{
/* Insert first unit to the noOfUnitsArray */
argsPackPtr->noOfFirstUnitsArray[i] = wFirstUnit ;
checkStatus(MATCH_PerformMatchingAlgorithm (flashPtr,argsPackPtr->partitionsFlags[i],argsPackPtr->noOfUnitsArray[i],wFirstUnit,&wLastUnit,&wMatchedNoOfUnits,TRUE)) ;
if (argsPackPtr->noOfUnitsArray[i] != wMatchedNoOfUnits)
{ /* Means that that the PerformMatchingAlgorithm was not able to match the
number of logical good units requested for this partition in that case
calculate how many logical good units are missing */
/* Calculate the missing logical good units in the partition that matching failed */
argsPackPtr->unusedBlocks = (FLSDword)wMatchedNoOfUnits - (FLSDword)argsPackPtr->noOfUnitsArray[i] ;
/* Add to this number the number of good units needed in the reminding partitions */
for (j=i+1;j<argsPackPtr->noOfPartitions;j++)
argsPackPtr->unusedBlocks -= (FLSDword)argsPackPtr->noOfUnitsArray[j] ;
return flOK ;
}
/* Calculate the size of each partition in logical units */
argsPackPtr->partitionLogicalSize[i] = wLastUnit-wFirstUnit + 1 ;
wFirstUnit = wLastUnit + 1;
/* Now wLastUnit holds the first logical unit of the next partition */
/* Make sure the next partition does not start on the unavailable blocks */
if(((wFirstUnit % MTD_VARS->dwLogicalUnitsInFloor) == 0) &&
(wFirstUnit < MTD_VARS->dwLogicalUnitsInPlatform ) )
wFirstUnit = MATCH_VARS->FirstAvailUnitTable[wFirstUnit / MTD_VARS->dwLogicalUnitsInFloor];
} /* End loop - match the partitions */
/*** Step 5 - Calculate the unused blocks Field ***/
/* The field would return:
In case of matching success: The number of unused logical good blocks
In case of matching failure: The number of missing logical good blocks (-)
If last partition is MTD_SM:
The calculation of the logical units would be done as if
is is an independent area.
If last partition is MTD_AM:
The calculation of the logical units would be done as if
is is a part of the last partition
In both cases the matching would be done in AM
*/
if (argsPackPtr->partitionsFlags[argsPackPtr->noOfPartitions-1]==MTD_AM) /* The last partition is AM */
{
/* Find back the first logical unit of the last partition */
wFirstUnit = argsPackPtr->noOfFirstUnitsArray[i-1];
/* Perform matching algorithm of the last partition with big size */
checkStatus(MATCH_PerformMatchingAlgorithm (flashPtr,MTD_AM,BIGGEST_PARTITION_SIZE,wFirstUnit,&wLastUnit,&wMatchedNoOfUnits,FALSE)) ;
/* The PerformMatchingAlgorithm was not able to do the matching so it returned in
the wMatchedNoOfUnits field the number of logical good units which it managed to
find => This value would be written to the unusedBlocks field */
argsPackPtr->unusedBlocks = (FLSDword)wMatchedNoOfUnits-(FLSDword)argsPackPtr->noOfUnitsArray[i-1] ;
}
else
{
checkStatus(MATCH_PerformMatchingAlgorithm (flashPtr,MTD_AM,BIGGEST_PARTITION_SIZE,wFirstUnit,&wLastUnit,&wMatchedNoOfUnits,FALSE)) ;
/* The PerformMatchingAlgorithm was not able to do the matching so it returned in
the wMatchedNoOfUnits field the number of logical good units which it managed to
find => This value would be written to the unusedBlocks field */
argsPackPtr->unusedBlocks = (FLSDword)wMatchedNoOfUnits ;
}
#ifdef DEBUG_MTD
MATCH_printLOOKUP_Table (flashPtr) ;
#endif
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: createLogicalMapping exited.\r\n") ;
return flOK ;
}
/************************************************************************
* Name : MATCH_readBBT ()
*
* Parameters:
* flashPtr: The flash struct.
* The following arguments are passed using the flashPtr->args.XXX
* readMainBuf : User buffer for BB
* startUnit : Logical unit to start from
* noOfUnits : Number of logical unit to report
*
* Returns :
* flOK on success , any other value for failure
************************************************************************/
FLStatus MATCH_readBBT (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
LogicUnitType wUnit ;
FLDword dwPhyUnitArray[MAX_NUMBER_OF_PLANES];
FLBoolean fAllUnitAreGood,fMATCH_isGoodBlock;
FLByte FAR1 *bBBT_BuffPtr ;
FLWord i,wEndUnit ;
FLByte bFloor ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: readBBT entered.\r\n");
checkStatus (MTD_VARS->asicSetInNormalMode (flashPtr)) ;
flashPtr->completeOperation (flashPtr) ;
argsPackPtr = &(flashPtr->args) ;
bBBT_BuffPtr = argsPackPtr->readMainBuf ;
/*** Dummy call to this function => so that it will fill the BBT buffer cache */
checkStatus(MTD_VARS->isGoodBlock (flashPtr,0,ALWAYS_READ_FROM_FLASH,&fMATCH_isGoodBlock)) ;
wEndUnit = argsPackPtr->startUnit+argsPackPtr->noOfUnits;
if (MATCH_VARS->fTablesForLogicalMapWereCreated==FALSE)
{ /* In this case we have no tables => Check using a simple mathematical rule */
/* Find the Physical units of the Logical unit using mathematical formula */
for (wUnit=argsPackPtr->startUnit ; wUnit < wEndUnit ; wUnit++,bBBT_BuffPtr++)
{
bFloor = (FLByte)(wUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
/* Check if this unit is one of the units in the floor that the ASIC uses for download */
if ((wUnit%MTD_VARS->dwLogicalUnitsInFloor) < (FLWord)
((MTD_VARS->FirstUsableBlock[bFloor]+flashPtr->noOfPlanes-1)>>MTD_VARS->bNoOfPlanesBits))
{
*bBBT_BuffPtr=BBT_UNAVAIL_UNIT ;
}
else /* Find the Physical unit using a simple mathematical rule */
{
fAllUnitAreGood = TRUE ;
for (i=0;i<flashPtr->noOfPlanes;i++)
{
dwPhyUnitArray[i]=(wUnit<<MTD_VARS->bNoOfPlanesBits)+i ;
/* Check if one of these physical units is bad block */
checkStatus(MTD_VARS->isGoodBlock (flashPtr,dwPhyUnitArray[i],USE_BBT_CACHE,&fMATCH_isGoodBlock));
if (fMATCH_isGoodBlock==FALSE)
fAllUnitAreGood = FALSE ;
}
if (fAllUnitAreGood==TRUE)
*bBBT_BuffPtr=BBT_GOOD_UNIT ;
else
*bBBT_BuffPtr=BBT_BAD_UNIT ;
}
} /* End loop over required units */
}
else /* Logical mapping was done */
{
for (wUnit=argsPackPtr->startUnit ; wUnit < wEndUnit ; wUnit++,bBBT_BuffPtr++)
{
bFloor = (FLByte)(wUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
/* Check if this unit is one of the units in the floor that the ASIC uses for download */
if ((wUnit%MTD_VARS->dwLogicalUnitsInFloor) < (FLWord)
((MTD_VARS->FirstUsableBlock[bFloor]+flashPtr->noOfPlanes-1)>>MTD_VARS->bNoOfPlanesBits))
{
*bBBT_BuffPtr=BBT_UNAVAIL_UNIT ;
}
else if (wUnit<MATCH_VARS->FirstAvailUnitTable[bFloor])
{ /*** In this case this unit is a bad unit after the ASIC dedicated units ***/
/*** (because the FirstAvailUnitTable holds the first logical unit after ***/
/*** the skipped unit (media header) ***/
fAllUnitAreGood = TRUE ;
for (i=0;i<flashPtr->noOfPlanes;i++)
{
dwPhyUnitArray[i]=(wUnit<<MTD_VARS->bNoOfPlanesBits)+i ;
/* Check if one of these physical units is bad block */
checkStatus(MTD_VARS->isGoodBlock (flashPtr,dwPhyUnitArray[i],USE_BBT_CACHE,&fMATCH_isGoodBlock));
if (fMATCH_isGoodBlock==FALSE)
fAllUnitAreGood = FALSE ;
}
if (fAllUnitAreGood==TRUE)
*bBBT_BuffPtr=BBT_GOOD_UNIT ;
else
*bBBT_BuffPtr=BBT_BAD_UNIT ;
}
else if (!MATCH_IsLookUpUnit (flashPtr,wUnit))
{
*bBBT_BuffPtr=BBT_GOOD_UNIT ;
}
else /* Check if it appears in the Lookup table */
{
if (MATCH_searchLOOKUP_Table (flashPtr,wUnit,(PhyUnitType *)(dwPhyUnitArray))==TRUE)
*bBBT_BuffPtr=BBT_GOOD_UNIT ;
else
*bBBT_BuffPtr=BBT_BAD_UNIT ;
}
}
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: readBBT exited.\r\n");
return flOK ;
}
/***********************************************************************
* Name : MATCH_freeMemory
* Frees all the memory allocated by the MTD (only if it was allocated)
*
* Parameters:
* The routine return the following error codes:
* flOK : Success
*
***********************************************************************/
FLStatus MATCH_freeMemory (FLFlash *flashPtr)
{
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: freeMemory entered.\r\n");
if (MATCH_VARS->fTablesForLogicalMapWereCreated)
{
#ifdef MTD_READ_BBT
#ifdef FL_MALLOC
/*** Free the memory - Mathematical/LookUpTable ***/
FL_FREE (MATCH_VARS->mathLookup.bTable) ;
/*** Free the memory - LookUpTable ***/
FL_FREE (MATCH_VARS->lookUpTable.logicalUnit) ;
FL_FREE (MATCH_VARS->lookUpTable.physicalUnit) ;
#endif /* FL_MALLOC */
#endif /* MTD_READ_BBT */
MATCH_VARS->fTablesForLogicalMapWereCreated = FALSE ;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: freeMemory exited.\r\n");
return flOK ;
}
#endif /* MTD_READ_BBT */
/************************************************************************
* Name : MATCH_init ()
* 1. Initialize the flashPtr->mtdVars struct to point at MTD_VARS_ARR
*
* Parameters:
* flashPtr: The flash struct.
* Returns :
* flOK on success , any other value for failure
************************************************************************/
void MATCH_init (FLFlash *flashPtr)
{
FLByte socketNo = (FLByte)flSocketNoOf (flashPtr->socket);
flashPtr->mtdVars = &MTD_VARS_ARR[socketNo];
MTD_VARS->SavedDOC_State_Ptr = &SAVED_STATE[socketNo] ;
MTD_VARS->MATCH_unitLogicalToPhysical = MATCH_unitLogicalToPhysical ;
#ifdef MTD_READ_BBT
#ifdef HW_PROTECTION
MTD_VARS->MATCH_searchPhyUnitInLOOKUP_Table = MATCH_searchPhyUnitInLOOKUP_Table ;
#endif
flashPtr->readBBT = MATCH_readBBT ;
flashPtr->definePartitions = MATCH_createLogicalMapping ;
flashPtr->dismount = MATCH_freeMemory ;
MTD_VARS->MatchingAlgVars = &MATCH_VARS_ARR[socketNo] ;
MATCH_VARS->fTablesForLogicalMapWereCreated = FALSE ; /* This default would ensure that we will do SM before calling DefinePartition */
#endif /* MTD_READ_BBT */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -