📄 intel_p30_2x16.c
字号:
}
*gpulCurAddr = FLASH_CLEAR_STATUS;
gbUnlocked = FALSE;
//
// 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;
}
}
//
// Erase the Flash
//
while((DWORD)gpulCurAddr < (gdwStartAddr + gdwLength))
{
//
// 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);
*gpulCurAddr = FLASH_CLEAR_STATUS;
if(!bSuccess)
{
break;
}
//
// 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.
//
//
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)
{
#if(FCLOCK<=166)
//
// 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
int i;
int ulCountCmp;
ulCountCmp = ulCount;
//EdbgOutputDebugString("200\r\n");
for(i=0;( i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCount < dwLength); i++)
//for(i=0; i<4096 && ulCount < dwLength; i++)
{
pulDest[ulCount>>1] = 0x00400040; //#define FLASH_WRITE_WORD 0x0040
pulDest[ulCount>>1] = pulSource[ulCount>>1];
bSuccess = WaitForReady(&pulDest[ulCount>>1], 50000, EXT_STATUS_WBUFFER_READY);
if( !bSuccess )
{
EdbgOutputDebugString("\r\nfail at 0x%x 0x%x\r\n.",
(ULONG) (&pulDest[ulCount>>1]),
(ULONG) (&pulSource[ulCount>>1]));
while (1);
return bSuccess;
}
//if( ulCount % 1023 == 0)
// EdbgOutputDebugString("+");
ulCount += sizeof(ULONG);
}
if( bSuccess )
{
pulDest[ulCountCmp>>1] = FLASH_READ_MODE;
for(i=0; (i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCountCmp < (int)dwLength); i++)
//for(i=0; i<4096 && ulCountCmp < dwLength; i++)
{
// verify pargramed word
unsigned short t;
//pusDest[ulCountCmp>>1] = FLASH_READ_MODE;
t = pulDest[ulCountCmp>>1];
if( t != pulSource[ulCountCmp>>1] )
{
bSuccess = FALSE;
EdbgOutputDebugString("\r\nmismatch at 0x%x 0x%x 0x%x != 0x%x failed\r\n.",
(ULONG) (&pulDest[ulCountCmp>>1]),
(ULONG) (&pulSource[ulCountCmp>>1]),
t,
pulSource[ulCountCmp>>1] );
while(1);
return bSuccess;
}
//if( ulCountCmp % 1023 == 0)
// EdbgOutputDebugString("-");
ulCountCmp += sizeof(ULONGT);
}
}
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_INTEL;
*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 + -