VxWorks各部分初始化流程 分类: vxWorks 2014-03-14 08:44 253人阅读 评论(0) 收藏
一)configAll.h中定义所有定置系统配置的宏
INCLUDED SOFTWARE FACILITIES:定义了基本组件;
EXCLUDED FACILITIES:定义了扩充组件,缺省不包括;
KERNEL SOFTWARE CONFIGURATION:内核运行的基本参数定义,包括文件个数、任务个数等等;
"GENERIC" BOARD CONFIGURATION:板通用属性定义;
"MISCELLANEOUS" CONSTANTS:共享的信号量以及相关对象个数定义;
INCLUDED NETWORK FACILITIES:包括的网络协议组件定义;
EXCLUDED NETWORK FACILITIES:未包括的网络协议组件定义;
二)boot流程(bootrom)
usrInit()
{
intVecBaseSet ((FUNCPTR *) VEC_BASE_ADRS)设置中断向量;
excVecInit ()设置异常向量;
sysHwInit ()初始化硬件
usrKernelInit ()配置VXWORK内核;
kernelInit ((FUNCPTR) usrRoot, ROOT_STACK_SIZE,启动usrRoot();
}
usrRoot()
{
memInit (pMemPoolStart, memPoolSize);/* XXX select between memPartLibInit */初始化内存;
/* set up system timer */
sysClkConnect ((FUNCPTR) usrClock, 0);/* connect clock interrupt routine */
sysClkRateSet (60);/* set system clock rate */
sysClkEnable ();/* start it */
/*必须的硬件初始化步骤*/
/*启动tboot任务*/
taskSpawn ("tBoot", bootCmdTaskPriority, bootCmdTaskOptions,
bootCmdTaskStackSize, (FUNCPTR) bootCmdLoop,
0,0,0,0,0,0,0,0,0,0);
}
bootCmdLoop()
{
/*根据用户输入走入不同分支*/
autoboot()
/*根据取得的BOOT_LINE_ADRS地址,进入bootLoad流程*/
}
bootLoad()
{
/*根据bootline配置选择启动路径*/
flashLoad() or netLoad()
/*如果从网络启动,网络初始化,静态IP or dhcpGet()*/
}
三)vxWorks启动流程
usrInit()
/* the first C code executed after the system boots. This routine is called by the assembly language start-up routine sysInit() which is in the sysALib module of the target-specific directory*/
{
sysHwInit ();/* initialize system hardware */
usrKernelInit ();/* configure the Wind kernel */
/* start the kernel specifying usrRoot as the root task */
kernelInit ((FUNCPTR) usrRoot, * )
}
usrRoot()
/* first task to run under the multitasking kernel. It performs all final initialization and then starts other tasks*/
{
调用 memInit (pMemPoolStart, memPoolSize); /* initialize memory pool */
或memPartLibInit (pMemPoolStart, memPoolSize);/* initialize memory pool */
初始化系统内存池;
调用memShowInit ()初始化内存显示例程;
调用usrMmuInit ()初始化MMU单元;
调用 sysClkConnect ((FUNCPTR) usrClock, 0); /* connect clock ISR */
sysClkRateSet (60); /* set system clock rate */
sysClkEnable (); /* start it */
初始化系统时钟;
初始化_func_selWakeupListInit;
调用 iosInit (NUM_DRIVERS, NUM_FILES, "/null");初始化I/O系统;
安装控制台驱动,创建控制台设备,设置BAND率;
初始化PC控制台设备;
调用 ioGlobalStdSet (STD_IN, consoleFd);
ioGlobalStdSet (STD_OUT, consoleFd);
ioGlobalStdSet (STD_ERR, consoleFd);
将标准输入、输出、错误输出定向到控制台设备上;
调用hashLibInit (); /* initialize hash table package */
symLibInit (); /* initialize symbol table package */
symShowInit (); /* initialize symbol table show */
初始化系统符号表;
调用excInit ()初始化异常处理;
调用logInit (consoleFd, MAX_LOG_MSGS)初始化登录;
调用sigInit ()初始化信号量库;
调用dbgInit ()初始化调试库;
调用pipeDrv ()初始化管道;
stdioInit (); /* initialize standard I/O library */
stdioShowInit ();
初始化标准I/O;
调用sigqueueInit (NUM_SIGNAL_QUEUES); /* initialize queued signals */
semPxLibInit ();
semPxShowInit ();
mqPxLibInit (MQ_HASH_SIZE);
mqPxShowInit ();
aioPxLibInit (MAX_LIO_CALLS);
aioSysInit(MAX_AIO_SYS_TASKS, AIO_TASK_PRIORITY, AIO_TASK_STACK_SIZE);
初始化POSIX;
调用 hashLibInit (); /* initialize hash table package */
dosFsInit (NUM_DOSFS_FILES); /* init dosFs filesystem */
初始化DOS文件系统;
调用 rawFsInit (NUM_RAWFS_FILES); /* init rawFs filesystem */ 初始化原始文件系统;
调用rt11FsInit (NUM_RT11FS_FILES)初始化RT11文件系统;
调用ramDrv ()初始内存虚拟盘;
初始化SCSI;
调用fdDrv (FD_INT_VEC, FD_INT_LVL)初始化软驱;
调用ideDrv (IDE_INT_VEC, IDE_INT_LVL, IDE_CONFIG)初始化IDE盘;
初始化硬盘驱动;
初始化LPT;
调用 pcmciaShowInit (); /* install PCMCIA show routines */
pcmciaInit (); /* init PCMCIA Lib */
初始化PCMCIA;
调用tffsDrv ()初始化TFFS;
调用fioLibInit ()初始化格式化I/O;
调用floatInit ()初始化浮点设备;
调用mathSoftInit ()初始化软浮点设备;
调用mathHardInit ()初始化硬浮点设备;
调用spyLibInit ()初始化CPU监视工具;
调用timexInit ()初始化函数定时工具;
调用envLibInit (ENV_<I>var</I>_USE_HOOKS)初始化环境变量;
初始化NTPASSFS;
调用moduleLibInit ()初始化模块管理器;
调用symSyncLibInit ()同步目标机与主机的符号表;
调用sysFFSMount ();初始化文件系统;
调用
usrBootLineInit (sysStartType); /* crack the bootline */
usrNetInit (BOOT_LINE_ADRS); /* initialize network support */
初始化网络通讯协议;
初始化PASSFS;
初始化DOS_DISK;
调用usrSmObjInit (BOOT_LINE_ADRS)初始化共享内存对象;
初始化WindMP;
写保护文本段和向量表;
调用selectInit ()初始化SELECT;
调用sysSymTbl = symTblCreate (SYM_TBL_HASH_SIZE_LOG2, TRUE, memSysPartId)创建系统符号表;
调用sysSymTbl = symTblCreate (SYM_TBL_HASH_SIZE_LOG2, TRUE, memSysPartId);
netLoadSymTbl ()
创建网络符号表;
初始化C++库;
初始化Wind Web服务器;
调用httpd ()初始化HTTP;
调用rBuffLibInit();
rBuffShowInit (); /* install rBuff show routine */
初始化RBUFF;
调用windviewConfig ()初始化WINDVIEW;
调用wdbConfig();初始化调试接口;
打印SHELL界面;
初始化交互界面,提示用户输入信息,口令验证;
调用usrUglInit ()初始化UGL;
调用javaConfig ()初始化JAVA;
调用usrHtmlInit ()初始化HTML;
调用USER_APPL_INIT初始化用户应用程序;TmsAppInit()
}
四)网络初始化
usrNetInit()
{
调用hostTblInit ()初始化主机表;(在hostlib。C中,该表用于DNS)
调用usrNetProtoInit ()初始化各种协议,包括IP、RIP、IP过滤、UDP、TCP、ICMP、IGMP、多播路由、OSPF;
调用netLibInit ()初始化网络库,包括创建网络任务环、创建网络处理任务、初始化缓冲区、接口初始化、
添加INTE域、INTE域初始化、路由表初始化、增强路由初始化、多播HASH表初始化、网络类型初始化;
调用muxLibInit()初始化MUX;
调用muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, ipEtherResolvRtn)初始化
以太网的IP地址解析;
调用muxAddrResFuncAdd (M2_ifType_atm, 0x800, ipAtmResolvRtn)初始化ATM的IP地址解析;
调用muxAddrResFuncAdd (M2_ifType_ppp, 0x800, ipPppResolvRtn)初始化POS的IP地址解析;
/*此处初始化了所有外部链路类型的IP地址解析函数,形成函数链表,在IP绑定时,
根据END接口类型和协议类型,获取地址解析函数,就可以完成地址解析了)读endDevTbl,调用muxDevLoad()加载END并调用muxDevStart()启动END;*/
若从磁盘启动则初始化必要的END:
{
调用pEnd = endFindByName(params.other, params.unitNum);获取一个other中的END;
调用(ipAttach(params.unitNum, params.other) != OK)绑定IP协议栈到该END上;
设置attached = TRUE;
如果!attached,调用usrNetIfAttach (params.other, params.unitNum,params.ead) != OK}则
初始化BSD类型的接口;
调用usrNetIfConfig (params.bootDev, params.unitNum, params.ead,
params.targetName,
netmask) !=OK}配置IP地址
}
如果从以太网启动,则:
{
调用pEnd = endFindByName(params.other, params.unitNum);获取一个other中的END;
调用(ipAttach(params.unitNum, params.other) != OK)绑定IP协议栈到该END上;
设置attached = TRUE;
如果!attached,调用usrNetIfAttach (params.other, params.unitNum,params.ead) != OK}
则初始化BSD类型的接口;
调用usrNetIfConfig (params.bootDev, params.unitNum, params.ead,
params.targetName,
netmask) !=OK}配置IP地址;
}
如果不从BACKPLANE启动,则设置此BACKPLANE为第二接口:
{
调用usrNetIfAttach (bpDev, params.unitNum, params.bad);
(void) usrNetIfConfig (bpDev, params.unitNum, params.bad,
(char *) NULL, netmask);
配置BACKPLANE;
}
如果params.targetName[0]目标主机名不为空,则调用:
usrNetIfAttach ("lo", 0, "127.0.0.1");
usrNetIfConfig ("lo", 0, "127.0.0.1", "localhost", 0);
初始化ARP代理服务器;
如果定义了网关地址,则设置路由;
调用hostAdd (params.hostName, params.had);将HOST加入到主机表;
pingLibInit(),初始化PING;
……
}
五)网络缓冲区定义
/* network buffers configuration */
/*
* mBlk, clBlk configuration table for network stack data pool.
* Only used for data transfer in the network stack.
*/
M_CL_CONFIG mClBlkConfig =
{
/*
no. mBlks no. clBlks memArea memSize
----------- ---------- ------- -------
*/
NUM_NET_MBLKS, NUM_CL_BLKS, NULL, 0
};
/*
* network stack data cluster pool configuration table
* Only used for data transfer in the network stack.
*/
CL_DESC clDescTbl [] =
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{64, NUM_64, NULL, 0},
{128, NUM_128, NULL, 0},
{256, NUM_256, NULL, 0},
{512, NUM_512, NULL, 0},
{1024, NUM_1024, NULL, 0},
{2048, NUM_2048, NULL, 0}
};
int clDescTblNumEnt = (NELEMENTS(clDescTbl));
/*
* mBlk, clBlk configuration table for network stack system pool.
* Used for network stack system structures such as routes, sockets,
* protocol control blocks, interface addresses, mulitcast addresses,
* and multicast routing entries.
*/
M_CL_CONFIG sysMclBlkConfig =
{
/*
no. mBlks no. clBlks memArea memSize
----------- ---------- ------- -------
*/
NUM_SYS_MBLKS, NUM_SYS_CL_BLKS, NULL, 0
};
/*
* network stack system cluster pool configuration table
* Used for network stack system structures such as routes, sockets,
* protocol control blocks, interface addresses, mulitcast addresses,
* and multicast routing entries.
*/
CL_DESC sysClDescTbl [] =
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{64, NUM_SYS_64, NULL, 0},
{128, NUM_SYS_128, NULL, 0},
{256, NUM_SYS_256, NULL, 0},
{512, NUM_SYS_512, NULL, 0},
};
int sysClDescTblNumEnt = (NELEMENTS(sysClDescTbl));
以上的常数定义在netBufLib.H中;
在目前的定义中:
系统内核的缓冲区有512个Mbuf,有256个Mclk;
网络协议的缓冲区有400个Mbuf,有330个Mclk;
在mbuf.h将mbuf重定义为mBlk;
#define mbuf mBlk
在mblk中实现了原来mbuf的定义;
六)IP协议栈初始化流程
usrNetProtoInit ()
{
调用ipLibInit (&ipCfgParams)初始化IP ;
调用rawIpLibInit ()初始化原始IP;
调用rawLibInit ()初始化原始IP库;
调用ipFilterLibInit ()初始化IP过滤;
调用udpLibInit (&udpCfgParams)初始化UDP库;
调用udpShowInit ()初始化UDP显示;
调用tcpLibInit (&tcpCfgParams)初始化TCP库;
调用tcpShowInit ()初始化TCP显示;
调用icmpLibInit (&icmpCfgParams);初始化ICMP;
调用icmpShowInit ()初始化ICMP显示;
调用igmpLibInit ();初始化IGMP;
调用igmpShowInit ();初始化IGMP显示;
调用mCastRouteLibInit ();初始化MCAST;
调用ospfLibInit ();初始化OSPF;
调用 ospfRegisterProtocol ();初始化OSPF注册;
netLibInit()流程:
调用 if ((netJobRing = rngCreate (JOB_RING_SIZE)) == (RING_ID) NULL)
panic ("netLibInit: couldn't create job ring\n");
初始化任务环;
调用 if (rebootHookAdd ((FUNCPTR) ifreset) == ERROR)
logMsg ("netLibInit: unable to add reset hook\n", 0, 0, 0, 0, 0, 0);
初始化复位钩子;
调用 semBInit (netTaskSemId, SEM_Q_PRIORITY, SEM_EMPTY);初始化信号量;
调用 splSemInit ();初始化信号量;
调用 mbinit ();初始化网络缓冲区;
调用 ifinit ();初始化接口;
调用addDomain (&inetdomain);添加域;
调用domaininit ()初始化域;
调用route_init ()初始化路由表;
调用routeIntInit ()初始化增强路由表;
调用mcastHashInit ();初始化多播HASH;
调用netTypeInit ()初始化网络类型;
调用 netTaskId = taskSpawn ("tNetTask", netTaskPriority,
netTaskOptions, netTaskStackSize,
(FUNCPTR) netTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
创建网络任务netTask;
netTask()网络任务流程
调用 semTake (netTaskSemId, WAIT_FOREVER);获取信号量;
调用rngIsEmpty (netJobRing)检查网络事件环是否有任务,如果有事件
则调用rngBufGet (netJobRing, (char *) &jobNode,sizeof (jobNode)) != sizeof (jobNode))获取事件,
并执行;
判断_netIsrMask中断字,确定是IP包到、还是ARP包到;
如果是IP包到,则调用ipintr ();处理IP包后清除_netIsrMask中断字;
如果是ARP包到,则调用arpintr ()处理ARP包后清除_netIsrMask中断字;
schednetisr()软中断流程:
获取软中断类型;
设置_netIsrMask软中断字;
调用semGive (netTaskSemId)激活网络处理任务。
TMSAppinit中调用muxIterateByName( SW_DEVICE_NAME, swIpAttach, NULL )添加相应的网络接口;
rc = ipAttach( unit0, EM_DEVICE_NAME );初始化外部网络接口
swIpAttach()的流程如下:
调用rc = ipAttach( unit, SW_DEVICE_NAME );初始化网络接口
ipAttach()流程:
调用 if (endFindByName (pDevice, unit) == NULL)确定是否有该END;
在ipDrvCtrl[]中获取一个空的空间放置IP驱动属性;
调用if((pDrvCtrl->tkFlag = muxTkDrvCheck(pDevice)) == TRUE)确定是否是NPT类型的END,
如果是则以后绑定用TK;
调用if((pDrvCtrl->pIpCookie = muxTkBind(pDevice, unit, ipTkReceiveRtn,绑定IP协议栈;
调用 bzero(pDrvCtrl->drvName,8);
strncpy(pDrvCtrl->drvName, pDevice,sizeof(pDrvCtrl->drvName)-1);
设置ipDrvCtrl[]域中成员名;
调用pIfp = (struct ifnet *) &pDrvCtrl->idr;获取ifNet;
设置ifNet;
调用muxIoctl(pDrvCtrl->pIpCookie, EIOCGFLAGS, (caddr_t)&flags)获取底层硬件标志;
调用muxIoctl(pDrvCtrl->pIpCookie, EIOCGMIB2233,(caddr_t)&pM2ID) == ERROR)获取底层硬件MIB变量;
设置ifnet;
确定接口类型,如果广播类型的接口,则设置接口广播标志;
调用if((pDrvCtrl->pArpCookie = muxTkBind(pDevice, unit,ipTkReceiveRtn,绑定ARP协议;
调用if (muxIoctl (pDrvCtrl->pIpCookie, EIOCGHDRLEN,
(caddr_t)&ifHdrLen)!= OK)获取底层硬件地址长度;
设置ifnet硬件地址长度;
设置ifnet的接口操作函数例程;
调用pIfp->if_resolve = muxAddrResFuncGet(pIfp->if_type, 0x800)获取该接口类型的地址解析函数;
调用if_attach (pIfp);将ifnet加入接口链表中;
调用pIfp->if_start = (FUNCPTR) ipTxStartup;初始化接口启动函数;
如果出错,则进行出错的善后处理
}
参考文档
1)vxWorks BSP code
2)Vxworks网络协议栈初始化流程(网友edwzyy)
INCLUDED SOFTWARE FACILITIES:定义了基本组件;
EXCLUDED FACILITIES:定义了扩充组件,缺省不包括;
KERNEL SOFTWARE CONFIGURATION:内核运行的基本参数定义,包括文件个数、任务个数等等;
"GENERIC" BOARD CONFIGURATION:板通用属性定义;
"MISCELLANEOUS" CONSTANTS:共享的信号量以及相关对象个数定义;
INCLUDED NETWORK FACILITIES:包括的网络协议组件定义;
EXCLUDED NETWORK FACILITIES:未包括的网络协议组件定义;
二)boot流程(bootrom)
usrInit()
{
intVecBaseSet ((FUNCPTR *) VEC_BASE_ADRS)设置中断向量;
excVecInit ()设置异常向量;
sysHwInit ()初始化硬件
usrKernelInit ()配置VXWORK内核;
kernelInit ((FUNCPTR) usrRoot, ROOT_STACK_SIZE,启动usrRoot();
}
usrRoot()
{
memInit (pMemPoolStart, memPoolSize);/* XXX select between memPartLibInit */初始化内存;
/* set up system timer */
sysClkConnect ((FUNCPTR) usrClock, 0);/* connect clock interrupt routine */
sysClkRateSet (60);/* set system clock rate */
sysClkEnable ();/* start it */
/*必须的硬件初始化步骤*/
/*启动tboot任务*/
taskSpawn ("tBoot", bootCmdTaskPriority, bootCmdTaskOptions,
bootCmdTaskStackSize, (FUNCPTR) bootCmdLoop,
0,0,0,0,0,0,0,0,0,0);
}
bootCmdLoop()
{
/*根据用户输入走入不同分支*/
autoboot()
/*根据取得的BOOT_LINE_ADRS地址,进入bootLoad流程*/
}
bootLoad()
{
/*根据bootline配置选择启动路径*/
flashLoad() or netLoad()
/*如果从网络启动,网络初始化,静态IP or dhcpGet()*/
}
三)vxWorks启动流程
usrInit()
/* the first C code executed after the system boots. This routine is called by the assembly language start-up routine sysInit() which is in the sysALib module of the target-specific directory*/
{
sysHwInit ();/* initialize system hardware */
usrKernelInit ();/* configure the Wind kernel */
/* start the kernel specifying usrRoot as the root task */
kernelInit ((FUNCPTR) usrRoot, * )
}
usrRoot()
/* first task to run under the multitasking kernel. It performs all final initialization and then starts other tasks*/
{
调用 memInit (pMemPoolStart, memPoolSize); /* initialize memory pool */
或memPartLibInit (pMemPoolStart, memPoolSize);/* initialize memory pool */
初始化系统内存池;
调用memShowInit ()初始化内存显示例程;
调用usrMmuInit ()初始化MMU单元;
调用 sysClkConnect ((FUNCPTR) usrClock, 0); /* connect clock ISR */
sysClkRateSet (60); /* set system clock rate */
sysClkEnable (); /* start it */
初始化系统时钟;
初始化_func_selWakeupListInit;
调用 iosInit (NUM_DRIVERS, NUM_FILES, "/null");初始化I/O系统;
安装控制台驱动,创建控制台设备,设置BAND率;
初始化PC控制台设备;
调用 ioGlobalStdSet (STD_IN, consoleFd);
ioGlobalStdSet (STD_OUT, consoleFd);
ioGlobalStdSet (STD_ERR, consoleFd);
将标准输入、输出、错误输出定向到控制台设备上;
调用hashLibInit (); /* initialize hash table package */
symLibInit (); /* initialize symbol table package */
symShowInit (); /* initialize symbol table show */
初始化系统符号表;
调用excInit ()初始化异常处理;
调用logInit (consoleFd, MAX_LOG_MSGS)初始化登录;
调用sigInit ()初始化信号量库;
调用dbgInit ()初始化调试库;
调用pipeDrv ()初始化管道;
stdioInit (); /* initialize standard I/O library */
stdioShowInit ();
初始化标准I/O;
调用sigqueueInit (NUM_SIGNAL_QUEUES); /* initialize queued signals */
semPxLibInit ();
semPxShowInit ();
mqPxLibInit (MQ_HASH_SIZE);
mqPxShowInit ();
aioPxLibInit (MAX_LIO_CALLS);
aioSysInit(MAX_AIO_SYS_TASKS, AIO_TASK_PRIORITY, AIO_TASK_STACK_SIZE);
初始化POSIX;
调用 hashLibInit (); /* initialize hash table package */
dosFsInit (NUM_DOSFS_FILES); /* init dosFs filesystem */
初始化DOS文件系统;
调用 rawFsInit (NUM_RAWFS_FILES); /* init rawFs filesystem */ 初始化原始文件系统;
调用rt11FsInit (NUM_RT11FS_FILES)初始化RT11文件系统;
调用ramDrv ()初始内存虚拟盘;
初始化SCSI;
调用fdDrv (FD_INT_VEC, FD_INT_LVL)初始化软驱;
调用ideDrv (IDE_INT_VEC, IDE_INT_LVL, IDE_CONFIG)初始化IDE盘;
初始化硬盘驱动;
初始化LPT;
调用 pcmciaShowInit (); /* install PCMCIA show routines */
pcmciaInit (); /* init PCMCIA Lib */
初始化PCMCIA;
调用tffsDrv ()初始化TFFS;
调用fioLibInit ()初始化格式化I/O;
调用floatInit ()初始化浮点设备;
调用mathSoftInit ()初始化软浮点设备;
调用mathHardInit ()初始化硬浮点设备;
调用spyLibInit ()初始化CPU监视工具;
调用timexInit ()初始化函数定时工具;
调用envLibInit (ENV_<I>var</I>_USE_HOOKS)初始化环境变量;
初始化NTPASSFS;
调用moduleLibInit ()初始化模块管理器;
调用symSyncLibInit ()同步目标机与主机的符号表;
调用sysFFSMount ();初始化文件系统;
调用
usrBootLineInit (sysStartType); /* crack the bootline */
usrNetInit (BOOT_LINE_ADRS); /* initialize network support */
初始化网络通讯协议;
初始化PASSFS;
初始化DOS_DISK;
调用usrSmObjInit (BOOT_LINE_ADRS)初始化共享内存对象;
初始化WindMP;
写保护文本段和向量表;
调用selectInit ()初始化SELECT;
调用sysSymTbl = symTblCreate (SYM_TBL_HASH_SIZE_LOG2, TRUE, memSysPartId)创建系统符号表;
调用sysSymTbl = symTblCreate (SYM_TBL_HASH_SIZE_LOG2, TRUE, memSysPartId);
netLoadSymTbl ()
创建网络符号表;
初始化C++库;
初始化Wind Web服务器;
调用httpd ()初始化HTTP;
调用rBuffLibInit();
rBuffShowInit (); /* install rBuff show routine */
初始化RBUFF;
调用windviewConfig ()初始化WINDVIEW;
调用wdbConfig();初始化调试接口;
打印SHELL界面;
初始化交互界面,提示用户输入信息,口令验证;
调用usrUglInit ()初始化UGL;
调用javaConfig ()初始化JAVA;
调用usrHtmlInit ()初始化HTML;
调用USER_APPL_INIT初始化用户应用程序;TmsAppInit()
}
四)网络初始化
usrNetInit()
{
调用hostTblInit ()初始化主机表;(在hostlib。C中,该表用于DNS)
调用usrNetProtoInit ()初始化各种协议,包括IP、RIP、IP过滤、UDP、TCP、ICMP、IGMP、多播路由、OSPF;
调用netLibInit ()初始化网络库,包括创建网络任务环、创建网络处理任务、初始化缓冲区、接口初始化、
添加INTE域、INTE域初始化、路由表初始化、增强路由初始化、多播HASH表初始化、网络类型初始化;
调用muxLibInit()初始化MUX;
调用muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, ipEtherResolvRtn)初始化
以太网的IP地址解析;
调用muxAddrResFuncAdd (M2_ifType_atm, 0x800, ipAtmResolvRtn)初始化ATM的IP地址解析;
调用muxAddrResFuncAdd (M2_ifType_ppp, 0x800, ipPppResolvRtn)初始化POS的IP地址解析;
/*此处初始化了所有外部链路类型的IP地址解析函数,形成函数链表,在IP绑定时,
根据END接口类型和协议类型,获取地址解析函数,就可以完成地址解析了)读endDevTbl,调用muxDevLoad()加载END并调用muxDevStart()启动END;*/
若从磁盘启动则初始化必要的END:
{
调用pEnd = endFindByName(params.other, params.unitNum);获取一个other中的END;
调用(ipAttach(params.unitNum, params.other) != OK)绑定IP协议栈到该END上;
设置attached = TRUE;
如果!attached,调用usrNetIfAttach (params.other, params.unitNum,params.ead) != OK}则
初始化BSD类型的接口;
调用usrNetIfConfig (params.bootDev, params.unitNum, params.ead,
params.targetName,
netmask) !=OK}配置IP地址
}
如果从以太网启动,则:
{
调用pEnd = endFindByName(params.other, params.unitNum);获取一个other中的END;
调用(ipAttach(params.unitNum, params.other) != OK)绑定IP协议栈到该END上;
设置attached = TRUE;
如果!attached,调用usrNetIfAttach (params.other, params.unitNum,params.ead) != OK}
则初始化BSD类型的接口;
调用usrNetIfConfig (params.bootDev, params.unitNum, params.ead,
params.targetName,
netmask) !=OK}配置IP地址;
}
如果不从BACKPLANE启动,则设置此BACKPLANE为第二接口:
{
调用usrNetIfAttach (bpDev, params.unitNum, params.bad);
(void) usrNetIfConfig (bpDev, params.unitNum, params.bad,
(char *) NULL, netmask);
配置BACKPLANE;
}
如果params.targetName[0]目标主机名不为空,则调用:
usrNetIfAttach ("lo", 0, "127.0.0.1");
usrNetIfConfig ("lo", 0, "127.0.0.1", "localhost", 0);
初始化ARP代理服务器;
如果定义了网关地址,则设置路由;
调用hostAdd (params.hostName, params.had);将HOST加入到主机表;
pingLibInit(),初始化PING;
……
}
五)网络缓冲区定义
/* network buffers configuration */
/*
* mBlk, clBlk configuration table for network stack data pool.
* Only used for data transfer in the network stack.
*/
M_CL_CONFIG mClBlkConfig =
{
/*
no. mBlks no. clBlks memArea memSize
----------- ---------- ------- -------
*/
NUM_NET_MBLKS, NUM_CL_BLKS, NULL, 0
};
/*
* network stack data cluster pool configuration table
* Only used for data transfer in the network stack.
*/
CL_DESC clDescTbl [] =
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{64, NUM_64, NULL, 0},
{128, NUM_128, NULL, 0},
{256, NUM_256, NULL, 0},
{512, NUM_512, NULL, 0},
{1024, NUM_1024, NULL, 0},
{2048, NUM_2048, NULL, 0}
};
int clDescTblNumEnt = (NELEMENTS(clDescTbl));
/*
* mBlk, clBlk configuration table for network stack system pool.
* Used for network stack system structures such as routes, sockets,
* protocol control blocks, interface addresses, mulitcast addresses,
* and multicast routing entries.
*/
M_CL_CONFIG sysMclBlkConfig =
{
/*
no. mBlks no. clBlks memArea memSize
----------- ---------- ------- -------
*/
NUM_SYS_MBLKS, NUM_SYS_CL_BLKS, NULL, 0
};
/*
* network stack system cluster pool configuration table
* Used for network stack system structures such as routes, sockets,
* protocol control blocks, interface addresses, mulitcast addresses,
* and multicast routing entries.
*/
CL_DESC sysClDescTbl [] =
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{64, NUM_SYS_64, NULL, 0},
{128, NUM_SYS_128, NULL, 0},
{256, NUM_SYS_256, NULL, 0},
{512, NUM_SYS_512, NULL, 0},
};
int sysClDescTblNumEnt = (NELEMENTS(sysClDescTbl));
以上的常数定义在netBufLib.H中;
在目前的定义中:
系统内核的缓冲区有512个Mbuf,有256个Mclk;
网络协议的缓冲区有400个Mbuf,有330个Mclk;
在mbuf.h将mbuf重定义为mBlk;
#define mbuf mBlk
在mblk中实现了原来mbuf的定义;
六)IP协议栈初始化流程
usrNetProtoInit ()
{
调用ipLibInit (&ipCfgParams)初始化IP ;
调用rawIpLibInit ()初始化原始IP;
调用rawLibInit ()初始化原始IP库;
调用ipFilterLibInit ()初始化IP过滤;
调用udpLibInit (&udpCfgParams)初始化UDP库;
调用udpShowInit ()初始化UDP显示;
调用tcpLibInit (&tcpCfgParams)初始化TCP库;
调用tcpShowInit ()初始化TCP显示;
调用icmpLibInit (&icmpCfgParams);初始化ICMP;
调用icmpShowInit ()初始化ICMP显示;
调用igmpLibInit ();初始化IGMP;
调用igmpShowInit ();初始化IGMP显示;
调用mCastRouteLibInit ();初始化MCAST;
调用ospfLibInit ();初始化OSPF;
调用 ospfRegisterProtocol ();初始化OSPF注册;
netLibInit()流程:
调用 if ((netJobRing = rngCreate (JOB_RING_SIZE)) == (RING_ID) NULL)
panic ("netLibInit: couldn't create job ring\n");
初始化任务环;
调用 if (rebootHookAdd ((FUNCPTR) ifreset) == ERROR)
logMsg ("netLibInit: unable to add reset hook\n", 0, 0, 0, 0, 0, 0);
初始化复位钩子;
调用 semBInit (netTaskSemId, SEM_Q_PRIORITY, SEM_EMPTY);初始化信号量;
调用 splSemInit ();初始化信号量;
调用 mbinit ();初始化网络缓冲区;
调用 ifinit ();初始化接口;
调用addDomain (&inetdomain);添加域;
调用domaininit ()初始化域;
调用route_init ()初始化路由表;
调用routeIntInit ()初始化增强路由表;
调用mcastHashInit ();初始化多播HASH;
调用netTypeInit ()初始化网络类型;
调用 netTaskId = taskSpawn ("tNetTask", netTaskPriority,
netTaskOptions, netTaskStackSize,
(FUNCPTR) netTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
创建网络任务netTask;
netTask()网络任务流程
调用 semTake (netTaskSemId, WAIT_FOREVER);获取信号量;
调用rngIsEmpty (netJobRing)检查网络事件环是否有任务,如果有事件
则调用rngBufGet (netJobRing, (char *) &jobNode,sizeof (jobNode)) != sizeof (jobNode))获取事件,
并执行;
判断_netIsrMask中断字,确定是IP包到、还是ARP包到;
如果是IP包到,则调用ipintr ();处理IP包后清除_netIsrMask中断字;
如果是ARP包到,则调用arpintr ()处理ARP包后清除_netIsrMask中断字;
schednetisr()软中断流程:
获取软中断类型;
设置_netIsrMask软中断字;
调用semGive (netTaskSemId)激活网络处理任务。
TMSAppinit中调用muxIterateByName( SW_DEVICE_NAME, swIpAttach, NULL )添加相应的网络接口;
rc = ipAttach( unit0, EM_DEVICE_NAME );初始化外部网络接口
swIpAttach()的流程如下:
调用rc = ipAttach( unit, SW_DEVICE_NAME );初始化网络接口
ipAttach()流程:
调用 if (endFindByName (pDevice, unit) == NULL)确定是否有该END;
在ipDrvCtrl[]中获取一个空的空间放置IP驱动属性;
调用if((pDrvCtrl->tkFlag = muxTkDrvCheck(pDevice)) == TRUE)确定是否是NPT类型的END,
如果是则以后绑定用TK;
调用if((pDrvCtrl->pIpCookie = muxTkBind(pDevice, unit, ipTkReceiveRtn,绑定IP协议栈;
调用 bzero(pDrvCtrl->drvName,8);
strncpy(pDrvCtrl->drvName, pDevice,sizeof(pDrvCtrl->drvName)-1);
设置ipDrvCtrl[]域中成员名;
调用pIfp = (struct ifnet *) &pDrvCtrl->idr;获取ifNet;
设置ifNet;
调用muxIoctl(pDrvCtrl->pIpCookie, EIOCGFLAGS, (caddr_t)&flags)获取底层硬件标志;
调用muxIoctl(pDrvCtrl->pIpCookie, EIOCGMIB2233,(caddr_t)&pM2ID) == ERROR)获取底层硬件MIB变量;
设置ifnet;
确定接口类型,如果广播类型的接口,则设置接口广播标志;
调用if((pDrvCtrl->pArpCookie = muxTkBind(pDevice, unit,ipTkReceiveRtn,绑定ARP协议;
调用if (muxIoctl (pDrvCtrl->pIpCookie, EIOCGHDRLEN,
(caddr_t)&ifHdrLen)!= OK)获取底层硬件地址长度;
设置ifnet硬件地址长度;
设置ifnet的接口操作函数例程;
调用pIfp->if_resolve = muxAddrResFuncGet(pIfp->if_type, 0x800)获取该接口类型的地址解析函数;
调用if_attach (pIfp);将ifnet加入接口链表中;
调用pIfp->if_start = (FUNCPTR) ipTxStartup;初始化接口启动函数;
如果出错,则进行出错的善后处理
}
参考文档
1)vxWorks BSP code
2)Vxworks网络协议栈初始化流程(网友edwzyy)
版权声明:本文为博主原创文章,未经博主允许不得转载。