📄 m512_lgc.c
字号:
/*** from the currect LogicalUnit ***/
dwLogicalSectorOffset = dwLogicalSectorOffset % (MTD_VARS->dwSectorsInLogicalUnit>>bMode_Shift) ;
/*** Step 7: Find the page & plane that matched to the LogicalSectorNo ***/
bPage = (FLByte)(dwLogicalSectorOffset >> MTD_VARS->bNoOfPlanesBits) << bMode_Shift ;;
/*** Step 8 : Find the Physiacl units that matched to this logical unit ***/
checkStatus (MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalUnit,wPhysicalUnitArray)) ;
/*** Step 9 : Write a sequence that writes to NoOfPlanes-Plane pages ***/
writeArgs.floor = bFloor ;
writeArgs.phyUnits = wPhysicalUnitArray ;
writeArgs.phyPage = bPage ;
if (((dwLogicalSectorOffset%2)==0) && (dwNoOfSectors>=2))
bNoOfWrittenSectors = 2 ;
else
bNoOfWrittenSectors = 1 ;
writeArgs.sectorOffset = (FLWord)(dwLogicalSectorOffset % (1<<MTD_VARS->bNoOfPlanesBits)) ;
writeArgs.noOfPhySectors = bNoOfWrittenSectors ;
writeArgs.mainBuffer = (FLByte FAR1 *)(bMainBufferPtr) ;
writeArgs.extraBuffer = (FLByte FAR1 *)(bExtraBufferPtr) ;
if (bNoOfWrittenSectors<=2)
writeArgs.opFlags = dwOpFlags|dwDoNotPollFlag ;
else
writeArgs.opFlags = dwOpFlags ;
writeArgs.verifyWrite = argsPackPtr->verifyWriteMode ;
writeArgs.offset = argsPackPtr->offset ;
writeArgs.length = argsPackPtr->length ;
status = M512_pageProgram_Seq (flashPtr,&writeArgs) ;
/*** Calculate the output parameters of the routine ***/
/*** 1.noOfSectorsPassed field ***/
/*** 2.maxBitError field ***/
argsPackPtr->noOfSectorsPassed += writeArgs.noOfSectorsPassed ;
if (writeArgs.maxBitErrors>argsPackPtr->maxBitError)
argsPackPtr->maxBitError = writeArgs.maxBitErrors ;
/*** Check the status of the pageProgram operation ***/
if (status)
{
DBG_PRINT_ERR(FLZONE_MTD,"logicalWrite:pageProgram_Seq failed \r\n");
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalWrite exited.\r\n");
return status ;
}
/*** Advance the MainBuffer & ExtraBuffer pointers ***/
bMainBufferPtr = BYTE_ADD_FAR (bMainBufferPtr,(bNoOfWrittenSectors*FLASH_SECTOR_DATA_SIZE)) ;
if (argsPackPtr->extraBuf)
{
#ifndef NO_PHYSICAL_IO
if(dwOpFlags & MTD_SW_EDC)
bExtraBufferPtr = BYTE_ADD_FAR (bExtraBufferPtr,(bNoOfWrittenSectors*(FLASH_SECTOR_HM_SIZE+FLASH_SECTOR_BCH_SIZE))) ;
#endif /* NO_PHYSICAL_IO */
bExtraBufferPtr = BYTE_ADD_FAR (bExtraBufferPtr,bNoOfWrittenSectors*FLASH_EXTRA_BUFFER_SIZE) ;
}
dwNoOfSectors -= bNoOfWrittenSectors ;
dwLogicalSectorNo += bNoOfWrittenSectors ;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalWrite exited.\r\n");
return flOK ;
}
#endif
/************************************************************************
* Name : M512_getEraseCount
* Gets the Number of times a logical erase unit has been erased
*
* Parameters:
* Inputs:
* flashPtr.StartUnit : The logical start unit to check
* Outputs:
* flashPtr.EraseCount: The Erase count of the logical erase unit
* Returns:
* flOK : Success
* flTimedOut : The maximum delay time has expired, but the
* device is not ready yet.
* flSequenceError : The ASIC has detected Sequence Error
***********************************************************************/
FLStatus M512_getEraseCount (FLFlash *flashPtr)
{
LogicUnitType wBlockNo,wLogicalUnit ;
FLByte bFloor ;
PhyUnitType wPhysicalUnitArray[M512_MAX_NUMBER_OF_PLANES] ;
MTDArgumentPacket *argsPackPtr ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseCount entered.\r\n");
flashPtr->completeOperation (flashPtr) ;
MTD_VARS->asicSetInNormalMode (flashPtr) ;
#ifdef FPGA_SIM
/*** In FPGA there is not erase mark support so return OK ***/
return flOK ;
#endif
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 ***/
/*** 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 ***/
checkStatus (M512_phyGetEraseCount (flashPtr,wPhysicalUnitArray,&argsPackPtr->eraseCount,bFloor)) ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseCount exited.\r\n");
return flOK ;
}
/***********************************************************************
* Name : M512_getEraseMark
* Checks if the logical unit has the erase mark
*
* Parameters:
* Inputs:
* flashPtr.StartUnit : The logical start unit to check
* Outputs:
* flashPtr.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 M512_getEraseMark (FLFlash *flashPtr)
{
LogicUnitType wBlockNo,wLogicalUnit ;
FLByte bFloor,bEraseMark ;
PhyUnitType wPhysicalUnitArray[M512_MAX_NUMBER_OF_PLANES] ;
MTDArgumentPacket *argsPackPtr ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseMark entered.\r\n");
flashPtr->completeOperation (flashPtr) ;
MTD_VARS->asicSetInNormalMode (flashPtr) ;
#ifdef FPGA_SIM
/*** In FPGA there is not erase mark support so return OK ***/
return flOK ;
#endif
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 ***/
/*** 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 ***/
checkStatus (M512_phyGetEraseMark (flashPtr,wPhysicalUnitArray,&bEraseMark,bFloor)) ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: getEraseMark exited.\r\n");
if (bEraseMark==M512_ERASE_MARK)
return flOK ;
else
return flUnitIsNotErased ;
}
/***********************************************************************
* Name : M512_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 M512_setCallBack (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setCallBack entered.\r\n");
MTD_VARS->asicSetInNormalMode (flashPtr) ;
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: M512_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 M512_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");
M512_asicSetMode (flashPtr,NORMAL_MODE) ;
flashPtr->completeOperation (flashPtr) ;
argsPackPtr = &flashPtr->args ;
argsPackPtr->maxBitError = 0 ;
/* Send key to all floors */
for (bFloor=0;bFloor<flashPtr->noOfFloors;bFloor++)
{
M512_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 ((!M512_Is_LOCK_Negated(flashPtr))&&(M512_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 ((M512_IsDPS0_KeyInserted(flashPtr)) || /* Key is in */
((!M512_IsDPS0_WP(flashPtr) ) &&
(!M512_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 ((!M512_Is_LOCK_Negated(flashPtr))&&(M512_IsDPS1_LOCK_Enabled(flashPtr)))
return flWrongKey ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -