最近在做2440的wince 开发,由于wince 系统NANDFLASH在启动时需要拷贝内核到内存这个过程时间较长需要用户等待,这时我想在拷贝过程中添加一个显示进度或动画来提示用户(当然也可以使用XIPKERNEL来加快启动速度,实际上我已经使用呵呵..)那么如何添加就是问题了:最后找到拷贝数据的函数:
BOOL BP_ReadData(HANDLE hPartition, LPBYTE pbBuffer, DWORD dwLength)
{
if (hPartition == INVALID_HANDLE_VALUE)
return FALSE;
DWORD dwNumSects, dwBlockAddress;
static LPBYTE pbSector = g_pbBlock;
PPARTSTATE pPartState = (PPARTSTATE) hPartition;
DWORD dwNextPtrValue = pPartState->dwDataPointer + dwLength;
if (!pbBuffer || !pbSector || dwLength == 0)
return(FALSE);
RETAILMSG (1, (TEXT("ReadData6: Start = 0x%x, Length = 0x%x./r/n"), pPartState->dwDataPointer, dwLength));
// Check to make sure buffer size is within limits of partition
if (((dwNextPtrValue - 1) / g_FlashInfo.wDataBytesPerSector) >= pPartState->pPartEntry->Part_TotalSectors) {
RETAILMSG (1, (TEXT("ReadData: trying to read past end of partition./r/n")));
return FALSE;
}
// Get the starting physical sector
DWORD dwSectorAddr = Log2Phys (pPartState->dwDataPointer / g_FlashInfo.wDataBytesPerSector + pPartState->pPartEntry->Part_StartSector);
// If current pointer is not on a sector boundary, copy bytes up to the first sector boundary
DWORD dwOffsetSector = pPartState->dwDataPointer % g_FlashInfo.wDataBytesPerSector;
if (dwOffsetSector)
{
if (!FMD_ReadSector(dwSectorAddr, pbSector, NULL, 1))
{
RETAILMSG (1, (TEXT("ReadData: failed to read sector (0x%x)./r/n"), dwSectorAddr));
return(FALSE);
}
DWORD dwNumBytesRead = g_FlashInfo.wDataBytesPerSector - dwOffsetSector;
if (dwNumBytesRead > dwLength)
dwNumBytesRead = dwLength;
memcpy(pbBuffer, pbSector + dwOffsetSector, dwNumBytesRead);
dwLength -= dwNumBytesRead;
pbBuffer += dwNumBytesRead;
dwSectorAddr++;
}
// Compute sector length.
dwNumSects = (dwLength / g_FlashInfo.wDataBytesPerSector);
// NAND FMD only supports single-sector reads at the moment.
while (dwNumSects--)
{
dwBlockAddress = (dwSectorAddr / g_FlashInfo.wSectorsPerBlock);
// RETAILMSG (1, (TEXT("ReadData: dwNumSects=(0x%x)./r/n"), dwNumSects));
// If the block is marked bad, skip to next block. Note that the assumption in our error checking
// is that any truely bad block will be marked either by the factory during production or will be marked
// during the erase and write verification phases. If anything other than a bad block fails ECC correction
// in this routine, it's fatal.
if (IS_BLOCK_UNUSABLE(dwBlockAddress))
{
dwSectorAddr += g_FlashInfo.wSectorsPerBlock;
++dwNumSects; // Compensate for fact that we didn't write any sector data.
continue;
}
// Read the sector - if this fails ECC correction, we fail the whole read operation.
// Note - only single sector reads supported at the moment.
if (!FMD_ReadSector(dwSectorAddr, pbBuffer, NULL, 1))
{
RETAILMSG (1, (TEXT("ReadData: failed to read sector (0x%x)./r/n"), dwSectorAddr));
return(FALSE);
}
++dwSectorAddr;
pbBuffer += g_FlashInfo.wDataBytesPerSector;
}
DWORD dwNumExtraBytes = (dwLength % g_FlashInfo.wDataBytesPerSector);
if (dwNumExtraBytes)
{
// Skip bad blocks
while (IS_BLOCK_UNUSABLE(dwSectorAddr / g_FlashInfo.wSectorsPerBlock))
{
dwSectorAddr += g_FlashInfo.wSectorsPerBlock;
if ((dwSectorAddr / g_FlashInfo.wSectorsPerBlock) >= g_FlashInfo.dwNumBlocks)
{
// This should never happen since partition has already been created
RETAILMSG (1, (TEXT("ReadData: corrupt partition. Reformat flash./r/n")));
return FALSE;
}
}
if (!FMD_ReadSector(dwSectorAddr, pbSector, NULL, 1))
{
RETAILMSG (1, (TEXT("ReadData: failed to read sector (0x%x)./r/n"), dwSectorAddr));
return(FALSE);
}
memcpy(pbBuffer, pbSector, dwNumExtraBytes);
}
pPartState->dwDataPointer = dwNextPtrValue;
return(TRUE);
}
红色部分为拷贝过程,因此在这个过程中添加即可,但是这个函数在
D:/WINCE500/PUBLIC/COMMON/OAK/DRIVERS/ETHDBG/BOOTPART/bootpart.cpp里,因此需要移植到BSP中,拷贝D:/WINCE500/PUBLIC/COMMON/OAK/DRIVERS/ETHDBG/BOOTPART/目录到BSP中的D:/WINCE500/PLATFORM/SMDK2440A/Src/Bootloader下并修改D:/WINCE500/PLATFORM/SMDK2440A/Src/Bootloader/Eboot下的文件sources:
$(_COMMONOAKROOT)/lib/$(_CPUINDPATH)/bootpart.lib /
修改为
$(_TARGETPLATROOT)/lib/$(_CPUINDPATH)/bootpart.lib /
这样就把bootpart移植到BSP中了,就可以在BOOL BP_ReadData(HANDLE hPartition, LPBYTE pbBuffer, DWORD dwLength)
函数中添加进度条了。关于如何具体添加进度条,呵呵请看下回