You are previewing Building Embedded Linux Systems, 2nd Edition.
O'Reilly logo
Building Embedded Linux Systems, 2nd Edition

Book Description

There's a great deal of excitement surrounding the use of Linux in embedded systems -- for everything from cell phones to car ABS systems and water-filtration plants -- but not a lot of practical information. Building Embedded Linux Systems offers an in-depth, hard-core guide to putting together embedded systems based on Linux. Updated for the latest version of the Linux kernel, this new edition gives you the basics of building embedded Linux systems, along with the configuration, setup, and use of more than 40 different open source and free software packages in common use. The book also looks at the strengths and weaknesses of using Linux in an embedded system, plus a discussion of licensing issues, and an introduction to real-time, with a discussion of real-time options for Linux. This indispensable book features arcane and previously undocumented procedures for:

  • Building your own GNU development toolchain

  • Using an efficient embedded development framework

  • Selecting, configuring, building, and installing a target-specific kernel

  • Creating a complete target root filesystem

  • Setting up, manipulating, and using solid-state storage devices

  • Installing and configuring a bootloader for the target

  • Cross-compiling a slew of utilities and packages

  • Debugging your embedded system using a plethora of tools and techniques

  • Using the uClibc, BusyBox, U-Boot, OpenSSH, thttpd, tftp, strace, and gdb packages

  • By presenting how to build the operating system components from pristine sources and how to find more documentation or help, Building Embedded Linux Systems greatly simplifies the task of keeping complete control over your embedded operating system.

    Table of Contents

    1. Preface
      1. Focus on Self-Sufficiency
      2. Audience for This Book
      3. Scope and Background Information
      4. Organization of the Material
      5. Hardware Used in This Book
      6. Software Versions
      7. Typographical Conventions
      8. Using Code Examples
      9. Contact Information
      10. Safari® Books Online
      11. Acknowledgments for the First Edition
      12. Acknowledgments for the Second Edition
    2. 1. Introduction
      1. Definitions
        1. What Is Linux?
        2. What Is Embedded Linux?
        3. What Is Real-Time Linux?
      2. Real Life and Embedded Linux Systems
        1. Types of Embedded Linux Systems
          1. Size
          2. Time constraints
          3. Networkability
          4. User interaction
        2. Reasons for Choosing Linux
          1. Quality and reliability of code
          2. Availability of code
          3. Hardware support
          4. Communication protocol and software standards
          5. Available tools
          6. Community support
          7. Licensing
          8. Vendor independence
          9. Cost
        3. Players in the Embedded Linux Scene
          1. Free software and open source community
          2. Industry
          3. Resources
        4. Copyright and Patent Issues
          1. Textbook GPL
          2. Pending issues
          3. RTLinux patent
        5. A Word on Distributions
          1. To use or not to use
          2. How to choose a distribution
          3. What to avoid doing with a distribution
      3. Design and Implementation Methodology
        1. Creating a Target Linux System
        2. Setting Up and Using Development Tools
        3. Developing for the Embedded
        4. Networking
    3. 2. Basic Concepts
      1. Types of Hosts
        1. Linux Workstation
        2. Unix Workstation
        3. Windows (Vista, XP, 2000, NT, 98, etc.) Workstation
      2. Types of Host/Target Development Setups
        1. Linked Setup
        2. Removable Storage Setup
        3. Standalone Setup
      3. Types of Host/Target Debug Setups
      4. Generic Architecture of an Embedded Linux System
      5. System Startup
      6. Types of Boot Configurations
        1. Solid-State Storage Media
        2. Disk
        3. Network
      7. System Memory Layout
    4. 3. Hardware Support
      1. Processor Architectures
        1. ARM
        2. AVR32
        3. Intel x86
        4. M32R
        5. MIPS
        6. Motorola 68000
        7. PowerPC
        8. SuperH
      2. Buses and Interfaces
        1. PCI/PCI-X/PCIe
        2. ExpressCard (Replaces PCMCIA’s PC Card)
        3. PC/104, PC/104-Plus, PCI-104, and PCI/104-Express
        4. CompactPCI/CompactPCIe
        5. SCSI/iSCSI
        6. USB
        7. IEEE1394 (FireWire)
        8. InfiniBand
        9. GPIB
        10. I<sup xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">2</sup>CC
      3. I/O
        1. Serial Port
        2. Parallel Port
        3. Modem
        4. Data Acquisition
        5. Keyboard
        6. Mouse
        7. Display
        8. Sound
        9. Printer
      4. Storage
        1. Memory Technology Devices
        2. PATA, SATA, and ATAPI (IDE)
        3. Non-MTD Flash-Based devices
      5. General-Purpose Networking
        1. Ethernet
        2. IrDA
        3. IEEE 802.11A/B/G/N (Wireless)
        4. Bluetooth
      6. Industrial-Grade Networking
        1. CAN
        2. Modbus
      7. System Monitoring
    5. 4. Development Tools
      1. A Practical Project Workspace
      2. GNU Cross-Platform Development Toolchain
        1. Introduction to Building a GNU Toolchain
          1. Terms and GNU configuration names
          2. Linux kernel headers
          3. Binutils
          4. The C library
          5. The threading library
          6. Component versions
          7. Additional build requirements
          8. Build overview
          9. Workspace setup
          10. Resources
        2. Building the Toolchain
          1. Manually building a toolchain
          2. Automated cross toolchain build systems
          3. Crosstool
          4. Ptxdist
            1. Ptxdist overview
            2. Installing Ptxdist
            3. Setting up Ptxdist
            4. Creating a toolchain project
            5. Building the toolchain
        3. Using the Toolchain
      3. C Library Alternatives
        1. uClibc
          1. Buildroot
          2. Customizing the uClibc configuration
        2. Diet libc
          1. Library setup
          2. Usage
      4. Java
        1. Sun Java Micro Edition
        2. Non-Sun-Related Open Source Virtual Machines
        3. The GNU Java Compiler
      5. Perl
        1. Microperl
        2. Miniperl
      6. Python
      7. Other Programming Languages
      8. Eclipse: An Integrated Development Environment
        1. Installing Eclipse
        2. Running Eclipse
        3. Extending Eclipse
          1. Installing a plug-in
          2. Target Management toolkit
          3. Subclipse
        4. Working With Eclipse
          1. Projects
            1. Managed build projects
            2. Makefile projects
          2. Development
          3. Target management
            1. Defining remote connections
      9. Terminal Emulators
        1. Accessing the Serial Port
        2. Eclipse Terminal
        3. Minicom
        4. UUCP cu
        5. C-Kermit
    6. 5. Kernel Considerations
      1. Selecting a Kernel
        1. Embedded Linux Kernels
        2. 2.4 Series Kernels
        3. The 2.6 Series Linux Kernel
          1. Using a stable release tarball
          2. Tracking development with git
          3. Third-party kernel trees and patches
      2. Configuring the Kernel
        1. Configuration Options
        2. Configuration Methods
        3. Managing Multiple Configurations
        4. Using the EXTRAVERSION Variable
      3. Compiling the Kernel
        1. Building the Kernel
        2. Building the Modules
      4. Installing the Kernel
        1. Managing Multiple Kernel Images
        2. Installing Kernel Modules
      5. In the Field
        1. Dealing with Kernel Failure
    7. 6. Root Filesystem Content
      1. Basic Root Filesystem Structure
      2. Libraries
        1. glibc
        2. uClibc
      3. Kernel Modules
      4. Kernel Images
      5. Device Files
        1. Static Device Files
        2. udev
          1. The need for dynamic devices
          2. Building udev
          3. Starting udev
          4. udev’s operation
          5. udev rules
          6. Coldplugging
          7. Kernel configuration
          8. Lightweight udev implementation: BusyBox mdev
      6. Main System Applications
        1. Complete Standard Applications
        2. BusyBox
          1. Setup
          2. Compilation
          3. Usage
          4. TinyLogin: BusyBox logging utilities
        3. embutils
          1. Setup
          2. Usage
      7. Custom Applications
      8. System Initialization
        1. Standard System V init
        2. BusyBox init
        3. Minit
    8. 7. Storage Device Manipulation
      1. MTD-Supported Devices
        1. MTD Usage Basics
          1. MTD /dev entries
          2. Configuring the kernel
          3. The MTD utilities
          4. Installing the MTD utilities for the host
          5. Installing the MTD utilities for the target
        2. Native CFI Flash
          1. Kernel configuration
          2. Partitioning
          3. Required /dev entries
          4. Erasing
          5. Writing and reading
        3. DiskOnChip
          1. Kernel configuration
          2. Required /dev entries
          3. Erasing
          4. Installing bootloader image
          5. NFTL formatting
          6. Partitioning
      2. Disk Devices
        1. CompactFlash
        2. Floppy Disk
        3. Hard Disk
      3. To Swap or Not To Swap
    9. 8. Root Filesystem Setup
      1. Filesystem Types for Embedded Devices
        1. Characterizing Filesystems
          1. Online write support
          2. Persistence
          3. Power-down reliability
          4. Compression
          5. Characteristics specific to storage device types
        2. Filesystem Types
          1. The second extended filesystem (Ext2)
          2. The third extended filesystem (Ext3)
          3. Cramfs
          4. Squashfs
          5. JFFS2
          6. YAFFS2
          7. Tmpfs
      2. Writing a Filesystem Image to Flash Using an NFS-Mounted Root Filesystem
      3. Placing a Disk Filesystem on a RAM Disk
      4. Rootfs and Initramfs
      5. Choosing a Filesystem’s Type and Layout
        1. Applications, Libraries, and Static Data
          1. Keeping the filesystem in RAM
          2. Using read-only persistent storage
          3. Using online writable persistent storage
        2. Dynamic Configuration Files and Data
        3. Temporary Files
        4. Layout Example
      6. Handling Software Upgrades
        1. Software Upgrades in Controlled Environments (Non-Fail-Safe)
          1. Replacing a filesystem in-place in RAM
          2. rsync
          3. Package management tools
        2. Fail-Safe Software Upgrades
          1. Architecture of a fail-safe solution
          2. Example procedure for a fail-safe solution
    10. 9. Setting Up the Bootloader
      1. Embedded Bootloaders
        1. LILO
        2. GRUB
        3. loadlin
        4. Coreboot (Formerly the LinuxBIOS)
        5. U-Boot
        6. RedBoot
      2. Server Setup for Network Boot
        1. Setting Up the DHCP Daemon
        2. Setting Up the TFTP Daemon
        3. Mounting a Root Filesystem on an NFS Server
      3. Using the U-Boot Bootloader
        1. Compiling and Installing
        2. Booting with U-Boot
        3. Using U-Boot’s Environment Variables
        4. Creating Boot Scripts
        5. Preparing Binary Images
        6. Booting Using BOOTP/DHCP, TFTP, and NFS
        7. Downloading Binary Images to Flash
        8. Updating U-Boot
    11. 10. Setting Up Networking Services
      1. Network Settings
      2. Busybox
      3. Dynamic Configuration Through DHCP
      4. The Internet Super-Server
        1. inetd
        2. xinetd
      5. Remote Administration with SNMP
      6. Network Login Through Telnet
        1. netkit-telnetd
      7. Secure Communication with SSH
      8. Serving Web Content Through HTTP
        1. Boa
        2. thttpd
        3. A Word on Apache
        4. Dynamically Generated Web Content
      9. Provisioning
    12. 11. Debugging Tools
      1. Eclipse
      2. Debugging Applications with gdb
        1. Building and Installing gdb Components
        2. Using the gdb Components to Debug Target Applications
        3. Interfacing with a Graphical Frontend
      3. Tracing
        1. Single-Process Tracing
        2. System Tracing
      4. Performance Analysis
        1. Process Profiling
        2. Code Coverage
        3. System Profiling
          1. Basic /proc figures
          2. Complete profile using LTTng
        4. Kernel Profiling
        5. Measuring Interrupt Latency
      5. Memory Debugging
        1. Electric Fence and DUMA
          1. Electric Fence
          2. DUMA
        2. MEMWATCH
      6. A Word on Hardware Tools
    13. 12. Introduction to Real-Time Linux
      1. What Is Real-Time Processing?
      2. Should Your Linux Be Real-Time?
        1. Why Does the Kernel Need to Be Real-Time Aware?
        2. What Is Latency?
      3. Common Real-Time Kernel Requirements
        1. A Fine-Grained Preemptible Kernel
        2. Strictly Enforced Task Priorities
        3. Handling External Events in a Bounded Time Frame
      4. Some Typical Users of Real-Time Computing Technology
      5. The Linux Paths to Real-Time
        1. The Co-Kernel Approach
        2. The Fully Preemptible Kernel Approach
    14. 13. The Xenomai Real-Time System
      1. Porting Traditional RTOS Applications to Linux
      2. The Xenomai Architecture
        1. The Interrupt Pipeline
        2. The Hardware and System Abstraction Layers
        3. The Xenomai Core and Nucleus
        4. The Xenomai Skins
      3. How Xenomai Works
        1. The Real-Time Shadow
        2. New Sets of System Calls
        3. Sharing Kernel Features and Domain Migration
      4. The Real-Time Driver Model
        1. RTDM Mediation
      5. Xenomai, Chameleon by Design
    15. 14. The RT Patch
      1. Interrupts As Threads
        1. Hard IRQs As Threads
        2. Interrupts and CPU Affinities
        3. Softirqs As Threads
        4. Softirq Timer Threads
      2. Priority Inheritance
      3. Configuring the Kernel with the RT Patch
        1. No Forced Preemption
        2. Voluntary Kernel Preemption
        3. Preemptible Kernel
        4. Complete Preemption
      4. High-Resolution Timers
      5. The Latency Tracer
        1. Event Trace
        2. Function Call Trace
        3. Wakeup Latency Timing
      6. Conclusion
    16. Index
    17. About the Authors
    18. Colophon
    19. Copyright