发信人: bigapple (红富士), 信区: NTM
标 题: (Embedded RT-Linux Part1)General Introduction
发信站: 哈工大紫丁香 (Wed Jun 21 09:15:59 2000) , 站内信件
Embedded RT-Linux
Part 1: General Introduction
by Ingo Cyliax
Ingo kicks off this miniseries on using Linux as an embedded operating system
with an overview and a comparison to other freely available OSs. As we start s
eeing more and more projects that use Linux, it’ll be pretty clear why they d
o.
In past columns dealing with real-time operating systems, I’ve mentioned Linu
x and explained how I use it as a development system and the primary OS on my
laptop. Starting this month, I want to show you how to use Linux as an embedde
d OS—even as a real-time embedded OS.
I’ve been a Linux user and developer for about two years. I’m also a fan of
other freely distributed Unix-like OSs, like NetBSD and FreeBSD. Both are dire
ct descendents of the BSD (Berkeley Software Distribution) operating systems.
I still use them for other projects. For example, my web and mail server runs
FreeBSD.
But, Linux has such a huge following, I wanted to make sure you had the latest
information. I also discuss some differences between Linux and FreeBSD/NetBSD
.
INTRODUCING LINUX
Linux is an alternative OS for PC (and non-PC) platforms. There are really two
aspects to what is generally considered Linux—the kernel, which is the true
Linux component, and the applications that have been developed and ported to L
inux. The applications range from clones of simple Unix command-line utilities
like ls and vi to C and Fortran compilers and even commercial applications.
Together, the Linux kernel and the extensive applications that come bundled wi
th it are called distributions.
Also, the kernel and a number of applications are available under the GNU copy
right, or GPL. Check out Pat Villani’s series of excellent articles on FreeDO
S (INK 95–96), where he describes the GPL and the issues concerning the embedded-systems integrator.
I should note that one of the differences between the Linux kernel and the Net
BSD/FreeBSD kernel is that the Linux kernel is GPL protected whereas the other
s are not. Whether GPL is right for your project depends on your requirements.
Usually, it’s not a problem. GPL only requires you to make available the sour
ces for components that are already under GPL. Other components, applications,
and modules that you develop can be excluded.
A real-time extender, which extends the kernel using a dynamically loadable mo
dule, is also freely available. It works similar to real-time extenders for OS
s like Windows NT, by dividing applications into processes and threads that ar
e real-time aware and standard user processes that go unaffected. There’s mor
e, but I’ll get into Linux’s real-time extension in a later column.
WHY LINUX?
Naturally, this question is tugging at your brain. There are several reasons t
o consider Linux as an embedded operating system for many applications.
For one thing, it’s freely available and includes a TCP/IP stack. Also, it ha
s multiarchitecture support for Intel, 68k, PowerPC, Alpha, Sparc, SMP, and ot
hers. So, you can obtain and begin using Linux with very little trouble.
One of the great benefits of using Linux is the large support network that exi
sts for it, and let’s not forget the fact that Linux supports many devices an
d bus architectures right out of the box. Of course, Linux is somewhat modular
and there are many tools and programming languages available. With features l
ike this, Linux starts to make more sense, huh?
Let’s talk about these points in more detail. I already mentioned that Linux
is freely available. Obviously, that’s nice because you won’t pay royalties
for embedding Linux in your product. But, you need to make sure all of the mod
ules and components you plan to use for your project are freely available. Mos
t are.
You can download most Linux distributions from the Internet. But, this can be
tedious over a slow link, so most of us opt to buy a CD-ROM. Yet, being able t
o download a distribution over the ’Net is extremely useful if you’re in the
field and need to upgrade you embedded system or get a new version of a devic
e driver.
Linux has a TCP/IP stack built in. The TCP/IP implementation is very robust, s
ince many Internet-service providers use Linux for their high-throughput web s
ervers. The programming interface for the TCP/IP stack is the standard Socket
API.
Linux runs on a multitude of architectures. I’m only going to talk about the
Intel port, but it’s good to know that you’re not stuck with Intel. Some of
the details in each port are different, but for the most part, Linux is Linux,
at least at the application level.
Linux is ported to 68k, which includes VME-bus modules, Alpha, and PowerPCs. A
nd, there’s a port in progress for MIPS processors.
The US Robotics Palm Pilot may be the smallest system that Linux is ported for
. It’s a PDA based on Motorola’s 68328 Dragonball processor. There’s also w
ork in progress to port Linux to smaller Intel processors, like the 80188.
Since Linux has such a great following, there’s a large support network. Alth
ough many people provide Linux support by writing or porting applications and
drivers in an effort to attain fame and glory, there are also several companie
s that are providing commercial support for Linux. Often, these companies rein
tegrate the fixes into the Linux kernel development effort.
There is yet another side effect to this large support group. Many of the fame
-and-glory developers are students who have learned OS internals by observing
the Linux kernel, and they’ll eventually enter the job market.
Consequently, the number of software engineers familiar with Linux is growing,
and they’re even proficient at the kernel level. That’s good news, and perh
aps one compelling reason why much of Linux will stay freely available with th
e GPL.
There are a great number of device drivers available for Linux. Because Linux
has been ported to so many different architectures, it supports various bus ar
chitectures, like ISA bus, PCMCIA, PCI, VME bus, S-bus, and others.
Many vendors of PC-compatible cards have Linux drivers available. While the qu
ality of device drivers for Linux varies, many popular cards and chip sets are
well supported. Also, there’s hope of fixing or adapting the device driver f
or your purposes, since sources are available for most device drivers.
Drivers are available for just about all of the Ethernet chip sets, all standa
rd AT peripherals (COM, IDE, floppy, etc.), and many VGA chip sets. Also, many
CD-ROMs and SCSI devices are supported. Table 1 shows a list of devices that
are supported in an older distribution of RedHat.
Table 1—Here is a list of some of the devices that are typically supported wi
th a standard Linux kernel. In addition to these devices, many peripheral-card
vendors also offer Linux-driver modules for their cards.
Ethernet Controllers
3Com 3c501 (throw it away!)
3Com EtherLink II
3Com Etherlink Plus
3Com EtherLink16
3Com EtherLink III
3Com 3c590/3c595 Vortex
Ansel Communications Model 3200 EISA Ethernet adapter
Apricot 82596
ARCnet for IP driver
Allied Telesis AT1700
DE425, DE434, DE435, DE450, and DE500 DEC EtherWORKS cards
D-Link DE-600 Ethernet pocket adapter
D-Link DE-620 Ethernet pocket adapter
DEC DEPCA and EtherWORKS DE100, DE101, DE200, DE201, DE202, DE210, DE422
Digi RightSwitch SE-4, SE-6
Cabletron E2100
EtherExpress Pro/10
EtherExpress
ICL EtherTeam 16i/32 EISA
EtherWORKS 3: DE203, DE204, DE205
Fujitsu FMV-181/182/183/184
HP PCLAN/plus
HP LAN
HP10/100VG ANY LAN: J2577, J2573, 27248B, J2577, J2573, J2585
Shared-memory IBM Token Ring 16/4
AMD PCnet32, PCnetPCI
NE1000, NE2000, and compatible
NI5210 Ethernet
NI6510 Ethernet
Parallel Link Internet Protocol
Sangoma S502/S508 series multi-protocol PC interface card
SMC Ultra, SMC EtherEZ ISA
SMC 9000 series Ethernet
Starmode Radio IP
DEC 21040, most 21*40 Ethernet
AT&T GIS (nee NCR) WaveLAN Ethernet-like radio transceiver
WD8003- and WD8013-compatible ether cards
SCSI Host Adapters
SCSI driver for Symbios/NCR 53c700 series and 53c800 series host adapters
BusLogic MultiMaster (NOT Flashpoint) SCSI host adapter driver
NCR53c406a-based SCSI host adapter driver
AdvanSys SCSI host adapter driver
Adaptec AHA-152x host adapter driver
Adaptec AHA-154x and 631x-based host adapter driver
Adaptec AHA-174x host adapter driver
Adaptec AHA-2740, 28xx, 29xx, 39xx, aic7xxx-based host adapter driver
DTC 3180/3280 host adapter driver
All DMA-capable DPT SCSI host adapters
All PIO-capable DPT SCSI host adapters
Future Domain TMC-16xx SCSI host adapters
IN2000 SCSI host adapters
Symbios/NCR 53C810, 53C815, 53C820, 53C825 SCSI host adapters
Pro Audio Spectrum/Studio 16
IOMEGA PPA3/Parallel ZIP
Qlogic FAS408 SCSI host adapter
QLogic ISP1020 SCSI host adapter
Seagate ST-01/02, Future Domain TMC-8xx SCSI host adapter
Trantor T128/T128F/T228 SCSI host adapter
UltraStor 14F/34F (not 24F) SCSI host adapter
UltraStor 14F/24F/34F SCSI host adapter
WD7000-FASST2/WD7000-ASC/WD7000-AX/WD7000-EX SCSI host adapter
CD-ROM Drivers
Aztech CD268 CD-ROM driver
Sony CDU-31A CD-ROM driver
Philips/LMS cm20 CD-ROM driver
GoldStar R420 CD-ROM driver
ISP16/MAD16/Mozart soundcard-based CD-ROM driver
Mitsumi CD-ROM driver
Mitsumi XA/Multisession CD-ROM driver
SoundBlaster Pro/Matsushita/Panasonic/Longshine/CreativeLabs/TEAC/ECS-AT CD-RO
M
Sanyo CD-ROM device driver
Sony CDU-535 CD-ROM driver
However, a flash file-system driver isn’t supported. That’s unfortunate. It
would be nice for working with embedded systems. Hopefully, someone is working
on it.
But, all is not lost—it’s still possible to boot Linux from a flash file sys
tem. Flash disks, like SanDisk’s CompactFlash devices, work under Linux becau
se it acts just like a IDE drive. Next month, I’ll look at these issues in de
tail when I embed Linux.
Linux supports dynamic module loading, which means libraries and devices drive
rs can be loaded by the OS after boot time to extend the base functionality of
the kernel. Dynamic modules are nothing new, but they do make configuration e
asy.
You build a simple kernel that can be configured to deal with different device
configurations by changing a configuration file. This construction also impro
ves memory use, since only the required device drivers are loaded when needed.
Of course, you can still configure a Linux kernel to be static by compiling i
n all the device drivers it needs for a particular application.
Many applications and programming languages are available for Linux. This feat
ure might not be important for building embedded systems, but it’s nice to ha
ve access to all the applications on your development system.
The normal compiler used for Linux is the GNU C compiler (a complete C, C++, a
nd Objective C compiler). The companion debugger (gdb) is flexible and can eve
n deal with remote debugging via Ethernet or serial port. This capability mean
s that you can debug your embedded system remotely from a desktop or, in my ca
se, a laptop. Of course, you can also run the debugger on the console of the e
mbedded system.
In conjunction with the GNU C compiler and related tools, you’ll find commerc
ial compiler and development environments. I listed one compiler vendor in my
sources, and you can find others in the Linux Journal.
RUNNING SUPPORT
Although the recommended minimum size for running Linux with X-Windows is usua
lly 8–16 MB, it’s overkill for running Linux in an embedded system. What is the minimum configuration we need?
To run Linux on a PC architecture, we need at least an i386-class machine beca
use Linux has to run in 32-bit protected mode. Several embedded ’386 boards o
ut there should run Linux just fine.
In fact, I was even able to boot and run Linux on my 16-MHz ’386SX laptop wit
h 5 MB of memory. It runs fine, although you probably don’t want to compile a
program or run an Xserver on it. But then, that’s not the point of a minimum
system.
The minimum memory configuration to load a standard Linux kernel and have it b
e able to do something is 4 MB. It should be possible to configure and build a
minimum size kernel that should work in about 2 MB.
Now we have an i386 and 4 MB of memory, what else do we need? Well, to boot Li
nux, we need a boot device.
Linux can’t use flash memory as disks, but it can boot from it. In fact, Linu
x can load and initialize the kernel using any kind of boot device the BIOS ca
n handle. So, it’s possible to boot Linux from a flash memory after all, but
it can’t access the boot flash-memory disk once it’s loaded.
You may ask, what good is it to boot from flash memory if you can’t access th
e disk after booting? Well, there are at least two techniques you can use to i
nitialize an initial RAM disk while booting, and this RAM-disk image can conta
in the essentials of what’s needed to run Linux.
What do we need to run Linux once the kernel has booted? By incorporating our
system into one Linux program, we can get away with a small set of files. List
ing 1 has the details.
Listing 1—You need this minimum set of files to boot Linux and start an appli
cation program. Of course, you need to add more device-driver entries in the /
dev directory if your application needs to access other devices besides the sc
reen and the RAM disk.
/lib
/lib/libc.so.5
/lib/ld-linux.so.1
/bin
/bin/sh
/bin/insmod
/etc
/etc/ld.so.cache
/dev
/dev/console
/dev/null
/dev/ram
/dev/systty
/dev/tty1
/dev/tty2
/dev/tty3
/dev/tty4
/linuxrc
The most critical components are the console device entry /dev/console and wha
tever device entries that are needed. Once booted, the kernel opens and runs w
hatever program or command script is contained in /linuxrc. That’s about all
you need for a minimal configuration.
Even though Linux wasn’t designed as an embedded OS, it ended up having featu
res like small initial size and capability for RAM disks and modular device dr
ivers. These features are there because the developers wanted Linux to be easy
to install.
A single floppy can hold a complete mini-Linux system, complete with enough ut
ilities to format and initialize the file system on a hard disk and do a boots
trap install of Linux from another medium. We can use this to our advantage by
including our embedded applications, instead of the installation utilities to
build an embedded Linux system.
Now let’s look at a system I’ve been using to play around with embedded Linu
x. It’s based on Motorola’s embedded Pentium SBC, the NLX 55, shown in Photo
1.
Photo 1—The Motorola NLX55 motherboard features a Pentium MMX CPU, graphics c
ontroller, and 10-/100-Mbps Ethernet controller. Unique to this board, it also
includes a socket for a SanDisk flash-based ATA card.
The motherboard contains everything needed to build a system and run an embedd
ed application. It has a 233-MHz Pentium MMX CPU, slots for two DIMM modules,
10-/100-Mbps Ethernet controller, dual-IDE controller, floppy control, and SVG
A controller. It also contains a flash-card socket on the motherboard.
SanDisk’s CompactFlash is a flash-based media that contains an IDE controller
on the card itself. To the system, it looks just like another IDE drive. Moto
rola also sells a starter system that includes a case and power supply as well
as a standard IDE drive for development.
With this system, you can develop embedded applications while running off the
hard disk and build a flash-card module of our embedded system. Then, just reb
oot, change the boot sequence in the BIOS setup, and have the system boot from
the flash card to test your application. Next month, I’ll use it to build a
flash card-based Linux installation.
INSTALLING LINUX
Obtaining Linux is easy. As I said, you can get most Linux distributions from
the ’Net for free. All you need is patience while downloading it. You can als
o purchase a CD-ROM of various distributions. Most commonly available distribu
tions have enough of the basic components necessary to allow you to embed Linu
x.
Once you have an installation, you should build a desktop system to serve as y
our development platform. This process is relatively painless and there are a
lot of resources on the ’Net. If your target system is capable enough to serv
e as a development environment, you can install it there.
RT EXTENSION OF LINUX
The standard Linux kernel doesn’t pretend to be real time in the traditional
way. Like many Unix kernels, the kernel is not preemptive and thus can’t be r
elied on for predictable interrupt response. But, some clever people developed
a real-time extender for Linux that turns it into RT-Linux.
RT-Linux has a layer added between the Linux kernel and the hardware timer int
erface. After installing the RT extension, the Linux kernel and its processes
turn into a single real-time task that always runs at the lowest priority.
Real-time applications are loaded into the kernel memory space using the Linux
module facility. Once the application has loaded and started real-time tasks,
the tasks have control of all the hardware and memory in the system. RT-Linux
provides calls to start, suspend, and destroy tasks. There’s also a timer fa
cility to set up timers with real-time responses.
A FIFO is used for real-time tasks to communicate with regular user processes.
The FIFOs appear as standard Unix character devices that a user process opens
and then reads and writes to. Table 2 shows the basic API available in the RT
extender.
Table 2—The real-time extension to Linux (RT-Linux) provides this API for pro
grams that are written to run in this mode. Most of the services are pretty st
andard interfaces you’d see in a bigger RTOS. But, the FIFO interface can be
used to communicate with non-real-time threads.
rtf_create(unsigned int fifo, int size) create a FIFO
rtf_destroy(unsigned int fifo) get rid of the FIFO
rtf_resize(unsigned int minor, int size) change the size of the FIFO
rt_fifo_put(unsigned int fifo, char * buf, int count) write to FIFO
rt_fifo_get(unsigned int fifo, char * buf, int count) read from FIFO
rtf_create_handler(unsigned int fifo, int (*handler)(unsigned int fifo)) crea
te a handler that is called when a user process reads or writes to a FIFO devi
ce
rt_task_init(RT_TASK *task, void (*fn)
(int data), int data, int stack_size, int priority); create a task
rt_task_make_periodic(RT_TASK *task, RTIME start_time, RTIME period); arrange
so that the task is called at a periodic interrupt
rt_task_delete(RT_TASK *task); (int data), int data, int stack_size, int prior
ity); get rid of task
rt_task_wait(void); give up time slice, wait until next time slice
rt_task_suspend(RT_TASK *task); suspend any task
rt_get_time(void); read the current time
rt_request_timer(void (*fn)(void)); allocate a timer, which will call a handle
r when it expires
rt_free_timer(void); return timer
rt_set_timer(RTIME time); set the timer to go off at a specific time
rt_no_timer(void); clear timer
Although, RT-Linux is rather primitive in its implementation, it has the essen
tials you need to implement real-time applications.
WHAT'S NEXT
I’ve given you an overview of Linux and RT-Linux as well as how you can use i
t as an embedded OS. I’ll concentrate on the details of Linux in upcoming art
icles.
Next month, I’ll show you how to embed a minimal Linux configuration into a s
mall system. After that, you’ll learn more about Linux embedded software deve
lopment and how to use RT-Linux.
You’re also likely to see Linux in some of my projects. It may not be the ans
wer for every embedded-systems problem, but it’s another tool in the toolbox.
And since it’s still being developed and is constantly evolving, it will be
interesting to see what problems people end up solving with Linux. RPC.EPC
Ingo Cyliax has been writing for INK for two years on topics such as embedded
systems, FPGA design, and robotics. He is a research engineer at Derivation Sy
stems Inc., a San Diego–based formal synthesis company, where he works on formal-method design tools for high-assurance systems and develops embedded-system products. Before joining DSI, Ingo worked for over 12 years as a system and research engineer for several universities and as an independent consultant. You may reach him at cyliax@derivation.com.
附件:
(0 字节)
附件:
(0 字节)
附件:
(0 字节)
附件:
(0 字节)
附件:
(0 字节)
附件:
(0 字节)
附件:
(10 字节)