设备驱动程序的主体可以说是写好了。现在要把驱动程序嵌入内核。驱动程序可以按照两种方式编译。一种是编译进kernel,另一种是编译成模块 (modules),如果编译进内核的话,会增加内核的大小,还要改动内核的源文件,而且不能动态的卸载,不利于调试,所以推荐使用模块方式。 int init_module(void) { int result;
result = register_chrdev(0, "test", &test_fops);
if (result < 0) { printk(KERN_INFO "test: can't get major numbern"); return result; }