📄 oren_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/oren_lgc.c-arc $
*
* Rev 1.15 Jan 27 2004 08:14:00 oris
* Changed comments
*
* Rev 1.14 Jan 13 2004 10:42:40 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.13 Jan 08 2004 15:00:20 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.12 Nov 16 2003 18:22:22 roneng
* Change bug in LogicalRead in SW_EDC mode (The Extra Buffer was not advanced correctly)
*
* Rev 1.11 Oct 30 2003 00:52:02 OriS
* Bug fix - Check for key inserted state only on a write or read protected partition.
*
* Rev 1.10 Sep 30 2003 17:59:34 oris
* Added FL prefix to SECTOR_SIZE and SECTOR_SIZE_BITS
*
* Rev 1.9 Sep 01 2003 19:04:34 oris
* - Added 2K page Support in LogicalRead (to enable reading up to 4 sectors in a page)
* - Added 2K page support in LogicalWrite (to enable writing of up to 1 unit in pageProgram_Seq
* - Removed tffsRAMXXX calls.
* - Added default FLTXT macro for converting text to printable text strings.
* - Added new supported technologies definitions:
* FL_SUPPORT_WRITE_CACHE 0x10
* FL_2K_ADDRESS_SPACE 0x20
* FL_SUPPORT_SEQUENTIAL_READ 0x40
* - changed MTDS definition to FL_MTDS
*
* Rev 1.8 Aug 10 2003 14:11:18 roneng * - Added 2K page Support in LogicalRead (to enable reading up to 4 sectors in a page) * - Added 2K page support in LogicalWrite (to enable writing of up to 1 unit in pageProgram_Seq *
* Rev 1.7 Jun 12 2003 15:38:08 roneng
* Checking status of LogicalRead is done only after output parameters were calculated
*
* Rev 1.6 May 16 2003 00:58:24 OriS
* Compilation error when HW_PROTECTION is undefined.
*
* Rev 1.5 May 11 2003 19:50:34 roneng
* Fix casting warning
*
* Rev 1.4 May 06 2003 11:53:48 OriS
* Changed TFFSCPY to tffsRAMcpy
* Changed TFFSCMP to tffsRAMcmp
* Changed TFFSSET to tffsRAMset
*
* Rev 1.3 Apr 27 2003 16:28:30 Oris
* Bug fix in argument check of logical read, write and erase
*
* Rev 1.2 Apr 27 2003 14:09:30 Oris
* Added check for accesses out side the media range.
*
* Rev 1.1 Apr 27 2003 09:03:50 Oris
* Changed D2TST flag to be default and to be removed by NO_PHYSICAL_IO.
*
* Rev 1.0 Apr 09 2003 12:15:56 OriS
* Initial revision.
*
*/
/************************************************************************
* Name : logicalmtd.c *
* *
* Written : Ronen Golan *
* *
* Abstract: This file contains the routines of the Logical MTD *
************************************************************************/
/***************************** #include ****************************/
#include "docsys.h"
#include "logicmtd.h"
#include "oren_mtd.h"
#include "oren_exp.h"
/***************************** 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 *************************/
/****************** Mathematical/LockUpTable Operations *****************
************************************************************************/
#ifndef FL_READ_ONLY
/************************************************************************
* Name :OREN_logicalErase
*
* Erase one or more contiguous Flash erasable blocks
*
* The default routine returns a write-protect error.
*
* INPUT:
* flash : Pointer identifying drive
* The following fields are used as inputs in the flash struct:
* flash.args.noOfUnits: The number of logical units to erase
* flash.args.startUnit: The logical erase unit to start erasing from
* flash.args.delayedStatus: A pointer to where the output of the operation
* will be returned when adding the MTD_DO_NOT_WAIT
* flag
* flash.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 OREN_logicalErase (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
LogicUnitType wLogicalUnit,wBlockNo ;
FLByte bFloor,bBank ;
PhyUnitType wPhysicalUnitArray[OREN_MAX_NUMBER_OF_PLANES] ;
FLByte bPhyShift = 0 ;
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");
checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
dwOpFlags = argsPackPtr->opFlags ;
dwDoNotPollFlag = argsPackPtr->opFlags & MTD_DO_NOT_WAIT ;
dwOpFlags = argsPackPtr->opFlags & ~dwDoNotPollFlag ;
argsPackPtr->noOfSectorsPassed = 0 ;
wLogicalUnit = argsPackPtr->startUnit ;
if (dwOpFlags & MTD_NO_MATCHING)
bPhyShift = MTD_VARS->bNoOfPlanesBits ;
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<<bPhyShift)) ;
/*** Step 2 - Mask BlockNo to be the unit offset in this specific floor ***/
wBlockNo = (LogicUnitType)(wBlockNo % (MTD_VARS->dwLogicalUnitsInFloor<<bPhyShift)) ;
/*** Step 3 - Find the specific bank that this BlockNo resides in & set the bank ***/
bBank = (FLByte)(wBlockNo / (MTD_VARS->dwLogicalUnitsInBank<<bPhyShift)) ;
/*** Step 4 - Mask the BlockNo to be the block offset in a specific bank ***/
wBlockNo = (LogicUnitType)(wBlockNo % (MTD_VARS->dwLogicalUnitsInBank<<bPhyShift)) ;
/*** Step 5 - Find the Physical units that are matched to this Logical unit ***/
checkStatus ((MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalUnit,wPhysicalUnitArray))) ;
if ((dwOpFlags & MTD_NO_MATCHING)==0)
{
if (wLogicalUnit!=argsPackPtr->startUnit+argsPackPtr->noOfUnits-1)
status=OREN_erase_Seq (flashPtr,wPhysicalUnitArray,flashPtr->noOfPlanes,argsPackPtr->opFlags,bFloor,bBank) ;
else
status=OREN_erase_Seq (flashPtr,wPhysicalUnitArray,flashPtr->noOfPlanes,argsPackPtr->opFlags|dwDoNotPollFlag,bFloor,bBank) ;
}
else
{ /* MTD_NO_MATCHING */
status=OREN_erase_Seq (flashPtr,&wBlockNo,1,argsPackPtr->opFlags,bFloor,bBank) ;
}
if (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: OREN_logicalRead *
* *
* Read data from 1..N logical flash sectors. *
* *
* Parameters: *
* flash : Pointer identifying drive *
* *
* The routine uses the following inputs: *
* flash.arguments.noOfSectors : The number of sectors to read. *
* flash.arguments.startSector : First sector to start reading from *
* flash.arguments.readMainBuf : Pointer to user buffer *
* flash.arguments.extraBuf : Pointer to user buffer *
* flash.arguments.opFlags : Available flags are: *
* MTD_DATA : Read from sector info area to mainBuf. *
* MTD_EXTRA : Read from sector extra area to extraBuf. *
* The routine sets the following outputs: *
* flash.arguments.maxBitsError : *
* flash.arguments.freeSectorsFound : *
* flash.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. *
* *
* *
************************************************************************/
FLStatus OREN_logicalRead (FLFlash *flashPtr)
{
MTDArgumentPacket *argsPackPtr ;
LogicUnitType wLogicalUnit ;
PhyUnitType wPhysicalUnitArray[OREN_MAX_NUMBER_OF_PLANES] ;
FLByte FAR1 *bMainBufferPtr ;
FLByte FAR1 *bExtraBufferPtr;
OREN_OperationArgsStruct readArgs ;
FLDword dwLogicalSector,dwLogicalSectorOffset,dwNoOfSectorsLeft ;
FLByte bPlane ;
FLStatus status ;
argsPackPtr = &flashPtr->args ;
#ifndef FL_SKIP_ARGS_CHECK
if(argsPackPtr->startSector >= (flashPtr->mediaSize >> FL_SECTOR_SIZE_BITS))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -