UINT16 FlashWrite(DWORD dwPhysStart, DWORD dwPhysLen)
{
volatile WORD *pdwFlash;
volatile WORD *pdwBlockAddress;
volatile WORD *pdwDeviceAddress;
volatile WORD *pdwFlashCache;
volatile WORD *pdwFlashStart;
volatile WORD *pdwRamStart;
DWORD dwLength = dwPhysLen;
DWORD i,j,b;
DWORD val = 0;
WORD count;
DWORD sizeFlashCache; // size in bytes of the flash cache
DWORD chunksPerBlock;
pdwFlash = (volatile WORD *)((FLASH_START + dwEBOOT_OFFSET) | CACHED_TO_UNCACHED_OFFSET);
pdwBlockAddress = (volatile WORD *)((FLASH_START + dwEBOOT_OFFSET) | CACHED_TO_UNCACHED_OFFSET);
pdwDeviceAddress = (volatile WORD *)((FLASH_START + dwEBOOT_OFFSET) | CACHED_TO_UNCACHED_OFFSET);
pdwFlashCache = (volatile WORD *)(dwPhysStart | CACHED_TO_UNCACHED_OFFSET);
/*其中
FLASH_START = BOOT_FLASH_BASE_C_VIRTUAL + CHCHED_TO_UNCACHED_OFFSET
= 0x80000_0000 + 0x2000_0000 = 0xa000_0000
dwEBOOT_OFFSET = 0x8_0000
所以 pdwFlash = 0xa000_0000 + 0x8_0000 = 0xa008_0000
pdwBlockAddress = pdwDeviceAddress = pdwFlash
pdwFlashCache = 0xa000_0000
*/
FlashErase((DWORD)pdwFlash, dwPhysLen);
b = 0;
if ( (flashType == K3) || (flashType == L18) || (flashType == L30) || (flashType == P33) )
{
sizeFlashCache = 64; // 64 bytes total
chunksPerBlock = 2048; // 128K / 64bytes = 2048 //这两条是什么意思呢?
}
EdbgOutputDebugString("\n\rNow programming Flash ... \r\n");
while ( dwPhysLen > 0 )
{
/*if(pdwDeviceAddress<0xBC900000){
}else{
pdwBlockAddress = (volatile UINT16 *) (0xBC900000);//0xBC900000????????
}
*/
if ( dwPhysLen > sizeFlashCache )
{
count = (WORD)(sizeFlashCache / 2);
}
else
{
count = (WORD)(dwPhysLen / 2);
}
//通过打印信息可以看到 count = 32
// Issue Write to Buffer Command
*pdwBlockAddress = 0x00E8; //写命令
while ( (*pdwBlockAddress & 0x0080) != 0x0080 )
{
*pdwBlockAddress = 0x00E8;
}
*pdwBlockAddress = (count - 1);
pdwFlashStart = pdwDeviceAddress;
pdwRamStart = pdwFlashCache;
// Write up to "count" DWORDS into the Flash memory staging area
for ( i = 0; i < count; i++ )
{
*pdwDeviceAddress++ = *pdwFlashCache++;
}
// increment the number of 32/64 byte segments written.
b++;
// Now program the buffer into Flash
*pdwBlockAddress = 0x00D0;
i = 0;
while ( (i & 0x0080) != 0x0080 )
{
i = *pdwBlockAddress;
}
dwPhysLen -= count << 1;
// Read back the segment just written
*pdwFlash = 0x00FF;
*pdwFlashStart = 0x00FF; //读命令
for ( i = 0; i < count; i++ )
{
/*if ( (flashType == L18) || (flashType == L30) ||(flashType == P33) )
{
//*pdwFlashStart = 0x00FF;
}
*/
if ( *pdwFlashStart++ != *pdwRamStart++ )
{
EdbgOutputDebugString( "\r\nFlash programming failure at address\r\n%X: Ideal %X Actual %X\r\n", pdwFlashStart-1, *(pdwRamStart-1), *(pdwFlashStart-1) );
return 1;
}//内核大于32M时到这就会出错,
//报错信息:Flash programming failure at address A2000000:
Ideal 00000000 Actual 0000FFFF
(实际0x0000ffff说明擦除成功但是没写进去)
Flash programming Error. System halted! }
if ( (b % chunksPerBlock) == 0 )
{
EdbgOutputDebugString(".");
}//下载过程
}
pdwFlash = (volatile WORD *)((FLASH_START+dwEBOOT_OFFSET) | CACHED_TO_UNCACHED_OFFSET);
// Put Flash into read mode.
*pdwFlash = 0x00FF;
EdbgOutputDebugString( "\r\nComparing Flash vs RAM image ...\n\r");
//再次校验
pdwFlashCache = (volatile WORD *)(dwPhysStart | CACHED_TO_UNCACHED_OFFSET);
for ( j = 0; j < dwLength/2; j++ )
{
if ( *pdwFlash++ != *pdwFlashCache++ )
{
EdbgOutputDebugString( "\r\nBeat!\r\n%X: Ideal %X Actual %X\r\n", pdwFlash-1, *(pdwFlashCache-1), *(pdwFlash-1) );
return 1;
}
}
EdbgOutputDebugString( "Flash programmed successfully!\r\n" );
return 0;
}
感觉就出现在flashwrite这个函数里,但是实在找不到是什么原因造成不能下载32M以上的NK,只能求教各位高手啦!!谢谢啦!
上面有一个地方注释错了:
pdwFlashCache = (volatile WORD *)(dwPhysStart | CACHED_TO_UNCACHED_OFFSET);
通过main.cpp中usbdown()调用:FlashWrite( RAM_IMAGE_START, dwPhysLen)看
dwPhysStart = RAM_IMAGE_START = 0x96CB8000 (这个是NK放在SDRAM的虚拟地址)
所以pdwFlashCache = 0x96CB8000 | 0x2000_0000 = 0xb6c8_8000
WiNCE 5.0 的进程有限制,最多支持32个进程,每个进程最大支持访问32M内存,所以应用程序不能访问大于32M的物理内存,要使用的话可以考虑用 内存映射文件 处理,或者分块加载大文件
WiNCE 5.0 的进程有限制,最多支持32个进程,每个进程最大支持访问32M内存,所以应用程序不能访问大于32M的物理内存,要使用的话可以考虑用 内存映射文件 处理,或者分块加载大文件
dwEBOOT_OFFSET = 0x8_0000
所以 pdwFlash = 0xa000_0000 + 0x8_0000 = 0xa008_0000
为什么要把EBOOT的大小Reserve出来?难道你的EBOOT不用它本身来更新吗?
一再强调读写Flash要完全按照它的Spec去进行读写,这样我就不知道还会有什么问题?
注意检查一下所有变量的类型定义,WORD是16位的,看会不会越界