📄 intel_p30_2x16.c
字号:
//
//go to the next bloxk
//
gdwCurEraseBlock = gdwCurEraseBlock+1;
if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
{
gdwCurEraseBlock=0;
gdwCurEraseRegion=gdwCurEraseRegion+1;
//
//return error the current postiotn > the Flash MAX length
//
if(gdwCurEraseRegion>=gdwNumEraseRegion)
return FALSE;
}
}
//
// Erase the Flash
//
while((DWORD)gpulCurAddr < (gdwStartAddr + gdwLength))
{
// EdbgOutputDebugString("Erasing %d, size %x-- %x\r\n.",gdwCurEraseBlock
// ,sBlockInfo[gdwCurEraseRegion].block_size, gpulCurAddr);
//
// Clear the lock bits if the flash block was locked.
//
*gpulCurAddr = FLASH_LOCK_BIT;
*gpulCurAddr = FLASH_LOCK_CLEAR;
*gpulCurAddr = FLASH_READ_STATUS;
//
// Wait for the Flash block command to succeed.
//
bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
*gpulCurAddr = FLASH_CLEAR_STATUS;
if(!bSuccess)
{
break;
}
//
// Erase the flash block
//
*gpulCurAddr = FLASH_BLOCK_ERASE;
*gpulCurAddr = FLASH_BLOCK_ERASE_RESUME;
*gpulCurAddr = FLASH_READ_STATUS;
//
// Wait for the Flash block command to succeed.
//
bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
if(!bSuccess)
{
break;
}
*gpulCurAddr = FLASH_READ_MODE;
/* *gpulCurAddr = FLASH_READ_MODE;
{
volatile ULONG * ptest=gpulCurAddr;
ULONG i;
for(i=0; i< sBlockInfo[gdwCurEraseRegion].block_size; i+=4 ){
if( *ptest != 0xFFFFFFFF ){
EdbgOutputDebugString("Error, block at %x is not erased %x ****\r\n.",ptest ,*ptest);
break;
}
ptest++;
}
if( i< sBlockInfo[gdwCurEraseRegion].block_size ){
EdbgOutputDebugString("Error, erased %x again\r\n.",gpulCurAddr );
continue;
}
}*/
//
// Occasionally write out a dot so they don't think
// the system is dead.
//
EdbgOutputDebugString(".");
//
// Increment to the next block.
//
//gpulCurAddr += FLASH_BLOCK_SIZE>>2;
gpulCurAddr+= sBlockInfo[gdwCurEraseRegion].block_size>>2;
//
//go to the next bloxk
//
gdwCurEraseBlock = gdwCurEraseBlock+1;
if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
{
gdwCurEraseBlock=0;
gdwCurEraseRegion=gdwCurEraseRegion+1;
//
//return error the current postiotn > the Flash MAX length
//
if(gdwCurEraseRegion>=gdwNumEraseRegion)
return FALSE;
}
}
return bSuccess;
}
extern volatile int bStop;
//****************************************************************************
// WriteFlashJ3_2x16
//****************************************************************************
// Writes to J3 Flash. Different from parameters than OEMWriteFlash.
//
// dwDest - Address in flash where the start of the downloaded image
// is to be written. Note that if this is not a flash
// block-aligned address, the platform code will need
// to take this into account and handle it as a special
// case.
//
// dwSource - Location of the Flash Cache.
//
// dwLength - Length of the image, in bytes, to be written to flash.
//
#if 0
BOOL WriteFlashP30_2x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
ULONG ulCount;
ULONG ulEndCount;
volatile PULONG pulBlockAddress;
volatile PULONG pulDest, pulSource;
ULONG usWordsToWrite;
ULONG ulStart,ulCurrent;
BOOL bSuccess;
ULONG ulAddDelay;
ULONG ulBufferSizeLen=0;
ulCount = 0;
pulDest = (PULONG)dwDest;
pulSource = (PULONG)dwSource;
//
//get the current region and block index
//
GotEraseFlashSectorIndex_P30_2X16(dwDest);
while( ulCount < dwLength)
{
//
// Calculate the block address
//
gdwCurEraseBlockMask = ~(sBlockInfo[gdwCurEraseRegion].block_size-1);
pulBlockAddress = (ULONG *)(((ULONG)&pulDest[ulCount>>2]) & gdwCurEraseBlockMask);
//
// Write the Flash to buffer command until the flash is ready.
//
ulStart = GetSystemTimeInMsec();
ulAddDelay = 1;
do
{
*pulBlockAddress = FLASH_WRITE_TO_BUFFER;
//
// Check to make sure that we are not in a loop.
//
ulCurrent = GetSystemTimeInMsec();
if(ulStart + 10000 <ulCurrent)
{
EdbgOutputDebugString("FLASH_WRITE_TO_BUFFER - Failed\n.");
EdbgOutputDebugString("pulBlockAddress = %x.\n",(ULONG)pulBlockAddress);
EdbgOutputDebugString("*pulBlockAddress = %x.\n",(ULONG)*pulBlockAddress);
*pulBlockAddress = FLASH_READ_STATUS;
EdbgOutputDebugString("*FLASH_READ_STATUS pulBlockAddress = %x.\n",(ULONG)*pulBlockAddress);
while(1);
return FALSE;
}
DelayInuSec(ulAddDelay);
ulAddDelay =(ulAddDelay<<1);
}
while((*pulBlockAddress & EXT_STATUS_WBUFFER_READY)!= EXT_STATUS_WBUFFER_READY);
//
// Program the Flash size to be written.
//
usWordsToWrite = (gdwFlashBufferSize - 1)>>2;
*pulBlockAddress = (usWordsToWrite<<16) | usWordsToWrite;
ulEndCount = ulCount + gdwFlashBufferSize;
ulBufferSizeLen = ulBufferSizeLen+gdwFlashBufferSize;
do
{
pulDest[ulCount>>2] = pulSource[ulCount>>2];
ulCount += sizeof(ULONG);
//
// Account for timing problem.
//
do
{
} while(!(*pulBlockAddress & EXT_STATUS_WBUFFER_READY) && (ulAddDelay-- != 0));
} while(ulCount < ulEndCount);
if(ulBufferSizeLen>sBlockInfo[gdwCurEraseRegion].block_size)
{
ulBufferSizeLen=0;
//
//go to the next bloxk
//
gdwCurEraseBlock = gdwCurEraseBlock+1;
if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
{
gdwCurEraseBlock=0;
gdwCurEraseRegion=gdwCurEraseRegion+1;
//
//return error the current postiotn > the Flash MAX length
//
if(gdwCurEraseRegion>=gdwNumEraseRegion)
return FALSE;
}
}
//
// End of programming the block.
//
*pulBlockAddress = FLASH_BLOCK_PROGRAM_RESUME;
// DelayInuSec(500);
//
// Occasionally write out a dot so they don't think
// the system is dead.
//
if(((ULONG)&pulDest[ulCount>>2] & (sBlockInfo[gdwCurEraseRegion].block_size - 1)) == 0)
{
EdbgOutputDebugString(".");
}
//
// Wait for the Flash block command to succeed.
//
bSuccess = WaitForReady(pulBlockAddress, 6000, EXT_STATUS_WBUFFER_READY);
if(!bSuccess)
{
EdbgOutputDebugString("FLASH_BLOCK_PROGRAM_RESUME - Failed\n.");
EdbgOutputDebugString("pulBlockAddress = %x.\n",(ULONG)pulBlockAddress);
EdbgOutputDebugString("*pulBlockAddress = %x.\n",(ULONG)*pulBlockAddress);
*pulBlockAddress = FLASH_READ_STATUS;
EdbgOutputDebugString("*FLASH_READ_STATUS pulBlockAddress = %x.\n",(ULONG)*pulBlockAddress);
while(1);
break;
}
}
*pulBlockAddress = FLASH_READ_MODE;
return TRUE;
}
#else
#define CLEAR_STATUS_CMD 0x00500050
//
BOOL WriteFlashP30_2x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
ULONG ulCount;
volatile ULONG * pulBlockAddress;
volatile ULONG * pulDest;
volatile ULONG * pulSource;
BOOL bSuccess;
ULONG ulBufferSizeLen=0;
ulCount = 0;
pulDest = (ULONG*)dwDest;
pulSource = (ULONG*)dwSource;
//
//get the current region and block index
//
GotEraseFlashSectorIndex_P30_2X16(dwDest);
EdbgOutputDebugString("P30 FLASH_WRITE src %x dest %x len %x \r\n",dwSource, dwDest, dwLength);
while( ulCount < dwLength)
{
ULONG i;
ULONG ulCountCmp;
ulCountCmp = ulCount;
for(i=0;( i<(sBlockInfo[gdwCurEraseRegion].block_size)) && (ulCount < dwLength); i+=4)
{
pulDest[ulCount>>2] = 0x00400040;
pulDest[ulCount>>2] = pulSource[ulCount>>2];
bSuccess = WaitForReady(&pulDest[ulCountCmp>>2], 50000, EXT_STATUS_WBUFFER_READY);
// bSuccess = WaitForReady(&pulDest[ulCount>>2], 50000, EXT_STATUS_WBUFFER_READY);
if( !bSuccess )
{
EdbgOutputDebugString("\r\nfail at 0x%x 0x%x\r\n.",
(ULONG) (&pulDest[ulCount>>2]),
(ULONG) (&pulSource[ulCount>>2]));
while (1);
return bSuccess;
}
pulDest[ulCountCmp>>2] = CLEAR_STATUS_CMD;
ulCount += sizeof(ULONG);
}
EdbgOutputDebugString(".");
//
//go to the next bloxk
//
gdwCurEraseBlock = gdwCurEraseBlock+1;
if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
{
gdwCurEraseBlock=0;
gdwCurEraseRegion=gdwCurEraseRegion+1;
//
//return error the current postiotn > the Flash MAX length
//
if(gdwCurEraseRegion>=gdwNumEraseRegion)
return FALSE;
}
}
pulBlockAddress = (unsigned long*)PHYSICAL_ADDR_FLASH;
*pulBlockAddress = FLASH_READ_MODE;
return TRUE;
}
#endif
//****************************************************************************
// WaitForReady
//****************************************************************************
// Wait until the flash is ready.
//
//
static int WaitForReady
(
volatile ULONG *pFlash,
ULONG ulTimeoutInMsec,
ULONG ulBitField
)
{
ULONG ulStart;
ULONG ulCurrent;
BOOL bSuccess = FALSE;
ulStart = GetSystemTimeInMsec();
do
{
//
// See if there are errors.
//
if((*pFlash & ulBitField)== ulBitField)
{
bSuccess = TRUE;
break;
}
//
// Get the current time.
//
ulCurrent = GetSystemTimeInMsec();
} while(ulCurrent<ulStart + ulTimeoutInMsec);
if(!bSuccess)
{
EdbgOutputDebugString("*pFlash = %x .\n",(ULONG)*pFlash);
}
return bSuccess;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -