LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > scophream
User Name
Password

Notices


Rate this Entry

linux??????????

Posted 08-01-2008 at 11:52 PM by scophream

?????????
sudo aptitude install linux-source
????????????????????
????????????????
sudo ln -s /usr/src/linux-source-2.6.25/ /lib/modules/`uname -r`/build
?????????????????build??????????????????
????????????????????????????/usr/src????/boot?????????????????????sudo make menuconfig?????load???????????/boot????????????make??
?????????????????
#include
#include
static int hello_init(void)
{
printk("Hello,world!\n");
}
static void hello_exit(void)
{
printk("goodbye\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

???Makefile?????

obj-m :=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
??????build????/lib/modules????????build?

???????hello.c?????make????

zhoulv@debian:~/project/module$ ls
hello.c Makefile
zhoulv@debian:~/project/module$ make
make -C /lib/modules/2.6.25-2-686/build M=/home/zhoulv/project/module modules
make[1]: Entering directory `/usr/src/linux-source-2.6.25'

WARNING: Symbol version dump /usr/src/linux-source-2.6.25/Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] /home/zhoulv/project/module/hello.o
/home/zhoulv/project/module/hello.c: In function ‘hello_init’:
/home/zhoulv/project/module/hello.c:6: warning: no return statement in function returning non-void
Building modules, stage 2.
MODPOST 1 modules
CC /home/zhoulv/project/module/hello.mod.o
LD [M] /home/zhoulv/project/module/hello.ko
make[1]: Leaving directory `/usr/src/linux-source-2.6.25'
zhoulv@debian:~/project/module$ ls
hello.c hello.mod.c hello.o modules.order
hello.ko hello.mod.o Makefile Module.symvers

?????????????
zhoulv@debian:~/project/module$ sudo insmod hello.ko

??????

zhoulv@debian:~/project/module$ sudo lsmod |grep hello
hello 1184 0
zhoulv@debian:~/project/module$ ls
hello.c hello.mod.c hello.o modules.order
hello.ko hello.mod.o Makefile Module.symvers
zhoulv@debian:~/project/module$

?????
zhoulv@debian:~/project/module$ dmesg
...........
[ 7657.010030] Hello,world!
zhoulv@debian:~/project/module$

Hello,world?????!

????
zhoulv@debian:~/project/module$ sudo rmmod hello
zhoulv@debian:~/project/module$ dmesg
........
[ 4700.764823] goodbye
zhoulv@debian:~/project/module$

(NOTE:????????insmod ???.ko,?.ko?????????????????.ko?

?????????????make clean


Posted in Uncategorized
Views 851 Comments 0
« Prev     Main     Next »

  



All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration