【驱动学习】Essential Linux Device Driver学习笔记(一)

Essential Linux Device Driver的配套网站为:http://elinuxdd.com/~elinuxdd/

由于Linux提供免费的源代码,因此可以Linux的源码,定制自己的内核,让设备在几秒钟之内启动。

 

一、Linux系统的演进

  1. 1991年,Linux Torvalds开发了Linux操作系统。第一次发布只支持Intel 386处理器
  2. 后来,内核复杂性逐步增加,支持众多体系架构、多处理器硬件和高性能集群(x86、IA64、ARM、PowerPC、Alpha、MIPS和SPARC等)

二、GNU Copyleft

GNU工程比Linux诞生还早,它发起的目标是定制一个免费的类Unix操作系统(GNU是GNU's Not Unix的递归缩写)。

一个完整的GNU操作系统基于Linux内核构建,但也包含其他一些组件(如库、编译器和实用程序(utility))。

GNU工程的主要发起者——自由软件基金会——创造了GNU公共许可证(GPL),其也被称为"版权左派(copyleft)",其防止有人中途将免费软件转换为商用软件。谁修改了copyleft的软件,就必须以copyleft的方式分享他的软件。

因此,若修改了内核, 就必须在社区分享此修改。

 

不过通过系统调用访问内核服务的Linux应用程序没有看做衍生的工作,因此并不受限于GPL。

 

三、kernel.org

Linux内核的源代码主要存放在www.kernel.org,该网站包含所有的已经发布的内核版本。

除了已经发布的内核以外,kernel.org还包含了有一线开发人员提供的补丁,这些补丁可以作为未来稳定版本的试验平台。

 

四、邮件列表和论坛

LKML(Linux kernel Mailing List,Linux内核邮件列表)是开发人员就开发问题进行辩论并决定Linux未来要包含哪些功能的论坛。可以在www.lkml.org看到实时的邮件列表。

 

内核的大部分子项目都拥有自己的邮件列表。

 

http://lwn.net上可以获得Linux开发社区的最新消息。

 

五、查看源代码

在研究内核源代码之前,先下载Linux源代码,并学会如何打补丁,且要查看内核源代码树的布局。

首先,到www.kernel.org下载最新的稳定的源代码,

然后,进行解压缩。现在则拥有位于/usr/src/linux-X.Y.Z/目录的源代码树,下面通过打-mm补丁(Andrew Morton)启动一些实验性测试特性。运行如下命令:

1)下载补丁:

bash> cd /usr/src
bash> wget www.kernel.org/pub/linux/kernel/people/akpm/patches/X.Y/X.Y.Z/X.Y.Z-mm2/X.Y.Z-mm2.bz2


2)打上下载的补丁

bash> cd /usr/src/linux-X.Y.Z/
bash> bzip2 -dc ../X.Y.Z-mm2.bz2 | patch -p1

命令中的-dc选项表示让bzip2将指定的文件解压缩到标准输出。它以管道方式输送到补丁实用程序,补丁程序会将补丁中的代码修改引用到源代码树中的每个需要修改的文件。

 

注:从2.6.24内核版本开始,i386和x86_64(与32位的i386系统对应的64位系统)架构源码树已经被统一到公共的arch/x86/目录中。

 

六、编译内核

下载了内核和补丁后,现在对代码稍作一点修改,并编译和运行它。

进入到顶层的init/目录总,对初始化文件main.c做一项小的修改,即在start_kernel()函数的开头加上一行打印信息。如下:

asmlinkage void __init start_kernel(void)
{
	char * command_line;
	extern const struct kernel_param __start___param[], __stop___param[];
	
	/*     
	 * Added by WXE
	 */
	printk("I like Linux, written by WXE!");
	 
	/* 
	 * Need to run as early as possible, to initialize the 
	 * lockdep hash: 
	 */
	lockdep_init();
	smp_setup_processor_id();
	debug_objects_early_init();
	...
	...
}



然后,如如下链接http://blog.csdn.net/wuxiaoer717/article/details/8624115中的方法进行比较编译 。

 

完成后,重启Linux并启动到新内核,启动后的第一条信息显示了添加的那句话。

 

七、可加载模块

在Linux内核中,所支持的设备可以以内核模块的形式提供其他的功能,在运行的时候,可以动态地按需加载模块。

为了生成模块,进入内核源代码根目录并运行

bash> cd /usr/src/linux-X.Y.Z
bash> make modules

运行如下命令安装编译生成的模块

bash> make modules_install

 

以下工具可用于操纵模块:insmod、rmmod、lsmod、modprobe、modinfo和depmod。

其中,insmod和rmmod用于加载和移除模块。

lsmod用于列出目前已经加载的模块,

modprobe是insmod的一个更智能的版本,它先分析/lib/modules/X.Y.Z/modules.dep文件再加载它所依赖的模块。

 

内核模块减小了内核的大小,并缩短了开发——编译——测试的周期。


 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Chapter 1, "Introduction," starts our tryst with Linux. It hurries you through downloading the kernel sources, making trivial code changes, and building a bootable kernel image. Chapter 2, "A Peek Inside the Kernel," takes a brisk peek into the innards of the Linux kernel and teaches you some must-know kernel concepts. It first takes you through the boot process and then describes kernel services particularly relevant to driver development such as kernel threads, timers, concurrency, and memory management. Chapter 3, "Getting Started with Device Drivers," gets you started with the art of writing Linux device drivers. It looks at interrupt handling, the new Linux device model, and Linux assembly. In this chapter, you'll also learn to use kernel helper interfaces such as linked lists, work queues, completion functions, and notifier chains. These helper facilities simplify your code, weed out redundancies from the kernel, and help long-term maintenance. Chapter 4, "Character Drivers," looks at the architecture of character device drivers. Several concepts introduced in this chapter such as polling, asynchronous notification, and I/O control, are relevant to subsequent chapters as well, since many device classes discussed in the rest of the book are 'super' character devices. Chapter 5, "Serial Drivers," explains the kernel layer that handles serial devices. The serial layer consists of low-level drivers, the TTY layer, and line disciplines. Chapter 6, "Input Drivers," discusses the kernel's input subsystem that is responsible for servicing devices such as keyboards, mice, and touch panels. Chapter 7, "The Inter-Integrated Circuit Protocol," dissects drivers for devices such as EEPROMs that are connected to the system I2C bus or SMBus. The chapter also looks at other serial technologies such as the SPI bus and one-wire bus. Chapter 8,"PCMCIA and Compact Flash," delves into the PCMCIA subsystem. It teaches you to write drivers for devices having a PCMCIA or Compact Flash form factor. Chapter 9, "Peripheral Component Interconnect," looks at kernel support for PCI and its derivatives such as CardBus and PCI Express. Chapter 10, "Universal Serial Bus," explores USB architecture and device drivers. Chapter 11, "Video Drivers," explains the Linux video family. Chapter 12, "Audio Drivers," describes the Linux audio family. Chapter 13, "Block Drivers," covers drivers for devices such as IDE and SCSI. It also looks at filesystem drivers. Chapter 14, "Network Interface Cards," is dedicated to network devices. You'll learn about kernel networking data structures and how to interface network drivers with protocol layers. Chapter 15, "Linux Without Wires," looks at driving different wireless technologies such as Bluetooth, Infrared, WiFi and cellular communication. Chapter 16, "Memory Technology Devices," discusses flash memory enablement. This chapter first looks at flash-based protocols and chipsets primarily used on embedded devices. It ends by examining drivers for the Firmware Hub found on desktops and laptops. Chapter 17, "Embedding Linux," steps into the world of embedded Linux. It takes you through the main firmware components of an embedded solution, such as bootloader, kernel, and device drivers. Given the soaring popularity of Linux in the embedded space, it's likely that you'll use the device driver skills that you acquire from this book, to enable embedded devices. Chapter 18, "User Mode Drivers," looks at driving different types of devices from user space. Some device drivers, especially ones that are heavy on policy and light on performance requirements, are better off residing in user land. This chapter also explains how the new ultra-scalable process scheduler improves response times of user mode drivers. Chapter 19, "More Devices and Drivers," takes a tour of a potpourri of driver families not covered thus far, such as Error Detection And Correction (EDAC), cpufreq<...

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值