wince2416自动更新

wince2416已经有了相关的接口函数,但此次研究的结果是3张tf卡只有一张初始化成功

首先是 将tf卡初始化成功,然后将tf卡一些主要信息读出,比如,根文件列表的位置是从多少扇区开始,.bin是否存在,开始的扇区数,所占扇区的大小等等,最后是将.bin写到指定的一个内存地址,但一次写道内存地址有个问题是有时会出现tf检测未准备状态。

代码如下

1,

BOOL OEMReadData(DWORD dwData, PUCHAR pData)
{
 BOOL ret;
// int i;
   // OALMSG(OAL_FUNC, (TEXT("+OEMReadData.\r\n")));
// OALMSG(TRUE, (TEXT("\r\nINFO: dwData = 0x%x, pData = 0x%x \r\n"), dwData, pData));
 if(1)
 {//OALMSG(1, (TEXT("+OEMReadData. %d**\r\n"),dwData));
  ret = OEMSDReadData( dwData,  pData);
  //OALMSG(1, (TEXT("+OEMReadData.%d %s\r\n")),dwData,pData);
 }

 if ( g_bUSBDownload == FALSE )
 {
  ret = EbootEtherReadData(dwData, pData);
 }
 else
 {//ret = OEMSDReadData( dwData,  pData);
 // ret = UbootReadData(dwData, pData);
    }


 return(ret);
}

2,

BOOL OEMSDReadData(DWORD cbData, LPBYTE pbData)
{
  // EdbgOutputDebugString("first is ok\r\n");

         //EdbgOutputDebugString("FILESIZE=%d  tempper=%d  KP=%d\r\n",FILESIZE,tempper,KP);
 if((first)||(cbData==7))
 {
 if(first)
  {
  if(!InitSD())
  return FALSE;
  EdbgOutputDebugString("xy=%d\r\n",xy);


  if(!fat_findMBR())

  {EdbgOutputDebugString("xyxyyxy\r\n");}
  FindNK();
  }
 //();
 //ListrDirFile();
 //if(!FindNK())
 // return FALSE;
 //for(i=0;i<64;i++)
 //{
 // Rd_Block(NextBlock,downPtIndex);
 // NextBlock++;
 //}
 downPtIndex = OSBUFFER;
 readPtIndex1= OSBUFFER;
 if(xy==0)
 { PBR_ADDRESS_LENGTH=PBR_ADDRESSSTEP_LENGTH;
  NextBlock=PBR_ADDRESSSTEP;//PBR_ADDRESSNK;//PBR_ADDRESS+32776;
 }//PBR_ADDRESS+//datastart+(fob.start_cluster-2)*SecPerClus;
 if(xy==1)
 {downPtIndex = 0xa1b00000;
 readPtIndex1= 0xa1b00000;
  NextBlock=PBR_ADDRESSEBOOT;//PBR_ADDRESS+32776+8;
  
  PBR_ADDRESS_LENGTH=PBR_ADDRESSEBOOT_LENGTH;
 }
 if(xy==2)
 {downPtIndex = 0x31000000;
 readPtIndex1= 0x31000000;
  NextBlock=PBR_ADDRESSNK;//PBR_ADDRESS+32776+(88-3)*8;
  PBR_ADDRESS_LENGTH=PBR_ADDRESSNK_LENGTH;
 }

 xy++;

 first=FALSE;
    //EdbgOutputDebugString("first is true downPtIndex is 0x%x, readPtIndex1 = 0x%x\r\n",downPtIndex, readPtIndex1);
 //strcpy(str, "Load NK                              ");
 //LCDEdbgOutputDebugString((unsigned char *)&str, 10, 4, 25, 0xffff, 0x0000);
 //OEMShowProcess(11, FALSE,  TRUE); 
 }
 
 //DWORD PBR_ADDRESSSTEP_LENGTH;
 //DWORD PBR_ADDRESSEBOOT_LENGTH; 
 //DWORD PBR_ADDRESSNK_LENGTH; 

 while(TRUE)
  {
 if ( downPtIndex > readPtIndex1 + cbData )
  {
  //EdbgOutputDebugString("%s!\r\n",(LPBYTE)readPtIndex1);

   memcpy(pbData, (LPBYTE)readPtIndex1, cbData);
   //EdbgOutputDebugString("%s!\r\n",pbData);
   readPtIndex1 += cbData;
   return TRUE;
  }
 else
  {
   //EdbgOutputDebugString("second downPtIndex is 0x%x, readPtIndex1 = 0x%x\r\n",downPtIndex, readPtIndex1);
   Rd_Image( NextBlock, PBR_ADDRESS_LENGTH,downPtIndex );
   {
   //return FALSE;
   }
   //EdbgOutputDebugString("Reading block %d please waiting!\r\n",NextBlock);
 
   //NextBlock+=cbData/512+1;
   downPtIndex+=PBR_ADDRESS_LENGTH+512;

  }
  }
 
 
 {
 while(0)
 {
  if ( downPtIndex > readPtIndex1 + cbData )
  {//EdbgOutputDebugString("svs is good1 %d\r\n",readPtIndex1);
   memcpy(pbData, (LPBYTE)readPtIndex1, cbData);
  // EdbgOutputDebugString("svs is good2 %d\r\n",readPtIndex1);
   readPtIndex1 += cbData;
   
   //OEMShowProcess(11, FALSE,  FALSE);
   //EdbgOutputDebugString("first downPtIndex is 0x%x, readPtIndex1 = 0x%x\r\n",downPtIndex, readPtIndex1);
   return TRUE;
  }
  else
  {
   //EdbgOutputDebugString("second downPtIndex is 0x%x, readPtIndex1 = 0x%x\r\n",downPtIndex, readPtIndex1);
   if(!Rd_Block(NextBlock,downPtIndex))
    {
    
    EdbgOutputDebugString("Reading badblock %d noting!\r\n",NextBlock);

    return FALSE;
    }
   EdbgOutputDebugString("Reading block %d please waiting!\r\n",NextBlock);
   NextBlock++;
   downPtIndex+=512;
  }
 }
}

 return TRUE;
}

 

