跳至主要内容

【转】S3c2410/2440的Eboot流程介绍

对于嵌入式系统来说,一般都需要一个bootloader来下载和引导操作系统,常用的bootloader有eboot,uboot以及vivi等,对于windows ce来说最理想的bootloader当然是eboot(我也做了利用uboot下载和引导ce,以后我会介绍)。下面我就把自己开发eboot的过程和大家分享。eboot的流程可以如下图所示:

1)eboot和nk公用一段起始代码fw.s,所以我们会在eboot文件夹下的arm子文件夹找到fw.s,里面就一句话: INCLUDE ..\\..\\kernel\\hal\\arm\\fw.s,对于这段起始代码我就不详细分析,无非是建立好中断向量表,设置好系统的工作频率,设置MMU等,然后就跳转到eboot的main函数

2)eboot的main函数在eboot文件夹的main.c里面,代码如下:

void main (void)

{

BootloaderMain ();

SPIN_FOREVER;

}

是不是觉得很简单,好像什么也没有做,但是注意这个BootloaderMain函数,这个就是eboot真正的main函数,这个函数在

$(_WINCEROOT)\PUBLIC\COMMON\OAK\DRIVERS\ETHDBG\BLCOMMON\blcommon.c里面,这个函数是微软的ce对eboot的通用函数,它会调用在eboot文件夹里面由OEM商或者自己写的一些函数。那既然我们知道了真正的main函数在哪里,那么下面我们跟着BootloaderMain走吧。

3)在BootloaderMain 函数里面首先执行KernelRelocate,这是把一些全局变量存放到ram里面去,这个函数不是很重要。

4)下面就是执行OEMDebugInit,看到OEM三个字母了没有,这就说明这个函数是OEM商,或者我们自己需要实现的,在eboot下的main函数里面可以找到这个函数,这主要是提供给blcommon一些回调函数如下所示:

BOOL OEMDebugInit()

{

// Assign callback functions to be usec by blcommon.

g_pOEMReportError = OEMReportError;//错误报告函数

g_pOEMVerifyMemory = OEMVerifyMemory;// 下载映象时检测内存是否正常

g_pOEMMultiBINNotify = OEMMultiBINNotify; //通知需要下载的所有bin文件

OEMInitDebugSerial();//初始化串口调试输出

return TRUE;

}

这些被调用的函数也是OEM商或者我们自己编写的。前面三个函数都可以在main.c里面找到,代码比较罗唆,而且基本上和硬件没有太大关系,我们看看最后一个初始化串口调试输出的函数,这个文件在D:\WINCE420\PLATFORM\smdk2410eboot+rtc\KERNEL\HAL\debug.c里面,我这里是设置串口0为调试输出口,三星自带的用的是串口1,并且把波特率设置为115200,大家如果需要用串口0作为调试输出口可以参考我的修改:

#define UART0BaudRate 115200

void OEMInitDebugSerial(void)

{

volatile UART1reg *s2410UART0 = (UART0reg *)UART0_BASE;

volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;

s2410IOP->rGPHCON &= ~((3 << 8) | (3 << 10));

s2410IOP->rGPHCON |= ((2 << 4) | (2 << 6)); //

s2410IOP->rGPHUP |= (1 << 2) | (1 << 3);

s2410UART0->rUFCON = 0x0; // Disable the FIFO

s2410UART0->rUMCON = 0x0; // Disable AFC.

s2410UART0->rULCON = 0x3; // Normal mode, N81.

s2410UART0->rUCON = 0x245;

s2410UART0->rUBRDIV = ( (int)(S2410PCLK/16.0/UART0BaudRate + 0.5) -1 );

}

调用完这个调试输出初始化函数以后,eboot的调试信息就会从串口0出来(当然nk的调试信息也会从这个串口出来了,因为这一部分是和nk复用的^_^)

5)BootloaderMain调用完OEMDebugInit后就调用下一个函数了-OEMPlatformInit,这个函数也在eboot的main.c里面可以找到,主要是初始化你的硬件平台,包括设置RTC时钟,初始化一下你的NANDflash,然后就是读TOC (table of contents),一般TOC都会烧到nand的block1里面,如果读TOC失败,就会用默认的参数重写TOC,读TOC这段代码比较简单,在fmd.cpp里面,大家可以自己研究。然后就是进入倒计时,如果在你设置的延迟时间内按键盘的话就会进入BootMonitor这个函数,这个函数主要是输出eboot的选择菜单,根据你的选择进行操作,如果在延迟时间结束你没有按键盘的话就会根据你设置的是Download new(下载新的映象)还是Launch existing(加载在nand中的映象)来进行下一步操作,我们先看看BootMonitor这个函数,这个函数虽然代码很多,但是其实非常简单,就是根据你的输入来设置改变一些全局变量,eboot在后面会根据这些变量来进行相应的操作。

如果选择了下载映象,在OEMPlatformInit函数里会调用InitEthDevice初始化网卡,然后返回true,InitEthDevice函数在ether.c里面,具体需要根据你使用的网卡,把一些接口提供给eboot,下面是我的InitEthDevice函数,我使用的是DM9000网卡:

BOOL InitEthDevice(PBOOT_CFG pBootCfg)

{

USHORT wMAC[3];

PBYTE pBaseIOAddress = NULL;

DWORD dwMultiplier = 0;

// Boot CS8900.

//

if (!pBaseIOAddress)

{

// Use the MAC address programmed into flash by the user.

//

memcpy(wMAC, pBootCfg->EdbgAddr.wMAC, 6);

pfnEDbgInit = DM9000DBG_Init;

pfnEDbgGetFrame = DM9000DBG_GetFrame;

pfnEDbgSendFrame = DM9000DBG_SendFrame;

pBaseIOAddress = (PBYTE)CS8900DBG_IOBASE;

dwMultiplier = CS8900DBG_MEMBASE;

memcpy(pDriverGlobals->eth.TargetAddr.wMAC, pBootCfg->EdbgAddr.wMAC, 6);

pDriverGlobals->misc.EbootDevice = (UCHAR)DOWNLOAD_DEVICE_CS8900;

}

// Initialize the built-in Ethenet controller.

//

if (!pfnEDbgInit((PBYTE)pBaseIOAddress, dwMultiplier, wMAC))

{

EdbgOutputDebugString("ERROR: InitEthDevice: Failed to initialize Ethernet controller.\r\n");

return(FALSE);

}

// Make sure MAC address has been programmed.

//

if (!wMAC[0] && !wMAC[1] && !wMAC[2])

{

EdbgOutputDebugString("ERROR: InitEthDevice: Invalid MAC address read from NIC.\r\n");

return(FALSE); }

memcpy(&pDriverGlobals->eth.TargetAddr.wMAC, &wMAC, (3 * sizeof(USHORT)));

return(TRUE);

}

DM9000DBG_Init; DM9000DBG_GetFrame; DM9000DBG_SendFrame;这几个函数都需要在你的网卡驱动里面实现,这里只需要把这几个函数提供给eboot就行了。

6)BootloaderMain下面就调用OEMPreDownload进行一些下载前的准备工作,之后就会调用DownloadImage下载内核,下载完了后就调用OEMLaunch启动RAM里面的内核,注意OEMLaunch里面会需要和PB建立连接,如果我们要绕过PB下载nk(我在以前的文章里面已经介绍过实现的方法了)我们就需要屏蔽这段代码(在#ifndef SIMULATOR

评论

此博客中的热门博文

【转】smb协议栈使用示例

/*  * * uncdownload.c  * *  * * Utility for downloading files from SMB shares using libsmbclient  * *  * * Copyright(C) 2006 Sophos Plc, Oxford, England.  * *  * * This program is free software; you can redistribute it and/or modify it under the terms of the  * * GNU General Public License Version 2 as published by the Free Software Foundation.  * *  * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  * * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  * * See the GNU General Public License for more details.  * *  * * You should have received a copy of the GNU General Public License along with this program; if not,  * * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  * *  * */ # include < sys / types . h > # include < sys / time . h > # include ...

【转】Ether Types

Ether Types (last updated 2008-09-09) NOTE: Please see [RFC5342] for current information and registration procedures. This registry will be revised soon and will be replaced with up-to-date information. Many of the networks of all classes are Ethernets (10Mb) or Experimental Ethernets (3Mb). These systems use a message "type" field in much the same way the ARPANET uses the "link" field. If you need an Ether Type, contact: IEEE Registration Authority IEEE Standards Department 445 Hoes Lane Piscataway, NJ 08854 Phone +1 732 562 3813 Fax: +1 732 562 1571 Email: <ieee-registration-authority& ieee.org > http://standards.ieee.org/regauth/index.html The following list of EtherTypes is contributed unverified information from various sources. Another list of EtherTypes is maintained by Michael A. Patton and is accessible at: <URL: http://www.cavebear.com/CaveBear/Ethernet/ > <URL: ftp://ftp.cavebear.com/pub/Ethernet-codes > Assign...

【转】udp编程实例

UDP通讯实例 2008-04-29 15:30:05 / 个人分类: linux C编程 UDP协议的几点好处: 1.UDP不要求保持一个连接; 2.UDP没有因接收方认可收到数据包(或者当数据包没有正确抵达而自动重传)而带来的开销; 3.设计UDP的目的是用于短应用和控制信息; 4.在一个数据包接一个数据包的基础上,UDP要求的 网络 带宽比TCP更小。 UDP的几个缺点: 1.程序员必须创建代码检测传输错误并进行重传(如果应用程序要求这样做); 2.程序员必须把大数据包分片。 code: <1> /* * sender.c--UDP protocol example */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> int port = 6789; int main() {     int socket_descrīptor;     int iter = 0;     char buf[80];     struct sockaddr_in address;     /* Initialize socket address structure for Interner Protocols */     bzero(&address, sizeof(address)); // empty data structure     address.sin_family = AF_INET;     address.sin_addr.s_addr = inet_addr("127.0.0.1");     address...