WINCE6.0 mboot 流程分析

来源:互联网 发布:手机淘宝晒图评价流程 编辑:程序博客网 时间:2024/05/20 00:51

BootSetup()             汇编语言 实现的一些CPU 相关的初始化

 

BootloaderMain()     主体函数

                 

 

void BootloaderMain (void)
{
       if (!KernelRelocate (pTOC))
    {
        // spin forever
        HALT (BLERR_KERNELRELOCATE);
    }

 

 

    // (1) Init debug support. We can use OEMWriteDebugString afterward.
    if (!OEMDebugInit ())      {
        // spin forever
        HALT (BLERR_DBGINIT);
    }

 

//OEMDebugInit中做的事情:    利用OEMInitDebugSerial(); 初始化串口,这个函数之后你即可打印数据

//                                             BoardInit()-> InitProtoType()初始化板子CPU各个模块的寄存器,如clock、GPIO、DISPLAY..

//                                                                                           
//
//                                            

 

 

       // (2) initialize platform (clock, drivers, transports, etc)
    if (!OEMPlatformInit ())
    {
        // spin forever
        HALT (BLERR_PLATINIT);
    }

   

//OEMPlatformInit 中做的事情: 利用MainMenu( BSP_ARGS ) ;利用串口输入输出字符模式  以菜单的表现形式控制整个流程

//                                             InitBootParams(pBootCfg);  pBootCfg 为mboot 的一些网络配置或其他启动参数

//                                             注意两个不同的结构体  BSP_ARGS(板子的基本信息如版本号)与PBOOT_CFG  (启动参数)

//

//                                            无论是手动启动还是自动启动 最终都是调用AutoBoot()函数

//

//                                            注意一般的mboot 包含了多种启动烧录与启动模式:如USB、网络、SD。。。这里比较特殊的是网络

//                                            方式,由M$ 提供的库支持,所以对它的处理也比较特殊,一般除了网络方式外其他的方式均放

//                                            在Switch(){}中可以对应找到下载到内存的函数与 SaveImage() 这里面SaveImage是第三方开发的

//                                           如果Switch(){}没有找到你要用的网络,接下来就进入了M$时间,OEMInitEthDevice()初始化网络设

//                                            备为接下来的网络下载做准备,下载过程也与其他方式有很大不同网络下载的bin格式所以,利用M¥的

//                                            解压函数,最终成为nb0,方式再烧进去Nandflash,并且启动前 关闭了MMU,进行了一些存储器方面的

//                                            物理地址与虚拟地址的映射(鄙人不才,还没搞得很清楚);所以在你用网络下载并直接从内存起来之

//                                             后你的驱动如果用映射寄存器的方式,可能就会失效!!

//

//

//

//                                       
//
//             

 

 

     当你用网络下载方式 才会执行到下面的函数 所谓的M$时间

 

 // system ready, preparing for download
    KITLOutputDebugString ("System ready!/r/nPreparing for download.../r/n");

    // (4) call OEM specific pre-download function
    switch (dwAction = OEMPreDownload ())    //注意这个switch 中 没有使用 case  之间的break
    {

 

case BL_DOWNLOAD:
        // (5) download image
        if (!DownloadImage (&dwImageStart, &dwImageLength, &dwLaunchAddr))//M$提供的下载函数
        {
            // error already reported in DownloadImage
            SPIN_FOREVER;
        }
        bDownloaded = TRUE;

        // Check for pTOC signature ("CECE") here, after image in place
        if (*(LPDWORD) OEMMapMemAddr (dwImageStart, dwImageStart + ROM_SIGNATURE_OFFSET) == ROM_SIGNATURE)
        {
            dwpToc = *(LPDWORD) OEMMapMemAddr (dwImageStart, dwImageStart + ROM_SIGNATURE_OFFSET + sizeof(ULONG));
            // need to map the content again since the pointer is going to be in a fixup address
            dwpToc = (DWORD) OEMMapMemAddr (dwImageStart, dwpToc + g_dwROMOffset);

            KITLOutputDebugString ("ROMHDR at Address %Xh/r/n", dwImageStart + ROM_SIGNATURE_OFFSET + sizeof (DWORD)); // right after signature
        }

        // fall through
  case BL_JUMP:
        // Before jumping to the image, optionally check the image signature.
        // NOTE: if we haven't downloaded the image by now, we assume that it'll be loaded from local storage in OEMLaunch (or it
        // already resides in RAM from an earlier download), and in this case, the image start address might be 0.  This means
        // that the image signature routine will need to find the image in storage or in RAM to validate it.  Since the OEM"s
        // OEMLaunch function will need to do this anyways, we trust that it's within their abilities to do it here.
        //
        if (g_bBINDownload && g_pOEMCheckSignature)
        {
            if (!g_pOEMCheckSignature(dwImageStart, g_dwROMOffset, dwLaunchAddr, bDownloaded))
                HALT(BLERR_CAT_SIGNATURE);
        }
        // (5) final call to launch the image. never returned
        OEMLaunch (dwImageStart, dwImageLength, dwLaunchAddr, (const ROMHDR *)dwpToc);//第三方实现
        // should never return
        // fall through
 default:
        // ERROR! spin forever
        HALT (BLERR_INVALIDCMD);

 

 


       }

//OEMPreDownload 中做的事情:EbootInitEtherTransport() 因为网络文件传输用的是tftp协议,所以相关一些tftp的准备工

//                                                                                            作                                    
//

//DownloadImage(): 下载bin 并且转换为nb0

//

//OEMLaunch() :       网络下载并利用第三方开发的SaveImage()保存,最后指定NK地址Launch(); 

 

 

  我的一些主干函数 是在oem.c中,这个可能要看每个BSP提供商而定了,我的方法就是以oem.c中函数与微软的主框架相结合的读源码

 

原创粉丝点击