linux设备驱动程序上的一个简单程序 [英] A simple program on linux device driver
问题描述
#include<linux/module.h>
#include<linux/init.h>
int my_init(void){
printk("<1> Angus : Module Insertion is successful!");
return 0;
}
void my_cleanup(void){
printk("<1> Angus : Module unloading successful!");
}
module_init(my_init);
module_cleanup(my_cleanup);
Makefile:
obj-m:=simple.o
aoll:
make -C /usr/src/linux-headers-3.2.0-25-generic-pae/ M=$(PWD) modules
clean:
make -C /usr/src/linux-headers-3.2.0-25-generic-pae/ M=$(PWD) clean
make -C =>将在执行make之前更改到目录, 在这个路径/usr/src/linux-headers-3.2.0-25-generic-pae/中,我有Makefile, 为什么需要M = $(PWD)?它有什么作用,在哪里可以检查$ PWD? /usr/src/linux-headers-3.2.0-25-generic-pae/中的Makefile具有目标all:modules和目标模块,并具有目标clean. 什么是obj-m?
make -C => will change to the directory before doing a make, In this path /usr/src/linux-headers-3.2.0-25-generic-pae/ I have Makefile , why is the M=$(PWD) needed ? what does it do, where I can check for $PWD ? The Makefile inside the /usr/src/linux-headers-3.2.0-25-generic-pae/ has the target all:modules and target modules and has the target clean. What is obj-m ?
推荐答案
您最好阅读 Linux Device Drivers,第三版(第版免费提供)第24页上的段落href ="http://oreilly.com/openbook/linuxdrive3/book/index.html" rel ="nofollow"> http://oreilly.com/openbook/linuxdrive3/book/index.html ).
-C 选项可将目录更改为提供的目录.在那里,它找到了内核的顶级Makefile.然后, M = 选项使Makefile在尝试构建模块目标之前移回模块源目录( $ PWD 是包含当前路径的变量.目录).
The -C option makes it change the directory to the one provided. There, it finds the kernel's top-level Makefile. Then, the M= option causes that Makefile to move back to your module source directory before trying to build the modules target ($PWD is a variable containing the path of your current directory).
obj-m 是一个变量,其中包含要构建的内核模块的列表(请参见
obj-m is a variable containing the list of kernel modules to be build (see https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt) .
这篇关于linux设备驱动程序上的一个简单程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!