Browse Source

最基础模块的手动安装与卸载。不是字符设备,不会出现在dev中

xuxinyi 1 năm trước cách đây
mục cha
commit
adcaafb6c5
3 tập tin đã thay đổi với 20 bổ sung17 xóa
  1. 1 16
      驱动文件/1/leds-user-defind.c
  2. 19 0
      驱动文件/1/readme.md
  3. 0 1
      驱动文件/readme.md

+ 1 - 16
驱动文件/1/leds-user-defind.c

@@ -1,26 +1,11 @@
 #include <linux/module.h>
 #include <linux/init.h>
-
-static int majorNumber;                  // 设备号
-#define CLASS_NAME "my_char_class"
 static int __init helloworld_init(void) {
  pr_info("Hello world initialization!\n");
-
  return 0;
 }
 static void __exit helloworld_exit(void) {
-    pr_info("Hello world exit\n");
-    mejornNumber = register_chrdev(0, "hello");
-    if (mejorNumber < 0)
-    {
-        printk(KERN_ALERT "Registering device failed with %d\n",mejorNumber );
-        return majorNumber
-    }
-    printk(KERN_INFO "I was assigned major number %d. To talk to\n",mejorNumber );
-
-    //创建设备类
-    my_class = class_create(THIS_MODULE, "hello_class");
-    
+ pr_info("Hello world exit\n");
 }
 module_init(helloworld_init);
 module_exit(helloworld_exit);

+ 19 - 0
驱动文件/1/readme.md

@@ -0,0 +1,19 @@
+最基础模块。(注意,这个模块不会在dev文件夹中出现,只有注册字符设备或块设备才会在dev中创建节点)
+22.编译成模块(.ko)文件
+    obj-m+= leds-user-defind.o
+    将模块导入泰山派的linux系统中
+    adb push xx\xx.ko /data/xx.ko
+23.加载模块
+    1.进入adb shell
+        cd /data
+    2.找到xx.ko文件
+        lsmod 查看已存在的module
+        insmod xx.ko
+    3.lsmod 查看是否加载成功
+    ![alt text](image-6.png)
+    4.查看模块打印的数据
+        dmesg | grep "hello"
+    ![alt text](image-7.png)
+    5.卸载模块
+        rmmod xx
+    ![alt text](image-8.png)

+ 0 - 1
驱动文件/readme.md

@@ -1 +0,0 @@
-1.led