3,

 


void Rd_Image(DWORD sectoroffset,DWORD block,DWORD targetAddr)
{
 U32 i, j, OneBlockSize, Addr_temp;
 U32 TotalReadByte, WriteBlockCnt=0;
 DWORD up=0;
 
 U32 transtime;
 
 DWORD tempData;
 BYTE *Rx_datbuffer;
 //Rx_buffer=(int *)targetAddr;
 
 block=block/512+1;
 BlockNum_HSMMC_ch1 = block;
 rd_cnt=0; 
 HS_DMA_END_ch1 = 0; 
 ReadBlockCnt_INT_ch1 = 0; 
//    BYTE *Rx_datbuffer;
 Addr_temp = sectoroffset; 
 Rx_datbuffer=(BYTE *)targetAddr;
 memset(Rx_buffer,0,block);
 if(SectorMode_ch1 == 1)
  sectoroffset = sectoroffset;
 else
  sectoroffset = sectoroffset * 512;
 
 OneBlockSize = Card_OneBlockSize;
 //EdbgOutputDebugString("block%d/r/n",block);

//    EdbgOutputDebugString("\nPolling mode data read\n");
 updata:

    while (!IsCardInProgrammingState_CH1());
//if(up==0)
{
    SetBlockSizeReg_CH1(7, 512); // Maximum DMA Buffer Size, Block Size
    SetBlockCountReg_CH1(block); // Block Numbers to Write
    SetArgumentReg_CH1(sectoroffset); // Card Address to Write
}
    if(block == 1)//single block
     {
//      EdbgOutputDebugString("Single block read\n");
      SetTransferModeReg_CH1(0, 1, 0, 1, 0);
      SetCommandReg_CH1(17, 0); // CMD17: Single-Read      
     }
    else//multi block
     {
//      EdbgOutputDebugString("Multi block read\n");
      SetTransferModeReg_CH1(1, 1, 1, 1, 0);
      SetCommandReg_CH1(18, 0); // CMD18: Multi-Read
     }

    while (!WaitForCommandComplete_CH1());
    ClearCommandCompleteStatus_CH1();
    
    for(j=0; j<((block)); j++)
     {
      if (!WaitForBufferReadReady_CH1())
      {

      EdbgOutputDebugString("ReadBuffer NOT Ready\n");
      while (!IsCardInProgrammingState_CH1());
      //if(up==0)
       {
       SetBlockSizeReg_CH1(7, 512); // Maximum DMA Buffer Size, Block Size
       SetBlockCountReg_CH1(block-j); // Block Numbers to Write
       SetArgumentReg_CH1(sectoroffset+j); // Card Address to Write
       EdbgOutputDebugString("sectoroffset =%d j= %d/r/n",sectoroffset,j);
       //block++;

       }
      if(block == 1)//single block
       {
       //      EdbgOutputDebugString("Single block read\n");
       SetTransferModeReg_CH1(0, 1, 0, 1, 0);
       SetCommandReg_CH1(17, 0); // CMD17: Single-Read      
       }
      else//multi block
       {
       //      EdbgOutputDebugString("Multi block read\n");
       SetTransferModeReg_CH1(1, 1, 1, 1, 0);
       SetCommandReg_CH1(18, 0); // CMD18: Multi-Read
       }

       while (!WaitForCommandComplete_CH1());
       ClearCommandCompleteStatus_CH1();

      }
      if (!WaitForBufferReadReady_CH1())
      {EdbgOutputDebugString("ReadBuffer NOT Ready\n");}
      
       ClearBufferReadReadyStatus_CH1();
      for(i=0; i<512/4; i++)
      {
       //*Rx_buffer++ = s2416SDI->BDATA;
       //rd_cnt++;
       
                            tempData= s2416SDI->BDATA;
                            //EdbgOutputDebugString("%x,",tempData);
                   *Rx_datbuffer=(BYTE)((tempData>>0)&0xff);
                   //EdbgOutputDebugString("%x,",*Rx_datbuffer);
                   *Rx_datbuffer++;
                   *Rx_datbuffer=(BYTE)((tempData>>8)&0xff);
                   //EdbgOutputDebugString("%x,",*Rx_datbuffer);
                   *Rx_datbuffer++;
                   *Rx_datbuffer=(BYTE)((tempData>>16)&0xff);
                   //EdbgOutputDebugString("%x,",*Rx_datbuffer);
                   *Rx_datbuffer++;
                   *Rx_datbuffer=(BYTE)((tempData>>24)&0xff);
                   //EdbgOutputDebugString("%x,",*Rx_datbuffer);
                            *Rx_datbuffer++;
       //EdbgOutputDebugString("\n block count = %d", tempData);
                         //   DelayUS(100);
      }
      WriteBlockCnt ++;
      EdbgOutputDebugString("\nRead block count = %d", WriteBlockCnt);
     }
  
    TotalReadByte = wt_cnt *4;
//    EdbgOutputDebugString("\nWrite count=%dByte\n",TotalReadByte);
    
//    EdbgOutputDebugString("\nWrite count=%x\n",rd_cnt);
    if(!WaitForTransferComplete_CH1())
     {
//     EdbgOutputDebugString(("Transfer NOT Complete\n"));
     }
    ClearTransferCompleteStatus_CH1();


 HS_DMA_END_ch1 = 0; 
 rd_cnt = 0;
 ReadBlockCnt_INT_ch1 = 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值