📄 docbdk.c
字号:
sizeof(BootRecord)];
VolumeRecord * volumePtr;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkMount() Entered.\r\n");
if ((flBdkVol->bdkGlobalStatus & BDK_S_HEADER_FOUND)==0)/* header not found */
{
#ifdef MTD_STANDALONE
FLFlash * flashPtr;
checkStatus(bdkFindDiskOnChip((FLDword FAR2 *)&dwTemp,(FLDword FAR2 *)&dwTemp));
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkMount() - DiskOnChip found.\r\n");
/* flBdkVol->flash was initialized by bdkFindDiskOnChip */
flashPtr = flBdkVol->flash;
#endif /* MTD_STANDALONE */
dwNoOfBlocks = (FLDword)(flashPtr->mediaSize >> flashPtr->erasableBlockSizeBits);
wUnitsPerChip = (FLWord)dwNoOfBlocks / flashPtr->noOfChips;
flBdkVol->blockPerFloor = ((flashPtr->noOfChips + flashPtr->noOfFloors - 1)/
flashPtr->noOfFloors) * wUnitsPerChip;
flBdkVol->erasableBlockBits = flashPtr->erasableBlockSizeBits;
flBdkVol->sectorsInUnitBits = (FLByte)flashPtr->erasableBlockSizeBits - FL_SECTOR_SIZE_BITS;
flBdkVol->sectorsInUnitMask = (1 << flBdkVol->sectorsInUnitBits) - 1;
/* Set header signature acording to supported TLs*/
if ((flashPtr->flags & SAFTL_ENABLED)==0)
{
DBG_PRINT_ERR(FLZONE_BDK,"Error: bdkMount() Unknown DiskOnChip device, therfore Binary partitions are not supported.\r\n");
return( flFeatureNotSupported );
}
DBG_PRINT_FLOW(FLZONE_BDK,"SAFTL search for media header.\r\n");
/* Find media header */
checkStatus(bdkRetrieveHeader(headerBuffer));
/* Perform the BB matching */
#ifdef MTD_READ_BBT
checkStatus(bdkDefinePartition(headerBuffer));
#endif /* MTD_READ_BBT */
volumePtr = (VolumeRecord *) (headerBuffer+sizeof(BootRecord));
flBdkVol = flBdkVols + flNoOfPartitions;
for (bMaxPartition = 0 ;(BINARY_PARTITIONS >= bMaxPartition + flNoOfPartitions) &&
(LE4(volumePtr->flags) & BDK_SAFTL_BINARY) ; flBdkVol++,volumePtr++)
{
tffscpy(flBdkVol,flBdkVols + flNoOfPartitions,sizeof(BDKVol));
flBdkVol->erasableBlockBits = flashPtr->erasableBlockSizeBits;
flBdkVol->sectorsInUnitBits = (FLByte)flashPtr->erasableBlockSizeBits - FL_SECTOR_SIZE_BITS;
flBdkVol->sectorsInUnitMask = (1 << flBdkVol->sectorsInUnitBits) - 1;
dwVolumeFlags = LE4(volumePtr->flags);
#ifndef FL_SKIP_ARGS_CHECK
#ifndef MTD_READ_BBT
if(dwVolumeFlags & BDK_SAFTL_ADVANCED_MATCHING)
{
if(bMaxPartition == 0)
{
DBG_PRINT_ERR(FLZONE_BDK,"ERROR - No SPL partition found - undefine NO_READ_BBT_CODE.\r\n\n");
return flBadFormat;
}
break;
}
#endif /* MTD_READ_BBT */
#endif /* FL_SKIP_ARGS_CHECK */
flBdkVol->startPartitionBlock = (FLWord)LE4(volumePtr->firstUnit);
flBdkVol->endPartitionBlock = (FLWord)LE4(volumePtr->lastUnit);
#ifdef HW_PROTECTION
flBdkVol->protectionArea = (FLByte)LE4(volumePtr->protectionArea);
flBdkVol->protectionType = (FLWord)(dwVolumeFlags &
(PROTECTABLE | CHANGEABLE_PROTECTION));
#endif /* HW_PROTECTION */
flHandleTable[flSocketNo][bMaxPartition] = flNoOfPartitions+bMaxPartition;
bMaxPartition++;
flBdkVol->bdkGlobalStatus = BDK_S_DOC_FOUND | BDK_S_HEADER_FOUND;
/* Find MTD flags and update unit size in case of forced reliable mode */
if(dwVolumeFlags & BDK_SAFTL_NO_MATCHING)
{
flBdkVol->MTDFlags = MTD_NO_MATCHING;
}
else
{
flBdkVol->MTDFlags = 0;
}
if(dwVolumeFlags & BDK_SAFTL_REL_PARTITION)
{
if((dwVolumeFlags & BDK_SAFTL_FAST_PARTITION) &&
(flashPtr->flashTechnology & FL_SUPPORT_FAST ))
{
flBdkVol->MTDFlags |= MTD_REL_MODE | MTD_FAST_MODE;
}
else if(flashPtr->flashTechnology & FL_SUPPORT_RELIABLE)
{
flBdkVol->MTDFlags |= MTD_REL_MODE;
}
/* Reduce erasable block size */
if((flashPtr->flashTechnology & FL_SUPPORT_MLC) &&
(flBdkVol->MTDFlags & MTD_REL_MODE ) )
{
flBdkVol->sectorsInUnitBits--;
flBdkVol->sectorsInUnitMask = (1L<<flBdkVol->sectorsInUnitBits)-1;
flBdkVol->erasableBlockBits--;
}
}
} /* End loop over the binary partitions and initializing them */
flNoOfPartitions = (FLByte)(flNoOfPartitions + bMaxPartition);
} /* End if this is the first time we mounted this media */
/* set the current partition by changing the flBdkVol global pointer */
if ((flPartitionNo>MAX_BINARY_PARTITIONS_PER_DRIVE) ||
(flHandleTable[flSocketNo][flPartitionNo] == BDK_INVALID_VOLUME_HANDLE))
{
DBG_PRINT_FLOW(FLZONE_BDK,"Device is not formated the specified binary partition.\r\n");
return flBadDriveHandle;
}
else
{
flBdkVol = &flBdkVols[flHandleTable[flSocketNo][flPartitionNo]];
}
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkMount() Exit.\r\n");
return flOK;
}
#ifdef MTD_STANDALONE
#ifdef EXIT
/*-------------------------------------------------------------------
* b d k E x i t
*
* Reset BDK variables and Free 'bdkWin' memory.
*
* Parameters : None
*
* global variable input :
* flBdkVol : current binary partition record
* flBdkVol->bdkGlobalStatus : Was DiskOnChip already found
*
* global variable output :
* None
*
* use functions:
* bdkInit : Clear all global data structures.
* flash->dismount : Free dynamicaly allocated memory
*
* Return:
* None
*-------------------------------------------------------------------*/
void bdkExit( void )
{
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkExit() Entered.\r\n");
if( flBdkVol->bdkGlobalStatus & BDK_S_DOC_FOUND ) /* DiskOnChip was found */
{
/* Free DiskOnChip memory window pointer - for virual memory platforms */
freePointer(bdkWin,DOC_WIN);
#ifdef MTD_READ_BBT
/* Free memory used y matching tables */
if(flBdkVol->flash->dismount != NULL)
flBdkVol->flash->dismount(flBdkVol->flash);
#endif /* MTD_READ_BBT */
}
bdkInit();
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkExit() Exit.\r\n");
FL_SYS_FUNC_RELEASE;
}
#endif /* EXIT */
/*--------------------------------------------------------------------------
* b d k F i n d D i s k O n C h i p
*
* Find DiskOnChip in the specified memory range and identify the flash
* media (initialize flash). Update 'docSize' and 'docAddress' according
* to the DiskOnChip size and address respectively.
*
* Note : If the DiskOnChip location is known, specify the same address
* for DOC_LOW_ADDRESS and DOC_HIGH_ADDRESS. or use bdkSetDocWindow
*
* Parameters : 'docAddress' - pointer to the DiskOnChip address
* 'docSize' - pointer to the returned size
*
* global variable input :
* flBdkVol - current binary partition record
* flBdkVol->bdkGlobalStatus - was this device found before
* bdkDocWindow - if > 0 only this address will be checked
*
* global variable output :
* flBdkVol->flash - flash record enabling media I\O
* bdkGlobalStatus - set to BDK_S_DOC_FOUND
* bdkDocWindow - save physical window address
*
* use functions:
* bdkInit - Init package data structures
* flRegisterDOCRam - Register RAM MTD
* flRegisterDOCOREN - Register OREN MTD
* Socket Initializetion - Init socket(routine pointer is set by
* registrarion of the socket)
* MTD Identify - Identify DOC (Routine pointers are set
* but registration of MTD)
*
* Return:
* flOK - success
* other Non-zero value - error returned from called functions.
*
* Routine for BDK stand alone package.
*------------------------------------------------------------------------*/
FLStatus bdkFindDiskOnChip(FLDword FAR2 *docAddressPtr, FLDword FAR2 *docSizePtr )
{
FLFlash *flashPtr;
FLSocket *socketPtr;
if(flInitStatus==FALSE)
bdkInit();
if ((flBdkVol->bdkGlobalStatus & BDK_S_DOC_FOUND) == 0) /* initialize MTD */
{
flBdkVol = flBdkVols;
flashPtr = flFlashOf(0);
socketPtr = flSocketOf(0);
flBdkVol->flash = flashPtr;
checkStatus(flRegisterComponents());
checkStatus(flIdentifyFlash(socketPtr,flashPtr));
/* Identify flashPtr connected to the ASIC */
flBdkVol->bdkDocWindow = ((FLDword)flashPtr->socket->window.baseAddress << 12);
flBdkVol->bdkGlobalStatus |= BDK_S_DOC_FOUND;
} /* End if - first time this device was accessed */
*docAddressPtr = flBdkVol->bdkDocWindow;
*docSizePtr = flBdkVol->flash->mediaSize ;
return flOK;
}
/*--------------------------------------------------------------------------
* b d k S e t B o o t P a r t i t i o n N o
*
* Set current binary partiton pointer to a specific binary partition
*
* Note : This routine is neccesay only for partitions > 0 .
*
* Parameters : 'partitionNo' - serial number of binary partition
*
* global variable output :
* flPartitionNo - changed to the current partition number.
*
* use functions: bdkMount()
*
* Return:
* flOK on success
* flBadParameter if BDK is not customized to support that many partitions.
*
* Routine for BDK stand alone package only.
*------------------------------------------------------------------------*/
FLStatus bdkSetBootPartitionNo(FLByte bPartitionNo)
{
FLStatus status;
FLByte savedbPartitionNo;
savedbPartitionNo = flPartitionNo;
flPartitionNo = bPartitionNo;
status = bdkMount();
if(status != flOK)
{
flPartitionNo = savedbPartitionNo;
DBG_PRINT_ERR(FLZONE_BDK,"ERROR: Failed Setting BDK partiton.\r\n");
DBG_PRINT_ERR_PRM(FLZONE_BDK,(FLTXT(" With status %d.\r\n"),status));
}
return status;
}
/*-------------------------------------------------------------------
* b d k C h e c k S i g n O f f s e t
*
* This routine is kept for backward compatability. Since SAFTL does not support
* different signature offsets, the routine does nothing. It is in just to keep the
* old interface unchanged.
*
* Parameters : 'signPtr' - 4-character signature of storage units
*
* global variable input :
* None
*
* global variable output :
* None
*
*
* Return :
* flOK - success
*
* Routine for BDK stand alone package only.
*-------------------------------------------------------------------*/
FLStatus bdkCheckSignOffset( FLByte FAR2 *signPtr )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -