Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Linux Device Drivers Development
Linux Device Drivers Development

Linux Device Drivers Development: Develop customized drivers for embedded Linux

eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Linux Device Drivers Development

Device Driver Basis

A driver is a piece of software whose aim is to control and manage a particular hardware device, hence the name device driver. From an operating system point of view, it can be either in the kernel space (running in privileged mode) or in the user space (with lower privileges). This book only deals with kernel space drivers, especially Linux kernel drivers. Our definition is that a device driver exposes the functionality of the hardware to user programs.

This book's aim is not to teach you how to become a Linux guru—I'm not even one at all—but there are some concepts you should understand prior to writing a device driver. C programming skills are mandatory; you should be at least familiar with pointers. You should also be familiar with some of the manipulating functions. Some hardware skills are required too. So, this chapter essentially...

User space and kernel space

The concepts of kernel space and user space are a bit abstract. It is all about memory and access rights. One may consider the kernel to be privileged, whereas the user apps are restricted. It is a feature of a modern CPU, allowing it to operate either in privileged or unprivileged mode. This concept will be clearer to you in Chapter 11, Kernel Memory Management:

User space and kernel space

The preceding diagram introduces the separation between kernel and user space, and highlights the fact that system calls represent the bridge between them (we discuss this later in this chapter). We can describe each space as follows:

  • Kernel space: This is a set of addresses where the kernel is hosted and where it runs. Kernel memory (or kernel space) is a memory range, owned by the kernel, protected by access flags, preventing any user apps from messing with the...

Driver skeletons

Let's consider the following helloworld module. It will be the basis for our work during the rest of this chapter:

helloworld.c

#include <linux/init.h> 
#include <linux/module.h> 
#include <linux/kernel.h> 
 
static int __init helloworld_init(void) { 
    pr_info("Hello world!\n"); 
    return 0; 
} 
 
static void __exit helloworld_exit(void) { 
    pr_info("End of the world\n"); 
} 
 
module_init(helloworld_init); 
module_exit(helloworld_exit); 
MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>"); 
MODULE_LICENSE("GPL"); 

Module entry and exit point

Kernel drivers all have entry and exit points: the former corresponds to the function called...

Errors and message printing

Error codes are interpreted either by the kernel or by the user space application (through the errno variable). Error handling is very important in software development, more than it is in kernel development. Fortunately, the kernel provides a couple of errors that cover almost every error you'll encounter, and sometimes you will need to print them out in order to help you debug.

Error handling

Return the wrong error code for a given error and it will result in either the kernel or user space app producing unwanted behavior and making a wrong decision. To keep things clear, there are predefined errors in the kernel tree that cover almost every case you may face. Some of the errors (with their...

Module parameters

As a user program does, a kernel module can accept arguments from the command line. This allows dynamically changing the behavior of the module according to given parameters, and can help the developer not having to indefinitely change/compile the module during a test/debug session. In order to set this up, you should first declare the variables that will hold the values of command line arguments, and use the module_param() macro on each of these. The macro is defined in include/linux/moduleparam.h (this should be included in the code too: #include <linux/moduleparam.h>), shown as follows:

module_param(name, type, perm); 

This macro contains the following elements:

  • name: The name of the variable used as the parameter
  • type: The parameter's type (bool, charp, byte, short, ushort, int, uint, long, ulong), where charp stands for char pointer
  • perm: This...

Building your first module

There are two places to build a module. It depends on whether you want people to enable the module by themselves or not using the kernel config interface.

The module's makefile

A makefile is a special file used to execute a set of actions, among which the most important is the compilation of programs. There is a dedicated tool to parse makefiles, called make. Prior to jumping to the description of the whole make file, let's introduce the obj-<X> kbuild variable.

In almost every kernel makefile, you will see at least one instance of an obj<-X> variable. This actually corresponds to the obj-<X> pattern, where <X> should be either y, m, left blank, or n. This is used...

Summary

This chapter showed you the basics of driver development and explained the concept of modules/built-in devices, as well as their loading and unloading. Even if you are not able to interact with the user space, you are ready to write a complete driver, print a formatted message, and understand the concept of init/exit. The next chapter will deal with character devices, with which you will be able to target enhanced features, write code accessible from the user space, and have a significant impact on the system.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to develop customized Linux device drivers
  • Learn the core concepts of device drivers such as memory management, kernel caching, advanced IRQ management, and so on.
  • Practical experience on the embedded side of Linux

Description

Linux kernel is a complex, portable, modular and widely used piece of software, running on around 80% of servers and embedded systems in more than half of devices throughout the World. Device drivers play a critical role in how well a Linux system performs. As Linux has turned out to be one of the most popular operating systems used, the interest in developing proprietary device drivers is also increasing steadily. This book will initially help you understand the basics of drivers as well as prepare for the long journey through the Linux Kernel. This book then covers drivers development based on various Linux subsystems such as memory management, PWM, RTC, IIO, IRQ management, and so on. The book also offers a practical approach on direct memory access and network device drivers. By the end of this book, you will be comfortable with the concept of device driver development and will be in a position to write any device driver from scratch using the latest kernel version (v4.13 at the time of writing this book).

Who is this book for?

This book will help anyone who wants to get started with developing their own Linux device drivers for embedded systems. Embedded Linux users will benefit highly from this book. This book covers all about device driver development, from char drivers to network device drivers to memory management.

What you will learn

  • • Use kernel facilities to develop powerful drivers
  • • Develop drivers for widely used I2C and SPI devices and use the regmap API
  • • Write and support devicetree from within your drivers
  • • Program advanced drivers for network and frame buffer devices
  • • Delve into the Linux irqdomain API and write interrupt controller drivers
  • • Enhance your skills with regulator and PWM frameworks
  • • Develop measurement system drivers with IIO framework
  • • Get the best from memory management and the DMA subsystem
  • • Access and manage GPIO subsystems and develop GPIO controller drivers

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 20, 2017
Length: 586 pages
Edition : 1st
Language : English
ISBN-13 : 9781782174752
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 20, 2017
Length: 586 pages
Edition : 1st
Language : English
ISBN-13 : 9781782174752
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
Mastering Linux Kernel Development
$54.99
Linux Device Drivers Development
$48.99
Mastering Embedded Linux Programming
$54.99
Total $ 158.97 Stars icon
Banner background image

Table of Contents

22 Chapters
Introduction to Kernel Development Chevron down icon Chevron up icon
Device Driver Basis Chevron down icon Chevron up icon
Kernel Facilities and Helper Functions Chevron down icon Chevron up icon
Character Device Drivers Chevron down icon Chevron up icon
Platform Device Drivers Chevron down icon Chevron up icon
The Concept of Device Tree Chevron down icon Chevron up icon
I2C Client Drivers Chevron down icon Chevron up icon
SPI Device Drivers Chevron down icon Chevron up icon
Regmap API – A Register Map Abstraction Chevron down icon Chevron up icon
IIO Framework Chevron down icon Chevron up icon
Kernel Memory Management Chevron down icon Chevron up icon
DMA – Direct Memory Access Chevron down icon Chevron up icon
The Linux Device Model Chevron down icon Chevron up icon
Pin Control and GPIO Subsystem Chevron down icon Chevron up icon
GPIO Controller Drivers – gpio_chip Chevron down icon Chevron up icon
Advanced IRQ Management Chevron down icon Chevron up icon
Input Devices Drivers Chevron down icon Chevron up icon
RTC Drivers Chevron down icon Chevron up icon
PWM Drivers Chevron down icon Chevron up icon
Regulator Framework Chevron down icon Chevron up icon
Framebuffer Drivers Chevron down icon Chevron up icon
Network Interface Card Drivers Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(30 Ratings)
5 star 56.7%
4 star 10%
3 star 16.7%
2 star 10%
1 star 6.7%
Filter icon Filter
Top Reviews

Filter reviews by




texier pierre-jean Oct 29, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
From Linux Kernel to network interface, this book covers a lot of interesting topics:- device-tree,- i2c drivers,- RTC drivers,- PWM drivers,- ...There is also a very good chapter which explain how to develop with the Linux IIO framework.Recommended for Embedded Linux Engineer !
Amazon Verified review Amazon
sandeep bhuyan Jul 04, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
i love this book,we can get lot of information about Linux Driver Development
Amazon Verified review Amazon
Nguefack Nov 01, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book helped me a lot to find a solution to a business problem that we had ...The content is very well explained and simple to understand even for beginners ....The practical examples are really clear ..Very good Book...Rosty ....
Amazon Verified review Amazon
Electronics fan May 26, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Started this book not knowing anything about Linux device drivers, left this book knowing a bunch about Linux drivers.
Amazon Verified review Amazon
Daiane Dec 08, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The first part of this book has a great introduction to the meanings and terms needed to become a linux developer. I think it does help a lot for the readers starting with Linux. The second part of the book has several important chapters describing the drivers and frameworks used nowadays in the source code.It's very easy to read and I like very much how text flows. I liked this book very much!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.