[Linux设备驱动第三版]小记 [1-3章]

本文介绍了Linux设备驱动的基本概念,包括设备驱动的角色、如何通过系统调用与硬件交互。重点讲解了字符设备、块设备和网络设备的区别,并强调了模块化设计的重要性。此外,讨论了内核模块的加载、初始化和退出函数,以及安全性注意事项,如未经初始化的内存和防止信息泄露。最后提到了Linux内核版本管理和模块加载工具如insmod、modprobe和rmmod。
摘要由CSDN通过智能技术生成

Chapter 1:

Device drivers are distinct “black boxes” that make a particular piece of hardware respond to a well-defined internal programming interface; they hide completely the details of how the device works.

 

User activities are performed by means of a set of standardized calls that are independent of the specific driver; mapping those calls to device-specific operations that acton real hardware is then the role of the device driver.

 

the role of a device driver is providing mechanism, not policy.

 

write kernel code to access the hardware, but don’t force particular policies on the user, since different users have different needs.leaving all the issues about how to use the hardware to the applications.

 

Driver: it is a software layer that lies between the applications and the actual device.

 

Each piece of code that can be added to the kernel at runtime is called a module.

 

Each module is made up of object code(not linked into a complete executable) that can be dynamically linked to the running kernel by the insmod program and can be unlinked by the rmmod program.

 

Driver is generally classifiable as a char module, a block module, or a network module.

 

A character (char) device is one that can be accessed as a stream of bytes (like a file);Such a driver usually implements at least the open, close, read, and write system calls.

 

block devices are accessed by filesystem nodes in the /dev directory. A block device is a device (e.g., a disk) that can host a filesystem.

 

 A network interface is in charge of sending and receiving data packets, driven by the network subsystem of the kernel. A network driver knows nothing about individual connections; it only handles packets. Communication between the kernel and a network device driver is completely different from that used with char and block drivers.

 

In the official kernel distribution, only an authorized user can load modules; the system call init_module checks if the
invoking process is authorized to load a module into the kernel.

 

Any input received from user processes should be treated with great suspicion; never trust it unless you can verify it.

 

Be careful with uninitialized memory; any memory obtained from the kernel should be zeroed or otherwise initialized before being made available to a user process or device. Otherwise, information leakage (disclosure of data, passwords, etc.) could result.

 

a maliciously modified kernel could allow anyone to load a module, thus opening an unexpected back door via init_module.

 

the even-numbered kernel versions (i.e., 2.6.x) are the stable ones that are intended for general distribution. The odd versions (such as 2.7.x), on the contrary, are development snapshots and are quite ephemeral.

 

This book covers Version 2.6 of the kernel. Our focus has been to show all the features available to device driver writers in 2.6.10.

 

The central gathering point for Linux kernel developers is the linux-kernel mailing list.

 

 


 

Chapter 2:

Regardless of the origin of your kernel, building modules for 2.6.x requires that you have a configured and built kernel tree on your system. 2.6 modules are linked against object files found in the kernel source tree; the result is a more robust module loader, but also the requirement that those object files be available.

 

Kernel hackers typically keep a “sacrificial” system around for the purpose of testing new code.

 

MODULE_LICENSE is used to tell the kernel that this module bears a free license; without such a declaration, the kernel complains when the module is loaded.

 

The printk function is de

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值