⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devs-eth-synth-ecosynth.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Synthetic Target Ethernet Driver</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="Synthetic Target Ethernet Driver"HREF="devs-eth-synth-ecosynth-ref.html"><LINKREL="PREVIOUS"TITLE="Synthetic Target Ethernet Driver"HREF="devs-eth-synth-ecosynth-ref.html"><LINKREL="NEXT"TITLE="Synthetic Target Watchdog Device"HREF="devs-watchdog-synth-ref.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="devs-eth-synth-ecosynth-ref.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="devs-watchdog-synth-ref.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="DEVS-ETH-SYNTH-ECOSYNTH">Synthetic Target Ethernet Driver</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN18897"></A><H2>Name</H2>Synthetic Target Ethernet Support&nbsp;--&nbsp;Allow synthetic target applications to perform ethernet I/O</DIV><DIVCLASS="REFSECT1"><ANAME="AEN18900"></A><H2>Overview</H2><P>The synthetic target ethernet package can provide up to four networkdevices, <TTCLASS="VARNAME">eth0</TT> to <TTCLASS="VARNAME">eth3</TT>. These canbe used directly by the eCos application or, more commonly, by aTCP/IP stack that is linked with the eCos application. Each eCosdevice can be mapped on to a real Linux network device. For example,if the Linux PC has two ethernet cards and <TTCLASS="VARNAME">eth1</TT> isnot currently being used by Linux itself, then one of the eCos devicescan be mapped on to this Linux device. Alternatively, it is possibleto map some or all of the eCos devices on to the ethertap supportprovided by the Linux kernel.    </P><P>The ethernet package depends on the I/O auxiliary provided by thesynthetic target architectural HAL package. During initialization theeCos application will attempt to instantiate the desired devices, bysending a request to the auxiliary. This will load a Tcl script<TTCLASS="FILENAME">ethernet.tcl</TT> that is responsible for handling theinstantiation request and subsequent I/O operations, for exampletransmitting an ethernet packet. However, some of the low-level I/Ooperations cannot conveniently be done by a Tcl script so<TTCLASS="FILENAME">ethernet.tcl</TT> will actually run a separate program<BCLASS="COMMAND">rawether</B> to interact with the Linux network device.     </P><DIVCLASS="INFORMALFIGURE"><ANAME="AEN18910"><P></P><DIVCLASS="MEDIAOBJECT"><P><IMGSRC="overview.png"ALIGN="CENTER"></P></DIV><P></P></DIV><P>On the target-side there are configuration options to control whichnetwork devices should be present. For many applications a singledevice will be sufficient, but if the final eCos application issomething like a network bridge then the package can support multipledevices. On the host-side each eCos network device needs to be mappedon to a Linux one, either a real ethernet device or an ethertapdevice. This is handled by an entry in the target definition file:    </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet {    eth0 real eth1    eth1 ethertap tap3 00:01:02:03:FE:05    &#8230;}</PRE></TD></TR></TABLE><P>The ethernet package also comes with support for packet logging,and provides various facilities for use by user Tcl scripts.    </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-INSTALL"></A><H2>Installation</H2><P>Before a synthetic target eCos application can access ethernet devicesit is necessary to build and install host-side support. The relevantcode resides in the <TTCLASS="FILENAME">host</TT>subdirectory of the synthetic target ethernet package, and building itinvolves the standard <BCLASS="COMMAND">configure</B>,<BCLASS="COMMAND">make</B> and <BCLASS="COMMAND">make install</B> steps.The build involves a new executable <BCLASS="COMMAND">rawether</B> whichmust be able to access a raw Linux network device. This is achieved byinstalling it suid root, so the <BCLASS="COMMAND">make install</B> stephas to be run with superuser privileges.    </P><DIVCLASS="CAUTION"><P></P><TABLECLASS="CAUTION"BORDER="1"WIDTH="100%"><TR><TDALIGN="CENTER"><B>Caution</B></TD></TR><TR><TDALIGN="LEFT"><P>Installing <BCLASS="COMMAND">rawether</B> suid root introduces apotential security problem. Although normally<BCLASS="COMMAND">rawether</B> is executed only by the I/O auxiliary,theoretically it can be run by any program. Effectively it gives anyuser the ability to monitor all ethernet traffic and to injectarbitrary packets into the network. Also, as with any suid rootprograms there may be as yet undiscovered exploits. Users and systemadministrators should consider the risks before running <BCLASS="COMMAND">makeinstall</B>.     </P></TD></TR></TABLE></DIV><P>There are two main ways of building the host-side software. It ispossible to build both the generic host-side software and allpackage-specific host-side software, including the ethernet support,in a single build tree. This involves using the<BCLASS="COMMAND">configure</B> script at the toplevel of the eCosrepository. For more information on this, see the<TTCLASS="FILENAME">README.host</TT> file at the top of the repository.Note that if you have an existing build tree which does not includethe synthetic target ethernet support then it will be necessary torerun the toplevel configure script: the search for appropriatepackages happens at configure time.    </P><P>The alternative is to build just the host-side for this package.This requires a separate build directory, building directly in thesource tree is disallowed. The <BCLASS="COMMAND">configure</B> optionsare much the same as for a build from the toplevel, and the<TTCLASS="FILENAME">README.host</TT> file can be consulted for moredetails. It is essential that the ethernet support be configured withthe same <TTCLASS="OPTION">--prefix</TT> option as other eCos host-sidesoftware, especially the I/O auxiliary provided by the architecturalsynthetic target HAL package, otherwise the I/O auxiliary will beunable to locate the ethernet support.    </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-OPTIONS"></A><H2>Target-side Configuration Options</H2><P>The target-side code can be configured to support up to four ethernetdevices, <TTCLASS="VARNAME">eth0</TT> to <TTCLASS="VARNAME">eth3</TT>. Bydefault <TTCLASS="VARNAME">eth0</TT> is enabled if the configurationincludes a TCP/IP stack, otherwise it is disabled. The other threedevices are always disabled by default. If any of the devices areenabled then there will also be the usual configuration optionsrelated to building this package. Other options related to networkdevices, for example whether or not to use DHCP, are provided bythe generic network device package.    </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-REAL"></A><H2>Real Ethernet</H2><P>One obvious way of providing a synthetic target eCos application withethernet I/O is to use a real ethernet device in the PC: transmittedpackets go out on a real network, and packets on the network addressedto the right MAC address are passed on to eCos. This way synthetictarget networking behaves just like networking on a real target withethernet hardware. For example, if there is a DHCP server anywhere onthe network then eCos will be able to contact it during networkingstartup and get hold of IP address information.    </P><P>Configuring the ethernet support to use a real ethernet devicerequires a simple entry in the target definition file:    </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet {    &lt;eCos device&gt; real &lt;linux device&gt;    &#8230;}</PRE></TD></TR></TABLE><P>For example, to map the eCos network device <TTCLASS="VARNAME">eth0</TT> tothe Linux device <TTCLASS="VARNAME">eth1</TT>:    </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet {    eth0 real eth1    &#8230;}</PRE></TD></TR></TABLE><P>It is not possible for an ethernet device to be shared by both theeCos TCP/IP stack and the Linux one: there would be no simple way towork out which stack incoming packets are intended for. In theoryit might be possible to do some demultiplexing using distinct IPaddresses, but it would be impossible to support some functionalitysuch as DHCP. Therefore the <BCLASS="COMMAND">rawether</B> program willrefuse to access any ethernet device already in use. On a typicalLinux system <TTCLASS="VARNAME">eth0</TT> will be used for Linuxnetworking, and the PC will have to be equipped with additionalethernet devices for use by eCos.    </P><P>The <BCLASS="COMMAND">rawether</B> program will access the hardware viathe appropriate Linux device driver, so it is important that thesystem is set up such that the relevant module will be automaticallyloaded or is already loaded. The details of this will depend on theinstalled distribution and version, but typically it will involve anentry in <TTCLASS="FILENAME">/etc/modules.conf</TT>.    </P></DIV><DIVCLASS="REFSECT1"><ANAME="DEVS-ETH-ECOSYNTH-ETHERTAP"></A><H2>Ethertap</H2><P>The Linux kernel's ethertap facility provides a virtual networkinterface. A Linux application, for example the<BCLASS="COMMAND">rawether</B> program, can open a special characterdevice <TTCLASS="FILENAME">/dev/net/tun</TT>, perform various<TTCLASS="FUNCTION">ioctl</TT> calls, and then <TTCLASS="FILENAME">write</TT>and <TTCLASS="FILENAME">read</TT> ethernet packets. When the device isopened the Linux kernel automatically creates a new network interface,for example <TTCLASS="VARNAME">tap0</TT>. The Linux TCP/IP stack can bemade to use this network interface like any other interface, receivingand transmitting ethernet packets. The net effect is a virtual networkconnecting just the Linux and eCos TCP/IP stacks, with no other nodesattached. By default all traffic remains inside this virtual networkand is never forwarded to a real network.    </P><P>Support for the ethertap facility may or may not be providedautomatically, depending on your Linux distribution and version. Ifyour system does not have a device <TTCLASS="FILENAME">/dev/net/tun</TT>or a module <TTCLASS="FILENAME">tun.o</TT> then the appropriate kerneldocumentation should be consulted, for example<TTCLASS="FILENAME">/usr/src/linux-2.4/Documentation/networking/tuntap.txt</TT>.If you are using an old Linux kernel then the ethertap functionalitymay be missing completely. When the <BCLASS="COMMAND">rawether</B>program is configured and built, the <BCLASS="COMMAND">configure</B>script will check for a file <TTCLASS="FILENAME">/usr/include/linux/if_tun.h</TT>. If thatfile is missing then <BCLASS="COMMAND">rawether</B> will be built withoutethertap functionality, and only real ethernet interfaces will besupported.    </P><P>The target definition file is used to map eCos network devices on toethertap devices. The simplest usage is:    </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">synth_device ethernet {    eth0 ethertap    &#8230;}</PRE></TD></TR></TABLE><P>The Linux kernel will automatically allocate the next available tap

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -