Situ
Objective: To be familiar with the basic process of driver programming and debugging. 1. Prepare
Operating system: ubuntu12.04 LTS2. Source Code[CPP] View plain copy #include <linux/init.h> #include <linux/module.h> static int hello_init (void) {pr_info ("Hello, world.\n"); return 0; } static void Hello_exit (void) {pr_info ("Goodbye, cruel world\n"); } module_init (Hello_init); Module_exit (Hello_exit); Module_license ("Dual BSD/GPL");3.Makefile[Plain] View plain copy obj-m: = hello.o Kerneldir: =/usr/src/linux-headers-$ (Shell uname-r) PWD: = $ (Shell PWD ) Modules: $ (make)-C $ (Kerneldir) m=$ (PWD) modules Modules_install: $ (make)-C $ (Kerneldir) m=$ (PWD) M Odules_install4. CompileMake: [Plain] View plain copy ckt@ubuntu:~/work/ldd/hello$ make make-c/usr/src/linux-headers-3.13.0-32-genericm=/hom E/ckt/work/ldd/hello Modules Make[1]: Entering directory '/usr/src/linux-headers-3.13.0-32-generic ' CC [M]/home/ckt /WORK/LDD/HELLO/HELLO.O Buildingmodules, Stage 2. Modpost 1modules LD [M]/home/ckt/work/ldd/hello/hello.ko make[1]: Leaving directory '/usr/src/linux-headers-3.13.0- 32-generic '5. Test
[plain] View Plain copy lsmod #查看当前加载的模块 sudo insmod hello.ko #加载hello. Ko module sudo rmmod hello #移除hello. Ko module cat/var/log/syslog #查看日志