📄 docbdk.c
字号:
iBlock = (word)(iBlock + bdkVol->flash->firstUsableBlock);
if (iBlock > bdkVol->endImageBlock)
break;
}
status = flash->read (flash , bdkVol->bdkSignOffset +
((CardAddress)iBlock << bdkVol->erasableBlockBits) ,
(byte FAR1 *)signRead, BDK_SIGNATURE_NAME,EXTRA);
if(status!=flOK)
{
DEBUG_PRINT(("(EXTRA)read failed.\r\n"));
return status;
}
if( tffscmp((void FAR1 *)signRead, (void FAR1 *)(bdkVol->signBuffer),
BDK_SIGNATURE_NAME ) == 0 )
break;
}
if( iBlock > bdkVol->endImageBlock )
return( flNoSpaceInVolume ); /* Finish (last block) */
bdkVol->curReadImageAddress = (CardAddress )iBlock << bdkVol->erasableBlockBits;
bdkVol->curReadImageBlock++;
}
/* read data */
readLen = (word)BDK_MIN(bdkVol->actualReadLen, (dword)bufferLen);
if((bdkVol->bdkEDC)&&(bdkVol->bdkSignOffset!=0))
{
modes=EDC;
}
else
{
modes=0;
}
status = (flash->read(flash, bdkVol->curReadImageAddress, buf, readLen, modes));
if(status!=flOK)
{
DEBUG_PRINT(("(EXTRA)read failed.\r\n"));
return status;
}
bdkVol->curReadImageAddress += (CardAddress )readLen;
bdkVol->actualReadLen -= (dword)readLen;
#ifdef BDK_CHECK_SUM
if (checkSum!=NULL)
{
while (readLen>0)
{
readLen--;
*checkSum+=buf[readLen];
}
}
#endif /* BDK_CHECK_SUM */
return( flOK );
}
#ifdef UPDATE_BDK_IMAGE
/*-------------------------------------------------------------------
* b d k U p d a t e B o o t A r e a I n i t
*
* Initialize update operations on the DiskOnChip starting at 'startUnit',
* with a size of 'areaLen' bytes and 'signature'.
*
* Note : Blocks in the DiskOnChip are marked with a 4-byteacter signature
* followed by a 4-digit hexadecimal number.
*
* Parameters: 'startUnit' - start unit in image for updating
* 'areaLen' - BDK image size
* 'updateFlag' - update whole image or part of it
* BDK_COMPLETE_IMAGE_UPDATE
* 'signature' - 4-byteacter signature of storage units
*
* global variable input :
* bdkVol - current binary partition record
* flash - flash record enabling media I\O
* bdkGlobalStatus - was this partition accessed before
* bdkSavedSignBuffer - signature offset of previous access
* bdkSignOffset - current signature offset
*
* global variable output :
* bdkGlobalStatus - set to BDK_S_INFO_FOUND
* signBuffer - initialize with given signature
* bdkSavedSignBuffer - save current signatur for next access
* bootImageSize - size of the entire sub partition in bytes
* realBootImageSize - number of units writen in the sub partition
* 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
* actualUpdateLen - length left to write
* curUpadateImageAddress - current address to write to
* Return :
* flOK - success
* flDriveNotAvailable - DiskOnChip ASIC was not found
* flUnknownMedia - failed in Flash chips recognition
* flBadDownload - DiskOnChip Millennium Plus reported an uncorrectable
* protection violation. This device is unusable.
* 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
*
* Routine for both OSAK and the BDK stand alone package.
*-------------------------------------------------------------------*/
FLStatus bdkUpdateBootAreaInit( word startUnit, dword areaLen,
byte updateFlag, byte FAR2 *signature )
{
word imageBlockSize;
checkStatus(getBootAreaInfo( startUnit , signature ));
imageBlockSize = (word)( bdkVol->bootImageSize >> bdkVol->erasableBlockBits);
if( ((dword)(imageBlockSize-startUnit) << bdkVol->erasableBlockBits) < areaLen )
return( flNoSpaceInVolume );
bdkVol->actualUpdateLen = areaLen;
bdkVol->curUpdateImageBlock = startUnit;
bdkVol->updateImageFlag = updateFlag;
bdkVol->curUpdateImageAddress = getPhysAddressOfUnit( startUnit );
bdkVol->bdkGlobalStatus &= ~BDK_S_INFO_FOUND;
return( flOK );
}
/*-------------------------------------------------------------------
* b d k U p d a t e B o o t A r e a B l o c k
*
* Write 'buffer' to the DiskOnChip BDK Image area.
*
* Note : Before the first use of this function 'bdkUpdateBootAreaInit'
* must be called
*
* Parameters: 'buf' - BDK image buffer
* 'bufferLen' - buffer length in bytes
*
* global variable input :
* bdkVol - current binary partition record
* flash - flash record enabling media I\O
* signBuffer - sub partition signature
* bdkSignOffset - current signature offset
* curUpdateImageAddress - current address to read from
* actualUpdateLen - length left to read
* endImageBlock - last signatured block in sub partition
* erasableBlockBits - no' of bits used to represent a block
*
* global variable output :
* curUpdateImageAddress - updated address to read from
* actualUpdateLen - updated length left to read
*
* Return :
* flOK - success
* flBadLength - required length will cause crossing unit boundry
* flNoSpaceInVolume - no more signatured units found
* flDataError - MTD read fault
* flHWProtection - HW protection was triggerd
* flWriteFault - MTD write fault
*
* Routine for both OSAK and the BDK stand alone package.
*-------------------------------------------------------------------*/
FLStatus bdkUpdateBootAreaBlock( byte FAR1 *buf, word bufferLen )
{
word iBlock, writeLen, i0, j;
FLStatus status;
FLFlash* flash = bdkVol->flash;
byte modes;
byte signRead[SIGNATURE_LEN];
if( (bufferLen > flash->erasableBlockSize) ||
(bufferLen > bdkVol->actualUpdateLen))
return( flBadLength );
/* find next good unit and prepare it for work */
if( (bdkVol->curUpdateImageAddress & (flash->erasableBlockSize-1)) == 0 )
{
/* find next signatured unit */
iBlock = (word)( bdkVol->curUpdateImageAddress >> bdkVol->erasableBlockBits );
for(;( 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),
(byte FAR1 *)signRead, BDK_SIGNATURE_NAME ,EXTRA);
if(status!=flOK)
{
DEBUG_PRINT(("(EXTRA)read failed.\r\n"));
return status;
}
if( tffscmp( (void FAR1 *)signRead, (void FAR1 *)(bdkVol->signBuffer),
BDK_SIGNATURE_NAME ) == 0 )
break;
}
if( iBlock > bdkVol->endImageBlock )
return( flNoSpaceInVolume );
/* Erase the newly found unit */
#ifdef BDK_ACCESS
if(bdkVol->updateImageFlag & ERASE_BEFORE_WRITE)
#endif
checkStatus(flash->erase (flash, iBlock, 1 ));
/* Update signature number */
if( (bdkVol->actualUpdateLen <= flash->erasableBlockSize) &&
(bdkVol->updateImageFlag & BDK_COMPLETE_IMAGE_UPDATE) )
{
/* Last block FFFF */
tffscpy( (void FAR1 *)&bdkVol->signBuffer[BDK_SIGNATURE_NAME],
(void FAR1 *)"FFFF", SIGNATURE_NUM );
}
else
{
for(i0=bdkVol->curUpdateImageBlock,j=SIGNATURE_LEN;(j>BDK_SIGNATURE_NAME);j--)
{
bdkVol->signBuffer[j-1] = (i0 % 10) + '0';
i0 /= 10;
}
}
/* update internal pointers */
bdkVol->curUpdateImageAddress = (CardAddress )iBlock << bdkVol->erasableBlockBits;
bdkVol->curUpdateImageBlock++;
/* Mark new block */
status = flash->write(flash,
(bdkVol->bdkSignOffset + bdkVol->curUpdateImageAddress),
(byte FAR1 *)bdkVol->signBuffer, SIGNATURE_LEN, EXTRA);
#ifdef VERIFY_WRITE
if (status == flWriteFault) /* Check if failed due to erase operation */
{
/* Check signature is written properly */
flash->read(flash , (bdkVol->bdkSignOffset + bdkVol->curUpdateImageAddress),
(byte FAR1 *)signRead, SIGNATURE_LEN ,EXTRA);
if(tffscmp(signRead,bdkVol->signBuffer,BDK_SIGNATURE_NAME))
{
return flWriteFault;
}
/* Check unit number is not "FFFF" */
if(tffscmp(signRead+BDK_SIGNATURE_NAME,"FFFF",BDK_SIGNATURE_NAME))
{
dword tmp=0;
checkStatus(flash->write(flash,(bdkVol->bdkSignOffset +
bdkVol->curUpdateImageAddress), &tmp, sizeof (dword), EXTRA));
}
}
#endif /* VERIFY_WRITE */
}
/* Write the data to the flash and update internal pointers */
writeLen = (word)BDK_MIN(bdkVol->actualUpdateLen, (dword)bufferLen);
if((bdkVol->bdkEDC)&&(bdkVol->bdkSignOffset!=0))
{
modes=EDC;
}
else
{
modes=0;
}
checkStatus(flash->write(flash,bdkVol->curUpdateImageAddress,buf,writeLen,modes));
bdkVol->curUpdateImageAddress += (CardAddress)writeLen;
bdkVol->actualUpdateLen -= (dword)writeLen;
return( flOK );
}
#ifdef ERASE_BDK_IMAGE
/*-------------------------------------------------------------------
* b d k E r a s e A r e a
*
* Erase given number of blockds in the binary sub partition.
*
* Parameters: 'startUnit' - start unit in image for updating
* 'noOfBlocks' - number of blocks to erase
* 'signature' - 4-byteacter signature of storage units
*
* global variable input :
* bdkVol - current binary partition record
* flash - flash record enabling media I\O
* bdkGlobalStatus - was this partition accessed before
* bdkSavedSignBuffer - signature offset of previous access
* bdkSignOffset - current signature offset
*
* global variable output :
* bdkGlobalStatus - set to BDK_S_INFO_FOUND
* signBuffer - initialize with given signature
* bdkSavedSignBuffer - save current signatur for next access
* bootImageSize - size of the entire sub partition in bytes
* startPartitionBlock - low physical boundry of the partition
* endPartitionBlock - high physical boundry of the partition
* realBootImageSize - number of units writen in the sub partition
* startImageBlock - physical unit number of the first and
* endImageBlock last units marked with the signature
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -