/* Given the minor device number and name,
Tell Linux how many device numbers to apply for,
Linux system help you find the major device number*/
if((alloc_chrdev_region(&devno, 0, 1, "hello_driver")) <0){
pr_err("Cannot allocate major number\n");
return -1;
}
/*Creating struct class, class name, with /proc/sys/kernel/hotplug*/
if(IS_ERR(dev_class = class_create(THIS_MODULE,"hello_class"))){
pr_err("Cannot create the struct class\n");
goto r_class;
}
/*Creating device, device name, with /proc/sys/kernel/hotplug*/
if(IS_ERR(device_create(dev_class,NULL,devno,NULL,"hello_device"))){
pr_err("Cannot create the Device 1\n");
goto r_device;
}
/*Creating cdev structure*/
cdev_init(&hello_cdev,&fops);
1.
go to hello_device directory and make
go to hello_device directory and make
2.
insmod ./hello_device.ko
3.
echo a > /dev/hello_device
~or
run ./hello_app
source download:
沒有留言:
張貼留言