📄 docbdk.c
字号:
for(iBlock=bdkVol->startImageBlock;
((startUnit > 0) && (iBlock <= bdkVol->endImageBlock));iBlock++)
{
if ((dword)(iBlock % bdkVol->blockPerFloor) < bdkVol->flash->firstUsableBlock)
{
iBlock = (word)(iBlock + bdkVol->flash->firstUsableBlock);
if (iBlock > bdkVol->endImageBlock)
break;
}
status = flash->read( flash , bdkVol->bdkSignOffset +
((CardAddress)iBlock << bdkVol->erasableBlockBits) ,
signRead , BDK_SIGNATURE_NAME , EXTRA);
if(status!=flOK)
{
DEBUG_PRINT(("(EXTRA)read failed.\r\n"));
return 0L;
}
if(tffscmp((void FAR1*)signRead,(void FAR1*)(bdkVol->signBuffer),BDK_SIGNATURE_NAME)==0)
startUnit--;
}
return( (CardAddress)iBlock << bdkVol->erasableBlockBits );
}
/*--------------------------------------------------------------------------*
* g e t B o o t A r e a I n f o
*
* Mount the binary sub partitions by reading the signature area of each
* unit of the entire partition.
*
* Note : Assume that the DiskOnChip was already found (bdkFoundDiskOnChip).
*
* Parameters :
* startUnit : unit number in the binary sub partition.
* signature : signature of the binary sub partition.
*
* global variable input :
* bdkVol - current binary partition record
* bdkGlobalStatus - partition predsent status.
* bdkSavedStartUnit - start unit of previous access
* bdkSavedSignOffset - signature offset of previous access
* bdkSignOffset - current signature offset
* bdkDocWindow - explicitly sets the windows address
*
* global variable output :
* flash - flash record enabling media I\O
* bdkGlobalStatus - set to BDK_S_INFO_FOUND
* signBuffer - initialize with given signature
* bdkSavedStartUnit - save start unit for next access
* bdkSavedSignOffset - save current signature for next access
* startPartitionBlock - low physical boundry of the partition
* endPartitionBlock - high physical boundry of the partition
* startImageBlock - physical unit number of the first and
* endImageBlock last units marked with the signature
* bootImageSize - size of the entire sub partition in bytes
* realBootImageSize - number of units writen in the sub partition
*
* Return :
* flOK - success
* flDriveNotAvailable - DiskOnChip ASIC was not found
* flUnknownMedia - failed in Flash chips recognition
* flBadFormat - TL format does not exists
* flNoSpaceInVolume - there are 0 units marked with this signature
* flDataError - MTD read fault.
* flHWProtection - HW read protection was triggerd
* flFeatureNotSupported - Not a DiskOnChip device.
*
* Routine for both OSAK and the BDK stand alone package.
*-------------------------------------------------------------------*/
static FLStatus getBootAreaInfo( word startUnit , byte FAR2* signature )
{
FLFlash * flash;
word iBlock;
word numBlock;
#ifdef MTD_STANDALONE
dword temp;
checkStatus(bdkFindDiskOnChip((dword FAR2 *)&temp,(dword FAR2 *)&temp));
DEBUG_PRINT(("Debug: getBootAreaInfo() - DiskOnChip found.\r\n"));
#endif /* MTD_STANDALONE */
/* set bdkVol pointer to the proper binary partition */
checkStatus(bdkMount());
DEBUG_PRINT(("Debug: getBootAreaInfo() - BDK mount succeed.\r\n"));
/* Check if this sub-partition was already analized */
if ((!(bdkVol->bdkGlobalStatus & BDK_S_INFO_FOUND)) ||
(tffscmp((void FAR1 *)(bdkVol->signBuffer),
(void FAR1 *)signature,BDK_SIGNATURE_NAME) != 0) ||
(bdkVol->bdkSignOffset!=bdkVol->bdkSavedSignOffset) ||
(startUnit<bdkVol->bdkSavedStartUnit) ||
(bdkVol->bdkSavedStartUnit + (bdkVol->realBootImageSize >>
bdkVol->erasableBlockBits)<= startUnit))
{
/* The partition needs mounting */
tffscpy((void FAR1 *)(bdkVol->signBuffer),(void FAR1 *)signature,
BDK_SIGNATURE_NAME);
bdkVol->bdkSavedSignOffset = bdkVol->bdkSignOffset;
bdkVol->bdkSavedStartUnit = startUnit;
bdkVol->startImageBlock = 0;
bdkVol->bootImageSize = 0L;
bdkVol->realBootImageSize = 0L;
/* Find the boundries and number of the units marked with the signature */
DEBUG_PRINT(("Debug: searching for signtured blocks.\r\n"));
flash = bdkVol->flash;
numBlock = 0;
for (numBlock = 0 , iBlock = bdkVol->startPartitionBlock;
iBlock<=bdkVol->endPartitionBlock;iBlock++)
{
if ((dword)(iBlock % bdkVol->blockPerFloor) < bdkVol->flash->firstUsableBlock)
{
iBlock = (word)(iBlock + bdkVol->flash->firstUsableBlock);
if (iBlock > bdkVol->endPartitionBlock)
break;
}
/* check for unit signature */
DEBUG_PRINT(("Debug: getBootAreaInfo() - Reading unit signature...\r\n"));
checkStatus(flash->read(flash,bdkVol->bdkSignOffset +
((CardAddress)iBlock << bdkVol->erasableBlockBits),
bdkVol->signBuffer,SIGNATURE_LEN,EXTRA));
DEBUG_PRINT(("Debug: getBootAreaInfo() - Signature read done.\r\n"));
if(tffscmp( (void FAR1 *)signature , (void FAR1 *)bdkVol->signBuffer,
BDK_SIGNATURE_NAME ) == 0 )
{
if( numBlock == 0 )
bdkVol->startImageBlock = iBlock;
numBlock++;
bdkVol->endImageBlock = iBlock;
if(( bdkVol->realBootImageSize == 0L ) && (numBlock>startUnit) &&
(tffscmp((void FAR1 *)&bdkVol->signBuffer[BDK_SIGNATURE_NAME],
(void FAR1 *)"FFFF", SIGNATURE_NUM) == 0 ))
{
bdkVol->realBootImageSize =
((dword)(numBlock - startUnit) << bdkVol->erasableBlockBits);
}
}
}
if (numBlock<=startUnit)
{
DEBUG_PRINT(("Debug: getBootAreaInfo() - No space in volume.\r\n"));
return( flNoSpaceInVolume );
}
bdkVol->bootImageSize = (dword)numBlock << bdkVol->erasableBlockBits;
if( bdkVol->realBootImageSize == 0L ) /* In case the image without FFFF */
bdkVol->realBootImageSize =
((dword)(numBlock - startUnit) << bdkVol->erasableBlockBits);
tffscpy((void FAR1 *)(bdkVol->signBuffer),(void FAR1 *)signature,
BDK_SIGNATURE_NAME);
bdkVol->bdkGlobalStatus |= BDK_S_INFO_FOUND;
}
return( flOK );
}
#ifndef NO_INFTL_SUPPORT
/*----------------------------------------------------------------------*/
/* b d k R e t r i e v e H e a d e r */
/* */
/* Retreave media header by oring the headers of each floor */
/* */
/* Note: The header of each floor is read to the first half of the */
/* buffer and then ORed to the second half therfore constructing the */
/* real header in the upper half. The data is copied to the first half */
/* while cast back from little endian */
/* */
/* Parameters: */
/* headerBuffer - buffer returning the retieved header. */
/* */
/* Returns: */
/* flOK on success any other value on error */
/*----------------------------------------------------------------------*/
FLStatus bdkRetrieveHeader (dword * headerBuffer)
{
word iUnit;
dword endUnit; /* Might be larger then word */
dword * bbt = (headerBuffer+BDK_HEADER_FIELDS);
FLFlash * flash=bdkVol->flash;
byte floorNo;
FLBoolean flag;
byte index;
FLStatus status;
tffsset(headerBuffer,0,BDK_HEADER_FIELDS * 2 * sizeof(LEmin));
for (endUnit = 0,floorNo = 0 ; floorNo < flash->noOfFloors ; floorNo++)
{
iUnit = (word)(endUnit + flash->firstUsableBlock);
endUnit += bdkVol->blockPerFloor;
for (flag = FALSE;(iUnit<endUnit)&&(flag==FALSE);iUnit++)
{
for (index=0;index<BDK_NO_OF_MEDIA_HEADERS;index++) /* all copies */
{
status = flash->read(flash,((CardAddress)iUnit<<flash->erasableBlockSizeBits)
+ index * BDK_HEADERS_SPACING,bbt,
BDK_HEADER_FIELDS*sizeof(LEmin),FL_DATA);
if (status != flOK)
{
DEBUG_PRINT(("Debug: ERROR reading original unit header.\r\n"));
return flBadFormat;
}
if (tffscmp(bbt, "BNAND", sizeof("BNAND")) == 0)
{
flag=TRUE;
break;
}
}
}
if (flag == FALSE) /* Header not found in all header copies */
{
DEBUG_PRINT(("Debug: binary partition data could not be found.\r\n"));
return flBadFormat;
}
/* merge with previous headers */
for (index = 0 ; index < BDK_HEADER_FIELDS; index++)
{
headerBuffer[index] |= bbt[index];
}
} /* loop of the floors */
return flOK;
}
#endif /* NO_INFTL_SUPPORT */
/*--------------------------------------------------------------------------*
* b d k M o u n t
*
* Routine that finds the media header unit and initializes it. The header
* supplies the number of binary partition in the DiskOnChip and their
* boundries. If the header is valid the curent partition pointer is set to
* the required partition.
*
* Note : 1) Drive argument is assumed to be O.K and DiskOnChip already found
* 2) If there are no binary partitions O.K will be returned but the
* bdkVol pointer will not be changed.
*
* Parameters : None
*
* global variable input :
* globalSocketNo : DiskOnChip drive number (always 0 for BDK)
* globalPartitionNo : Binary partition number in the DiskOnChip
* bdkGlobalStatus - was this partition accessed before
* bdkVol - current binary partition record
* flash - flash record enabling media I\O
* noOfPartitions - the current amount of partitions
* bdkVols - array of the binary partitions records
*
* global variable output :
* bdkVol - new current binary partition record
* handleTable - partition to record converion table
* bdkGlobalStatus - set to BDK_S_HEADER_FOUND
* erasableBlockBits - number of bits representing a unit
* startPartitionBlock - physical unit number of first unit
* endPartitionBlock - and last units of the partition
* noOfPartitions - increment with the new found partitions
*
* Return:
* flOK - success
* flBadFormat - TL format does not exists
* flFeatureNotSupported - Not a DiskOnChip device.
* flNoSpaceInVolume - No binary partition at all
* flBadDriveHandle - No such binary partition on the media or number
* binary partitions exceeds the cusomized limit.
* flDataError - fail in buffer reading codes
* flHWProtection - HW read protection was triggerd
*
* Routine for both OSAK and the BDK stand alone package.
*--------------------------------------------------------------------------*/
static FLStatus bdkMount(void)
{
FLFlash * flash = bdkVol->flash;
dword iBlock;
dword noOfBlocks;
byte blockMultiplierBits;
byte maxPartition = 0;
byte buf1[TL_SIGNATURE];
byte buf2[TL_SIGNATURE];
#ifndef NO_INFTL_SUPPORT
LEmin headerBuffer[BDK_HEADER_FIELDS*2]; /* assume big enough */
VolumeRecord * volume;
#endif /* NO_INFTL_SUPPORT */
if ((bdkVol->bdkGlobalStatus & BDK_S_HEADER_FOUND)==0)/* header not found */
{
/* Find number of bits used to represent erasable block */
bdkVol->erasableBlockBits = flash->erasableBlockSizeBits;
noOfBlocks = (dword)(flash->chipSize * flash->noOfChips)
>> bdkVol->erasableBlockBits;
bdkVol->blockPerFloor = (word)
(flash->chipSize >> flash->erasableBlockSizeBits) *
((flash->noOfChips + (flash->noOfChips % flash->noOfFloors)) /
flash->noOfFloors);
DEBUG_PRINT(("Debug: searching for TL media header.\r\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -