Ifyou are a hardware developer, software developer, systemintegrator, or product manager who's begun exploring embedded Linux for interfacing applications, this book isfor you... Linux i
Trang 1• Table of
Contents
•
Embedded Linux®: Hardware, Software, and Interfacing
By Craig Hollabaugh Ph.D
Publisher : Addison WesleyPub Date : March 07, 2002ISBN : 0-672-32226-9Pages : 432
Slots : 1.0
Embedded Linux covers the development and
implementation of interfacing applications on an embeddedLinux platform It includes a comprehensive discussion ofplatform selection, crosscompilation, kernel compilation,root filesystem creation, booting, remote debugging, real-world interfacing, application control, data collection,
archiving, and presentation
This book includes serial, parallel, memory I/O, USB, andinterrupt-driven hardware designs using x86-,
StrongARM®-, and PowerPC®-based target boards Inaddition, you will find simple device driver module codethat connects external devices to the kernel, and networkintegration code that connects embedded Linux field
devices to a centralized control center Examples teachhardware developers how to store and activate field bits anddeliver process information using open source software Ifyou are a hardware developer, software developer, systemintegrator, or product manager who's begun exploring
embedded Linux for interfacing applications, this book isfor you
Trang 2Publisher : Addison WesleyPub Date : March 07, 2002ISBN : 0-672-32226-9Pages : 432
Slots : 1.0
Trang 5
Developing Lift Monitoring and Snow-Making Control for theRPX-CLLF
Trang 7GUI Development
Real-time Capabilities
The Embedded Linux Vendor OfferingsProject Trailblazer Hardware
Summary
Additional Reading
Top
Trang 8Many of the designations used by manufacturers and sellers to distinguish theirproducts are claimed as trademarks Where those designations appear in thisbook, and Addison-Wesley were aware of a trademark claim, the designationshave been printed in initial capital letters or in all capitals
The author and publisher have taken care in the preparation of this book, butmake no expressed or implied warranty of any kind and assume no
responsibility for errors or omissions No liability is assumed for incidental orconsequential damages in connection with or arising out of the use of the
information or programs contained herein
The publisher offers discounts on this book when ordered in quantity for specialsales
mechanical, photocopying, recording, or other-wise, without the prior consent
of the publisher Printed in the United States of America Published
simultaneously in Canada
Library of Congress Catalog Card Number 2001089582
Trang 91 2 3 4 5 6 7 8 9 10—CRS—05 04 03 02First printing, March 2002
Development Editor Mark Cierzniak
Trang 10Lohrding, Darla and Alfred Lorber, Venita and Craig Lujan, Jean and JohnMcLennan, Marce Miller, Lisa and Jim Olwine, Katie Purdum, Anna and MikeSadler, Jennifer and Fritz Siegrist, Karen and John Totten, Karyn Young, andespecially Melanie Kline
Trang 11Top
Trang 12Embedded systems, the once-sleepy backwater of information technology, arenow emerging as a multibillion-dollar industry that is already pervading oureveryday existences and changing our lives Around the world, "smart devices"are insinuating themselves into everyone's daily routine: You drive to work inyour electronically controlled car or ride a digitally guided commuter train, take
a call on your mobile phone, make copies at the office, sit in on a digital
conference call, and then go home and watch a movie from your cable box orDVD player If you look around you, you'll realize that 50 to 100 embeddedcomputers touch your life every day
Linux is taking this world of embedded and pervasive computing by storm.Once dominated by proprietary and obscure operating systems, tools, and
applications, embedded designs today benefit from the transparency and
functionality of open-source software, especially Linux Even conservativeestimates show embedded Linux garnering up to half of all new embeddeddesigns by the end of 2002
In my role at MontaVista Software, I have the pleasure of talking to thousands
of embedded developers and of sneaking glimpses into their varied projects Inthis context I first met Dr Craig Hollabaugh at LinuxWorld in New York in
2001 In the course of his writing this book, I had the pleasure of his companyseveral more times and numerous chats by phone
I find Craig's approach both sensible and comprehensive His choice of anapplication to run the fabled Silverjack winter resort both recalls the "meat andpotatoes" of the embedded applications space (control and instrumentation) andlaunches into today's hot new areas of pervasive computing (embedded Webinterfacing, multimedia, and messaging) His survey of available embeddedhardware and key interface technologies and his step-by-step account of theembedded Linux development process provide invaluable signposts for aspiringsystem designers
Craig's team of trailblazing engineers confronted the daunting task of acquiringand using embedded Linux development tools and deployment components.The Silverjack scenario and the details of the engineering effort mirror the
Trang 13LinuxDevices; and the efforts of embedded Linux platform vendors clear a path
to successful development and deployment of the next generation of smart,Linux-based devices
Trang 14Craig Hollabaugh has been fascinated by electronics since he bought an AMradio in elementary school He was first exposed to Unix during a cross-countrytalk session in 1985 Later, he administered networked Sun and DEC
spectrum 900MHz ISM industrial telemetry products Craig worked with morethan 200 developers, systems integrators, and equipment manufacturers to
In 1995 Craig co-founded Wireless Scientific, where he developed 20 spread-incorporate wireless telemetry within their SCADA applications or productlines In 1996 Wireless Scientific's Global Data Management project used Linux
as a development platform to remotely monitor and control additive tank levels
In 1997 Lanier Corporation charged Craig with architecting its next-generationVoiceWriter, a medical digital dictation and transcription system with revenuesbeyond $100 million His responsibilities included ensuring that product
development followed current/future technological trends, adhered to
technical/medical information standards, and incorporated Lanier's legacy
products
Craig consults from his home in Ouray, Colorado He developed the firmwarefor Antec's flagship cable distribution product, the Proteus Scalable Node AtClifton, Weiss and Associates, Craig is a member of a carrier-class
telecommunications network design team His current responsibilities involvedesigning and analyzing wired and wireless voice and data networks for DallasArea Rapid Transit, Metro North Railroad, New York City Transit, and
Pittsburgh Area Transit He's also designing FM, MP3, and Bluetooth headsetelectronics for Arriva
Trang 15of Ouraynet and his adult education classes in electronics and programming.Most recently, Craig co-founded The Silverjack Baking Company, where hewill bake and sell scrumptious delights from a horse-drawn bakery wagon onOuray's Main Street during the summer months If there's snow flying, you'llmost likely find him snowboarding at Telluride
Top
Trang 16The enthusiasm toward this book has been simply phenomenal Everyone Imention it to has supported my efforts in some way I'd like to start by thanking
a few people who helped me to see my greatness: Katie Purdum, Angelo
d'Amelio, Roger Smith, Gerri Spina, Eva Montibello, and Teresa Loconte
These day-to-day supporters then took over and continued the push: MelanieKline, Josh Kline, Mouse and Harry Durgin, Paul Vallejos, Ben Blouse, ScottKidner, Brian Kopp, and my little baby sister, Karen Totten I attribute the
book's readability to my editing team: John Hollabaugh, Rob Savoye, KittyJarrett, and Mark Cierzniak A special thanks to Rick Lehrbaum, for his
comprehensive embedded Linux Web site, linuxdevices.com I want to thankthese individuals at companies that offered their products and technical supportfor the book's examples: Doug Stead at Tri-M Systems, Stuart Adams at
Brightstar Engineering, Ken Applebaum, John Havre, and Matt Hoover at
Embedded Planet, Eugene Feng at Silicon Storage Technology, Juan Vazquez atESPTech, Tom Barnum at VersaLogic, and Bill Weinburg at MontaVista
Software The work of these individuals also contributed to the examples:
Thomas Oehser, Erik Mouw, Ori Pomerantz, Alessandro Rubini, Jonathan
Corbet, Tim Waugh, Jan Axelson, Craig Peacock, Riku Saikkonen, Jens Gecius,Detlef Fliegl, Brad Hards, Mark Pilon, Daniel Smolik, Markus Schlup, MichaelHipp, David Beal, Wolfgang Denk, Mark Hatle, Dan Malek, Larry Doolittle,and Jim Ready These open-source developers deserve a tremendous
acknowledgement for their activities: all the kernel programmers, Debian,
Apache Software Foundation, MySQL, and GNU This book exists because ofyour contributions, support, and encouragement I thank you
Top
Trang 17This is an exciting time The proliferation of Internet technology has
transformed our concept of information 24 hours per day, people rely on
network devices for business and personal use Over time, this dependence willgrow further Today's network devices, such as servers, routers, and desktopcomputers, form the Internet's infrastructure Tomorrow's devices will controlyour home's temperature, maintain inventory levels at your business, and
monitor automobile traffic patterns Only a handful of the billions of processorsproduced each year go into desktop or server computers The remaining
processors monitor and control other facets of the world
Individuals and businesses want smart, network-connected, devices to improvetheir lives, their efficiency, and their bottom dollar These devices must be
simple to operate, reliable, and inexpensive This is where Linux comes in.Advances in technology accompanied by competitive pricing allow Linux tomove from the desktop and server environment to embedded devices Linuxoffers reliability, features, open-source code, and a proven track record; thesefeatures make it perfectly suited for embedded system designs In this book, youwill find information to create an embedded Linux foundation You can thenextend this foundation in your own designs
Top
Trang 18When I first started researching material for this book, I assumed that onlineembedded Linux information was like other Linux information—plentiful andwell documented I quickly discovered that my assumption was wrong I foundembedded Linux documentation to be sparse, scattered, incomplete, and
sometimes dated This was discouraging and invigorating at the same time.Although I worried about being able to find adequate information, I was furtherconvinced of the need for this book People are designing embedded productswith Linux, so the information and knowledge are out there; it just hasn't allbeen in one place until now
As an instructor, I have determined that students best understand and retaintheoretical concepts and ideas when accompanied by examples When studentssee a concept in action—whether it is a robotic arm movement, a voltmeterreading, or an oscilloscope waveform—they're most likely to later apply thatconcept to solve their own problems That's why this book is full of step-by-stepexamples You will learn through the example and be able to apply that
knowledge to your own designs
Top
Trang 19This book includes a complete series of real-world interfacing examples
designed to introduce embedded Linux from hardware and software
perspectives After you create an embedded Linux development environment,you will step through hardware and software interfacing examples, using
asynchronous serial communication, the PC parallel port, USB, memory I/O,synchronous serial communication, and interrupts All interfacing examples arethen tied together using system integration All this material is presented byusing a winter resort automation project called Project Trailblazer You can findthe book's source code and scripts at www.embeddedlinuxinterfacing.com.The following text briefly summarizes each chapter
Chapter 1, "Introducing Embedded Linux," describes the brief history of Linux
as an embedded operating system and the implications of using open-sourcesoftware in product design
Chapter 2, "System Architecture," introduces a winter resort automation projectcalled Project Trailblazer and develops a series of project requirements ProjectTrailblazer and its requirements form the basis for the book's interfacing
examples
Chapter 3, "Selecting a Platform and Installing Tool Sets," describes the process
of platform selection Four target boards—which use x86, StrongARM, andPowerPC processors—are selected for Project Trailblazer This chapter thendescribes the creation of an embedded Linux development workstation called
tbdev1 All the development tools are either installed or compiled, including thecross-compiled tool chain for the StrongARM and PowerPC processors
Trang 20Chapter 7, "Parallel Port Interfacing," describes interfacing AC circuits to anx86 target board's parallel printer port A custom device driver called
helloworld_proc_module that uses a /proc directory entry is introduced
Chapter 8, "USB Interfacing," describes connecting a camera and speakers forvisual input and audio output to a target board's USB port
Chapter 9, "Memory I/O Interfacing," describes interfacing AC circuits to theStrongARM and PowerPC target boards' CPU buses
Chapter 10, "Synchronous Serial Communication Interfacing," describes SPIand I2C connections and communications A low-cost SPI temperature sensorand I2C LED display driver are interfaced to the target boards
Chapter 11, "Using Interrupts for Timing," describes Linux timing sources andthe measurement of each target board's average interrupt latency An event timerwith 1ms accuracy is developed to measure race times
Trang 21If you are a hardware engineer, software developer, system integrator, or
product manager who's begun exploring embedded Linux for interfacing
applications, then this book is for you The book's comprehensive interfacingexamples are simple, requiring only a basic understanding of digital logic
design, C and bash programming, and Linux system administration
Top
Trang 22This book uses several common conventions to help teach embedded Linux.The typographical conventions used in this book include the following:
Commands and computer output appear in a monospaced computer font.Commands you type appear in a boldfaced computer font
Italics are used to introduce you to new terms
In addition to typographical conventions, this book includes tips, which looklike this:
Trang 24In a couple years, it's likely that a fair percentage of the billions of processorsproduced every year will run Linux The massive Internet adoption of Linux,combined with technology advances and price reductions in hardware (CPUs)and memory (both flash and RAM), finally make embedding Linux a viableoption Since 1999 use of embedded Linux has gone from zero adoption totaking second place, in terms of market share, behind Wind River.1 Expertsestimate that embedded Linux will take over the number-one market share
position by the end of 20021 This is very interesting, considering that Linuxactually started as student project so many years ago Linux can become numberone, through the adoption of embedded Linux for designs that become products
Trang 25
Top
Trang 26Microprocessor industry advances form the foundation for using Linux as anembedded operating system Gone are the days of embedded designs that use 4-
bit microprocessors with several megabytes of memory The ever-changing pace
or 8-bit microprocessors; today it is just as easy and cost competitive to use 32-of hardware innovation and obsolescence presents an enormous developmentchallenge for real-time operating system (RTOS) vendors With limited
resources, these RTOS vendors make business decisions that often leave manydevelopers unsupported Developers always want the latest and greatest
hardware and software for their new embedded designs while also requiringhigh reliability Desktop operating systems provide the latest in software butlack reliability and require more memory and CPU resources RTOS vendorsoffer reliability but struggle with software development in the ever-changingworld of technology This is where Linux comes in
Linux offers reliability and efficiency, with a proven track record Open-sourcecode availability has spawned countless improvements, enhancements, andadditions in terms of performance, functionality, driver development, and
porting activities Designers of embedded systems like open-source softwarebecause they often modify subsystem code for their designs Linux supportsPortable Operations System Interface (POSIX), which allows developers toeasily port existing code Linux is successfully ported to several
microprocessors, including x86, SPARC, ARM, PowerPC, MIPS, and SuperH
Initially, developers were apprehensive about considering Linux as an
embedded operating system option because of its distributed development
approach and a perceived lack of support structure The support structure forembedded Linux has changed dramatically since 1999, thanks largely to theEmbedded Linux Consortium (ELC), which was founded with 50 members inMay 2000 and now has membership exceeding 125 companies This consortiumworks toward standardizing and promoting Linux for use in embedded
applications In addition, several companies were founded solely for embeddedLinux These companies don't merely repackage distributions and sell CDs.They have a wide range of embedded Linux products as well as design andsupport services Using embedded Linux, developers can design high- reliabilityproducts, using the latest and greatest hardware and software
Trang 27Top
Trang 28If you ask a dozen engineers to define embedded system, you'll get a dozendifferent answers Most embedded systems perform specific tasks Let's assumethat the simplest embedded system contains input and output capability, as well
as control logic This system performs some type of functionality, based on itsconfiguration Using these criteria, a discrete logic circuit that contains a 74123counter that implements control logic with a state machine could be considered
an embedded system You might add that this system needs to be
programmable, via software, and stored in the system firmware This new
definition for an embedded system consists of input/output (I/O) and controllogic stored in system firmware A desktop computer with a mouse, a keyboard,
a network connection, and a multitasking operating system running a graphicaluser interface (GUI) fulfills these requirements, but is it considered an
embedded system?
If you don't consider a desktop machine an embedded system, then what abouthandheld devices? They have I/O capability and can run control logic that'sstored in firmware Some say that desktop computers and handhelds are
general-purpose computing devices that are capable of running software toperform many different tasks An embedded system, on the other hand, is
primarily designed for a specific task—for example, a dishwasher controller orflight navigation system This specific functionality defines the sole purpose ofthe embedded design If that's the case, why are some embedded systems
designed with additional capability, such as program storage in nonvolatilememory and the capability of running multitasking operating systems that arecapable of executing additional tasks beyond the original design?
control a set-top box with a GUI, that is field upgradable, that simultaneouslyruns multiple programs (such as a video controller, a digital VCR, and the JavaVirtual Machine), and that makes secure Internet transactions It's hard to say
Trang 29hardware performance and the lower cost of that hardware has blurred the linebetween general-purpose computers and embedded systems Technology
advances have therefore made it hard to say what is embedded
Top
Trang 30If you ask engineers what real-time means, you'll get a number of differentanswers, filled with terms such as guarantees, hard, soft, deterministic,
preemptive, priority inversion, latency, interrupts, and scheduling Rick
Lehrbaum of linuxdevices.com posed that question to seven experts.3 Theseexperts somewhat agreed that a hard real-time system guarantees a deterministicresponse to an event and that a late response is considered a system failure.They also somewhat agreed that soft real-time systems attempt to minimizeevent response time and don't consider late responses a system failure Theexperts' opinions diverged when addressing real-time implementation and
system performance characterization
One performance aspect of Linux is clear: Stock Linux allows the kernel anddevice drivers to disable interrupts.4 This could seriously affect a system's
responsiveness Fortunately, open-source code availability has allowed solutions
to be developed to overcome this limitation These solutions follow two
approaches: Improve the Linux scheduler by making the kernel preemptive andrun Linux as a thread within a small RTOS Naturally, each approach has
advantages, disadvantages, supporters, and opponents
Top
Trang 31Open-source software—with its accessibility, reliability, and means of support
—clearly threaten the commercial software vendors who provide proprietarysolutions Using Linux for embedded development threatens the future marketshare for companies such as Microsoft and Wind River It's in their best
business interests to spread fear, uncertainty, and doubt within the embeddedindustry.5,6 For many years, Microsoft didn't consider Linux a threat in thedesktop, server, or embedded arenas That situation has changed, as Microsofthas stated that Linux is now its number-one target.7 Microsoft's attention toLinux further enhances Linux's position as a viable option for embedded
development Many developers see open source as a building block to createpowerful products Microsoft sees Linux as a threat to its future dominance ofthe embedded operating systems
Use of open-source software has specific implications In the context of usingLinux for embedded design, open-source software has to do with a particularlicensing model called the General Public License (GPL).8 (The entire GPL isnot covered here, but we will address some GPL requirements that affect youand your embedded Linux design.)
Linus Torvalds originally released the Linux kernel source under GPL Thismeans that you are free to use and redistribute Linux without royalty or
licensing fees, but you must make the Linux source code available to your
customers You can't sell Linux, but you can sell any distribution media or
enhancements that you develop For example, when you purchase a Red HatLinux product, you aren't buying Linux from Red Hat; you're buying Red Hat'senhancements to Linux Red Hat's enhancements include a program that
simplifies the installation process and some other goodies GPL states that all
"derived work" must also be released under GPL This means that if you modifysome piece of Linux kernel code, your modification is also covered under GPL
If you distribute a product based on your modified kernel code, you must makeavailable not only the original kernel source but also your modifications to it, insource form At this point, you may be asking, "If I never touch the kernel
source code but just use Linux for a product, how does GPL affect me? Do Ireally have to make my product available in source form?" The answer depends
Trang 32Let's assume, for example, that your embedded product contains a device driver
or kernel module that you developed You have an option to include that devicedriver in the kernel binary code at compile time or deploy the driver as a
loadable module If you build and distribute a kernel that includes your devicedriver, then your device driver code is automatically included under the GPLand you must make its source code available to your customers Device drivers
or modules that load dynamically after the kernel boot process are not includedunder the GPL, and you don't have to distribute your source code
NOTE
Designing products with Linux and other open-source software doesn't meanyou have to make your software open source Use of loadable modules andLGPL libraries protects your intellectual property
If an embedded product executes solely in the user space (that is, it has no
kernel code or device drivers), it is not affected by the Linux kernel source codeGPL An embedded product running an application in the user space can beaffected through linking to libraries that are included under the GPL or anotherlicensing model, called LGPL Originally called the Library General PublicLicense, LGPL now stands for Lesser General Public License This licensingmodel allows developers to link to code, such as libraries, without having theircode automatically included under the GPL GNU released glibc under LGPL.9
If an embedded application statically or dynamically links to glibc for
functionality, the application is not included under the GPL or LGPL, and you
do not have to release your source code
Use of open-source software promotes creativity and allows developers to
quickly design embedded applications that are reliable and robust Basing yourembedded design on open source software doesn't automatically mean that youhave to release your intellectual property in source form It's quite possible thatyou can develop device drivers and kernel modules that load after the kernelboot process and your user space application code links to LGPL libraries
Trang 33Top
Trang 34Linux was created more than a decade ago Since then, countless programmershave enhanced it, given it more features, and made it efficient, reliable, androbust Today, thousands of businesses rely on Linux for daily client and serveroperations Linux has a proven track record Commodity pricing of
microprocessors and memory devices will make future embedded designs using32-bit architectures commonplace Linux is already ported to these architecturesand embedded Linux products exist in the marketplace Embedded system
designers adopting Linux enjoy open-source code availability, POSIX
compliance, solid reliability, a large application base, and no licensing fees.These benefits, combined with commodity pricing, make Linux an excellentsolution for an embedded operating system
Top
Trang 36an overall understanding of the project or product System architectures providethe big picture Furthermore, a set of high-level system requirements help todefine the system architecture Also, a system architecture does not addresstechnical details of its blocks Details, such as component specification andselection, are determined during a block's design phase
This chapter introduces Project Trailblazer, a winter resort automation project.This project starts with the formation of the high-level system requirements,which will develop into a system architecture consisting of functional blocksand their interfaces This chapter does not address any technical details
concerning the functional block; it merely defines the Project Trailblazer systemarchitecture This book follows the Project Trailblazer development and thedesign and implementation of its functional blocks using embedded Linux
Top
Trang 37Silverjack Resort, located somewhere in the Rocky Mountains, is booming withactivity Guests from around the world travel to Silverjack to enjoy winter
activities in a scenic location Thanks to abundant natural and manufacturedsnow, the sporting season extends from November through April Silverjack's
10 lifts offer guests access to a wide variety of terrain, whether they're skiers,snowboarders, or snowshoers All these factors make Silverjack an attractivewinter resort destination Revenues have continually increased since the initialopening season, making the board of directors and investors happy The
forward-thinking Resort board members know that application of technologycan make the mountain safer, the operations more efficient, and the guests'experience more enjoyable They know that cutting-edge technology can helpattract customers to Silverjack
The board allocated funds for Project Trailblazer, which is a data acquisitionand control system serving all of the Silverjack Resort The board wants thisinformation system to be reliable, robust, and low cost; to use off-the-shelfhardware; and to be designed, deployed, and tested within six months
The Silverjack Engineering Department, with input from the Operations
Department, developed a set of high-level requirements in three areas: safety,operations, and suppliers These requirements don't contain any specific
technical details Rather, they offer guidelines to what needs to be developed.The board reviewed and approved these high-level requirements They gave theEngineering Department a green light to start Project Trailblazer
With great enthusiasm, the Engineering Department started designing ProjectTrailblazer It quickly discovered that Project Trailblazer was basically a giantintegration project with a short development timeframe The department needs aflexible and reliable solution that connects serial, parallel, input/output (I/O)port, and universal serial bus (USB) devices to the operations center After thedepartment attended a conference on embedded systems, the answer was clear:
It needed to use embedded Linux
Trang 38Top
Trang 39Silverjack Resort consists of 10 lifts serving three mountain peaks, a racecourse,and an aerial acrobatic area called the AirPark Snow-making equipment existsalong Lifts 4, 5, and 10 Guests have access to Lifts 4, 7, and 10 from the
village The Operations Control Center (OCC) in the village houses the
Operations, Information Technology (IT), and Engineering Departments Ahybrid fiber/copper network provides 10BaseT connectivity to all resort areasand facilities All networking and computer equipment reside behind a firewallthat uses private Class C addresses The IT Department allocated the privateClass C subnet 192.168.2.0 for Project Trailblazer's field equipment
Figure 2.1 shows Silverjack's physical layout, which includes the OCC, 10 lifts,and Project Trailblazer's data acquisition and control electronics
Figure 2.1 Silverjack's physical layout.
Figure 2.2 shows the Silverjack network This hybrid copper/fiber network
Trang 40Figure 2.2 Silverjack's data network.
Figure 2.3 details Silverjack's OCC, which is located in the village TheSilverjack router contains three interface cards that make connections to theInternet, Trailblazer mountain equipment, the Silverjack server, and theEngineering Department The subnet and host addresses are shown in Figure2.3
Figure 2.3 Silverjack's OCC.