NBOOT Analysis - NBOOT.c (2)

Publisher:张延强Latest update time:2016-12-31 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*
---------------------------------------------------------------
File name: NBOOT.c
Description: Perform Nand Bootloader operation
---------------------------------------------------------------
*/
#include "S3C244x.h"
#include "UART.h"
#include "Global.h"
#include "TOC.h"
#include "Nand.h"
#include "MMU.h"


#define TOC_BLOCK (2) //TOC occupies 2 blocks

#define SECTOR_SIZE 512 //Page size: 512 bytes
#define SECTOR_PER_BLOCK 256 //How many pages does each block contain

/**********************************************************
*File name: ReadNandImageToRam
*Input: unEntry entry point
*Output: WINCE image jump address
         0 is invalid
*Function description: Load WINCE image from NAND FLASH to SDRAM
***********************************************************/
UINT32 ReadNandImageToRam(UINT32 unEntry)
{
   UINT32 unSectorsNeeded;
   UINT32 unSector,unLength;
   UINT32 unRam,i;

   
   PTOC pTOC=(PTOC)0x33F00000;//If TOC type definition is used, no need to assign address by yourself
                                //If PTOC type definition is used, the address given by compiler to pTOC variable is unknown
                                //Therefore, it is necessary to force to assign its address
   NandReadSector(TOC_BLOCK*SECTOR_PER_BLOCK,(UINT8 *)pTOC);//Read the content of the 512th sector and assign it to TOC
   
   if(!TOCIsValid(pTOC))
   {
      DEBUGMSG("\r\nTOC is not valid\r\n");
      return 0;
   }
   DEBUGMSG("\r\nTOC is valid\r\n");
   //Parameter dwEntry defines the entry mode, whether to directly enter the WinCE kernel or start Eboot
   if(!(pTOC->id[unEntry].dwImageType &IMAGE_TYPE_RAMIMAGE))
   {
      return 0;
   }
   
   DEBUGMSG("\r\nImage is RamImage\r\n");
   
   unSectorsNeeded= pTOC->id[unEntry].dwTtlSectors; //Total number of sectors occupied by the image
   unRam=VIRTUAL_TO_PHYSICAL(pTOC->id[unEntry].dwLoadAddress);//Virtual address converted to physical address
   
   DEBUGMSGEx("\r\nSectors Total=",pTOC->id[unEntry].dwTtlSectors ,10);
   DEBUGMSGEx("\r\nVirtual Load Address =",pTOC->id[unEntry].dwLoadAddress,16);
   DEBUGMSGEx("\r\nPhysical Load Address =",unRam,16);
   
   i=0;
   
   while(unSectorsNeeded && i    {
       unSector = pTOC->id[unEntry].sgList[i].dwSector;
       unLength = pTOC->id[unEntry].sgList[i].dwLength;  
       
       while(unLength)
       {
         if(unSector % SECTOR_PER_BLOCK == 0)//256页检查一次坏块
         {
           if(!NandCheckBadBlock(unSector/SECTOR_PER_BLOCK))
           {
              unSector+=SECTOR_PER_BLOCK;//Bad block exists
             
              continue;//Do not perform the following operation
           }
           
           DEBUGMSG(".");
         }
         
         if(!NandReadSector(unSector,(UINT8 *)unRam))
         {
            DEBUGMSG("\r\nCan't Load WINCE Image\r\n");
            while(1);
         }
         
         unSector++;
         unLength--;
         
         unRam+=SECTOR_SIZE;
       }  
       
       unSectorsNeeded-=pTOC->id[unEntry].sgList[i].dwLength;    
       i++;

   }
 
   return (pTOC->id[unEntry].dwJumpAddress?VIRTUAL_TO_PHYSICAL(pTOC->id[unEntry].dwJumpAddress) ://获取加载镜像完成后的跳转地址
                                           VIRTUAL_TO_PHYSICAL(pTOC->id[unEntry].dwLoadAddress));
}

void PORTInit(void)
{

   rGPACON = 0x7fffff;
   rGPDCON = 0xaaaaaaaa;      
   rGPDUP  = 0xffff;     // The pull up function is disabled GPD[15:0]
   rGPECON = 0xaaaaaaaa;      
   rGPEUP  = 0xffff;    

   rGPFUP  = 0xff;    

   rGPGCON = 0xFD000000;
   rGPGUP  = 0xffff;  

   rGPHCON = 0x02faaa;

   rGPHUP  = 0x7ff;  
   
   rEXTINT0 = 0x22222222;    // EINT[7:0]
   rEXTINT1 = 0x22222222;    // EINT[15:8]
   rEXTINT2 = 0x22222222;    // EINT[23:16]
   
}
#define BSP_ARGS_ADDR               0x30020800
#define BSP_ARGS_SIZE               0x800

/*
ARGS内存空间的注解
在WINCE的EBOOT中
ARGS  80028000 00000800 RESERVED
自0x80028000处,大小为0x00000800的空间被命名为ARGS,这个空间类型为
RESERVED,用于保存Bootloader和操作系统之间的共享数据

总之在0x30020800地址处必须要对其进行初始化为0,否则WINCE不能够正常激活
以下选自2440的BSP上的代码。

在BSP中,boot loader和OAL之间有一些数据可以共享
这段数据被存放在(BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START这块内存里。
#define IMAGE_SHARE_ARGS_UA_START      0xA0020000
#define IMAGE_SHARE_ARGS_CA_START      0x80020800
#define IMAGE_SHARE_ARGS_SIZE          0x00000800
可以看出来,IMAGE_SHARE_ARGS_UA_START指向的是虚拟内存中的Uncached段,而IMAGE_SHARE_ARGS_CA_START指向虚拟内存中的Cached段。
我的g_oalAddressTable中这样定义:
DCD    0x80000000, 0x30000000, 64      ; 32 MB DRAM BANK 6
因此,它们分别是指向物理地址0x30020000和0x30020800。

然后看config.bib中,可以看到有这段定义:
; Common RAM areas
   AUD_DMA            80002000  00000800  RESERVED
   SDIO_DMA           80010000  00010000  RESERVED
   ARGS               80020800  00000800  RESERVED
   DBGSER_DMA         80022000  00002000  RESERVED
   SER_DMA            80024000  00002000  RESERVED
   IR_DMA             80026000  00002000  RESERVED
   SLEEP              80028000  00002000  RESERVED
   EDBG               80030000  00020000  RESERVED
   DISPLAY 80100000 00100000 RESERVED  

The physical address 0x30020800 corresponding to ARGS is reserved for IMAGE_SHARE_ARGS_CA_START. _BSPArgs  Memory\r\n" ); BufClr( (
char*)  BSP_ARGS_ADDR,  BSP_ARGS_SIZE); //The address and length of pBSPArgs need to be determined according to the BSP package DEBUGMSG("\r\nLoading BSPArgs Memory\r\n"  ); //The IO port must be initialized, otherwise the serial port cannot work properly  UARTInit(S3C2440PCLK,115200);  NandInit();  DEBUGMSGEx("\r\n\r\nPhysical BSPArgs Address = ",BSP_ARGS_ADDR,16);  DEBUGMSGEx("\r\nBSPArgs Size = ",BSP_ARGS_SIZE,16);  DEBUGMSG("\r\nClearing BSPArgs Memory\r\n");  BufClr((char*)BSP_ARGS_ADDR, BSP_ARGS_SIZE); //The address and length of pBSPArgs need to be determined according to the BSP package  DEBUGMSG("\r\nLoading WINCE\r\n");  RunWINCE=(void(*)(void))ReadNandImageToRam(1);  DEBUGMSGEx("\r\nPhysical Jump Address =",(UINT32)RunWINCE,16);  DEBUGMSGEx("\r\n Virtual Jump Address =",PHYSICAL_TO_VIRTUAL((UINT32)RunWINCE),16);  if(Run WINCE)  {     DEBUGMSG("\r\nLoad WINCE Successfully\r\n");     RunWINCE();  }  while(1);  return 0; }






 













 





 



Reference address:NBOOT Analysis - NBOOT.c (2)

Previous article:NBOOT Analysis - S3C244xInit.s (1)
Next article:ARM9 interrupt debugging (1)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号