跳至主要内容

【转】VxWorks镜像原理:构造与运行

一、概述
本文稍加定义,rom镜像为Tornado bootable工程编译出来的可以直接烧录在EEPROM/Flash中的镜像,其中包括了boot镜像与VxWorks镜像。boot镜像其实应该说是一个bootloader,但由于VxWokrs中创建的Bootable工程本身具有boot功能,而且其中还包含一个子镜像(sub image),在此称作VxWorks镜像,VxWorks镜像才是真正构成VxWorks的镜像,就好比boot镜像只是一个bios,或者更高一层类似于lilo/grub系统引导,而VxWorks镜像才是真正的操作系统。
VxWorks是如何将两个镜像合并在一起在另外一篇文章已经阐述,本文着重内部实现,关注于rom镜像于ram镜像的构成。VxWorks_romCompress是比较复杂的一个镜像,本文针对该压缩镜像,romResident,以及rom镜像都类似。
二、rom镜像构成
镜像主要由code段,data段组成,bss段不占据空间
----------------
| |
|--------------| 0xfffx xxxx = binArrayEnd
| subImage |
|--------------| 0xfffx xxxx = binArrayStart
| data |
|--------------| 0xfffx xxxx = ROM_DATA_ADRS
| text |
| | 0xfff0 0008 = ROM_TEXT_ADRS
-------------- - 0xfff0 0100 = ROM_BASE_ADRS
镜像地地址存放代码段,高地址存放数据段。数据段的其实地址为ROM_DATA_ADRS,决定于代码段长度,在ld中可以定义,代码中通过etext获取该值。binArrayStart与binArrayEnd之间存放的是VxWorks镜像,镜像与数据段的格式保存在rom镜像中。
生成rom镜像的ld参数如下:
LD_ROM_CMP_FLAGS= $(ROM_LDFLAGS) -Ttext $(ROM_TEXT_ADRS) \
-Tdata $(RAM_HIGH_ADRS)
可见将代码段定位在ROM_TEXT_ADRS,PPC中一般为0xFFF0 00100,而将数据段定位在RAM_HIGH_ADRS。ld如何定位,可以参考GNU ld手册。RAM_HIGH_ADRS地址决定了一会romStart拷贝中将数据段拷贝的目的内存地址。
三、ram镜像
ram镜像为rom镜像运行时在内存中的反应,结构如下:
---------------- LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE
| |
|--------------|
| temp data |
|--------------| RAM_DATA_ADRS
| initial sp |
|--------------| RAM_DATA_ADRS - STACK_SAVE
| |
|--------------|
| |
| subimage |
| |
|--------------| RAM_DST_ADRS (for non-resident images)
| |
-------------- 0x00000000 = LOCAL_MEM_LOCAL_ADRS

VxWorks_romCompress镜像中RAM_DST_ADRS为RAM_LOW_ADRS,而RAM_DATA_ADRS为RAM_HIGH_ADRS。RAM_HIGH_ADRS以上地址存放boot镜像数据段,而稍下点的地址作为堆栈,由结构中可以看出,子镜像的大小必须小于(RAM_HIGH_ADRS-RAM_LOW_ADRS)。该结构图为Tornado2.0的,2.2的结构中在RAM_HIGH_ADRS地址处还存放压缩镜像,当VxWorks镜像开始运行时,RAM_HIGH_ADRS以上地址都已经没有意义。
VxWorks镜像的ld参数为-Ttext $(RAM_LOW_ADRS),可见为什么必须解压到RAM_LOW_ADRS地址处。
四、代码拷贝解压
代码摘自Tornado2.0,2.2版本多一个拷贝的过程,原理类似。
void romStart
(
FAST int startType /* start type */
)
{
volatile FUNCPTR absEntry = (volatile FUNCPTR)RAM_DST_ADRS;
/*
* TongFutian 注释
* ROM_DATA_ADRS = etext
* RAM_DATA_ADRS = RAM_HIGH_ADRS
*/
/* relocate the data segment of the decompression stub */

copyLongs (ROM_DATA_ADRS, (UINT *)UNCACHED(RAM_DATA_ADRS),
((UINT)binArrayStart - (UINT)RAM_DATA_ADRS) / sizeof (long));
/* If cold booting, clear memory to avoid parity errors */
#ifdef ROMSTART_BOOT_CLEAR
if (startType & BOOT_CLEAR)
bootClear();

评论

此博客中的热门博文

【转】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...