Linux Devices Driver读书笔记


01 An Introduction to Device Drivers

01章 An Introduction to Device Drivers

驱动的角色

policy:     how to use capability Gnome ftp http

mechanism: what to be provided X Serv TCP/IP

内核介绍:任务,内存,文件管理,驱动,网络

模块:char module:open, close, read, and write system calls

 block module

         network module.

安全与版本

02章 Building and Running Modules

2.1建立纯净的内核环境

2.2helloworld,注意makefile的写法:

  1. obj-m:=hello.o   
  2. KERNELDIR:=/lib/modules/2.6.26-2-686/build   
  3. PWD :=$(shell pwd)   
  4. default:   
  5.         $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  

2.3驱动和应用程序的区别:初始化与退出,只能调用内核函数,不调用库,唯一的例外是头文件<stdarg.h>,内核函数定义在内核源码树linux/include下

用户空间和内核空间

内核并发:获取当前进程current

一些细节:由于内核栈很小(4096B),需要自己申请内存,不支持浮点运算

2.4编译和加载

讲解helloworld的makefile

装载卸载模块 insmod=ld 注意kernel/module.c中为insmod安排内存,调用模块并初始化

sys_为系统调用前缀

lsmod =cat /proc//modules  =ls /sys/module

版本依赖 必须为每个内核树重新编译,否则helloworld也会出错。

相关内容