WinCE开机Logo的实现(USB下载图片到nandflash)

WinCE开机启动Logo使用Eboot读取NandFlash中的图片数据,然后显示的方式。对于开机logo的方式网友http://jazka.blog.51cto.com/809003/664131有了详细的描述。但是自己在运用的时候遇到了一些问题。现在重新进行整理。

在loader.h中增加保留的block提供给图片用。

#define LOGO_BLOCK				8
#define LOGO_SECTOR_SIZE			FILE_TO_SECTOR_SIZE(LOGO_RAM_IMAGE_SIZE)
#define LOGO_BLOCK_SIZE				8//SECTOR_TO_BLOCK(LOGO_SECTOR_SIZE)
#define LOGO_SECTOR				BLOCK_TO_SECTOR(LOGO_BLOCK)
/*
#define CONFIG_BLOCK			16
#define  CONFIG_BLOCK_SIZE		1
#define  CONFIG_SECTOR			BLOCK_TO_SECTOR(CONFIG_BLOCK)
*/
#define RESERVED_BOOT_BLOCKS			(NBOOT_BLOCK_SIZE + TOC_BLOCK_SIZE + EBOOT_BLOCK_SIZE + LOGO_BLOCK_SIZE )

main.c中的MainMenu函数中增加通过USB下载图片的菜单

case 'G':
case 'g':
               
{
	DWORD dwDWNAddress;
	DWORD dwDWNlength;
	DWORD i;
	BYTE Temp[10];  
	DWORD dwStartAddr = 0; 
	LPBYTE lpDes = NULL;    
	lpDes = (LPBYTE)(FILE_CACHE_START); 
   
        OALMSG(TRUE, (TEXT("Please send the Logo through USB.\r\n"))); 
        g_bUSBDownload = TRUE;   
	if (!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
			!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
			!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNlength))
	{
		KITLOutputDebugString ("\r\nUnable to read add + size message.\r\n");
		return (FALSE);
	}
	else
	{
		KITLOutputDebugString ("\rAddr: 0x%x ; Size: 0x%x\n",dwDWNAddress,dwDWNlength);
	}

        if (!OEMReadData(640*480*2, lpDes))
        { 
        	OALMSG(TRUE, (TEXT("Error when sending the Logo through USB.\r\n"))); 
                SpinForever(); 
        } 
        for( i=0; i<20; i++)
              	OALMSG(0, (TEXT("->0x%x\r\n"),*(lpDes+(640*480*2-10)+i)));

        dwStartAddr = (DWORD)lpDes; 

        if (!WriteLogoToBootMedia(dwStartAddr, (DWORD)(640*480*2), dwStartAddr)) 
        { 
        	OALMSG(TRUE, (TEXT("Error when WriteLogoToBootMedia.\r\n"))); 
                SpinForever(); 
        } 
	break;
}
在OEMPlatformInit()函数初始化LCD完成之后进行读取NandFlash中的数据进行显示,EXT_Logo()函数在nand.cpp中

void    EXT_Logo(void)
{
	SectorInfo si;
	DWORD i,j,k;
	UINT32 start_addr = 0x100000;

	k = 	start_addr >> 9;

	for (i=0;i<2048;i++)
	{	 
		j = i + k;
		FMD_ReadSector(j, (PUCHAR)(IMAGE_FRAMEBUFFER_UA_BASE_eboot+(512*i)), &si, 1); 
	}

}


在Nand.cpp中添加写图片数据到NandFlash的函数WriteLogoToBootMedia()

