📄 oren_mtd.c
字号:
* global variable and the socket struct with baseaddress,size,... *
* *
* Note: This routine is used in the TrueFFS SDK only *
* *
* Parameters: *
* dwLowAddress : Low range of search *
* dwHighAddress: High range of search *
* *
* Returns: *
* FLStatus : 0 on success, otherwise failure *
************************************************************************/
FLStatus flRegisterDOCORENSOC(FLDword dwLowAddress, FLDword dwHighAddress)
{
int serialNo;
FLBoolean fResetAll = TRUE;
FLStatus status ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCORENSOC Entered.\r\n");
if( noOfSockets >= SOCKETS )
return flTooManyComponents;
/* Try to register DiskOnChip using */
for(serialNo = 0 ; noOfSockets < SOCKETS ; serialNo++ , noOfSockets++)
{
/*** Step 1 : Get a pointer to the last socket ***/
/*** noOfSockets - Is a global variable that holds the number of ***/
/*** sockets found. ***/
FLSocket * socket = flSocketOf(noOfSockets);
/*** Step 2 : Set the Socket volNo field ***/
/*** Set the socket volNo field to be the current noOfSockets ***/
socket->volNo = noOfSockets;
/*** Step 3 : Set the Socket fields ***/
/*** Set the socket fields by calling to docSocketInit routine ***/
/*** Found in DOCSOC.C and initializes the socket fields which ***/
/*** are not relevant for the MTD ***/
docSocketInit(socket);
/*** Step 4 : Set the Socket.window.baseAddress field ***/
/*** Search for base address of DOC that was not found yet ***/
/*** dwLowAddress recieves the next address to search ***/
status = OREN_docWindowBaseAddress (noOfSockets,dwLowAddress,dwHighAddress,
&dwLowAddress,&(socket->window.baseAddress),fResetAll);
fResetAll = FALSE; /* Don't change to reset mode on the next itteration */
/*** If (socket->window.baseAddress==0 => DOC was not found => return) ***/
/*** else repets STEP 1..5 ***/
if (status) /* DiskOnChip not detected */
break;
/*** Step 5 : Set the Socket.window.size & vol.window.base ***/
/*** Set the socket field to be 8Kbyte ***/
flSetWindowSize(socket, OREN_DocWindow(flFlashOf(flSocketNoOf(socket)))>>12L); /* The second argument is 4k units => 8K = 2*4 KBytes */
}
/*** In case that no DOC was found ***/
if( serialNo == 0 )
return flAdapterNotFound;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCORENSOC Entered.\r\n");
return flOK;
}
/************************************************************************
***************************** Init functions ***************************
************************************************************************/
/***********************************************************************
* Name: OREN_checkAndFixAccessError
*
* Recover from protection/Sequence error of the current asic state
* machine.
*
* Parameters:
* flashPtr : Pointer identifying drive
*
* Note : In order to exit from protection/sequance error the routine
* forces the flash into reset mode.
* The routine would check that the error status is cleared
*
* Returns:
* flOK - No error accured
* flGeneralFailure - Failed clearing error
* flSequanceError - Sequance error was fixed
* flHWProtection - Protetion error was fixed
***********************************************************************/
static FLStatus OREN_checkAndFixAccessError(FLFlash *flashPtr)
{
FLByte bTemp;
FLStatus status ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: OREN_checkAndFixAccessError Entered.\r\n");
/*** Check if there really is a violation and remmember it ***/
bTemp = OREN_Read8BitReg(flashPtr,OREN_FLASH_STATUS_REG);
if(bTemp & OREN_PROTECTION_ERROR_DETECTED)
{
DBG_PRINT_ERR(FLZONE_MTD,"OREN_checkAndFixAccessError:Protection error occurred.\r\n");
status = flHWProtection;
}
else if(bTemp & OREN_SEQUENCE_ERROR_DETECTED)
{
DBG_PRINT_ERR(FLZONE_MTD,"OREN_checkAndFixAccessError:Sequence error occurred. \r\n");
status = flSequenceError;
}
else
{
return flOK;
}
/*** Clear either protection error or sequance error ***/
OREN_FlashCommandRegWrite(flashPtr,RESET_COMMAND);
/*** Check if protection error was removed => if not return error ***/
if(OREN_IsSequenceOrProtectionError(flashPtr))
{
DBG_PRINT_FLOW(FLZONE_MTD,"OREN_checkAndFixAccessError:Can't recover from protection / sequance violation.\r\n");
return flGeneralFailure;
}
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: OREN_checkAndFixAccessError Exit.\r\n");
return status;
}
#ifndef FL_NO_USE_FUNC
/************************************************************************
* Name:OREN_setBusType
*
* Check validity and set the proper memory access routines for MTD.
*
* Parameters:
* volume : Pointer identifying drive
* dBusConfig : Socket access discriptor
* bInterleave : Interleave factor (1,2)
* bIF_CFG : if_cfg state:
* 8 - 8 bit
* 16 - 16 bit
*
* Returns:
* TRUE if routines are available and fit the DiskOnChip
* configuration otherwise FALSE.
*
* The variable pointer to by busConfig is added TrueFFS private
* MTD descriptors.
***********************************************************************/
static FLBoolean OREN_setBusType(FLFlash *volume,FLDword dBusConfig,FLByte bInterleave,FLByte bIF_CFG)
{
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setBusType Entered.\r\n");
if ((bIF_CFG==8) && (bInterleave==1))
dBusConfig |= FL_8BIT_DOC_ACCESS | FL_8BIT_FLASH_ACCESS ;
else if ((bIF_CFG==16) && (bInterleave==2))
dBusConfig |= FL_16BIT_DOC_ACCESS | FL_16BIT_FLASH_ACCESS ;
else if ((bIF_CFG==16) && (bInterleave==1))
dBusConfig |= FL_16BIT_DOC_ACCESS | FL_16BIT_FLASH_ACCESS ;
else if ((bIF_CFG==8) && (bInterleave==2))
dBusConfig |= FL_8BIT_DOC_ACCESS | FL_16BIT_FLASH_ACCESS ;
else
{
DBG_PRINT_FLOW(FLZONE_MTD,"setBusType: Invalid if_cfg/interleave .\r\n");
return FALSE;
}
if(setBusTypeOfFlash(volume,dBusConfig) != flOK)
return FALSE;
else
{
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setBusType exited .\r\n");
return TRUE;
}
}
#endif
/***********************************************************************
* Name : OREN_initMedia
*
* Check if this flash media is supported.
* Initialize fields in the DOC that are media specific.
*
* Parameters:
* flashPtr : Pointer identifying drive
*
* Returns:
* FLStatus : flOK on success,
* flUnknownMedia : Media is not recognized
***********************************************************************/
static FLStatus OREN_initMedia(FLFlash *flashPtr)
{
FLByte bMakerCode,bDeviceCode,bSubType=0 ;
FLStatus status ;
FLWord wTempShift ;
FLByte bEnhancedData[3] ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: initMedia Entered.\r\n");
status = OREN_readID_Seq (flashPtr,&bMakerCode,&bDeviceCode) ;
if (status)
return status ; /* The ReadID sequence failed */
#ifdef DEBUG_MTD
if (bMakerCode)
DBG_PRINT_WRN_PRM(FLZONE_MTD,(FLTXT("initMedia:MakerCode=0x%x DeviceCode=0x%x \r\n"),(FLWord)bMakerCode,(FLWord)bDeviceCode));
#endif
switch (bMakerCode)
{
case 0x98:/*** Toshiba chips ***/
{
switch (bDeviceCode)
{
case 0x73: /*** Toshiba 128 MegaBit (16 MB) ***/
MTD_VARS->bFlashType = OREN_SLC_TYPE ;
MTD_VARS->wPagesPerBlockBits = 5 ;
MTD_VARS->wUnitsInChip = 1024 ;
MTD_VARS->bPlaneArraysInChip = 1 ;
flashPtr->type = TC58128_FLASH ;
MTD_VARS->bNoOfPlanesBits = 0 ;
MTD_VARS->bAddressBytes = 3;
MTD_VARS->bPageSizeBits = 9;
flashPtr->maxEraseCycles = 100000L;
flashPtr->evenPagePPP = 3 ;
flashPtr->oddPagePPP = 3 ;
flashPtr->subType = 0x00 ;
flashPtr->averageWrite = 200 ;
flashPtr->averageErase = 2000 ;
DBG_PRINT_WRN(FLZONE_MTD,"initMedia:Toshiba 16MB (UnitSize=16KB) detected.\r\n");
break ;
case 0x75: /*** Toshiba 256 MegaBit (32 MB) ***/
MTD_VARS->bFlashType = OREN_SLC_TYPE ;
MTD_VARS->wPagesPerBlockBits = 5 ;
MTD_VARS->wUnitsInChip = 2048 ;
MTD_VARS->bPlaneArraysInChip = 1 ;
flashPtr->type = TC58256_FLASH ;
MTD_VARS->bNoOfPlanesBits = 0 ;
MTD_VARS->bAddressBytes = 3;
MTD_VARS->bPageSizeBits = 9;
flashPtr->maxEraseCycles = 100000L;
flashPtr->evenPagePPP = 3 ;
flashPtr->oddPagePPP = 3 ;
flashPtr->subType = 0x00 ;
flashPtr->averageWrite = 200 ;
flashPtr->averageErase = 2000 ;
DBG_PRINT_WRN(FLZONE_MTD,"initMedia:Toshiba 32MB (UnitSize=16KB) detected.\r\n");
break ;
case 0x76: /*** Toshiba 512 MegaBit (64 MB) ***/
#ifdef ERASED_FLASH
if (IsFlashErased(flashPtr)==FALSE)
#endif
checkStatus (OREN_readID_2_Seq (flashPtr,&bSubType)) ;
flashPtr->subType = (FlashType)(bSubType) ;
#ifndef ERASED_FLASH
if (flashPtr->subType==0x24)
#endif
{ /* MLC CHIP */
MTD_VARS->bFlashType = OREN_MLC_TYPE ;
MTD_VARS->wPagesPerBlockBits = 6 ;
MTD_VARS->wUnitsInChip = 2048;
MTD_VARS->bPlaneArraysInChip = 1 ;
flashPtr->averageWrite = 1200 ;
flashPtr->averageErase = 2000 ;
DBG_PRINT_WRN(FLZONE_MTD,"initMedia:Toshiba 64MB (UnitSize=32KB) MLC detected.\r\n");
}
#ifndef ERASED_FLASH
else if (flashPtr->subType==0x20)
{ /* SLC CHIP */
MTD_VARS->bFlashType = OREN_SLC_TYPE ;
MTD_VARS->wPagesPerBlockBits = 5 ;
MTD_VARS->wUnitsInChip = 4096 ;
MTD_VARS->bPlaneArraysInChip = 1 ;
flashPtr->averageWrite = 200 ;
flashPtr->averageErase = 2000 ;
DBG_PRINT_WRN(FLZONE_MTD,"initMedia:Toshiba 64MB (UnitSize=16KB) SLC detected.\r\n");
}
#endif
#ifndef ERASED_FLASH
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -