WinCE6.0 修改开机Logo方法集锦(二)-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

WinCE6.0 修改开机Logo方法集锦(二)

简介:
今天讲解第二种方法,将Logo图片的数据写入到Nand Flash中,在启动初始化LCD的时候,从固定的地址将数据读出并填充到显示缓存中。
       实验平台:WinCE6.0+Android6410 +4.3CLD
       以下内容参考自CSDN论坛的一个帖子,不过里面的描述不是特别清楚,该主题博文进行了整理。为尊重原创,给出链接http://topic.csdn.net/u/20100126/14/ef1fc7c4-d8db-426b-b6bf-b74d74cdd05a.html
      
       Logo图片写Flash的思路继续细分,又可以分为几种不同的实现方法,今天先描述实现方法一,这是其中比较简单的一种方法,不需要修改bib文件等配置性文件,只需要修改代码即可。
       首先提几个问题:
       1、在什么时候将Logo数据写入Nand Flash
       2、在什么时候读Nand Flash数据到显示缓存?
       3、要写的Logo的数据是什么?
       4、写入Flash的什么位置,又从什么位置读数据?
       5、写Flash的函数和读Flash的函数如何实现?
       上面几个问题弄清楚了,方法一基本就出来了。给出上面几个问题的解决方法:
       1、答:为了增加后期更加方便的升级开机启动Logo,在启动Eboot的主菜单中添加下载Logo的选项,如下图所示,选项G)便是通过USB下载Logo数据,同时将Logo数据写入到Nand Flash的某一位置上。
 
      
        2、答:在Eboot的初始化InitializeDisplay中,可以找到关于填充显示缓存的代码,改为从Flash的某一位置读取即可。
      3答:关于写Logo的数据,可以是bin格式的,也可以是原始的bmp格式。其实bin格式的内容也都是通过读取bmp文件的位图阵列而生成的。两者的差别就在于一个在Eboot里面实现读取bmp的位图阵列,一个是在独立的应用程序中读取的。
      4答:关于操作Nand Flash的位置问题,需要查看loader.h文件的相关代码,有关于Block的使用情况,如下所示。在这里为Logo数据分配一定的Block
// NAND Boot (loads into SteppingStone) @ Block 0 
#define NBOOT_BLOCK                                 0 
#define NBOOT_BLOCK_SIZE                        1 
#define NBOOT_SECTOR                                BLOCK_TO_SECTOR(NBOOT_BLOCK) 

// TOC @ Block 1 
#define TOC_BLOCK                                     1 
#define TOC_BLOCK_SIZE                            1 
#define TOC_SECTOR                                    BLOCK_TO_SECTOR(TOC_BLOCK) 

// Eboot @ Block 2 
#define EBOOT_BLOCK                                 2 
#define EBOOT_SECTOR_SIZE                     FILE_TO_SECTOR_SIZE(EBOOT_RAM_IMAGE_SIZE) 
#define EBOOT_BLOCK_SIZE                        SECTOR_TO_BLOCK(EBOOT_SECTOR_SIZE) 
#define EBOOT_SECTOR                                BLOCK_TO_SECTOR(EBOOT_BLOCK)
       5、答:Flash的读写操作函数实现主要在nand.cpp文件中,具体实现可以参考函数ReadOSImageFromBootMediaWriteOSImageToBootMedia
 
      下面给出详细的修改步骤:
      1、首先修改loader.h文件,为Logo数据分配一定的Block空间。添加如下代码:
// Eboot @ Block 2 
#define EBOOT_BLOCK                                 2 
#define EBOOT_SECTOR_SIZE                     FILE_TO_SECTOR_SIZE(EBOOT_RAM_IMAGE_SIZE) 
#define EBOOT_BLOCK_SIZE                        SECTOR_TO_BLOCK(EBOOT_SECTOR_SIZE) 
#define EBOOT_SECTOR                                BLOCK_TO_SECTOR(EBOOT_BLOCK) 

//-----------------------add by jazka 2011.09.04------------------------- 
//-----------------------------start-------------------------------------- 
// Logo @ Block 6~ 
#define LOGO_BLOCK                    6 
#define LOGO_BLOCK_SIZE                20 
#define LOGO_SECTOR                            BLOCK_TO_SECTOR(LOGO_BLOCK) 
//----------------------------- end --------------------------------------- 

//-----------------------modify by jazka 2011.09.04----------------------- 
//-----------------------------start--------------------------------------- 
//#define RESERVED_BOOT_BLOCKS                (NBOOT_BLOCK_SIZE + TOC_BLOCK_SIZE + EBOOT_BLOCK_SIZE) 
#define RESERVED_BOOT_BLOCKS                (NBOOT_BLOCK_SIZE + TOC_BLOCK_SIZE + EBOOT_BLOCK_SIZE + LOGO_BLOCK_SIZE)
从上面可以看出从Block6开始,为Logo分配了20BlockFlash空间,这样可以存放64KB*20=1280KB大小的Logo数据,即1M以内的图片数据。由于Logo占用了一定的Block空间,所以后面Nk的起始位置RESERVED_BOOT_BLOCKS需要向后移动。
       2、在Eboot启动主菜单中增加下载Logo数据的相应的选项。修改的代码如下:
                EdbgOutputDebugString ( "F) Low-level format the Smart Media card\r\n"); 
    //add by jazka 2011.09.05 
    //-----------------------------start--------------------------------- 
    EdbgOutputDebugString ( "G) DOWNLOAD Logo now(USB)\r\n"); 
    //----------------------------- end --------------------------------- 
                EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n"); 
                EdbgOutputDebugString ( "R) Read Configuration \r\n"); 
                EdbgOutputDebugString ( "U) DOWNLOAD image now(USB)\r\n"); 
                EdbgOutputDebugString ( "W) Write Configuration Right Now\r\n"); 
                EdbgOutputDebugString ( "\r\nEnter your selection: "); 

                while (! ( ( (KeySelect >= '0') && (KeySelect <= '9') ) || 
                                     ( (KeySelect == 'A') || (KeySelect == 'a') ) || 
                                     ( (KeySelect == 'B') || (KeySelect == 'b') ) || 
                                     ( (KeySelect == 'C') || (KeySelect == 'c') ) || 
                                     ( (KeySelect == 'D') || (KeySelect == 'd') ) || 
                                     ( (KeySelect == 'E') || (KeySelect == 'e') ) || 
                                     ( (KeySelect == 'F') || (KeySelect == 'f') ) || 
             ( (KeySelect == 'G') || (KeySelect == 'g') ) ||                 //add by jazak 2011.09.05 
                                     ( (KeySelect == 'L') || (KeySelect == 'l') ) || 
                                     ( (KeySelect == 'R') || (KeySelect == 'r') ) || 
                                     ( (KeySelect == 'U') || (KeySelect == 'u') ) || 
                                     ( (KeySelect == 'W') || (KeySelect == 'w') ) )) 
                { 
                        KeySelect = OEMReadDebugByte(); 
                }
    //add by jazka 2011.09.05 
    //--------------------------start----------------------------- 
    case 'G': 
    case 'g': 
      { 
        OALMSG(TRUE, (TEXT("Please send the Logo through USB.\r\n"))); 
        g_bUSBDownload = TRUE; 

        { 
          DWORD dwStartAddr = 0; 
          LPBYTE lpDes = NULL;         
          lpDes = (LPBYTE)(FILE_CACHE_START); 

          if (!OEMReadData(LCD_WIDTH*LCD_HEIGHT*2, lpDes)) 
          { 
            OALMSG(TRUE, (TEXT("Error when sending the Logo through USB.\r\n"))); 
            SpinForever(); 
          } 

          dwStartAddr = (DWORD)lpDes; 

          if (!WriteLogoToBootMedia(dwStartAddr, (DWORD)(LCD_WIDTH*LCD_HEIGHT*2), dwStartAddr)) 
          { 
            OALMSG(TRUE, (TEXT("Error when WriteLogoToBootMedia.\r\n"))); 
            SpinForever(); 
          } 
        } 
      } 
      break; 
    //-------------------------- end -----------------------------
