Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Developing Embedded Linux Device Drivers

Similar presentations


Presentation on theme: "Introduction to Developing Embedded Linux Device Drivers"— Presentation transcript:

1 Introduction to Developing Embedded Linux Device Drivers
Nick Gudman

2 Going to Cover Not Going to Cover
Kernel modules/objects Char, block, network, & binary blob drivers Char device functions Driver Infrastructure: Unified Device Model, SysFs, Platform driver, Device tree GPIO Interrupts Debugging & Tools References & Resource Discuss Edison Arduino libraries & mraa/upm Mutual Exclusion Blocking & Non-blocking Behavior* Kernel Threads* Timing Memory Allocation* Memory Mapping* Block Devices* Network Devices*

3 What is a device driver? Why program device drivers?
Hides how a piece of hardware/device works behind a standardized set of calls Standardized set of calls allow drivers to be inserted into kernel at runtime Makes a device available, but doesn't dictate how it is used Why program device drivers? Common way to start learning kernel development Learn the internals of Unix/Linux or another operating system Somebody has to

4 Debugging Tools of the Trade
dmesg, printk, Dynamic Debugging ProcFs DebugFs Kdbg Kernel Dumps Kernel Oops Hardware Debuggers <Insert editor of choice> Ctags & Cscope/Gscope Yocto Linaro Bitbake

5 Kernel Modules/Objects
An object or collection of objects either built in the kernel or dynamically linked to a running kernel Stackable Not just for device drivers bitbake -c menuconfig virtual/kernel modprobe, insmod, rmmod, lsmod, modinfo

6 Types of Device Drivers
Character Access as a stream of bytes like a file, usually sequentially Accessed through filesystem nodes (/dev) Ex. text consoles (/dev/console), serial ports (/dev/ttyS0, /dev/ttyUSB0) Block Device that can host a filesystem Any number of bytes can be read/write Ex. hard drives (/dev/sdaX), flash devices (/dev/mmcblkX) ls /dev/

7 Types of Device Drivers
Network Sends & receives data packets through sockets Driven by kernel network subsystem Only handles packets; doesn't know about connections Communicates completely differently than character and block devices Ex. eth0, wlan0 Binary Blobs Source not given Open source glue layer between binary blob and kernel api Ex. Nvidia Linux drivers, ndiswrapper

8 DON'T. WRITE. BINARY BLOBS.

9 Types of Device Drivers
Network Sends & receives data packets through sockets Driven by kernel network subsystem Only handles packets; doesn't know about connections Communicates completely differently than character and block devices Ex. eth0, wlan0 Binary Blobs Source not given Open source glue layer between binary blob and kernel api Ex. Nvidia Linux drivers, ndiswrapper

10 “Canonical” Functions of Char Devices
Open int (*open)(struct inode *inodp, struct file *filp); Release int (*release)(struct inode *inodp, struct file *filp); Read ssize_t (*read)(struct *filp, char *buf, size_t count, loff_t *offset); put_user(x, addr); unsigned long copy_to_user(void *to, const void *from, unsigned long n); Write ssize_t (*write)(struct file *filp, const char *buf, size_t count, loff_t *offset); get_user(x, addr); unsigned long copy_from_user(void *to, const void *from, unsigned long n);

11 Other Important Functions
unlocked_ioctl For device specific operations that don't fit well elsewhere Called when user application calls ioctl mmap Maps file or character device to user space processes Poll Lets an application wait (block) on several file descriptors at once fasync Asynchronously notifies (signals) application when data is ready lseek Update offsets for reads and writes

12 Driver Infrastructure
Unified Device Model One framework with similar data structures & functional methods Kernel headers for specific hardware ex. linux/gpio.h, linux/i2c-dev.h, linux/spidev.h, linux/serial.h, linux/pci.h, include/usb.h, etc SysFs - /sys Virtual filesystem Not required by unified device model User space driver Class → directory Class Instance → sub-directory Attribute → file

13 Arduino Example

14 SysFs Example

15 Driver Infrastructure
Platform Drivers Driver is an object Buses for hardware, classes for software groups Must provide at least probe and remove functions Device Tree Textual representation of board's hardware configuration Allow generic kernel to run To solve problem of growing number of hard coded, board-specific files Device tree source (.dts) and device tree source include (.dtsi) compiled into device tree blob (.dtb) with device tree compiler (dtc)

16 GPIO – General Purpose Input/Output
Divided into chips of 32 gpio<bank>_<pin> Gpio = (bank * 32) + pin ex. GPIO0_16: (0 * 32) + 16 = 16 Sets/gets direction, active_low, value, etc Can be hooked up to interrupts

17 Interrupts Stops normal execution
Typically divided into top & bottom halves Top Half Quick as possible Typically verifies hardware, clears pending interrupt, read/write or another action, prepares new info Bottom Half Tasklet/softirq Workqueue Kernel Thread Threaded Interrupt Handlers User Space Interrupt Handling – Userspace I/O (UIO), integrated into kernel

18 References & Resources
yocto-example-batman O'Reilly's Linux Device Drivers Book Linux Foundation & Feabhas Device Driver Courses

19 Introduction to Developing Embedded Linux Device Drivers
Nick Gudman

20 Why Linus Doesn't Like Kernel Debuggers
“Because I'm a bastard, and proud of it!” “Without a debugger, you basically have to go the next step: understand what the program does.” “You can use a kernel debugger if you want to, and I won't give you the cold shoulder...But I'm not going to help you use one”


Download ppt "Introduction to Developing Embedded Linux Device Drivers"

Similar presentations


Ads by Google