C Language
Publish date: Oct 16, 2019
Last updated: Apr 22, 2020
Last updated: Apr 22, 2020
Linux Driver development
#define
#define
is a C preprocessor directive used to define macros
.
#define MACRONAME (expression)
dereference/ indirection operator
For example, in C
int x;
int *p;
- we can declare a variable x that holds an integer value,
- and a variable p that holds a pointer to an integer value in memory:
Essential Linux device drivers Toolbox
- Peek inside Kernel
- Kernel Facilities
- kernel threads
- are like user processes but they live in kernel space and have access to special kernel functions and data structures
- Kernel Interfaces
- Kernel APIs
- kernel threads
- Linux device model
- Character / char drivers -printers, watchdogs
- Serial drivers
- UARTS drivers
- TTY drivers
- Input drivers - keyboard, mouse
- USB drivers
- touch screens drivers
- Audio/ Video/ Block device drivers
- Network interface cards
- Wireless drivers - Bluetooth, Wifi, GPRS, CDMA
- Embedding Linux
- Tool chains
- Bootloaders
- Memory Layout
- Debugging drivers
Introduction
- What is linux? where is the official source and mailing list? Where is the official source?
- How to buid linux from source?
- Linux has lodable modules
lsmod
- Kernel mode and user mode aka user/kernel space
- to effectively implement time-sharing system
- peek Internals of kernel from pseudo fs
proc
usuallt mounted at/
root
Kernel boot starts with the execution of real mode assembly code living in
/arch/x86/boot
directory
- How to create a new kernel thread?1
#include <linux/kthread.h>
What are devices and drivers?
Schematics of device from vendor, Role of device driver?
- device nodes
/dev
- drivers
/sys
- useful abstractions provided by kernel by
sysfs
,kobjects
,device classes
,udev
- Hotplug and Coldplug? Whats the difference?
- SPI available in market today includes RF (radio frewquency) chips, smart card interfaces, EEPROM, RTC, touch sensor, ADCs
- Write a
Makefile
for your driver file - Compilation would create a
.ko
file - Load the
.ko
file - Exporting/importing kernel symbol table
nm
- list symbols from object fileskernel headers printk KERNEL_ALERT # Makefile obj-m
Footnotes
[^2]: