Mastering Embedded Linux Programming

Harness the power of Linux to create versatile and robust embedded solutions

Mastering Embedded Linux Programming

This ebook is included in a Mapt subscription
Chris Simmonds

3 customer reviews
Harness the power of Linux to create versatile and robust embedded solutions
$0.00
$39.99
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781784392536
Paperback418 pages

Book Description

Mastering Embedded Linux Programming takes you through the product cycle and gives you an in-depth description of the components and options that are available at each stage. You will begin by learning about toolchains, bootloaders, the Linux kernel, and how to configure a root filesystem to create a basic working device. You will then learn how to use the two most commonly used build systems, Buildroot and Yocto, to speed up and simplify the development process. Building on this solid base, the next section considers how to make best use of raw NAND/NOR flash memory and managed flash eMMC chips, including mechanisms for increasing the lifetime of the devices and to perform reliable in-field updates. Next, you need to consider what techniques are best suited to writing applications for your device. We will then see how functions are split between processes and the usage of POSIX threads, which have a big impact on the responsiveness and performance of the final device The closing sections look at the techniques available to developers for profiling and tracing applications and kernel code using perf and ftrace.

Table of Contents

Chapter 1: Starting Out
Selecting the right operating system
The players
Project lifecycle
Open source
Hardware for embedded Linux
Hardware used in this book
Software used in this book
Summary
Chapter 2: Learning About Toolchains
What is a toolchain?
Types of toolchain - native versus cross toolchain
Choosing the C library
Finding a toolchain
Anatomy of a toolchain
Other tools in the toolchain
Looking at the components of the C library
Linking with libraries: static and dynamic linking
The art of cross compiling
Problems with cross compiling
Summary
Chapter 3: All About Bootloaders
What does a bootloader do?
The boot sequence
Booting with UEFI firmware
Moving from bootloader to kernel
Introducing device trees
Choosing a bootloader
U-Boot
Barebox
Summary
Chapter 4: Porting and Configuring the Kernel
What does the kernel do?
Choosing a kernel
Building the kernel
Compiling
Cleaning kernel sources
Booting your kernel
Porting Linux to a new board
Additional reading
Summary
Chapter 5: Building a Root Filesystem
What should be in the root filesystem?
Programs for the root filesystem
Libraries for the root filesystem
Device nodes
The proc and sysfs filesystems
Kernel modules
Transfering the root filesystem to the target
Creating a boot ramdisk
The init program
Configuring user accounts
Starting a daemon process
A better way of managing device nodes
Configuring the network
Creating filesystem images with device tables
Mounting the root filesystem using NFS
Using TFTP to load the kernel
Additional reading
Summary
Chapter 6: Selecting a Build System
No more rolling your own embedded Linux
Build systems
Package formats and package managers
Buildroot
The Yocto Project
Further reading
Summary
Chapter 7: Creating a Storage Strategy
Storage options
Accessing flash memory from the bootloader
Accessing flash memory from Linux
Filesystems for flash memory
Filesystems for NOR and NAND flash memory
Filesystems for managed flash
Read-only compressed filesystems
Temporary filesystems
Making the root filesystem read-only
Filesystem choices
Updating in the field
Further reading
Summary
Chapter 8: Introducing Device Drivers
The role of device drivers
Character devices
Block devices
Network devices
Finding out about drivers at runtime
Finding the right device driver
Device drivers in user-space
Writing a kernel device driver
Loading kernel modules
Discovering hardware configuration
Additional reading
Summary
Chapter 9: Starting up - the init Program
After the kernel has booted
Introducing the init programs
BusyBox init
System V init
systemd
Further reading
Summary
Chapter 10: Learning About Processes and Threads
Process or thread?
Processes
Threads
Scheduling
Further reading
Summary
Chapter 11: Managing Memory
Virtual memory basics
Kernel space memory layout
User space memory layout
Process memory map
Swap
Mapping memory with mmap
How much memory does my application use?
Per-process memory usage
Identifying memory leaks
Running out of memory
Further reading
Summary
Chapter 12: Debugging with GDB
The GNU debugger
Preparing to debug
Debugging applications using GDB
Remote debugging using gdbserver
Starting to debug
Debugging shared libraries
Just-in-time debugging
Debugging forks and threads
Core files
GDB user interfaces
Debugging kernel code
Additional reading
Summary
Chapter 13: Profiling and Tracing
The observer effect
Beginning to profile
Profiling with top
Introducing perf
Other profilers: OProfile and gprof
Tracing events
Introducing Ftrace
Using LTTng
Using Valgrind for application profiling
Callgrind
Helgrind
Using strace to show system calls
Summary
Chapter 14: Real-time Programming
What is real-time?
Identifying the sources of non-determinism
Understanding scheduling latency
Kernel preemption
The real-time Linux kernel (PREEMPT_RT)
Threaded interrupt handlers
Preemptible kernel locks
Getting the PREEMPT_RT patches
High resolution timers
Avoiding page faults in a real-time application
Interrupt shielding
Measuring scheduling latencies
Further reading
Summary

What You Will Learn

  • Understand the role of the Linux kernel and select an appropriate role for your application
  • Use Buildroot and Yocto to create embedded Linux systems quickly and efficiently
  • Create customized bootloaders using U-Boot
  • Employ perf and ftrace to identify performance bottlenecks
  • Understand device trees and make changes to accommodate new hardware on your device
  • Write applications that interact with Linux device drivers
  • Design and write multi-threaded applications using POSIX threads
  • Measure real-time latencies and tune the Linux kernel to minimize them

Authors

Table of Contents

Chapter 1: Starting Out
Selecting the right operating system
The players
Project lifecycle
Open source
Hardware for embedded Linux
Hardware used in this book
Software used in this book
Summary
Chapter 2: Learning About Toolchains
What is a toolchain?
Types of toolchain - native versus cross toolchain
Choosing the C library
Finding a toolchain
Anatomy of a toolchain
Other tools in the toolchain
Looking at the components of the C library
Linking with libraries: static and dynamic linking
The art of cross compiling
Problems with cross compiling
Summary
Chapter 3: All About Bootloaders
What does a bootloader do?
The boot sequence
Booting with UEFI firmware
Moving from bootloader to kernel
Introducing device trees
Choosing a bootloader
U-Boot
Barebox
Summary
Chapter 4: Porting and Configuring the Kernel
What does the kernel do?
Choosing a kernel
Building the kernel
Compiling
Cleaning kernel sources
Booting your kernel
Porting Linux to a new board
Additional reading
Summary
Chapter 5: Building a Root Filesystem
What should be in the root filesystem?
Programs for the root filesystem
Libraries for the root filesystem
Device nodes
The proc and sysfs filesystems
Kernel modules
Transfering the root filesystem to the target
Creating a boot ramdisk
The init program
Configuring user accounts
Starting a daemon process
A better way of managing device nodes
Configuring the network
Creating filesystem images with device tables
Mounting the root filesystem using NFS
Using TFTP to load the kernel
Additional reading
Summary
Chapter 6: Selecting a Build System
No more rolling your own embedded Linux
Build systems
Package formats and package managers
Buildroot
The Yocto Project
Further reading
Summary
Chapter 7: Creating a Storage Strategy
Storage options
Accessing flash memory from the bootloader
Accessing flash memory from Linux
Filesystems for flash memory
Filesystems for NOR and NAND flash memory
Filesystems for managed flash
Read-only compressed filesystems
Temporary filesystems
Making the root filesystem read-only
Filesystem choices
Updating in the field
Further reading
Summary
Chapter 8: Introducing Device Drivers
The role of device drivers
Character devices
Block devices
Network devices
Finding out about drivers at runtime
Finding the right device driver
Device drivers in user-space
Writing a kernel device driver
Loading kernel modules
Discovering hardware configuration
Additional reading
Summary
Chapter 9: Starting up - the init Program
After the kernel has booted
Introducing the init programs
BusyBox init
System V init
systemd
Further reading
Summary
Chapter 10: Learning About Processes and Threads
Process or thread?
Processes
Threads
Scheduling
Further reading
Summary
Chapter 11: Managing Memory
Virtual memory basics
Kernel space memory layout
User space memory layout
Process memory map
Swap
Mapping memory with mmap
How much memory does my application use?
Per-process memory usage
Identifying memory leaks
Running out of memory
Further reading
Summary
Chapter 12: Debugging with GDB
The GNU debugger
Preparing to debug
Debugging applications using GDB
Remote debugging using gdbserver
Starting to debug
Debugging shared libraries
Just-in-time debugging
Debugging forks and threads
Core files
GDB user interfaces
Debugging kernel code
Additional reading
Summary
Chapter 13: Profiling and Tracing
The observer effect
Beginning to profile
Profiling with top
Introducing perf
Other profilers: OProfile and gprof
Tracing events
Introducing Ftrace
Using LTTng
Using Valgrind for application profiling
Callgrind
Helgrind
Using strace to show system calls
Summary
Chapter 14: Real-time Programming
What is real-time?
Identifying the sources of non-determinism
Understanding scheduling latency
Kernel preemption
The real-time Linux kernel (PREEMPT_RT)
Threaded interrupt handlers
Preemptible kernel locks
Getting the PREEMPT_RT patches
High resolution timers
Avoiding page faults in a real-time application
Interrupt shielding
Measuring scheduling latencies
Further reading
Summary

Book Details

ISBN 139781784392536
Paperback418 pages
Read More
From 3 reviews

Read More Reviews