📄 m512_lgc.c
字号:
/***********************************************************************************/
/* M-Systems Confidential */
/* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003 */
/* All Rights Reserved */
/***********************************************************************************/
/* NOTICE OF M-SYSTEMS OEM */
/* SOFTWARE LICENSE AGREEMENT */
/* */
/* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
/* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
/* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
/* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
/* E-MAIL = info@m-sys.com */
/***********************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/mtd/m512_lgc.c-arc $
*
* Rev 1.14 Jan 27 2004 08:14:02 oris
* Changed comments
*
* Rev 1.13 Jan 13 2004 10:43:16 roneng
* Bug fix:
* - Protect Partition even if the first or the last units are BB.
* - If no good unit would be found than flUnitIsBad status would
* be returned.
*
* Rev 1.12 Jan 08 2004 15:00:12 roneng
* In ProtectionSet routine while setting protection and LowUnit or HighUnit are bad blocks than the DPS is not written correctly to controller.
*
* Rev 1.11 Oct 30 2003 00:52:18 OriS
* Bug fix - Check for key inserted state only on a write or read protected partition.
*
* Rev 1.10 Sep 30 2003 17:59:26 oris
* Bug fix - When we read 2 sectors from a page and the 2nd page has flDataError / flSequenceError , we try to read again but this time we read only one sector
* Added FL prefix to SECTOR_SIZE and SECTOR_SIZE_BITS
*
* Rev 1.9 Sep 01 2003 19:06:42 oris
* - Removed tffsRAMXXX calls.
* - Added default FLTXT macro for converting text to printable text strings.
* - changed MTDS definition to FL_MTDS
*
* Rev 1.8 Jun 12 2003 15:32:00 roneng
* Call to QA_CountBitFlips routine was added in In LogicalRead
*
* Rev 1.7 May 16 2003 00:57:48 OriS
* Compilation error when HW_PROTECTION is undefined.
*
* Rev 1.6 May 08 2003 23:17:14 OriS
* Bad debug print.
*
* Rev 1.5 May 06 2003 11:56:46 OriS
* Changed TFFSCPY to tffsRAMcpy
* Changed TFFSCMP to tffsRAMcmp
* Changed TFFSSET to tffsRAMset
*
* Rev 1.4 Apr 27 2003 16:28:32 Oris
* Bug fix in argument check of logical read, write and erase
*
* Rev 1.3 Apr 27 2003 14:12:36 Oris
* Added check for accesses out side the media range.
*
* Rev 1.2 Apr 27 2003 09:03:28 Oris
* Bug fix - floors support.
* Bug fix - infinite loop after sequence error.
* Changed D2TST flag to be default and to be removed by NO_PHYSICAL_IO.
*
* Rev 1.1 Apr 13 2003 20:29:50 OriS
* Removed FPGA_SIM definition.
* Bug fix - P3 now supports reliable SLC mode as well.
* Bug fix - noOfPhySectors was not initialized in second try
*
* Rev 1.0 Apr 09 2003 12:15:54 OriS
* Initial revision.
*
*/
/************************************************************************
* Name : m512_lgc.c *
* *
* Written : Ronen Golan *
* *
* Abstract: This file contains the routines of the Logical MTD *
************************************************************************/
/***************************** #include ****************************/
#include "docsys.h"
#include "logicmtd.h"
#include "m512_mtd.h"
#include "m512_exp.h"
/***************************** #define ******************************/
/***************************** Prototypes ***************************/
#ifdef QA_ACCESORIES
extern void QA_countEraseCycles (FLFlash *flashPtr,FLWord wLogicUnit) ;
extern void QA_CountBitFlips (FLFlash *flashPtr,FLSNative snNumOfErrorBits) ;
#endif
/************************ External variables ************************/
/************************ Static variables *************************/
#ifndef FL_READ_ONLY
/************************************************************************
* Name :M512_logicalErase
*
* Erase one or more contiguous Flash erasable blocks
*
* The default routine returns a write-protect error.
*
* INPUT:
* flashPtr : Pointer identifying drive
* The following fields are used as inputs in the flash struct:
* flashPtr.args.noOfUnits: The number of logical units to erase
* flashPtr.args.startUnit: The logical erase unit to start erasing from
* flashPtr.args.delayedStatus: A pointer to where the output of the operation
* will be returned when adding the MTD_DO_NOT_WAIT
* flag
* flashPtr.args.opFlags : Available flags are:
* MTD_DO_NOT_WAIT : Forces the MTD to return without polling
* the last erase unit operation.
* MTD_ADD_ERASE_MARK : The MTD should add the erase mark after
* the completion of the erase operation
* Disable EDC/ECC.
*
* OUTPUTS:
* The following fields are used as outputs in the flash struct:
* flash.args.noOfUnitsPassed: The number of logical units that
* have been successfully erased.
*
* The routine return the following error codes:
* flOK : Success
* flWriteFault : The erase operation failed to one of the
* required blocks.
* flHWProtection : protection violation has occurred due to the
* erasing of one of the required blocks.
*
***************************************************************************/
FLStatus M512_logicalErase (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
LogicUnitType wLogicalUnit,wBlockNo ;
FLByte bFloor ;
PhyUnitType wPhysicalUnitArray[M512_MAX_NUMBER_OF_PLANES] ;
FLDword dwDoNotPollFlag ;
FLDword dwOpFlags ;
FLStatus status ;
argsPackPtr = &flashPtr->args ;
#ifndef FL_SKIP_ARGS_CHECK
if(argsPackPtr->startUnit >= (flashPtr->mediaSize >> flashPtr->erasableBlockSizeBits))
{
DBG_PRINT_ERR(FLZONE_MTD,"ERROR - ACCESS outside the media space - logicalErase entered.\r\n");
return flGeneralFailure;
}
#endif /* FL_SKIP_ARGS_CHECK */
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalErase entered.\r\n");
/*** All floors are in NORMAL MODE ***/
MTD_VARS->asicSetInNormalMode (flashPtr) ;
dwOpFlags = argsPackPtr->opFlags ;
dwDoNotPollFlag = argsPackPtr->opFlags & MTD_DO_NOT_WAIT ;
dwOpFlags = argsPackPtr->opFlags & ~dwDoNotPollFlag ;
argsPackPtr->noOfSectorsPassed = 0 ;
wLogicalUnit = argsPackPtr->startUnit ;
/*** We need to work in FAST mode when: ***/
/*** 1. The device is SLC type and no MTD_REL_MODE was given. ***/
/*** in that case we read as MTD_FAST_MODE mode ***/
/*** 2. The device is MLC but we were forced to work in MTD_FAST_MODE ***/
if ((MTD_VARS->bFlashType==M512_SLC_TYPE) && ((dwOpFlags & MTD_REL_MODE)==0))
dwOpFlags |= (MTD_REL_MODE|MTD_FAST_MODE) ;/*** Force OpFlag to work in MTD_FAST_MODE mode ***/
while (wLogicalUnit<(argsPackPtr->startUnit+argsPackPtr->noOfUnits))
{
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)) ;
if (wLogicalUnit!=argsPackPtr->startUnit+argsPackPtr->noOfUnits-1)
status=M512_erase_Seq (flashPtr,wPhysicalUnitArray,flashPtr->noOfPlanes,dwOpFlags,bFloor) ;
else
status=M512_erase_Seq (flashPtr,wPhysicalUnitArray,flashPtr->noOfPlanes,dwOpFlags|dwDoNotPollFlag,bFloor) ;
if (status)
{ /*** If status fails exit with error status ***/
DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("logicalErase:returned status %d \r\n"),status)) ;
return status;
}
#ifdef QA_ACCESORIES
QA_countEraseCycles (flashPtr,wLogicalUnit) ;
#endif
wLogicalUnit++ ;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: logicalErase exited.\r\n");
return flOK ;
}
#endif
/************************************************************************
* Name: M512_logicalRead *
* *
* Read data from 1..N logical flash sectors. *
* *
* Parameters: *
* flash : Pointer identifying drive *
* *
* The routine uses the following inputs: *
* flashPtr.arguments.noOfSectors : The number of sectors to read. *
* flashPtr.arguments.startSector : First sector to start reading from *
* flashPtr.arguments.readMainBuf : Pointer to user buffer *
* flashPtr.arguments.extraBuf : Pointer to user buffer *
* flashPtr.arguments.opFlags : Available flags are: *
* MTD_DATA : Read from sector info area to mainBuf. *
* MTD_EXTRA : Read from sector extra area to extraBuf. *
* MTD_REL_MODE : Tells the controller the data is written *
* in the reliable mode. *
* MTD_FAST_MODE : Tells the controller the data is to be *
* written in the fast mode.If this *
* flag isn't set and the MTD_REL_MODE *
* mode is set, the MTD will use the *
* reliable mode. *
* MTD_DO_NOT_WAIT : Forces the MTD to return without polling *
* the last sector write operation. *
* MTD_SW_EDC : Allows access to the rest of the page's *
* extra area.When this flag is set the *
* extra area buffer is extended to 16 *
* bytes and will include the hamming, *
* BCH and dummy byte.No EDC\ECC will be *
* employed. *
* MTD_NO_MATCHING : This mode tells the MTD not to match *
* physical blocks into logical blocks. *
* Practically this mode exports the *
* physical addressing. *
* The routine sets the following outputs: *
* flashPtr.arguments.maxBitsError : *
* flashPtr.arguments.freeSectorsFound : *
* flashPtr.arguments.noOfSectorsPassed: *
* The routine return the following error codes: *
* flOK : Success *
* flDataError : At least one of the sectors has an *
* unrecoverable EDC error unless only the extra *
* area was requested and the sector is "free". *
* A sector is considered "free" if it has 2 or *
* less '0' bits *
* flHWProtection : A protection violation has occurred while *
* attempting to reading one of the sectors. *
* flTimedOut : The maximum delay time has expired, but the *
* device is not ready yet. *
* flSequenceError : The ASIC has detected Sequence Error *
************************************************************************/
FLStatus M512_logicalRead (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
LogicUnitType wLogicalUnit ;
FLByte bFloor ;
PhyUnitType wPhysicalUnitArray[M512_MAX_NUMBER_OF_PLANES] ;
FLByte FAR1 *bMainBufferPtr ;
FLByte FAR1 *bExtraBufferPtr;
M512_OperationArgsStruct readArgs ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -