📄 docbdk.c
字号:
FLStatus bdkCopyBootAreaInit(FLWord wStartUnit ,
FLDword dwAreaLen ,
FLByte FAR2 *signPtr)
{
FLWord wUnitNo;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootAreaInit() Entered.\r\n");
checkStatus(bdkMount());
tffscpy((void FAR1 *)(flBdkVol->signBuffer),(void FAR1 *)signPtr,
BDK_SIGNATURE_NAME);
checkStatus(bdkFindBlockInPartition(wStartUnit, &wUnitNo));
flBdkVol->actualReadLen = dwAreaLen;
flBdkVol->curReadOffset = 0;
flBdkVol->curReadImageSector = wUnitNo<<flBdkVol->sectorsInUnitBits;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootAreaInit() Exit.\r\n");
return( flOK );
}
/*-------------------------------------------------------------------
* b d k C o p y B o o t A r e a B l o c k
*
* Read to 'buffer' from the DiskOnChip BDK Image area.
*
* Note : Before the first use of this function 'bdkCopyBootAreaInit'
* must be called
*
* Parameters: 'buf' - buffer to read into
* 'dwBufferLen' - buffer length in bytes
* 'checkSum' - pointer to the checksum modulo 0x100
*
* global variable input :
* flBdkVol - current binary partition record
* flBdkVol->flash - pointer to flash structure
* flBdkVol->actualReadLen - length left to read
* flBdkVol->curReadOffset - offset from beginning of read (how many byte were read)
* flBdkVol->curReadImageSector - The next sector to read from.
* flBdkVol->sectorsInUnitBits - multiplier for number of sectors in unit.
* flBdkVol->sectorsInUnitMask - Mask for the number of sectors in a unit.
* flBdkVol->blockPerFloor - Number of block in each floor (except, maybe the last floor.
* flBdkVol->firstUsableBlock - Array containing the first usable unit in each floor.
* flBdkVol->endPartitionBlock - Last unit in current partition.
* flBdkVol->signBuffer - Signature of current sub-partition.
* flBdkVol->readBuffer - Internal buffer for reading less than one page by the user.
*
* global variable output :
* flBdkVol->actualReadLen - length left to read
* flBdkVol->curReadOffset - offset from beginning of read (how many byte were read)
* flBdkVol->curReadImageSector - The next sector to read from.
*
* use functions:
* flash->flashRead : Read data from flash.
*
* Return :
* flOK - success
* flBadLength - required length is more than specified by read init command
* other Non-zero value - error returned from called functions.
*
* Routine for both SDK and the BDK stand alone package.
*-------------------------------------------------------------------*/
FLStatus bdkCopyBootAreaBlock( FLByte FAR1 *bufPtr,
FLDword dwBufferLen, FLByte FAR2 *bCheckSumPtr )
{
FLDword dwRemainSectorsInUnit, dwCurReadLen;
FLFlash *flashPtr = flBdkVol->flash;
FLStatus status;
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
FLWord wPageOffset;
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootAreaBlock() Entered.\r\n");
/* Argument validity check */
if( dwBufferLen > flBdkVol->actualReadLen)
return( flBadLength );
#ifdef FL_NO_BDK_PARTIAL_PAGE_ACCESS
if (dwBufferLen & (FL_SECTOR_SIZE - 1))
return flBadLength;
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
while (dwBufferLen > 0) /* Loop until required number of bytes is read */
{
/***********************/
/* Find next good unit */
/***********************/
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
/* Make sure we are aligned on the begining of the sector */
wPageOffset = (FLWord)(flBdkVol->curReadOffset & FL_SECTOR_MASK);
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
if(((flBdkVol->curReadImageSector & flBdkVol->sectorsInUnitMask) == 0)
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
&& (wPageOffset == 0)
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
)
{
checkStatus(findNextGoodBlock ((FLWord)(flBdkVol->curReadImageSector >>
flBdkVol->sectorsInUnitBits)));
flBdkVol->curReadImageSector = flashPtr->args.startSector;
}
/*************/
/* read data */
/*************/
flashPtr->args.opFlags = MTD_DATA | flBdkVol->MTDFlags ;
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
if (wPageOffset)
{ /* Read modolu of a sector which is not starting at the beginning of page */
dwCurReadLen = BDK_MIN(dwBufferLen, (FLDword)(FL_SECTOR_SIZE - wPageOffset));
flashPtr->args.noOfSectors = 1;
flashPtr->args.startSector = flBdkVol->curReadImageSector;
flashPtr->args.readMainBuf = flBdkVol->readBuffer;
status = flashPtr->flashRead(flashPtr);
if(status!=flOK)
{
DBG_PRINT_FLOW(FLZONE_BDK,"(EXTRA)read failed.\r\n");
return status;
}
tffscpy(bufPtr, flBdkVol->readBuffer + wPageOffset, dwCurReadLen);
dwBufferLen -= dwCurReadLen;
flBdkVol->curReadOffset += dwCurReadLen;
flBdkVol->actualReadLen -= dwCurReadLen;
flBdkVol->curReadImageSector += (FLWord)((dwCurReadLen+wPageOffset)>>
FL_SECTOR_SIZE_BITS);
bufPtr = BYTE_ADD_FAR(bufPtr,dwCurReadLen);
} /* End if - partial page read operation */
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
dwRemainSectorsInUnit = (1L << flBdkVol->sectorsInUnitBits) -
(flBdkVol->curReadImageSector & flBdkVol->sectorsInUnitMask) ;
if (dwBufferLen >= FL_SECTOR_SIZE) /* Read full sectors */
{
flashPtr->args.noOfSectors = BDK_MIN(dwBufferLen >> FL_SECTOR_SIZE_BITS, dwRemainSectorsInUnit);
flashPtr->args.startSector = flBdkVol->curReadImageSector;
flashPtr->args.readMainBuf = bufPtr;
status = flashPtr->flashRead(flashPtr);
if(status!=flOK)
{
DBG_PRINT_FLOW(FLZONE_BDK,"(EXTRA)read failed.\r\n");
return status;
}
dwCurReadLen = flashPtr->args.noOfSectors << FL_SECTOR_SIZE_BITS;
dwRemainSectorsInUnit -= flashPtr->args.noOfSectors;
flBdkVol->curReadImageSector += flashPtr->args.noOfSectors;
flBdkVol->curReadOffset += dwCurReadLen;
dwBufferLen -= dwCurReadLen;
flBdkVol->actualReadLen -= dwCurReadLen;
bufPtr = BYTE_ADD_FAR(bufPtr,dwCurReadLen);
}
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
/* Read less than one sector starting on the beginning of it*/
if ((dwBufferLen > 0) && (dwRemainSectorsInUnit > 0))
{
dwCurReadLen = BDK_MIN(dwBufferLen, (FLDword)(FL_SECTOR_SIZE));
flashPtr->args.noOfSectors = 1;
flashPtr->args.startSector = flBdkVol->curReadImageSector;
flashPtr->args.readMainBuf = flBdkVol->readBuffer;
status = flashPtr->flashRead(flashPtr);
if(status!=flOK)
{
DBG_PRINT_FLOW(FLZONE_BDK,"(EXTRA)read failed.\r\n");
return status;
}
tffscpy(bufPtr, flBdkVol->readBuffer, dwCurReadLen);
flBdkVol->curReadOffset += dwCurReadLen;
dwBufferLen -= dwCurReadLen;
flBdkVol->actualReadLen -= dwCurReadLen;
bufPtr = BYTE_ADD_FAR(bufPtr,dwCurReadLen);
}
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
} /* End loop over required read sectors */
#ifdef BDK_CHECK_SUM
if (bCheckSumPtr!=NULL)
{
while (dwBufferLen>0)
{
dwBufferLen--;
*bCheckSumPtr+=bufPtr[dwBufferLen];
}
}
#endif /* BDK_CHECK_SUM */
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootAreaBlock() Exit.\r\n");
return( flOK );
}
#ifndef FL_READ_ONLY
/*-------------------------------------------------------------------
* 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 'wStartUnit',
* with a size of 'dwAreaLen' bytes and 'signature'.
*
*
* Parameters: 'wStartUnit' - start unit in image for updating
* 'dwAreaLen' - BDK image size
* 'updateFlag' - update whole image or part of it
* BDK_COMPLETE_IMAGE_UPDATE
* 'signPtr' - 4-byteacter signature of storage units
*
* global variable input :
* flBdkVol - current binary partition record
*
* global variable output :
* flBdkVol->signBuffer - initialize with given signature
* flBdkVol->actualUpdateLen - length left to write
* flBdkVol->curUpdateImageBlock - Set current block from the start of sub partition.
* flBdkVol->curUpdateImageSector - Set to the first sector of the image
* flBdkVol->updateImageFlag - Set given update flag.
* flBdkVol->userCacheLength - Set used user cache to 0
* flBdkVol->userCacheData - Empty user cache data
* flBdkVol->bdkGlobalStatus - Update information flag to non-valid.
*
* use functions:
* bdkMount - mount the current sub partition.
* bdkFindBlockInPartition - Find the given block number.
*
* Return :
* flOK - success
* other Non-zero value - error returned from called functions.
*
* Routine for both SDK and the BDK stand alone package.
*-------------------------------------------------------------------*/
FLStatus bdkUpdateBootAreaInit( FLWord wStartUnit, FLDword dwAreaLen,
FLByte bUpdateFlag, FLByte FAR2 *signPtr )
{
FLWord wUnitNo;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkUpdateBootAreaInit() Entered.\r\n");
checkStatus(bdkMount());
tffscpy((void FAR1 *)(flBdkVol->signBuffer),(void FAR1 *)signPtr,
BDK_SIGNATURE_NAME);
checkStatus(bdkFindBlockInPartition(wStartUnit, &wUnitNo));
flBdkVol->actualUpdateLen = dwAreaLen;
flBdkVol->curUpdateImageBlock = wStartUnit;
flBdkVol->curUpdateImageSector = wUnitNo<<flBdkVol->sectorsInUnitBits;
flBdkVol->updateImageFlag = bUpdateFlag;
#ifndef FL_NO_BDK_PARTIAL_PAGE_ACCESS
flBdkVol->userCacheLength = 0;
#endif /* FL_NO_BDK_PARTIAL_PAGE_ACCESS */
flBdkVol->bdkGlobalStatus &= ~BDK_S_INFO_FOUND;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkUpdateBootAreaInit() Exit.\r\n");
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
* 'dwBufferLen' - buffer length in bytes
*
* global variable input :
* flBdkVol - Current binary partition record.
* flBdkVol->flash - Pointer to flash structure.
* flBdkVol->actualUpdateLen - Remaining write operation length.
* flBdkVol->curUpdateImageSector - Current sector to write
* flBdkVol->sectorsInUnitBits - Multiplier for no of sectors in unit
* flBdkVol->sectorsInUnitMask - Mask for the number of sectors in a unit.
* flBdkVol->endPartitionBlock - Last unit of partition.
* flBdkVol->blockPerFloor - No of units in each floor except maybe last floor.
* flBdkVol->firstUsableBlock - Array of first usable unit in each floor.
* flBdkVol->updateImageFlag - user flag for update operation.
* flBdkVol->userCacheLength - used area of user cache from previous write operation.
* flBdkVol->userCacheData - user Data in case non-full page previously written.
*
* global variable output :
* flBdkVol->actualUpdateLen - Remaining write operation length.
* flBdkVol->curUpdateImageSector - Current sector to write
* flBdkVol->userCacheLength - used area of user cache from previous write operation.
* flBdkVol->userCacheData - user Data in case non-full page is written.
*
* use functions:
* flash->flashRead - Read data from flash.
* flash->flashErase - Erase unit on flash.
* flash->flashWrite - Write data on flash.
*
* Return :
* flOK - success
* flBadLength - required length is above specified by init command.
* other Non-zero value - error returned from called functions.
*
* Routine for both SDK and the BDK stand alone package.
*-------------------------------------------------------------------*/
FLStatus bdk
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -