From this blog post, we can finally give our driver module First_drv a formal compilation, now he has filled out his account registration information form, from the account of the child only one step!
Inside the kernel has its own set of methods to install the driver module, like the Civil Affairs Bureau staff know how to run an account for a person, for an ordinary citizen, the staff did what the operation of the hukou, not ordinary citizens need to care about, We are most concerned about how to put our completed account information registration form to the staff, how to show the staff that we have the account request.
In the Linux system, for the character device driver, we register the driver module to the kernel by Register_chrdev this function, we want to execute Insmod First_drv.ko, which is called first_drv_ init function is the time to complete the registration of the driver module, after all, this is the driver initialization function, in this function "to complete the task of registering the driver module to the kernel" is not its responsibility.
Let's take a look at how the previous first_drv_init was written:
static int __init first_drv_init (void) {PRINTK (kern_info "Hello world!\n"); return 0;}
We know that we will add a register_chrdev function inside, but we do not understand the use of this function, in the source insight of the linux-2.6.22.6 kernel source engineering Search, see how others use it, such as I searched for example:
int ret;
···
ret = Register_chrdev (Vfc_major, Vfcstr, &vfc_fops);
if (ret) {
PRINTK (kern_err "Unable to get major number%d\n", vfc_major);
Kfree (VFC_DEV_LST);
Return-eio;
}
···
return 0;
We focus on the color line,vfc_major is a macro definition,
We add the Register_chrdev function inside, and change the following:
static int __init first_drv_init (void) {int ret =-1; Register_chrdev () printk (kern_info "Hello world!\n"); return 0;}
This article is from the "12253782" blog, please be sure to keep this source http://12263782.blog.51cto.com/12253782/1873993
1th Linux driver ___ to driver module on account (ii)