PB5.0中的 bootpart移植实现拷贝内核进度显示(一)

最近在做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)
函数中添加进度条了。关于如何具体添加进度条,呵呵请看下回

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值