BOOL WriteLogoToBootMedia(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr) 
{ 
  DWORD dwBlock,dwNumBlocks; 
  LPBYTE pbBuffer; 
  SectorInfo si; 

  OALMSG(TRUE, (TEXT("+WriteLogoToBootMedia\r\n"))); 

  dwBlock = LOGO_BLOCK; 
  pbBuffer = (LPBYTE)dwImageStart; 

  OALMSG(0, (TEXT("^^^^^^^^ 0x%x ^^^^^^^^\r\n"), (unsigned short *)pbBuffer)); 

  dwNumBlocks = (dwImageLength/(g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock)) +    
                                                 (dwImageLength%(g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock) ? 1: 0); 

  OALMSG(0, (TEXT("dwImageLength = 0x%x \r\n"), dwImageLength)); // 600k = 640 * 480 * 2
  OALMSG(0, (TEXT("dwNumBlocks = 0x%x \r\n"), dwNumBlocks));  //	 5 = 600 /128

  while (dwNumBlocks--) 
  { 
    OALMSG(0, (TEXT("dwBlock(0x%x) X "), dwBlock)); // 8, 9, a, b, c
    OALMSG(0, (TEXT("g_FlashInfo.wSectorsPerBlock(0x%x)"), g_FlashInfo.wSectorsPerBlock)); // 64
    OALMSG(0, (TEXT(" = 0x%x \r\n"), dwBlock*g_FlashInfo.wSectorsPerBlock)); 

    FMD_ReadSector(dwBlock*g_FlashInfo.wSectorsPerBlock, NULL, &si, 1); 

    // Stepldr & Eboot image in nand flash 
    // block mark as BLOCK_STATUS_RESERVED & BLOCK_STATUS_READONLY & BLOCK_STATUS_BAD 
    if ((si.bBadBlock == 0x0) && (si.bOEMReserved !=3 )) 
    { 
      ++dwBlock; 
      ++dwNumBlocks;                // Compensate for fact that we didn't write any blocks. 
      continue; 
    } 

    if (!ReadBlock(dwBlock, NULL, g_pSectorInfoBuf)) 
    { 
      OALMSG(OAL_ERROR, (TEXT("WriteData: failed to read block (0x%x).\r\n"), dwBlock)); 
      return(FALSE); 
    } 

    if (!FMD_EraseBlock(dwBlock)) 
    { 
      OALMSG(OAL_ERROR, (TEXT("WriteData: failed to erase block (0x%x).\r\n"), dwBlock)); 
      return FALSE; 
    } 

    if (!WriteBlock(dwBlock, pbBuffer, g_pSectorInfoBuf)) 
    { 
if (!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
						!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
						!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNlength))
					{
						KITLOutputDebugString ("\r\nUnable to read add + size message.\r\n");
						return (FALSE);
					}
					else
					{
						KITLOutputDebugString ("\rAddr: 0x%x ; Size: 0x%x\n",dwDWNAddress,dwDWNlength);
					}

OALMSG(OAL_ERROR, (TEXT("WriteData: failed to write block (0x%x).\r\n"), dwBlock)); return(FALSE); } ++dwBlock; pbBuffer += g_FlashInfo.dwBytesPerBlock; OALMSG(0, (TEXT("dwBytesPerBlock : %d\r\n"), g_FlashInfo.dwBytesPerBlock)); } OALMSG(1, (TEXT(" DownLoading Logo success!\r\n"))); return TRUE; }




对于图片提取可以直接写入到NandFlash格式的数据使用Image2LCD这个软件选择16位彩色,RGB565生成BIN文件。下载地址http://download.csdn.net/detail/qq236106303/4371268


开始使用USB下载图片时候,遇到花屏的问题,使用H-JTAG下载上面生成的bin格式的图片。能够正常显示。因此确定是USB下载有问题。而显示函数和图片格式已经正确。但是HJTAG并口下载速度太慢,不适合生产使用。所以找了下原因。 发现时因为DNW通过USB下载的时候会自动在我们选择的文件之前加上头信息。因此在程序mainMenu中,我使用了

if (!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
						!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
						!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNlength))
					{
						KITLOutputDebugString ("\r\nUnable to read add + size message.\r\n");
						return (FALSE);
					}
					else
					{
						KITLOutputDebugString ("\rAddr: 0x%x ; Size: 0x%x\n",dwDWNAddress,dwDWNlength);
					}
先读取DNW强加的非图片的数据,之后没有出现花屏的现象。但是对于DNW的源码没有研究,所以也不是特别确定,幸亏问题可以解决。 调试的时候可以采用打印SDRAM中的数据的方法进行调试,因为程序中指定的下载到SDRAM的地址是FILE_CACHE_START这个地址。


下载完成logo以后,选择菜单马上进行下载NK.BIN文件,发现出现错误,说BIN文件的格式不支持。以为下载内核BIN文件,会根据开始7个字节的数据判断文件时Eboot还是nk。打印出来的信息看到开始的几个字节和NK,BIN里面的数据出现了偏移。因此也怀疑是DNW搞的鬼,最后在blcommon.c的DownloadImage函数中修改

if (!OEMReadData (2*sizeof (UCHAR), (LPBYTE) &dwDWNAddress) ||   //根据打印调试出来看,出现的2个字节偏移是因为在这里读取了DWORD,所以改成2个char
		!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNAddress) ||
		!OEMReadData (sizeof (DWORD), (LPBYTE) &dwDWNlength))
    {
            KITLOutputDebugString ("\r\nUnable to read add + size message.\r\n");
            return (FALSE);
     }
    else
    {
    		KITLOutputDebugString ("\rAddr: 0x%x ; Size: 0x%x\n",dwDWNAddress,dwDWNlength);
    }


通过上面的修改可以顺利的使用USB先下载LOGO.BIN然后再下载NK.BIN。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值