▶Book Description
Linux is a unified kernel that is widely used to develop embedded systems. As Linux has turned out to be one of the most popular operating systems used, the interest in developing proprietary device drivers has also increased. Device drivers play a critical role in how the system performs and ensures that the device works in the manner intended.
By offering several examples on the development of character devices and how to use other kernel internals, such as interrupts, kernel timers, and wait queue, as well as how to manage a device tree, you will be able to add proper management for custom peripherals to your embedded system. You will begin by installing the Linux kernel and then configuring it. Once you have installed the system, you will learn to use the different kernel features and the character drivers. You will also cover interrupts in-depth and how you can manage them. Later, you will get into the kernel internals required for developing applications. Next, you will implement advanced character drivers and also become an expert in writing important Linux device drivers.
By the end of the book, you will be able to easily write a custom character driver and kernel code as per your requirements.
▶What You Will Learn
- Become familiar with the latest kernel releases (4.19+/5.x) running on the ESPRESSObin devkit, an ARM 64-bit machine
- Download, configure, modify, and build kernel sources
- Add and remove a device driver or a module from the kernel
- Master kernel programming
- Understand how to implement character drivers to manage different kinds of computer peripherals
- Become well versed with kernel helper functions and objects that can be used to build kernel applications
- Acquire a knowledge of in-depth concepts to manage custom hardware with Linux from both the kernel and user space
▶Key Features
- Use Kernel facilities to develop powerful drivers
- Via a practical approach, learn core concepts of developing device drivers
- Program a custom character device to get access to kernel internals
▶Who This Book Is For
This book will help anyone who wants to develop their own Linux device drivers for embedded systems. Having basic hand-on with Linux operating system and embedded concepts is necessary.
▶What this book covers
- Chapter 1, Installing the Development System, presents how to install a complete development system based on Ubuntu 18.04.1 LTS, along with a complete testing system based on the Marvell ESPRESSObin board. The chapter will also present how to use the serial console and how to recompile the kernel from scratch, and will teach you some tricks for performing cross-compilations and software emulations.
- Chapter 2, A Peek Inside the Kernel, discusses how to create a custom kernel module, and how to read and manage kernel messages. Both of these skills are very useful for helping the developer to understand what is happening inside the kernel.
- Chapter 3, Working with Char Drivers, examines how to implement a really simple char driver, and how to exchange data between it and the userspace. The chapter ends by proposing some examples in order to underline the Everything is a file abstraction against a device driver.
- Chapter 4, Using the Device Tree, presents the device tree. The reader will learn how to read and understand it, how to write a custom device tree and then how to compile it in order to get a binary form that can be passed to the kernel. The chapter ends with a section about downloading firmware (within a peripheral) and how to configure the CPU's pins by using a Pin MUX tool. Examples are provided using the Armada 3720, i.Mx 7Dual, and SAMA5D3 CPUs.
- Chapter 5, Managing Interrupts and Concurrency, looks at how to manage interrupts and concurrency within the Linux kernel. It shows how to install an interrupt handler, how to defer a job to a later time, and how to manage kernel timers. At the end of the chapter, the reader will learn how to wait for an event (such as waiting for some data to be read) and how to protect their data against race conditions.
- Chapter 6, Miscellaneous Kernel Internals, discusses how to dynamically allocate memory inside the kernel, and how to use several helper functions that are useful for several everyday programming actions (such as strings manipulations, lists, and hash tables manipulations). The chapter will also introduce how to do I/O memory access, and how to safely spend time within the kernel in order to create well-defined busy loop delays.
- Chapter 7, Advanced Char Driver Operations, presents all the advanced operations that are available on character drivers: ioctl(), mmap(), lseek(), the poll()/select() system calls implementation, and asynchronous I/O via the SIGIO signal.
- Appendix A, Additional Information: Working with Char Drivers, This contains additional information on chapter 3.
- Appendix B, Additional Information: Using the Device Tree, This contains additional information on chapter 4.
- Appendix C, Additional Information: Managing Interrupts and Concurrency, This contains additional information on chapter 5.
- Appendix D, Additional Information: Miscellaneous Kernel Internals, This contains additional information on chapter 6.
- Appendix E, Additional Information: Advanced Char Driver Operations, This contains additional information on chapter 7.