这里把g_bUSBDownload设置为TRUE,以便后面选择USB进行下载。由于USB下载的速度和写Flash速度不匹配,所以先下载到内存中,然后在一下子写入Flash中(这部分详解见博客http://jazka.blog.51cto.com/809003/605776)。WriteLogoToBootMedia便是Flash的写函数,后面给出实现。
       3、修改LCD初始化函数InitializeDisplay,修改代码如下:
        // Fill Framebuffer 
#if(SMDK6410_LCD_MODULE == LCD_MODULE_UT_LCD35A) 
        memcpy((void *)EBOOT_FRAMEBUFFER_UA_START, (void *)InitialImage_rgb16_320x240, 320*240*2); 
#elif        (LCD_BPP == 16) 
        { 
    //delete by jazka 2011.08.31    修改开机启动界面 
             /* int i; 
                unsigned short *pFB; 
                pFB = (unsigned short *)EBOOT_FRAMEBUFFER_UA_START; 

                for (i=0; i<LCD_WIDTH*LCD_HEIGHT; i++) 
    { 
                        //*pFB++ = 0x0000;//0x001F;                // Blue 
      //*pFB++ = 0x001F;                                             //modify by jazka 2011.07.22 
      *pFB++ = InitialImage_rgb16_480x272[i]; 
    } 
    */ 

    //add by jazka 2011.08.31 
    //memcpy((void *)EBOOT_FRAMEBUFFER_UA_START, (void *)InitialImage_rgb16_480x272, 480*272*2); 

    //modify by jazka 2011.09.07 
    DWORD dwReadAddr = (DWORD)EBOOT_FRAMEBUFFER_UA_START; 
    if (!DisplayLogoFromBootMedia(dwReadAddr, (DWORD)LCD_WIDTH*LCD_HEIGHT*2, dwReadAddr)) 
    { 
      int i; 
      unsigned short *pFB; 
      pFB = (unsigned short *)EBOOT_FRAMEBUFFER_UA_START; 

      for (i=0; i<LCD_WIDTH*LCD_HEIGHT; i++) 
        *pFB++ = 0x0000;//0x001F;                // Blue 
    }
DisplayLogoFromBootMedia函数便是Flash的度函数,这里将读出的数据写入到显示缓存EBOOT_FRAMEBUFFER_US_START中,该函数的实现后面给出。
      4、修改nand.cpp文件,添加WriteLogoToBootMediaDisplayLogoFromBootMedia两个函数的实现。
/* 
  Write the Logo data to Nand Flash 
  add by jazka 2011.09.05 
*/ 
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(TRUE, (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(TRUE, (TEXT("dwImageLength = 0x%x \r\n"), dwImageLength)); 
  OALMSG(TRUE, (TEXT("dwNumBlocks = 0x%x \r\n"), dwNumBlocks)); 

  while (dwNumBlocks--) 
  { 
    OALMSG(TRUE, (TEXT("dwBlock(0x%x) X "), dwBlock)); 
    OALMSG(TRUE, (TEXT("g_FlashInfo.wSectorsPerBlock(0x%x)"), g_FlashInfo.wSectorsPerBlock)); 
    OALMSG(TRUE, (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)) 
    { 
      OALMSG(OAL_ERROR, (TEXT("WriteData: failed to write block (0x%x).\r\n"), dwBlock)); 
      return(FALSE); 
    } 

    ++dwBlock; 
    pbBuffer += g_FlashInfo.dwBytesPerBlock; 
    OALMSG(TRUE, (TEXT("dwBytesPerBlock : %d\r\n"), g_FlashInfo.dwBytesPerBlock)); 
  } 

  OALMSG(TRUE, (TEXT("_WriteLogoToBootMedia\r\n"))); 

  return TRUE; 
}
/* 
  Read the Logo data from Nand Flash 
  add by jazka 2011.09.05 
*/ 
BOOL DisplayLogoFromBootMedia(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr) 

  unsigned int * pFB32 = (unsigned int *)EBOOT_FRAMEBUFFER_UA_START; 
  unsigned int * dst = pFB32;        
  //unsigned int * p = NULL; 
  SectorInfo si; 

  DWORD dwBlock,dwNumBlocks; 

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

  dwBlock = LOGO_BLOCK; 

  OALMSG(TRUE, (TEXT("dwImageLength = 0x%x \r\n"), dwImageLength)); 
  OALMSG(TRUE, (TEXT("dwImageLength = 0x%x \r\n"), g_FlashInfo.wDataBytesPerSector)); 
  OALMSG(TRUE, (TEXT("dwImageLength = 0x%x \r\n"), g_FlashInfo.wSectorsPerBlock)); 

  if (0 == g_FlashInfo.wDataBytesPerSector || 0 == g_FlashInfo.wSectorsPerBlock) 
  { 
    return FALSE; 
  } 

  dwNumBlocks = (dwImageLength / (g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock)) + 
                (dwImageLength%(g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock) ? 1: 0); 
  OALMSG(TRUE, (TEXT("dwNumBlocks = 0x%x \r\n"), dwNumBlocks)); 

  while (dwNumBlocks--) 
  {    
    OALMSG(TRUE, (TEXT("dwBlock(0x%x) X "), dwBlock)); 
    OALMSG(TRUE, (TEXT("g_FlashInfo.wSectorsPerBlock(0x%x)"), g_FlashInfo.wSectorsPerBlock)); 
    OALMSG(TRUE, (TEXT(" = 0x%x \r\n"), dwBlock*g_FlashInfo.wSectorsPerBlock)); 

    //BOOL ReadBlock(DWORD dwBlock, LPBYTE pbBlock, PSectorInfo pSectorInfoTable) 
    if (!ReadBlock(dwBlock, (LPBYTE)dst, g_pSectorInfoBuf)) 
    { 
      OALMSG(OAL_ERROR, (TEXT("WriteData: failed to read block (0x%x).\r\n"), dwBlock)); 
      return(FALSE);    
    } 
    dst += g_FlashInfo.dwBytesPerBlock/4; 
    ++dwBlock; 
  } 
  OALMSG(TRUE, (TEXT("_ReadLogoFromBootMedia\r\n"))); 

  return TRUE; 
}
       5、关于Logo数据的文件bin的生成,网上有很多工具可以实现,其实可以自己写一个应用程序完成该功能。本人编写了24Bmp文件生成RGB565格式的bin文件的程序,这部分代码也可以在nand.app中写成一个函数,在写入Flash时调用转换为相应的RGB565数据即可,这样更新Logo时可以更直接。注意下载时的数据量是现在的3倍。
       这里就不给出源代码了,如果需要,请留言。
 

       今天就到这里,改天上实现方法二:将Logo.bin做成和Eboot.bin一样的格式,这样下载Eboot.bin的很多代码就可以直接使用。



本文转自jazka 51CTO博客,原文链接:http://blog.51cto.com/jazka/664131,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: