Linux Driver Development for Embedded Processors, Second Edition Год издания: 2018 Автор: Alberto Liberal de los Rios Жанр или тематика: Linux programming Издательство: Independently published ISBN: 9781729321829 Язык: Английский Формат: PDF Качество: Изначально компьютерное (eBook) Интерактивное оглавление: Да Количество страниц: 589 Описание: From Amazon.com: The flexibility of embedded Linux, the availability of powerful, energy efficient processors designed for embedded computing and the low cost of new processors are encouraging many industrial companies to come up with new developments based on embedded processors. Current engineers have powerful tools in their hands for developing applications previously unimagined, but they need to understand the countless features that Linux offers today. This book will teach you how to develop device drivers for Device Tree embedded Linux systems. You will learn how to write different types of Linux drivers, as well as the appropriate Application Program Interfaces (APIs) and methods to interface with kernel and user spaces. This book is meant to be practical, but also provides an important theoretical base. Nearly thirty drivers are written and ported to three different processors. You can choose between the NXP i.MX7D, Microchip SAMA5D2 and Broadcom BCM2837 processors to develop and test the drivers, whose implementation is described in detail in the practical lab sections of the book. Before you start reading, I encourage you to acquire one of these processor boards whenever you have access to some GPIOs, and at least one SPI and I2C controller. The hardware configurations of the different evaluation boards used to develop the drivers are explained in detail throughout this book; one of the boards used to implement the drivers is the famous Raspberry PI 3 Model B board. You will learn how to develop drivers, from the simplest ones that do not interact with any external hardware, to drivers that manage different kind of devices: accelerometers, DACs, ADCs, RGB LEDs, Multi-Display LED controllers, I/O expanders, buttons, and USB HID devices. You will also develop DMA drivers, drivers that manage interrupts, and drivers that write/read on the internal registers of the processor to control external devices. To ease the development of some of these drivers, you will use different types of frameworks: Miscellaneous framework, LED framework, UIO framework, Input framework and the IIO industrial framework. This second edition has been updated to the v4.9 LTS kernel. Since the end of March 2019, a new chapter and an appendix have been added to the text of the book. These are: Chapter 13, “Linux USB Device Drivers” and Appendix, “Porting Kernel Modules to the Microchip SAMA5D27-SOM1”. These two new chapters can be downloaded from the Github of this book for readers who have acquired the book before that date. In the Chapter 13, you will learn how to create a fully functional USB HID device based on the Microchip PIC32MX microcontroller that will send/receive data to/from a Linux USB Host device based on the Microchip SAMA5D27 processor; several custom Linux USB device drivers will be developed throughout this chapter. The Appendix describes the hardware settings for the ATSAMA5D27-SOM1-EK1 board that are needed to test the practical labs described throughout this book. To run the labs on this board, the SAMA5D27-SOM1 drivers based on the v4.14 LTS kernel and the SAMA5D27-SOM1 device tree settings can be downloaded from the GitHub repository of this book.
Примеры страниц
Оглавление
Preface..................................................................................................................13 Chapter 1: Building the System..........................................................................19 Bootloader..............................................................................................................20 Linux Kernel............................................................................................................22 System Call Interface and C Runtime Library.........................................................25 System Shared Libraries........................................................................................26 Root Filesystem......................................................................................................27 Linux Boot Process.................................................................................................28 Building a Linux Embedded System.......................................................................30 Setting up Ethernet Communication.......................................................................31 Building a Linux Embedded System for the NXP i.MX7D Processor.....................32 Introduction.............................................................................................................32 Host Packages.......................................................................................................33 Setting up the Repo Utility......................................................................................33 Yocto Project Setup and Image Building................................................................33 Working Outside of Yocto.......................................................................................36 Building the Linux Kernel........................................................................................38 Installing a TFTP Server.........................................................................................41 Installing a NFS Server...........................................................................................42 Setting the U-Boot Environment Variables.............................................................42 Building a Linux Embedded System for the Microchip SAMA5D2 Processor..............................................................................................43 Introduction.............................................................................................................43 Host Packages.......................................................................................................44 Yocto Project Setup and Image Building................................................................44 Working Outside of Yocto.......................................................................................46 Building the Linux Kernel........................................................................................47 Installing a TFTP Server.........................................................................................49 Installing a NFS Server...........................................................................................49 Setting the U-Boot Environment Variables.............................................................50 Building a Linux Embedded System for the Broadcom BCM2837 Processor...............................................................................................50 Raspbian................................................................................................................50 Building the Linux Kernel........................................................................................51 Copying Files to your Raspberry Pi........................................................................54 Working with Eclipse...............................................................................................55 Eclipse Configuration for Working with Kernel Sources.........................................56 Eclipse Configuration for Developing Linux Drivers...............................................67 Chapter 2: The Linux Device and Driver Model.................................................73 Bus Core Drivers....................................................................................................74 Bus Controller Drivers.............................................................................................76 Device Drivers........................................................................................................77 Introduction to the Device Tree...............................................................................78 Chapter 3: The Simplest Drivers.........................................................................83 Licensing.................................................................................................................84 LAB 3.1: "helloworld" Module.................................................................................84 Listing 3-1: helloworld_imx.c...................................................................................85 Listing 3-2: Makefile................................................................................................86 helloworld_imx.ko Demonstration...........................................................................86 LAB 3.2: "helloworld with parameters" Module.......................................................87 Listing 3-3: helloworld_imx_with_parameters.c.......................................................88 helloworld_imx_with_parameters.ko Demonstration...............................................88 LAB 3.3: "helloworld timing" Module.......................................................................88 Listing 3-4: helloworld_imx_with_timing.c...............................................................89 helloworld_imx_with_timing.ko Demonstration.......................................................90 Chapter 4: Character Drivers..............................................................................91 LAB 4.1: "helloworld character" Module.................................................................93 Registration and Unregistration of Character Devices...........................................94 Listing 4-1: helloworld_imx_char_driver.c...............................................................98 Listing 4-2: Makefile..............................................................................................102 Listing 4-3: ioctl_test.c..........................................................................................102 helloworld_imx_char_driver.ko Demonstration.....................................................102 Add the Module to the Kernel Build......................................................................103 Creating Device Files with devtmpfs.....................................................................104 LAB 4.2: "class character" Module.......................................................................105 Listing 4-4: helloworld_imx_class_driver.c............................................................107 helloworld_imx_class_driver.ko Demonstration....................................................109 Miscellaneous Character Driver............................................................................109 Registering a Minor Number.................................................................................110 LAB 4.3: "miscellaneous character" Module.........................................................111 Listing 4-5: misc_imx_driver.c...............................................................................111 misc_imx_driver.ko Demonstration.......................................................................113 Chapter 5: Platform Drivers...............................................................................115 LAB 5.1: "platform device" Module.......................................................................117 Listing 5-1: hellokeys_imx.c..................................................................................120 hellokeys_imx.ko Demonstration..........................................................................122 Documentation to Interact with the Hardware......................................................123 Hardware Naming Convention..............................................................................123 Pin Controller........................................................................................................124 Pin Control Subsystem.........................................................................................127 Device Tree Pin Controller Bindings.....................................................................134 GPIO Controller Driver..........................................................................................138 GPIO Descriptor Consumer Interface...................................................................140 Obtaining and Disposing GPIOs...........................................................................141 Using GPIOs.........................................................................................................141 GPIOs Mapped to IRQs........................................................................................143 GPIOs in Device Tree...........................................................................................143 Exchanging Data between Kernel and User Space.............................................144 MMIO (Memory-Mapped I/O) Device Access.......................................................145 LAB 5.2: "RGB LED platform device" Module......................................................147 LAB 5.2 Hardware Description for the i.MX7D Processor....................................147 LAB 5.2 Hardware Description for the SAMA5D2 Processor...............................149 LAB 5.2 Hardware Description for the BCM2837 Processor................................151 LAB 5.2 Device Tree for the i.MX7D Processor...................................................153 LAB 5.2 Device Tree for the SAMA5D2 Processor..............................................156 LAB 5.2 Device Tree for the BCM2837 Processor...............................................159 LAB 5.2 Code Description of the "RGB LED platform device" Module.................161 Listing 5-2: ledRGB_sam_platform.c....................................................................166 ledRGB_sam_platform.ko Demonstration.............................................................171 Platform Driver Resources....................................................................................172 Linux LED Class...................................................................................................174 LAB 5.3: "RGB LED class" Module.......................................................................176 LAB 5.3 DT for the i.MX7D, SAMA5D2 and BCM2837 Processors.....................176 LAB 5.3 Code Description of the "RGB LED class" Module.................................180 Listing 5-3: ledRGB_sam_class_platform.c..........................................................184 ledRGB_sam_class_platform.ko Demonstration...................................................188 Platform Device Drivers in the User Space..........................................................188 User Defined I/O: UIO...........................................................................................190 How UIO Works....................................................................................................192 Kernel UIO API.....................................................................................................193 LAB 5.4: "LED UIO platform" Module...................................................................195 LAB 5.4 DT for the i.MX7D, SAMA5D2 and BCM2837 Processors.....................195 LAB 5.4 Code Description of the "LED UIO platform" Module.............................197 Listing 5-4: led_sam_UIO_platform.c....................................................................199 Listing 5-5: UIO_app.c..........................................................................................201 led_sam_UIO_platform.ko with UIO_app Demonstration......................................203 Chapter 6: I2C Client Drivers.............................................................................205 The Linux I2C Subsystem.....................................................................................206 Writing I2C Client Drivers.....................................................................................210 I2C Client Driver Registration...............................................................................210 Declaration of I2C Devices in Device Tree...........................................................212 LAB 6.1: "I2C I/O expander device" Module.........................................................214 LAB 6.1 Hardware Description for the i.MX7D Processor....................................214 LAB 6.1 Hardware Description for the SAMA5D2 Processor...............................214 LAB 6.1 Hardware Description for the BCM2837 Processor................................216 LAB 6.1 Device Tree for the i.MX7D Processor...................................................216 LAB 6.1 Device Tree for the SAMA5D2 Processor..............................................218 LAB 6.1 Device Tree for the BCM2837 Processor...............................................220 LAB 6.1 Code Description of the "I2C I/O expander device" Module...................221 Listing 6-1: io_imx_expander.c.............................................................................224 io_imx_expander.ko Demonstration......................................................................228 The Sysfs Filesystem............................................................................................229 The Kobject Infrastructure....................................................................................230 LAB 6.2: "I2C multidisplay LED" Module..............................................................233 LAB 6.2 Hardware Description for the i.MX7D Processor....................................235 LAB 6.2 Hardware Description for the SAMA5D2 Processor...............................235 LAB 6.2 Hardware Description for the BCM2837 Processor................................235 LAB 6.2 Device Tree for the i.MX7D Processor...................................................235 LAB 6.2 Device Tree for the SAMA5D2 Processor..............................................237 LAB 6.2 Device Tree for the BCM2837 Processor...............................................239 Unified Device Properties Interface for ACPI and Device Tree............................240 LAB 6.2 Code Description of the "I2C multidisplay LED" Module........................242 Listing 6-2: ltc3206_imx_led_class.c.....................................................................246 ltc3206_imx_led_class.ko Demonstration.............................................................254 Chapter 7: Handling Interrupts in Device Drivers...........................................257 Linux Kernel IRQ Domain for GPIO Controllers...................................................260 Device Tree Interrupt Handling.............................................................................268 Requesting Interrupts in Linux Device Drivers......................................................272 LAB 7.1: "button interrupt device" Module............................................................274 LAB 7.1 Hardware Description for the i.MX7D Processor....................................274 LAB 7.1 Hardware Description for the SAMA5D2 Processor...............................274 LAB 7.1 Hardware Description for the BCM2837 Processor................................274 LAB 7.1 Device Tree for the i.MX7D Processor...................................................274 LAB 7.1 Device Tree for the SAMA5D2 Processor..............................................276 LAB 7.1 Device Tree for the BCM2837 Processor...............................................277 LAB 7.1 Code Description of the "button interrupt device" Module......................278 Listing 7-1: int_imx_key.c......................................................................................280 int_imx_key.ko Demonstration..............................................................................282 Deferred Work......................................................................................................283 Softirqs.................................................................................................................284 Tasklets................................................................................................................286 Timers...................................................................................................................286 Threaded Interrupts..............................................................................................290 Workqueues.........................................................................................................292 Locking in the Kernel............................................................................................296 Locks and Uniprocessor Kernels..........................................................................297 Sharing Spinlocks between Interrupt and Process Context.................................297 Locking in User Context.......................................................................................298 Sleeping in the Kernel...........................................................................................298 LAB 7.2: "sleeping device" Module.......................................................................300 LAB 7.2 Device Tree for the i.MX7D Processor...................................................301 LAB 7.2 Device Tree for the SAMA5D2 Processor..............................................302 LAB 7.2 Device Tree for the BCM2837 Processor...............................................303 LAB 7.2 Code Description of the "sleeping device" Module.................................305 Listing 7-2: int_imx_key_wait.c..............................................................................308 int_imx_key_wait.ko Demonstration......................................................................312 Kernel Threads.....................................................................................................312 LAB 7.3: "keyled class" Module............................................................................313 LAB 7.3 Hardware Description for the i.MX7D Processor....................................314 LAB 7.3 Hardware Description for the SAMA5D2 Processor...............................314 LAB 7.3 Hardware Description for the BCM2837 Processor................................315 LAB 7.3 Device Tree for the i.MX7D Processor...................................................316 LAB 7.3 Device Tree for the SAMA5D2 Processor..............................................319 LAB 7.3 Device Tree for the BCM2837 Processor...............................................322 LAB 7.3 Code Description of the "keyled class" Module......................................324 Listing 7-3: keyled_imx_class.c.............................................................................331 keyled_imx_class.ko Demonstration.....................................................................343 Chapter 8: Allocating Memory with Linux Drivers..........................................345 Walking ARM MMU Translation Tables................................................................346 Linux Address Types............................................................................................353 User Process Virtual to Physical Memory Mapping..............................................354 Kernel Virtual to Physical Memory Mapping.........................................................355 Kernel Memory Allocators.....................................................................................357 PAGE Allocator.....................................................................................................357 Page Allocator API...............................................................................................358 SLAB Allocator.....................................................................................................358 SLAB Allocator API...............................................................................................361 Kmalloc Allocator..................................................................................................362 LAB 8.1: "linked list memory allocation" Module ........................................................363 Listing 8-1: linkedlist_imx_platform.c ...........................................................................366 linkedlist_imx_platform.ko Demonstration ...................................................................371 Chapter 9: Linux DMA in Device Drivers..........................................................373 Cache Coherency.................................................................................................373 Linux DMA Engine API.........................................................................................375 Types of DMA Mappings......................................................................................378 LAB 9.1: "streaming DMA" Module.......................................................................382 Listing 9-1: sdma_imx_m2m.c..............................................................................390 sdma_imx_m2m.ko Demonstration.......................................................................395 DMA Scather/Gather Mappings............................................................................396 LAB 9.2: "scatter/gather DMA device" Module.....................................................397 Listing 9-2: sdma_imx_sg_m2m.c.........................................................................400 sdma_imx_sg_m2m.ko Demonstration.................................................................407 DMA from User Space..........................................................................................407 LAB 9.3: "DMA from user space" Module.............................................................409 Listing 9-3: sdma_imx_mmap.c............................................................................411 Listing 9-4: sdma.c................................................................................................416 sdma_imx_mmap.ko Demonstration.....................................................................417 Chapter 10: Input Subsystem Framework for Device Drivers........................419 Input Subsystem Drivers.......................................................................................420 LAB 10.1: "input subsystem accelerometer" Module............................................423 Device Tree..........................................................................................................425 Input Framework as an I2C Interaction................................................................426 Input Framework as an Input Device....................................................................428 Listing 10-1: i2c_imx_accel.c................................................................................431 i2c_imx_accel.ko Demonstration..........................................................................433 Using SPI with Linux.............................................................................................435 The Linux SPI Subsystem....................................................................................437 Writing SPI Client Drivers.....................................................................................440 SPI Client Driver Registration...............................................................................440 Declaration of SPI Devices in Device Tree...........................................................442 LAB 10.2: "SPI accel input device" Module..........................................................446 LAB 10.2 Hardware Description for the i.MX7D Processor..................................446 LAB 10.2 Hardware Description for the SAMA5D2 Processor.............................447 LAB 10.2 Hardware Description for the BCM2837 Processor..............................447 LAB 10.2 Device Tree for the i.MX7D Processor.................................................447 LAB 10.2 Device Tree for the SAMA5D2 Processor............................................449 LAB 10.2 Device Tree for the BCM2837 Processor.............................................451 LAB 10.2 Code Description of the "SPI accel input device" Module....................451 Listing 10-2: adxl345_imx.c..................................................................................462 adxl345_imx.ko Demonstration.............................................................................476 Chapter 11: Industrial I/O Subsystem for Device Drivers...............................479 IIO Device Sysfs Interface....................................................................................481 IIO Device Channels.............................................................................................481 The iio_info Structure............................................................................................484 Buffers..................................................................................................................485 IIO Buffer Sysfs Interface.....................................................................................485 IIO Buffer Setup....................................................................................................485 Triggers................................................................................................................487 Triggered Buffers..................................................................................................487 Industrial I/O Events.............................................................................................489 Delivering IIO Events to User Space....................................................................492 IIO Utils.................................................................................................................494 LAB 11.1: "IIO subsystem DAC" Module..............................................................494 Device Tree..........................................................................................................495 Industrial Framework as an I2C Interaction..........................................................497 Industrial Framework as an IIO Device................................................................498 Listing 11-1: ltc2607_imx_dual_device.c...............................................................504 LAB 11.2: "IIO subsystem DAC" Module with "SPIDEV dual ADC user" Application............................................................................................................508 LAB 11.2 Hardware Description for the i.MX7D Processor..................................510 LAB 11.2 Hardware Description for the SAMA5D2 Processor.............................510 LAB 11.2 Hardware Description for the BCM2837 Processor..............................510 LAB 11.2 Device Tree for the i.MX7D Processor.................................................511 LAB 11.2 Device Tree for the SAMA5D2 Processor............................................511 LAB 11.2 Device Tree for the BCM2837 Processor.............................................512 Listing 11-2: LTC2422_spidev.c...........................................................................512 ltc2607_imx_dual_device.ko with LTC2422_spidev Demonstration.....................516 LAB 11.3: "IIO subsystem ADC" Module..............................................................518 Device Tree..........................................................................................................518 Industrial Framework as a SPI Interaction............................................................520 Industrial Framework as an IIO Device................................................................521 Listing 11-3: ltc2422_imx_dual.c...........................................................................524 LTC2422_app User Space Application.................................................................526 Listing 11-4: ltc2422_app.c...................................................................................526 ltc2422_imx_dual.ko with ltc2422_app Demonstration.........................................529 LAB 11.4: "IIO subsystem ADC with hardware triggering" Module.......................529 LAB 11.4 DT for the i.MX7D, SAMA5D2 and BCM2837 Processors...................530 Sleep and Wake up in the Driver..........................................................................534 Interrupt Management..........................................................................................535 Listing 11-5: ltc2422_imx_trigger.c.......................................................................536 ltc2422_imx_trigger.ko with LTC2422_app Demonstration..................................540 Chapter 12: Using the Regmap API in Linux Device Drivers.........................541 Implementing Regmap..........................................................................................543 LAB 12.1: "SPI regmap IIO device" Module.........................................................546 Listing 12-1: adxl345_imx_iio.c.............................................................................557 adxl345_imx_iio.ko Demonstration.......................................................................569 References..........................................................................................................573 Index....................................................................................................................575
[only-soft.org].t101031.torrent
Торрент:
Зарегистрирован
[ 2019-07-24 19:15 ]
7 KB
Статус:
√проверено
Скачан:
0 раз
Размер:
10 MB
Оценка:
(Голосов: 0)
Поблагодарили:
0
Alberto Liberal de los Rios - Linux Driver Development for Embedded Processors, Second Edition [2018, PDF, ENG] скачать торрент бесплатно и без регистрации
Вы не можете начинать темы Вы не можете отвечать на сообщения Вы не можете редактировать свои сообщения Вы не можете удалять свои сообщения Вы не можете голосовать в опросах Вы не можете прикреплять файлы к сообщениям Вы можете скачивать файлы