📄 oren_lgc.c
字号:
if (argsPackPtr->extraBuf)
{
#ifndef NO_PHYSICAL_IO
if(argsPackPtr->opFlags & MTD_SW_EDC)
bExtraBufferPtr = BYTE_ADD_FAR (bExtraBufferPtr,wNoOfWrittenSectors*(FLASH_SECTOR_HM_SIZE + FLASH_SECTOR_BCH_SIZE));
#endif /* NO_PHYSICAL_IO */
/* Advance pointer by 8 * NoOfWrittenSectors */
bExtraBufferPtr = BYTE_ADD_FAR (bExtraBufferPtr,wNoOfWrittenSectors*FLASH_EXTRA_BUFFER_SIZE) ;
}
dwNoOfSectors -= wNoOfWrittenSectors ;
dwLogicalSectorNo += wNoOfWrittenSectors ;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalWrite exited.\r\n");
return flOK ;
}
#endif
#ifndef FL_READ_ONLY
/***********************************************************************
* Name : OREN_logicalWriteEraseMark
* Write the erase Mark to a logical unit
* The EraseMARK would be written to the first physical unit in the
* first page in the last FLByte of the extra area (offset 527)
* Parameters:
*
* Returns:
* ErrorStatus:
*
***********************************************************************/
FLStatus OREN_logicalWriteEraseMark (FLFlash *flashPtr,LogicUnitType wLogicalUnit)
{
LogicUnitType wBlockNo ;
FLByte bFloor,bBank ;
PhyUnitType wPhysicalUnitArray[OREN_MAX_NUMBER_OF_PLANES] ;
FLByte bEraseMark = OREN_ERASE_MARK ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalWriteEraseMark entered.\r\n");
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
wBlockNo = wLogicalUnit ;
/*** Step 1 - Find the Floor that the Logical Unit resides in ***/
bFloor = (FLByte) (wLogicalUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
/*** Step 2 - Mask BlockNo to be the unit offset in this specific floor ***/
wBlockNo = (LogicUnitType)(wBlockNo % MTD_VARS->dwLogicalUnitsInFloor) ;
/*** Step 3 - Find the specific bank that this BlockNo resides in & set the bank ***/
bBank = (FLByte)(wBlockNo / MTD_VARS->dwLogicalUnitsInBank) ;
/*** Step 4 - Mask the BlockNo to be the block offset in a specific bank ***/
wBlockNo = (LogicUnitType)(wBlockNo % MTD_VARS->dwLogicalUnitsInBank) ;
/*** Step 5 - Find the Physical units that are matched to this Logical unit ***/
checkStatus ((MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalUnit,wPhysicalUnitArray))) ;
checkStatus (OREN_phyWriteEraseMark (flashPtr,wPhysicalUnitArray[0],bEraseMark,bFloor,bBank)) ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalWriteEraseMark exited.\r\n");
return flOK ;
}
#endif
/***********************************************************************
* Name : OREN_getEraseCount
* Gets the Number of times a logical erase unit has been erased
*
* Parameters:
* Inputs:
* StartUnit : The logical start unit to check
* Outputs:
* EraseCount: The Erase count of the logical erase unit
*
***********************************************************************/
FLStatus OREN_getEraseCount (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseCount entered.\r\n");
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
argsPackPtr = &flashPtr->args ;
argsPackPtr->eraseCount = 0 ;
/* DBG_PRINT_WRN(FLZONE_MTD,"getEraseCount-Erase count not supported in this chip \n\r") ; */
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseCount exited.\r\n");
return flOK ;
}
/***********************************************************************
* Name: OREN_FindNumOfOnes
* This routine Finds how many bits of one the Input byte has
* Inputs:
* bInputByte: The byte to look for zero's
* Outputs:
* bNumOfZeros: How many "0" bits the byte has: 0,1,2 (2 means 2 or more zero bits)
************************************************************************/
FLByte OREN_FindNumOfOnes (FLByte bInputByte)
{
FLByte bNumOfZeros,j ;
/*** Check the number of zero's in the BadBlockIndicator ***/
bNumOfZeros = 0 ;
for (j=0;j<8;j++)
{
if (bInputByte%2==1)
bNumOfZeros++ ;
bInputByte = bInputByte>>1 ;
/*** If number of zero's equals 2 than the block is bad ***/
/*** no need to continue checking ***/
}
return bNumOfZeros ;
}
/***********************************************************************
* Name : OREN_getEraseMark
* Checks if the logical unit has the erase mark
*
* Parameters:
* Inputs:
* StartUnit : The logical start unit to check
* Outputs:
* EraseCount: The Erase count of the logical erase unit
* The routine return the following error codes:
* flOK : Unit is erased
* flUnitNotErase : The unit did not have the erase mark
*
***********************************************************************/
FLStatus OREN_getEraseMark (FLFlash *flashPtr)
{
LogicUnitType wBlockNo,wLogicalUnit ;
FLByte bFloor,bBank,bEraseMark,bXorResult ;
PhyUnitType wPhysicalUnitArray[OREN_MAX_NUMBER_OF_PLANES] ;
MTDArgumentPacket *argsPackPtr ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseMark entered.\r\n");
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
argsPackPtr = &flashPtr->args ;
wLogicalUnit=argsPackPtr->startUnit ;
wBlockNo = wLogicalUnit ;
/*** Step 1 - Find the Floor that the Logical Unit resides in ***/
bFloor = (FLByte) (wLogicalUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
/*** Step 2 - Mask BlockNo to be the unit offset in this specific floor ***/
wBlockNo = (LogicUnitType)(wBlockNo % MTD_VARS->dwLogicalUnitsInFloor) ;
/*** Step 3 - Find the specific bank that this BlockNo resides in & set the bank ***/
bBank = (FLByte)(wBlockNo / MTD_VARS->dwLogicalUnitsInBank) ;
/*** Step 4 - Mask the BlockNo to be the block offset in a specific bank ***/
wBlockNo = (LogicUnitType)(wBlockNo % MTD_VARS->dwLogicalUnitsInBank) ;
/*** Step 5 - Find the Physical units that are matched to this Logical unit ***/
checkStatus ((MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalUnit,wPhysicalUnitArray))) ;
/*** Read the erase mark of the physical unit ***/
/*** The erase mark is written only to the first page of the first physical unit ***/
checkStatus (OREN_phyGetEraseMark (flashPtr,wPhysicalUnitArray[0],&bEraseMark,0,bFloor,bBank)) ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseMark exited.\r\n");
/*** Check that the bEraseMark is equal to OREN_ERASE_MARK with up to 2 error bits ***/
bXorResult = bEraseMark ^ OREN_ERASE_MARK ;
/*** Find how many different bits exist ***/
/*** If there are 0,1,2 different bits => Erase mark is O.K ***/
/*** else erase mark is not good ***/
if (OREN_FindNumOfOnes (bXorResult)<=2)
return flOK ;
else
return flUnitIsNotErased ;
}
/***********************************************************************
* Name : OREN_setCallBack
* Set a callback routine to be called prior to the busy polling at the
* end of the write/Erase routines
* Parameters:
* The routine return the following error codes:
* flOK : Success
*
***********************************************************************/
FLStatus OREN_setCallBack (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setCallBack entered.\r\n");
argsPackPtr = &flashPtr->args ;
if (argsPackPtr->opFlags & MTD_WRITE_OP)
{
MTD_VARS->WriteCallBackRoutinePtr = argsPackPtr->myRoutine ;
MTD_VARS->WriteCallBackArgument = argsPackPtr->myargs ;
}
if (argsPackPtr->opFlags & MTD_ERASE_OP)
{
MTD_VARS->EraseCallBackRoutinePtr = argsPackPtr->myRoutine ;
MTD_VARS->EraseCallBackArgument = argsPackPtr->myargs ;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setCallBack entered.\r\n");
return flOK;
}
#if ((defined(HW_PROTECTION)) || (!defined(NO_IPL_CODE)))
/***********************************************************************
* Name: OREN_protectionKeyInsert
* Sends protection key only to protected areas.
*
* Parameters:
* flashPtr - FLFlash struct
* bDPS_No : indicated which protection area to work on. 0 or 1.
* Key : An 8 FLByte long array containing the protection password.
* Notes
* 1. The key should be sent to all of the device's floors even if
* one of the floors indicated that the key did not fit.
* The key should not be sent to a floor that indicates that
* it's key was already inserted.
* This way allows us to open partition that might have different
* keys for different floors as a result of a bug or a power failure.
* 2. Before sending the given key the MTD will try and send "00000000"
* (Ascii) key.
***********************************************************************/
FLStatus OREN_protectionKeyInsert(FLFlash *flashPtr,FLByte bDPS_No,FLByte FAR1* Key)
{
FLByte bFloor;
FLStatus tempStatus;
FLStatus status = flOK;
MTDArgumentPacket *argsPackPtr ;
FLByte bMask ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionKeyInsert entered.\r\n");
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
OREN_completeOperation (flashPtr) ;
argsPackPtr = &flashPtr->args ;
argsPackPtr->maxBitError = 0 ;
/* Send key to all floors */
for (bFloor=0;bFloor<flashPtr->noOfFloors;bFloor++)
{
OREN_AsicSetFloor (flashPtr,bFloor) ;
bMask = 1<<bFloor ;
switch (bDPS_No)
{
case 0: /* DPS_0 */
{
/*** If key was lock enabled & asserted => return wrong key ***/
/*** because altough KEY_OK set the area is still protected ***/
if ((OREN_Is_LOCK_Asserted(flashPtr))&&(OREN_IsDPS0_LOCK_Enabled(flashPtr)))
return flWrongKey ;
/* Check if the DPS is locked: */
/* 1. Check if The DPS is RP/WP */
/* 2. Check if the KEY_OK is on -> means not locked */
/* If these 2 conditions exist do not to try to open */
/* the protection since it is already open */
if ( (OREN_IsDPS0_KeyInserted(flashPtr)) ||
((!OREN_IsDPS0_WP(flashPtr))&&(!OREN_IsDPS0_RP(flashPtr))) )
continue ;
break;
}
case 1: /* DPS_1 */
{
/*** If key was lock enabled & asserted => return wrong key ***/
/*** because altough KEY_OK set the area is still protected ***/
if ((OREN_Is_LOCK_Asserted(flashPtr))&&(OREN_IsDPS1_LOCK_Enabled(flashPtr)))
return flWrongKey ;
/* Check if the DPS is locked: */
/* 1. Check if The DPS is RP/WP */
/* 2. Check if the KEY_OK is on -> means not locked */
/* If these 2 conditions exist do not to try to open */
/* the protection since it is already open */
if ((OREN_IsDPS1_KeyInserted(flashPtr)) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -