📄 m512_lgc.c
字号:
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries exited.\r\n");
return flOK ;
}
#ifndef FL_READ_ONLY
/***********************************************************************
* Name: M512_protectionSet
*
* Parameters:
* flashPtr - FLFlash struct
* AreaNo - Dps0 / Dps1 (0/1)
* AreaType:
* READ_PROTECTED - The area is protected against read operations.
* WRITE_PROTECTED - The area is protected against write operations.
* LOCK_PROTECTED - The Lock signal is enabled
* OTP_PROTECTED - Disables writing the protection key
* resulting a ROM-like partition
* LogicalLowUnit - The lowest Logical unit protected
* LogicalHighUnit - The highest Logical unit protected
* Key - Pointer to an 8 bytes array containing the key
* to be sent. If this field in set to NULL,
* the routine will automatically use the previous key.
* Modes:
* DO_NOT_COMMIT_PROTECTION Do not force a download of the controller
* state-machine at the end of the operation.
* COMMIT_PROTECTION Force a download of the controller
* state-machine and let the new protection
* parameters get into affect.
* ON_DPS_ONLY Ignores the boundary parameters and protect
* the DPS itself.
* LogicalHighUnit - The highest Logical unit protected
* MTD specific Flash get protection type routine
*
* No default routine is implemented for this routine.
*
* Parameters:
*
***********************************************************************/
FLStatus M512_protectionSet (FLFlash *flashPtr,FLByte bAreaNo,FLWord wAreaType,
FLWord wLogicalLowUnit,FLWord wLogicalHighUnit,
FLByte FAR1* Key,FLByte bModes,FLByte bFloor)
{
FLStatus status ;
DPS_Struct DPS,READ_DPS ;
PhyUnitType wPhyUnitArray [M512_MAX_NUMBER_OF_PLANES] ;
PhyUnitType wHighestPhyUnit,wLowestPhyUnit ;
FLWord i,wHighUnit,wLowUnit ;
#ifndef FL_SKIP_ARGS_CHECK
FLByte bLowFloor,bHighFloor;
#endif /* !FL_SKIP_ARGS_CHECK */
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries entered.\r\n");
flashPtr->completeOperation (flashPtr) ;
MTD_VARS->asicSetInNormalMode (flashPtr) ;
#ifndef ERASED_FLASH
/*** Step 1 - Before writing the DPS send default key ***/
status = M512_protectionKeyInsert(flashPtr,bAreaNo,(FLByte FAR1 *)("00000000")) ;
if (status)
{
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet:protectionKeyInsert returned status %d \r\n"),status)) ;
return flHWProtection ;
}
#endif
/*** Fill the reserved bytes with 0x00 ***/
tffsset (&DPS,0x0,sizeof(DPS)) ;
DPS.protectionType = M512_DPS_REVISION_NUMBER ;
if (wAreaType & READ_PROTECTED)
DPS.protectionType |= M512_READ_PROTECTED ; /* Enable read protection */
if (wAreaType & WRITE_PROTECTED)
DPS.protectionType |= M512_WRITE_PROTECTED ; /* Enable write protection */
if (wAreaType & LOCK_ENABLED)
DPS.protectionType |= M512_HW_LOCK_ENABLED ; /* Enable lock protection */
if (wAreaType & OTW_PROTECTED)
DPS.protectionType |= M512_OTP_PROTECTED ; /* Enable OTP protection */
if (Key)
{
tffscpy (DPS.protectionKey,Key,M512_KEY_LENGTH) ;
}
else
{
/* In this case key=NULL Read key from DPS */
status = M512_DPS_Read(flashPtr,&READ_DPS,(FL_DPS_IndexE)bAreaNo,M512_FIRST_GOOD_COPY,bFloor) ;
if (status)
{
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet: DPS_Read returned status %d \r\n"),status)) ;
return status ;
}
tffscpy (DPS.protectionKey,READ_DPS.protectionKey,M512_KEY_LENGTH) ;
}
if (bModes & MTD_ON_DPS_ONLY)
{
M512_AsicSetFloor (flashPtr,bFloor) ;
/*** Find the physical low Unit & Physical high units ***/
if (bAreaNo==0)
{
wHighUnit = M512_DPS0_HighProtectedUnit (flashPtr) ;
wLowUnit = M512_DPS0_LowProtectedUnit (flashPtr) ;
if ((wLowUnit==(wHighUnit-1)) && (wLowUnit==M512_DPS0_UnitLocation(flashPtr)))
{ /* In that case we don't need to protect the DPS since it is already protected ***/
return flOK ;
}
toLE2(DPS.lowUnit,M512_DPS0_UnitLocation(flashPtr)); /* Start from MainUnit */
toLE2(DPS.highUnit,(M512_DPS0_UnitLocation(flashPtr)+1)); /* End in Redundancy Unit */
}
else
{
wHighUnit = M512_DPS1_HighProtectedUnit (flashPtr) ;
wLowUnit = M512_DPS1_LowProtectedUnit (flashPtr) ;
if ((wLowUnit==(wHighUnit-1)) && (wLowUnit==M512_DPS1_UnitLocation(flashPtr)))
{ /* In that case we don't need to protect the DPS since it is already protected ***/
return flOK ;
}
toLE2(DPS.lowUnit, M512_DPS1_UnitLocation(flashPtr)); /* Start from MainUnit */
toLE2(DPS.highUnit,(M512_DPS1_UnitLocation(flashPtr)+1)); /* End in Redundancy Unit */
}
}
else
{
#ifndef FL_SKIP_ARGS_CHECK
bLowFloor = (FLByte)(wLogicalLowUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
if (bFloor!=bLowFloor)
{
DBG_PRINT_ERR(FLZONE_MTD,"DPS_Write:Floor given as input does not.\r\n") ;
DBG_PRINT_ERR(FLZONE_MTD,"DPS_Write:equal to floor derived from low unit.\r\n") ;
}
#endif /* !FL_SKIP_ARGS_CHECK */
/*** Translate the Logical unit to a set of Physical Units ***/
/*** The assumption is that there is one Good unit between Low & High units ***/
/*** and in that case LowUnit would not exceed above HighUnit ***/
while (wLogicalLowUnit<=wLogicalHighUnit)
{
if (MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalLowUnit,wPhyUnitArray)!=flOK)
wLogicalLowUnit++ ;
else
break ; /*** A matching for the low unit was found ***/
}
/*** Check that not all the units that DPS needs to protect are BB ***/
if (wLogicalLowUnit>wLogicalHighUnit)
return flUnitIsBad ;
/* Find the lowest unit in the array */
wLowestPhyUnit = wPhyUnitArray[0] ;
for (i=1;i<flashPtr->noOfPlanes;i++)
{
if (wPhyUnitArray[i]<wLowestPhyUnit)
wLowestPhyUnit = wPhyUnitArray[i] ;
}
/*** Divide the LowUnit by 2 because the unit in the DPS is defined ***/
/*** as the unit offset from the flash start & my mapping is different ***/
wLowestPhyUnit = wLowestPhyUnit>>1 ;
toLE2(DPS.lowUnit,wLowestPhyUnit); /* DPS.lowUnit = wLowestPhyUnit ; */
#ifndef FL_SKIP_ARGS_CHECK
bHighFloor = (FLByte)(wLogicalHighUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
if (bFloor!=bHighFloor)
{
DBG_PRINT_ERR(FLZONE_MTD,"DPS_Write:Floor given as input does not \r\n") ;
DBG_PRINT_ERR(FLZONE_MTD,"DPS_Write:equal to floor derived from high unit \r\n") ;
}
#endif /* !FL_SKIP_ARGS_CHECK */
/*** Translate the Logical unit to a set of Physical Units ***/
/*** The assumption is that there is one Good unit between Low & High units ***/
/*** and in that case HighUnit would not exceed below LowUnit ***/
while (MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalHighUnit,wPhyUnitArray)!=flOK)
wLogicalHighUnit-- ;
/* Find the highest unit in the array */
wHighestPhyUnit = wPhyUnitArray[0] ;
for (i=1;i<flashPtr->noOfPlanes;i++)
{
if (wPhyUnitArray[i]>wHighestPhyUnit)
wHighestPhyUnit = wPhyUnitArray[i] ;
}
/*** Divide the wHighestPhyUnit by 2 because the unit in the DPS is defined ***/
/*** as the unit offset from the flash start & my mapping is different ***/
wHighestPhyUnit = wHighestPhyUnit>>1 ;
toLE2(DPS.highUnit,wHighestPhyUnit); /* DPS.highUnit = wHighestPhyUnit ; */
}
status = M512_DPS_Write (flashPtr,&DPS,(FL_DPS_IndexE)bAreaNo,bFloor) ;
if (status)
{
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet:DPS_Write returned status %d \r\n"),status)) ;
return flHWProtection ;
}
if (bModes & COMMIT_PROTECTION)
{
status = flashPtr->download(flashPtr);
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries exited.\r\n");
return status ;
}
#endif /* FL_READ_ONLY */
#endif /* HW_PROTECTION */
/********************************************************************************
* Name : M512_doc2Identify
* This routine does the following :
* - perform call to the phyDoc2Identify
* - perform "hooking" of the Logical MTD API functions
* to the FLflash
* Status:
* Assumptions :
*******************************************************************************/
FLStatus M512_doc2Identify(FLFlash *flashPtr)
{
checkStatus(M512_phyDoc2Identify (flashPtr)) ;
#ifndef FL_READ_ONLY
flashPtr->flashWrite = M512_logicalWrite ;
flashPtr->flashErase = M512_logicalErase ;
#else
flashPtr->flashWrite = NULL;
flashPtr->flashErase = NULL;
#endif
flashPtr->flashRead = M512_logicalRead ;
flashPtr->getEraseCount = M512_getEraseCount ;
flashPtr->getEraseMark = M512_getEraseMark ;
flashPtr->setCallBack = M512_setCallBack ;
#ifdef HW_PROTECTION
flashPtr->protectionBoundries = M512_protectionBoundries ;
flashPtr->protectionKeyInsert = M512_protectionKeyInsert ;
flashPtr->protectionKeyRemove = M512_protectionKeyRemove ;
flashPtr->protectionType = M512_protectionType ;
#ifndef FL_READ_ONLY
flashPtr->protectionSet = M512_protectionSet ;
#endif /* FL_READ_ONLY */
#endif /* HW_PROTECTION */
return flOK ;
}
/************************************************************************
* flRegisterDOCM512 *
* *
* Registers this MTD for use *
* *
* Parameters: *
* None *
* *
* Returns: *
* FLStatus : 0 on success, otherwise failure *
************************************************************************/
FLStatus flRegisterDOCM512(void)
{
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCM512 Entered.\r\n");
if (noOfMTDs>=FL_MTDS)
return( flTooManyComponents );
/*** The mtdTable is a array of pointers to docPlusIdentify routines ***/
/*** Update the mtdTable[noOfMTDs++] with a pointer to my IdentifyDoc routine ***/
/*** & update the noOfMTDs global variable ***/
mtdTable[noOfMTDs++] = M512_doc2Identify ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCM512 Entered.\r\n");
return( flOK );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -